Shop data added

This commit is contained in:
Niels Vergucht 2018-12-03 13:04:33 +01:00
parent 7f44111b88
commit 42738e9306
7 changed files with 202 additions and 19 deletions

View File

@ -1,7 +1,10 @@
package com.songoda.epicbuckets.file;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.HashMap;
@ -11,6 +14,14 @@ public class ConfigManager {
private EpicBuckets epicBuckets;
private HashMap<String, Config> configDatabase;
private String backButtonPath = "BACK-BUTTON";
private String fillItemPath = "FILL-ITEM";
private String bulkShopIncreasePath = "BULK-SHOP-INVENTORY.increase-item";
private String bulkShopDecreasePath = "BULK-SHOP-INVENTORY.decrease-item";
private String bulkShopPurchasePath = "BULK-SHOP-INVENTORY.purchase-item";
private ItemStack backButton;
public ConfigManager() {
this.epicBuckets = EpicBuckets.getInstance();
setup();
@ -19,6 +30,23 @@ public class ConfigManager {
private void setup() {
epicBuckets.saveDefaultConfig();
createConfig("shops", true);
setupBackButton();
setupFillItem();
}
private void setupFillItem() {
boolean m = Validator.getInstance().isMaterial(epicBuckets.getConfig().getString(getFillItemPath() + ".material"));
backButton = ((!m) ? XMaterial.BLACK_STAINED_GLASS_PANE.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(getFillItemPath() + ".material")).parseItem());
backButton.getItemMeta().setDisplayName(epicBuckets.getConfig().getString(getFillItemPath() + ".name"));
}
private void setupBackButton() {
boolean m = Validator.getInstance().isMaterial(epicBuckets.getConfig().getString(getBackButtonPath() + ".material"));
backButton = ((!m) ? XMaterial.BARRIER.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(getBackButtonPath() + ".material")).parseItem());
backButton.getItemMeta().setDisplayName(epicBuckets.getConfig().getString(getBackButtonPath() + ".name"));
}
public void createConfig(String name, boolean resource) {
@ -36,4 +64,23 @@ public class ConfigManager {
return configDatabase.get(name).getConfig();
}
public String getBackButtonPath() {
return backButtonPath;
}
public String getFillItemPath() {
return fillItemPath;
}
public String getBulkShopIncreasePath() {
return bulkShopIncreasePath;
}
public String getBulkShopDecreasePath() {
return bulkShopDecreasePath;
}
public String getBulkShopPurchasePath() {
return bulkShopPurchasePath;
}
}

View File

@ -0,0 +1,22 @@
package com.songoda.epicbuckets.genbucket;
public enum GenbucketType {
HORIZONTAL("HORIZONTAL"),
INFUSED("INFUSED"),
PSUEDO("PSUEDO"),
VERTICAL("VERTICAL");
public final String name;
GenbucketType(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
}

View File

@ -1,6 +1,7 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.GenbucketType;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import org.bukkit.configuration.file.FileConfiguration;
@ -11,35 +12,67 @@ import java.util.HashMap;
public class Shop {
private EpicBuckets epicBuckets;
private FileConfiguration shops;
private HashMap<String, SubShop> subShops;
private ItemStack shopItem;
private String menuItem;
private String shopName;
private String path;
private ItemStack shopItem;
private int slot;
private String path;
private String shopPath;
private int backButton;
private GenbucketType trait;
private int inventorySize;
private boolean fillInventory;
private String inventoryName;
private boolean enabled = true;
public Shop(String menuItem, String name, String path) {
this.epicBuckets = EpicBuckets.getInstance();
this.shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");;
this.subShops = new HashMap<>();
this.menuItem = menuItem;
this.shopName = name;
this.path = path;
this.path = path;
this.shopPath = epicBuckets.getShopManager().getShopPath() + "." + shopName;
loadData();
setupShopItem();
loadSubShops();
}
private void loadSubShops() {
FileConfiguration shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
private void loadData() {
trait = Validator.getInstance().genbucketType(shops.getString(shopPath + "trait"));
backButton = Validator.getInstance().slot(shops.getString(shopPath + "goBackButton"));
inventorySize = Validator.getInstance().inventorySize(shops.getString(shopPath + "size"));
fillInventory = shops.getBoolean(shopPath + "fill");
inventoryName = shops.getString(shopPath + "inventory-name");
for (String shop : shops.getConfigurationSection(epicBuckets.getShopManager().getShopPath() + "." + shopName).getKeys(false)) {
if (!shops.isConfigurationSection(epicBuckets.getShopManager().getShopPath() + "." + shopName + "." + shop)) {
if (trait == null) {
epicBuckets.getDebugger().invalidGenbucketType(shopPath + "trait");
setEnabled(false);
}
if (backButton == -1) {
epicBuckets.getDebugger().invalidSlot(shopPath + "goBackButton");
setEnabled(false);
}
if (inventorySize == -1) {
epicBuckets.getDebugger().invalidInventorySize(shopPath + "size");
setEnabled(false);
}
}
private void loadSubShops() {
for (String shop : shops.getConfigurationSection(shopPath).getKeys(false)) {
if (!shops.isConfigurationSection(shopPath + "." + shop)) {
continue;
}
@ -54,8 +87,8 @@ public class Shop {
boolean m = Validator.getInstance().isMaterial(epicBuckets.getConfig().getString(itemPath + ".material"));
if (slot == -1) {
epicBuckets.getDebugger().invalidSlot(epicBuckets.getShopManager().getPath() + "." + menuItem);
enabled = false;
epicBuckets.getDebugger().invalidSlot(itemPath);
setEnabled(false);
}
shopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(itemPath + ".material")).parseItem());
@ -64,6 +97,10 @@ public class Shop {
shopItem.getItemMeta().setLore(epicBuckets.getConfig().getStringList(itemPath + ".lore"));
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}

View File

@ -1,9 +1,16 @@
package com.songoda.epicbuckets.shop;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.util.Validator;
import com.songoda.epicbuckets.util.XMaterial;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class ShopManager {
@ -11,29 +18,69 @@ public class ShopManager {
private FileConfiguration shops;
private EpicBuckets epicBuckets;
private String path = "MENU-ITEMS";
private String configPath = "MENU-ITEMS";
private String shopPath = "shops";
private ItemStack increaseItem;
private ItemStack decreaseItem;
private ItemStack purchaseItem;
private List<Integer> increaseSlots;
private List<Integer> decreaseSlots;
private int purchaseSlot;
private boolean useBackButtons;
public ShopManager() {
epicBuckets = EpicBuckets.getInstance();
shopDatabase = new HashMap<>();
increaseSlots = new ArrayList<>();
decreaseSlots = new ArrayList<>();
shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
loadData();
loadShops();
setupBulkShop();
}
private void setupBulkShop() {
boolean i = Validator.getInstance().isMaterial(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".material");
boolean d = Validator.getInstance().isMaterial(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".material");
boolean p = Validator.getInstance().isMaterial(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".material");
purchaseSlot = Validator.getInstance().slot(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".slot"));
if (purchaseSlot == -1) {
purchaseSlot = 40;
}
increaseItem = ((!i) ? XMaterial.GREEN_STAINED_GLASS_PANE.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".material")).parseItem());
decreaseItem = ((!i) ? XMaterial.RED_STAINED_GLASS_PANE.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".material")).parseItem());
purchaseItem = ((!i) ? XMaterial.YELLOW_STAINED_GLASS.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopPurchasePath() + ".material")).parseItem());
for (String s : epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopIncreasePath() + ".slots").split(",")) {
increaseSlots.add(Integer.parseInt(s));
}
for (String s : epicBuckets.getConfig().getString(epicBuckets.getConfigManager().getBulkShopDecreasePath() + ".slots").split(",")) {
increaseSlots.add(Integer.parseInt(s));
}
}
private void loadData() {
useBackButtons = shops.getBoolean("use-back-buttons");
}
private void loadShops() {
for (String key : epicBuckets.getConfig().getConfigurationSection(path).getKeys(false)) {
if (!epicBuckets.getConfig().isConfigurationSection(path + "." + key)) {
for (String key : epicBuckets.getConfig().getConfigurationSection(configPath).getKeys(false)) {
if (!epicBuckets.getConfig().isConfigurationSection(configPath + "." + key)) {
continue;
}
shopDatabase.put(epicBuckets.getConfig().getString(path + "." + key), new Shop(epicBuckets.getConfig().getString(path + "." + key), epicBuckets.getConfig().getString(path + "." + key + ".shop"), path + "." + key));
shopDatabase.put(epicBuckets.getConfig().getString(configPath + "." + key), new Shop(epicBuckets.getConfig().getString(configPath + "." + key), epicBuckets.getConfig().getString(configPath + "." + key + ".shop"), configPath + "." + key));
}
}
public String getPath() {
return path;
public String getConfigPath() {
return configPath;
}
public String getShopPath() {

View File

@ -74,6 +74,10 @@ public class SubShop {
genItem = ((!t) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".type")).parseItem());
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public boolean isEnabled() {
return enabled;
}

View File

@ -15,8 +15,16 @@ public class Debugger {
epicBuckets.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
}
public void invalidInventorySize(String item) {
sendConsole(item + " has an invalid inventory size, disabling shop..");
}
public void invalidGenbucketType(String item) {
sendConsole(item + " has an invalid Genbucket type, disabling shop..");
}
public void invalidSlot(String item) {
sendConsole(item + " has an invalid slot set, disabling shop..");
sendConsole(item + " has an invalid slot, disabling shop..");
}
public void invalidPrice(String item) {

View File

@ -1,6 +1,7 @@
package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.genbucket.GenbucketType;
public class Validator {
@ -15,6 +16,23 @@ public class Validator {
private Validator() {
}
public int inventorySize(String s) {
int i;
if (isInt(s)) {
i = Integer.parseInt(s);
if (i%9 == 0 && i<=54) return i;
}
return -1;
}
public GenbucketType genbucketType(String s) {
try {
return GenbucketType.valueOf(s);
} catch (Exception e) {
return null;
}
}
public boolean isDouble(String s) {
try {
Double.parseDouble(s);