mirror of
https://github.com/songoda/EpicBuckets.git
synced 2024-11-13 05:45:16 +01:00
SubShop data done
This commit is contained in:
parent
46d3e3e3fb
commit
7f44111b88
@ -20,8 +20,6 @@ public class Shop {
|
||||
private ItemStack shopItem;
|
||||
private int slot;
|
||||
|
||||
private String shopPath = "shops";
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public Shop(String menuItem, String name, String path) {
|
||||
@ -40,8 +38,8 @@ public class Shop {
|
||||
private void loadSubShops() {
|
||||
FileConfiguration shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
|
||||
|
||||
for (String shop : shops.getConfigurationSection(shopPath + "." + shopName).getKeys(false)) {
|
||||
if (!shops.isConfigurationSection(shopPath + "." + shopName + "." + shop)) {
|
||||
for (String shop : shops.getConfigurationSection(epicBuckets.getShopManager().getShopPath() + "." + shopName).getKeys(false)) {
|
||||
if (!shops.isConfigurationSection(epicBuckets.getShopManager().getShopPath() + "." + shopName + "." + shop)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -52,14 +50,12 @@ public class Shop {
|
||||
private void setupShopItem() {
|
||||
String itemPath = path + ".item";
|
||||
|
||||
boolean i = Validator.getInstance().isInt(epicBuckets.getConfig().getString(itemPath + ".slot"));
|
||||
slot = Validator.getInstance().slot(epicBuckets.getConfig().getString(itemPath + ".slot"));
|
||||
boolean m = Validator.getInstance().isMaterial(epicBuckets.getConfig().getString(itemPath + ".material"));
|
||||
|
||||
if (!i) {
|
||||
epicBuckets.getDebugger().sendConsole("&cMENU-ITEM." + menuItem + " has an invalid slot set, disabling shop..");
|
||||
if (slot == -1) {
|
||||
epicBuckets.getDebugger().invalidSlot(epicBuckets.getShopManager().getPath() + "." + menuItem);
|
||||
enabled = false;
|
||||
} else {
|
||||
slot = epicBuckets.getConfig().getInt(path + ".slot");
|
||||
}
|
||||
|
||||
shopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(epicBuckets.getConfig().getString(itemPath + ".material")).parseItem());
|
||||
@ -80,4 +76,8 @@ public class Shop {
|
||||
return shopName;
|
||||
}
|
||||
|
||||
public String getMenuItem() {
|
||||
return menuItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class ShopManager {
|
||||
private EpicBuckets epicBuckets;
|
||||
|
||||
private String path = "MENU-ITEMS";
|
||||
private String shopPath = "shops";
|
||||
|
||||
public ShopManager() {
|
||||
epicBuckets = EpicBuckets.getInstance();
|
||||
@ -31,4 +32,12 @@ public class ShopManager {
|
||||
}
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getShopPath() {
|
||||
return shopPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,24 +1,81 @@
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SubShop {
|
||||
|
||||
private EpicBuckets epicBuckets;
|
||||
|
||||
private String subShopPath;
|
||||
private boolean enabled;
|
||||
|
||||
private ItemStack shopItem;
|
||||
private ItemStack genItem;
|
||||
|
||||
private Shop parent;
|
||||
private String item;
|
||||
private String shopName;
|
||||
private int slot;
|
||||
private double price;
|
||||
private List<String> description;
|
||||
private List<String> genItemLore;
|
||||
|
||||
|
||||
public SubShop(Shop parent, String item) {
|
||||
this.epicBuckets = EpicBuckets.getInstance();
|
||||
|
||||
this.parent = parent;
|
||||
this.item = item;
|
||||
this.description = new ArrayList<>();
|
||||
this.genItemLore = new ArrayList<>();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
FileConfiguration shops = EpicBuckets.getInstance().getConfigManager().getConfig("shops");
|
||||
subShopPath = epicBuckets.getShopManager().getShopPath() + "." + parent.getMenuItem() + "." + item;
|
||||
|
||||
//TODO: load in all data for this sub shop
|
||||
loadData(shops);
|
||||
setupShopItem(shops);
|
||||
}
|
||||
|
||||
private void loadData(FileConfiguration shops) {
|
||||
boolean d = Validator.getInstance().isDouble(shops.getString(subShopPath + ".price"));
|
||||
|
||||
if (!d) {
|
||||
epicBuckets.getDebugger().invalidPrice(subShopPath);
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
this.shopName = shops.getString(subShopPath + ".name");
|
||||
this.description = shops.getStringList(subShopPath + ".description");
|
||||
this.genItemLore = shops.getStringList(subShopPath + ".item-lore");
|
||||
}
|
||||
|
||||
private void setupShopItem(FileConfiguration shops) {
|
||||
slot = Validator.getInstance().slot(shops.getString(subShopPath + ".slot"));
|
||||
boolean m = Validator.getInstance().isMaterial(shops.getString(subShopPath + ".icon"));
|
||||
boolean t = Validator.getInstance().isMaterial(shops.getString(subShopPath + ".type"));
|
||||
|
||||
if (slot == -1) {
|
||||
epicBuckets.getDebugger().invalidSlot(subShopPath);
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
shopItem = ((!m) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".icon")).parseItem());
|
||||
genItem = ((!t) ? XMaterial.WATER_BUCKET.parseItem() : XMaterial.valueOf(shops.getString(subShopPath + ".type")).parseItem());
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,4 +15,12 @@ public class Debugger {
|
||||
epicBuckets.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
|
||||
}
|
||||
|
||||
public void invalidSlot(String item) {
|
||||
sendConsole(item + " has an invalid slot set, disabling shop..");
|
||||
}
|
||||
|
||||
public void invalidPrice(String item) {
|
||||
sendConsole(item + " has an invalid price set, disabling shop..");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,15 @@ public class Validator {
|
||||
private Validator() {
|
||||
}
|
||||
|
||||
public boolean isDouble(String s) {
|
||||
try {
|
||||
Double.parseDouble(s);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isInt(String s) {
|
||||
try {
|
||||
Integer.parseInt(s);
|
||||
@ -33,4 +42,9 @@ public class Validator {
|
||||
}
|
||||
}
|
||||
|
||||
public int slot(String s) {
|
||||
if (isInt(s)) return Integer.parseInt(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user