mirror of
https://github.com/songoda/EpicBuckets.git
synced 2024-11-26 12:16:23 +01:00
Shop data added
This commit is contained in:
parent
7f44111b88
commit
42738e9306
@ -1,7 +1,10 @@
|
|||||||
package com.songoda.epicbuckets.file;
|
package com.songoda.epicbuckets.file;
|
||||||
|
|
||||||
import com.songoda.epicbuckets.EpicBuckets;
|
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.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -11,6 +14,14 @@ public class ConfigManager {
|
|||||||
private EpicBuckets epicBuckets;
|
private EpicBuckets epicBuckets;
|
||||||
private HashMap<String, Config> configDatabase;
|
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() {
|
public ConfigManager() {
|
||||||
this.epicBuckets = EpicBuckets.getInstance();
|
this.epicBuckets = EpicBuckets.getInstance();
|
||||||
setup();
|
setup();
|
||||||
@ -19,6 +30,23 @@ public class ConfigManager {
|
|||||||
private void setup() {
|
private void setup() {
|
||||||
epicBuckets.saveDefaultConfig();
|
epicBuckets.saveDefaultConfig();
|
||||||
createConfig("shops", true);
|
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) {
|
public void createConfig(String name, boolean resource) {
|
||||||
@ -36,4 +64,23 @@ public class ConfigManager {
|
|||||||
return configDatabase.get(name).getConfig();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.epicbuckets.shop;
|
package com.songoda.epicbuckets.shop;
|
||||||
|
|
||||||
import com.songoda.epicbuckets.EpicBuckets;
|
import com.songoda.epicbuckets.EpicBuckets;
|
||||||
|
import com.songoda.epicbuckets.genbucket.GenbucketType;
|
||||||
import com.songoda.epicbuckets.util.Validator;
|
import com.songoda.epicbuckets.util.Validator;
|
||||||
import com.songoda.epicbuckets.util.XMaterial;
|
import com.songoda.epicbuckets.util.XMaterial;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -11,35 +12,67 @@ import java.util.HashMap;
|
|||||||
public class Shop {
|
public class Shop {
|
||||||
|
|
||||||
private EpicBuckets epicBuckets;
|
private EpicBuckets epicBuckets;
|
||||||
|
private FileConfiguration shops;
|
||||||
|
|
||||||
private HashMap<String, SubShop> subShops;
|
private HashMap<String, SubShop> subShops;
|
||||||
|
|
||||||
|
private ItemStack shopItem;
|
||||||
private String menuItem;
|
private String menuItem;
|
||||||
private String shopName;
|
private String shopName;
|
||||||
private String path;
|
|
||||||
private ItemStack shopItem;
|
|
||||||
private int slot;
|
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;
|
private boolean enabled = true;
|
||||||
|
|
||||||
public Shop(String menuItem, String name, String path) {
|
public Shop(String menuItem, String name, String path) {
|
||||||
this.epicBuckets = EpicBuckets.getInstance();
|
this.epicBuckets = EpicBuckets.getInstance();
|
||||||
|
this.shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");;
|
||||||
|
|
||||||
this.subShops = new HashMap<>();
|
this.subShops = new HashMap<>();
|
||||||
|
|
||||||
this.menuItem = menuItem;
|
this.menuItem = menuItem;
|
||||||
this.shopName = name;
|
this.shopName = name;
|
||||||
this.path = path;
|
|
||||||
|
|
||||||
|
this.path = path;
|
||||||
|
this.shopPath = epicBuckets.getShopManager().getShopPath() + "." + shopName;
|
||||||
|
|
||||||
|
loadData();
|
||||||
setupShopItem();
|
setupShopItem();
|
||||||
loadSubShops();
|
loadSubShops();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadSubShops() {
|
private void loadData() {
|
||||||
FileConfiguration shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
|
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 (trait == null) {
|
||||||
if (!shops.isConfigurationSection(epicBuckets.getShopManager().getShopPath() + "." + shopName + "." + shop)) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,8 +87,8 @@ public class Shop {
|
|||||||
boolean m = Validator.getInstance().isMaterial(epicBuckets.getConfig().getString(itemPath + ".material"));
|
boolean m = Validator.getInstance().isMaterial(epicBuckets.getConfig().getString(itemPath + ".material"));
|
||||||
|
|
||||||
if (slot == -1) {
|
if (slot == -1) {
|
||||||
epicBuckets.getDebugger().invalidSlot(epicBuckets.getShopManager().getPath() + "." + menuItem);
|
epicBuckets.getDebugger().invalidSlot(itemPath);
|
||||||
enabled = false;
|
setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
shopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(itemPath + ".material")).parseItem());
|
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"));
|
shopItem.getItemMeta().setLore(epicBuckets.getConfig().getStringList(itemPath + ".lore"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,16 @@
|
|||||||
package com.songoda.epicbuckets.shop;
|
package com.songoda.epicbuckets.shop;
|
||||||
|
|
||||||
import com.songoda.epicbuckets.EpicBuckets;
|
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.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.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ShopManager {
|
public class ShopManager {
|
||||||
|
|
||||||
@ -11,29 +18,69 @@ public class ShopManager {
|
|||||||
private FileConfiguration shops;
|
private FileConfiguration shops;
|
||||||
private EpicBuckets epicBuckets;
|
private EpicBuckets epicBuckets;
|
||||||
|
|
||||||
private String path = "MENU-ITEMS";
|
private String configPath = "MENU-ITEMS";
|
||||||
private String shopPath = "shops";
|
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() {
|
public ShopManager() {
|
||||||
epicBuckets = EpicBuckets.getInstance();
|
epicBuckets = EpicBuckets.getInstance();
|
||||||
shopDatabase = new HashMap<>();
|
shopDatabase = new HashMap<>();
|
||||||
|
increaseSlots = new ArrayList<>();
|
||||||
|
decreaseSlots = new ArrayList<>();
|
||||||
shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
|
shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
|
||||||
|
|
||||||
|
loadData();
|
||||||
loadShops();
|
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() {
|
private void loadShops() {
|
||||||
for (String key : epicBuckets.getConfig().getConfigurationSection(path).getKeys(false)) {
|
for (String key : epicBuckets.getConfig().getConfigurationSection(configPath).getKeys(false)) {
|
||||||
if (!epicBuckets.getConfig().isConfigurationSection(path + "." + key)) {
|
if (!epicBuckets.getConfig().isConfigurationSection(configPath + "." + key)) {
|
||||||
continue;
|
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() {
|
public String getConfigPath() {
|
||||||
return path;
|
return configPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getShopPath() {
|
public String getShopPath() {
|
||||||
|
@ -74,6 +74,10 @@ public class SubShop {
|
|||||||
genItem = ((!t) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".type")).parseItem());
|
genItem = ((!t) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".type")).parseItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,16 @@ public class Debugger {
|
|||||||
epicBuckets.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
|
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) {
|
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) {
|
public void invalidPrice(String item) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.songoda.epicbuckets.util;
|
package com.songoda.epicbuckets.util;
|
||||||
|
|
||||||
import com.songoda.epicbuckets.EpicBuckets;
|
import com.songoda.epicbuckets.EpicBuckets;
|
||||||
|
import com.songoda.epicbuckets.genbucket.GenbucketType;
|
||||||
|
|
||||||
public class Validator {
|
public class Validator {
|
||||||
|
|
||||||
@ -15,6 +16,23 @@ public class Validator {
|
|||||||
private 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) {
|
public boolean isDouble(String s) {
|
||||||
try {
|
try {
|
||||||
Double.parseDouble(s);
|
Double.parseDouble(s);
|
||||||
|
Loading…
Reference in New Issue
Block a user