From 06e1d20576012c21a79ef3e24cb44a33da858c95 Mon Sep 17 00:00:00 2001 From: Eric Date: Thu, 3 Sep 2015 20:51:30 +0200 Subject: [PATCH] Merged all versions of ShopChest to one jar file --- plugin.yml | 2 +- src/de/epiceric/shopchest/Commands.java | 75 +++---------- src/de/epiceric/shopchest/ShopChest.java | 52 +++++---- .../shopchest/event/InteractShop.java | 3 +- .../shopchest/event/NotifyUpdate.java | 21 +++- .../event/RegenerateShopItemAfterRemove.java | 56 +-------- src/de/epiceric/shopchest/shop/Hologram.java | 89 --------------- src/de/epiceric/shopchest/shop/Shop.java | 15 ++- .../epiceric/shopchest/utils/JsonBuilder.java | 106 ------------------ src/de/epiceric/shopchest/utils/Utils.java | 29 ----- 10 files changed, 80 insertions(+), 368 deletions(-) delete mode 100644 src/de/epiceric/shopchest/shop/Hologram.java delete mode 100644 src/de/epiceric/shopchest/utils/JsonBuilder.java delete mode 100644 src/de/epiceric/shopchest/utils/Utils.java diff --git a/plugin.yml b/plugin.yml index 824a0ea..6210e02 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ShopChest main: de.epiceric.shopchest.ShopChest -version: 1.4.8 +version: 1.4.9 author: EpicEric website: https://www.spigotmc.org/resources/shopchest.11431/ depend: [Vault] diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index 6d39bc7..64bae46 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -4,32 +4,25 @@ import java.lang.reflect.Method; import java.util.List; import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import de.epiceric.shopchest.config.Config; -import de.epiceric.shopchest.shop.Hologram; -import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.utils.ClickType; -import de.epiceric.shopchest.utils.JsonBuilder; +import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.utils.ClickType.EnumClickType; -import de.epiceric.shopchest.utils.JsonBuilder.ClickAction; -import de.epiceric.shopchest.utils.JsonBuilder.HoverAction; -import de.epiceric.shopchest.utils.ShopUtils; +import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction; +import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction; +import de.epiceric.shopchest.interfaces.Utils; +import de.epiceric.shopchest.interfaces.jsonbuilder.*; import de.epiceric.shopchest.utils.UpdateChecker; - import net.md_5.bungee.api.ChatColor; import net.milkbowl.vault.permission.Permission; -import net.minecraft.server.v1_8_R3.EntityArmorStand; public class Commands extends BukkitCommand { @@ -165,67 +158,35 @@ public class Commands extends BukkitCommand { private void checkUpdates(Player player) { - JsonBuilder jb = new JsonBuilder().parse(Config.checking_update()); - jb.sendJson(player); + player.sendMessage(Config.checking_update()); UpdateChecker uc = new UpdateChecker(ShopChest.getInstance(), ShopChest.getInstance().getDescription().getWebsite()); if (uc.updateNeeded()) { ShopChest.latestVersion = uc.getVersion(); ShopChest.downloadLink = uc.getLink(); ShopChest.isUpdateNeeded = true; - JsonBuilder jb2 = new JsonBuilder(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); - jb2.sendJson(player); + + JsonBuilder jb; + switch (Utils.getVersion(plugin.getServer())) { + case "v1_8_R1": jb = new JsonBuilder_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + case "v1_8_R2": jb = new JsonBuilder_R2(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + case "v1_8_R3": jb = new JsonBuilder_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + default: return; + } + jb.sendJson(player); + } else { ShopChest.latestVersion = ""; ShopChest.downloadLink = ""; ShopChest.isUpdateNeeded = false; - JsonBuilder jb3 = new JsonBuilder().parse(Config.no_new_update()); - jb3.sendJson(player); + player.sendMessage(Config.no_new_update()); } } private void reload(Player player) { - for (Shop shop : ShopUtils.getShops()) { - Hologram hologram = shop.getHologram(); - - shop.getItem().remove(); - ShopUtils.removeShop(shop); - - for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) { - hologram.hidePlayer(p); - } - - for (Object o : hologram.getEntities()) { - EntityArmorStand e = (EntityArmorStand) o; - e.getWorld().removeEntity(e); - } - - - } - - for (String key : ShopChest.getInstance().shopChests.getKeys(false)) { - - OfflinePlayer vendor = ShopChest.getInstance().shopChests.getOfflinePlayer(key + ".vendor"); - int locationX = ShopChest.getInstance().shopChests.getInt(key + ".location.x"); - int locationY = ShopChest.getInstance().shopChests.getInt(key + ".location.y"); - int locationZ = ShopChest.getInstance().shopChests.getInt(key + ".location.z"); - World locationWorld = ShopChest.getInstance().getServer().getWorld(ShopChest.getInstance().shopChests.getString(key + ".location.world")); - Location location = new Location(locationWorld, locationX, locationY, locationZ); - ItemStack product = ShopChest.getInstance().shopChests.getItemStack(key + ".product"); - double buyPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.buy"); - double sellPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.sell"); - boolean infinite = ShopChest.getInstance().shopChests.getBoolean(key + ".infinite"); - - ShopUtils.addShop(new Shop(ShopChest.getInstance(), vendor, product, location, buyPrice, sellPrice, infinite)); - - } - - for (Player p : Bukkit.getOnlinePlayers()) { - Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation())); - } - + ShopChest.utils.reload(); player.sendMessage(Config.reloaded_shops(ShopChest.getInstance().shopChests.getKeys(false).size())); } diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index ad9d359..a7fd413 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -26,17 +26,22 @@ import de.epiceric.shopchest.event.ProtectChest; import de.epiceric.shopchest.event.RegenerateShopItem; import de.epiceric.shopchest.event.RegenerateShopItemAfterRemove; import de.epiceric.shopchest.event.UpdateHolograms; -import de.epiceric.shopchest.shop.Hologram; +import de.epiceric.shopchest.interfaces.Utils; +import de.epiceric.shopchest.interfaces.utils.Utils_R1; +import de.epiceric.shopchest.interfaces.utils.Utils_R2; +import de.epiceric.shopchest.interfaces.utils.Utils_R3; import de.epiceric.shopchest.shop.Shop; -import de.epiceric.shopchest.utils.JsonBuilder; -import de.epiceric.shopchest.utils.JsonBuilder.ClickAction; -import de.epiceric.shopchest.utils.JsonBuilder.HoverAction; +import de.epiceric.shopchest.interfaces.JsonBuilder; +import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction; +import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction; +import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R1; +import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R2; +import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R3; import de.epiceric.shopchest.utils.Metrics; import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.UpdateChecker; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; -import net.minecraft.server.v1_8_R3.EntityArmorStand; public class ShopChest extends JavaPlugin{ @@ -53,6 +58,8 @@ public class ShopChest extends JavaPlugin{ public static String latestVersion = ""; public static String downloadLink = ""; + public static Utils utils; + public static ShopChest getInstance() { return instance; } @@ -97,6 +104,17 @@ public class ShopChest extends JavaPlugin{ logger.severe("[ShopChest] [PluginMetrics] Could not submit stats."); } + switch (Utils.getVersion(getServer())) { + + case "v1_8_R1": utils = new Utils_R1(); break; + case "v1_8_R2": utils = new Utils_R2(); break; + case "v1_8_R3": utils = new Utils_R3(); break; + default: + logger.severe("[ShopChest] Incompatible Server Version!"); + getServer().getPluginManager().disablePlugin(this); + return; + } + setupPermissions(); instance = this; @@ -118,7 +136,13 @@ public class ShopChest extends JavaPlugin{ if (isUpdateNeeded) { for (Player p : getServer().getOnlinePlayers()) { if (p.isOp() || perm.has(p, "shopchest.notification.update")) { - JsonBuilder jb = new JsonBuilder(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); + JsonBuilder jb; + switch (Utils.getVersion(getServer())) { + case "v1_8_R1": jb = new JsonBuilder_R1(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break; + case "v1_8_R2": jb = new JsonBuilder_R2(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break; + case "v1_8_R3": jb = new JsonBuilder_R3(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break; + default: return; + } jb.sendJson(p); } @@ -165,21 +189,7 @@ public class ShopChest extends JavaPlugin{ @Override public void onDisable() { - for (Shop shop : ShopUtils.getShops()) { - Hologram hologram = shop.getHologram(); - - for (Player p : getServer().getOnlinePlayers()) { - hologram.hidePlayer(p); - } - - for (Object o : hologram.getEntities()) { - EntityArmorStand e = (EntityArmorStand) o; - e.getWorld().removeEntity(e); - } - - - shop.getItem().remove(); - } + utils.removeShops(); } diff --git a/src/de/epiceric/shopchest/event/InteractShop.java b/src/de/epiceric/shopchest/event/InteractShop.java index 36f745b..a6d2646 100644 --- a/src/de/epiceric/shopchest/event/InteractShop.java +++ b/src/de/epiceric/shopchest/event/InteractShop.java @@ -27,7 +27,8 @@ import de.epiceric.shopchest.utils.ClickType; import de.epiceric.shopchest.utils.EnchantmentNames; import de.epiceric.shopchest.utils.ItemNames; import de.epiceric.shopchest.utils.ShopUtils; -import de.epiceric.shopchest.utils.Utils; +import de.epiceric.shopchest.interfaces.Utils; + import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.EconomyResponse; import net.milkbowl.vault.permission.Permission; diff --git a/src/de/epiceric/shopchest/event/NotifyUpdate.java b/src/de/epiceric/shopchest/event/NotifyUpdate.java index 5d90d74..7158666 100644 --- a/src/de/epiceric/shopchest/event/NotifyUpdate.java +++ b/src/de/epiceric/shopchest/event/NotifyUpdate.java @@ -7,9 +7,13 @@ import org.bukkit.event.player.PlayerJoinEvent; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; -import de.epiceric.shopchest.utils.JsonBuilder; -import de.epiceric.shopchest.utils.JsonBuilder.ClickAction; -import de.epiceric.shopchest.utils.JsonBuilder.HoverAction; +import de.epiceric.shopchest.interfaces.Utils; +import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R1; +import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R2; +import de.epiceric.shopchest.interfaces.jsonbuilder.JsonBuilder_R3; +import de.epiceric.shopchest.interfaces.JsonBuilder; +import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction; +import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction; import net.milkbowl.vault.permission.Permission; public class NotifyUpdate implements Listener { @@ -25,9 +29,14 @@ public class NotifyUpdate implements Listener { if (ShopChest.isUpdateNeeded) { if (p.isOp() || perm.has(p, "shopchest.notification.update")) { - String version = ShopChest.latestVersion; - String link = ShopChest.downloadLink; - JsonBuilder jb = new JsonBuilder(Config.update_available(version)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, link); + JsonBuilder jb; + + switch (Utils.getVersion(ShopChest.getInstance().getServer())) { + case "v1_8_R1": jb = new JsonBuilder_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + case "v1_8_R2": jb = new JsonBuilder_R2(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + case "v1_8_R3": jb = new JsonBuilder_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + default: return; + } jb.sendJson(p); } } diff --git a/src/de/epiceric/shopchest/event/RegenerateShopItemAfterRemove.java b/src/de/epiceric/shopchest/event/RegenerateShopItemAfterRemove.java index 25bf0b1..a6e291b 100644 --- a/src/de/epiceric/shopchest/event/RegenerateShopItemAfterRemove.java +++ b/src/de/epiceric/shopchest/event/RegenerateShopItemAfterRemove.java @@ -1,22 +1,10 @@ package de.epiceric.shopchest.event; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.inventory.ItemStack; - import de.epiceric.shopchest.ShopChest; -import de.epiceric.shopchest.shop.Hologram; -import de.epiceric.shopchest.shop.Shop; -import de.epiceric.shopchest.utils.ShopUtils; -import net.minecraft.server.v1_8_R3.EntityArmorStand; public class RegenerateShopItemAfterRemove implements Listener { @@ -31,50 +19,8 @@ public class RegenerateShopItemAfterRemove implements Listener { } } - if (containsShopItem) reload(); + if (containsShopItem) ShopChest.utils.reload(); } - - private void reload() { - - for (Shop shop : ShopUtils.getShops()) { - Hologram hologram = shop.getHologram(); - - shop.getItem().remove(); - ShopUtils.removeShop(shop); - - for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) { - hologram.hidePlayer(p); - } - for (Object o : hologram.getEntities()) { - EntityArmorStand e = (EntityArmorStand) o; - e.getWorld().removeEntity(e); - } - - - } - - for (String key : ShopChest.getInstance().shopChests.getKeys(false)) { - - OfflinePlayer vendor = ShopChest.getInstance().shopChests.getOfflinePlayer(key + ".vendor"); - int locationX = ShopChest.getInstance().shopChests.getInt(key + ".location.x"); - int locationY = ShopChest.getInstance().shopChests.getInt(key + ".location.y"); - int locationZ = ShopChest.getInstance().shopChests.getInt(key + ".location.z"); - World locationWorld = ShopChest.getInstance().getServer().getWorld(ShopChest.getInstance().shopChests.getString(key + ".location.world")); - Location location = new Location(locationWorld, locationX, locationY, locationZ); - ItemStack product = ShopChest.getInstance().shopChests.getItemStack(key + ".product"); - double buyPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.buy"); - double sellPrice = ShopChest.getInstance().shopChests.getDouble(key + ".price.sell"); - boolean infinite = ShopChest.getInstance().shopChests.getBoolean(key + ".infinite"); - - ShopUtils.addShop(new Shop(ShopChest.getInstance(), vendor, product, location, buyPrice, sellPrice, infinite)); - - } - - for (Player p : Bukkit.getOnlinePlayers()) { - Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation())); - } - - } } diff --git a/src/de/epiceric/shopchest/shop/Hologram.java b/src/de/epiceric/shopchest/shop/Hologram.java deleted file mode 100644 index f9ed3d9..0000000 --- a/src/de/epiceric/shopchest/shop/Hologram.java +++ /dev/null @@ -1,89 +0,0 @@ -package de.epiceric.shopchest.shop; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; - -import net.minecraft.server.v1_8_R3.EntityArmorStand; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; - -public class Hologram { - - private List entitylist = new ArrayList(); - private String[] text; - private Location location; - private double DISTANCE = 0.25D; - int count; - - private HashMap visible = new HashMap(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Hologram(String text, Location location) { - this.text = new String[] {text}; - this.location = location; - create(); - } - - public String getText(int line) { - return text[line]; - } - - public Location getLocation() { - return location; - } - - public List getEntities() { - return entitylist; - } - - public void showPlayer(OfflinePlayer p) { - for (EntityArmorStand armor : entitylist) { - PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); - ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); - } - visible.put(p, true); - } - - public void hidePlayer(OfflinePlayer p) { - for (EntityArmorStand armor : entitylist) { - PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(armor.getId()); - ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); - - } - visible.put(p, false); - } - - public boolean isVisible(OfflinePlayer p) { - if (visible.containsKey(p)) return visible.get(p); else return false; - } - - private void create() { - for (String text : this.text) { - EntityArmorStand entity = new EntityArmorStand(((CraftWorld) this.location.getWorld()).getHandle(),this.location.getX(), this.location.getY(),this.location.getZ()); - entity.setCustomName(text); - entity.setCustomNameVisible(true); - entity.setInvisible(true); - entity.setGravity(false); - entitylist.add(entity); - this.location.subtract(0, this.DISTANCE, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, this.DISTANCE, 0); - } - this.count = 0; - } - -} diff --git a/src/de/epiceric/shopchest/shop/Shop.java b/src/de/epiceric/shopchest/shop/Shop.java index ead9576..c0a1bf2 100644 --- a/src/de/epiceric/shopchest/shop/Shop.java +++ b/src/de/epiceric/shopchest/shop/Shop.java @@ -1,7 +1,6 @@ package de.epiceric.shopchest.shop; import java.util.ArrayList; -import java.util.Random; import java.util.UUID; import org.bukkit.Location; @@ -19,6 +18,11 @@ import org.bukkit.util.Vector; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; +import de.epiceric.shopchest.interfaces.Hologram; +import de.epiceric.shopchest.interfaces.Utils; +import de.epiceric.shopchest.interfaces.hologram.Hologram_R1; +import de.epiceric.shopchest.interfaces.hologram.Hologram_R2; +import de.epiceric.shopchest.interfaces.hologram.Hologram_R3; import de.epiceric.shopchest.utils.ItemNames; public class Shop { @@ -137,8 +141,13 @@ public class Shop { else if ((buyPrice > 0) && (sellPrice > 0)) holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice); else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice); - hologram = new Hologram(holoText, holoLocation); - + switch (Utils.getVersion(plugin.getServer())) { + case "v1_8_R1": hologram = new Hologram_R1(holoText, holoLocation); break; + case "v1_8_R2": hologram = new Hologram_R2(holoText, holoLocation); break; + case "v1_8_R3": hologram = new Hologram_R3(holoText, holoLocation); break; + default: return null; + } + return hologram; } diff --git a/src/de/epiceric/shopchest/utils/JsonBuilder.java b/src/de/epiceric/shopchest/utils/JsonBuilder.java deleted file mode 100644 index 15dbe43..0000000 --- a/src/de/epiceric/shopchest/utils/JsonBuilder.java +++ /dev/null @@ -1,106 +0,0 @@ -package de.epiceric.shopchest.utils; - -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Pattern; - -import org.bukkit.ChatColor; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; - -import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_8_R3.PacketPlayOutChat; - - -public class JsonBuilder { - - /* JsonBuilder by FisheyLP */ - - public enum ClickAction { - RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL - } - public enum HoverAction { - SHOW_TEXT - } - - private List extras = new ArrayList(); - - public JsonBuilder(String... text) { - for(String extra : text) - parse(extra); - } - - public JsonBuilder parse(String text) { - String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; - text = text.replaceAll(regex, "§$1"); - if(!Pattern.compile(regex).matcher(text).find()) { - withText(text); - return this; - } - String[] words = text.split(regex); - - int index = words[0].length(); - for(String word : words) { - try { - if(index != words[0].length()) - withText(word).withColor("§"+text.charAt(index - 1)); - } catch(Exception e){} - index += word.length() + 2; - } - return this; - } - - public JsonBuilder withText(String text) { - extras.add("{text:\"" + text + "\"}"); - return this; - } - - public JsonBuilder withColor(ChatColor color) { - String c = color.name().toLowerCase(); - addSegment(color.isColor() ? "color:" + c : c + ":true"); - return this; - } - - public JsonBuilder withColor(String color) { - while(color.length() != 1) color = color.substring(1).trim(); - withColor(ChatColor.getByChar(color)); - return this; - } - - public JsonBuilder withClickEvent(ClickAction action, String value) { - addSegment("clickEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); - return this; - } - - public JsonBuilder withHoverEvent(HoverAction action, String value) { - addSegment("hoverEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); - return this; - } - - private void addSegment(String segment) { - String lastText = extras.get(extras.size() - 1); - lastText = lastText.substring(0, lastText.length() - 1) - + ","+segment+"}"; - extras.remove(extras.size() - 1); - extras.add(lastText); - } - - public String toString() { - if(extras.size() <= 1) return extras.size() == 0 ? "{text:\"\"}" : extras.get(0); - String text = extras.get(0).substring(0, extras.get(0).length() - 1) + ",extra:["; - extras.remove(0);; - for (String extra : extras) - text = text + extra + ","; - text = text.substring(0, text.length() - 1) + "]}"; - return text; - } - - public void sendJson(Player p) { - ((CraftPlayer) p).getHandle().playerConnection.sendPacket( - new PacketPlayOutChat(ChatSerializer.a(toString()))); - - - } - } \ No newline at end of file diff --git a/src/de/epiceric/shopchest/utils/Utils.java b/src/de/epiceric/shopchest/utils/Utils.java deleted file mode 100644 index d2766f3..0000000 --- a/src/de/epiceric/shopchest/utils/Utils.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.epiceric.shopchest.utils; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - -public class Utils { - - - public static int getAmount(Inventory inventory, Material type, short damage, ItemMeta itemMeta) { - ItemStack[] items = inventory.getContents(); - int amount = 0; - for (ItemStack item : items) { - if ((item != null) && (item.getType().equals(type)) && (item.getDurability() == damage) && (item.getAmount() > 0) && (item.getItemMeta().equals(itemMeta))) { - amount += item.getAmount(); - } - } - return amount; - } - - public static String getVersion() { - - return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; - - } - -}