-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
186 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/xyz/mackan/Slabbo/commands/SlabboCommandCompletions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package xyz.mackan.Slabbo.commands; | ||
|
||
import xyz.mackan.Slabbo.Slabbo; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class SlabboCommandCompletions { | ||
|
||
public static List<String> getImportFiles () { | ||
File folder = new File(Slabbo.getDataPath()); | ||
|
||
return Arrays.stream(folder.listFiles()) | ||
.filter(file -> file.isFile() && !file.getName().equalsIgnoreCase("shops.yml") && file.getName().endsWith(".yml")) | ||
.map(file -> file.getName()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/xyz/mackan/Slabbo/importers/ImportResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package xyz.mackan.Slabbo.importers; | ||
|
||
import xyz.mackan.Slabbo.types.Shop; | ||
|
||
import java.util.List; | ||
|
||
public class ImportResult { | ||
public List<Shop> shops; | ||
public List<String> skippedShops; | ||
|
||
public ImportResult (List<Shop> shops, List<String> skippedShops) { | ||
this.shops = shops; | ||
this.skippedShops = skippedShops; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/xyz/mackan/Slabbo/importers/UShopImporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package xyz.mackan.Slabbo.importers; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.configuration.ConfigurationSection; | ||
import org.bukkit.configuration.InvalidConfigurationException; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.inventory.ItemStack; | ||
import xyz.mackan.Slabbo.Slabbo; | ||
import xyz.mackan.Slabbo.types.Shop; | ||
import xyz.mackan.Slabbo.utils.ShopUtil; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
public class UShopImporter { | ||
public static ImportResult importUShops (File file) { | ||
List<String> skippedShops = new ArrayList<String>(); | ||
List<Shop> shops = new ArrayList<Shop>(); | ||
|
||
FileConfiguration uShopConfig = new YamlConfiguration(); | ||
|
||
try { | ||
uShopConfig.load(file); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} catch (InvalidConfigurationException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
|
||
for (String key : uShopConfig.getKeys(false)) { | ||
if (Slabbo.shopUtil.shops.containsKey(key)) { | ||
skippedShops.add(key); | ||
continue; | ||
} | ||
|
||
ConfigurationSection shopConfig = uShopConfig.getConfigurationSection(key); | ||
|
||
String shopOwnerId = shopConfig.getString("host"); | ||
|
||
UUID shopOwnerUUID = UUID.fromString(shopOwnerId); | ||
|
||
ItemStack itemStack = shopConfig.getItemStack("item"); | ||
|
||
int buyPrice = shopConfig.getInt("buyprice"); | ||
int sellPrice = shopConfig.getInt("sellPrice"); | ||
|
||
int quantity = shopConfig.getInt("stack"); | ||
|
||
int stock = shopConfig.getInt("amount"); | ||
|
||
boolean isAdmin = shopConfig.getBoolean("admin"); | ||
|
||
if (isAdmin) { | ||
stock = 0; | ||
} | ||
|
||
Location shopLocation = ShopUtil.fromString(key); | ||
|
||
Shop shop = new Shop(buyPrice, sellPrice, quantity, shopLocation, itemStack, stock, shopOwnerUUID, isAdmin, null); | ||
|
||
shops.add(shop); | ||
} | ||
|
||
return new ImportResult(shops, skippedShops); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters