diff --git a/config.yml b/config.yml index fed8369..f3e4076 100644 --- a/config.yml +++ b/config.yml @@ -41,6 +41,12 @@ main-command-name: "shop" # Value MUST be a number (e.g. 1, 1.5, 2.75, ...) maximal-distance: 1.75 +# Set whether the shops' chest should be protected by hoppers +hopper-protection: true + +# Set whether the shops' chest should be protected by explosions +explosion-protection: true + # Set the currency symbol after price values currency-symbol: $ @@ -233,7 +239,6 @@ messages: update: # Set the message when an update is available. - # Unfortunately only the last colored part of the text (if you have multiple colors) becomes clickable (default: only '&chere' is clickable). # Usable regex: %VERSION% update-available: "&l&6Version &c%VERSION% &6of &cShopChest &6is available &chere." diff --git a/plugin.yml b/plugin.yml index 9ca325b..f7b89cc 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: ShopChest main: de.epiceric.shopchest.ShopChest -version: 1.6.0.1 +version: 1.7.0 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 a88313b..379af76 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -14,8 +14,6 @@ import org.bukkit.inventory.ItemStack; import de.epiceric.shopchest.config.Config; 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.Utils; import de.epiceric.shopchest.interfaces.jsonbuilder.*; import de.epiceric.shopchest.utils.ClickType; @@ -179,10 +177,10 @@ public class Commands extends BukkitCommand { JsonBuilder jb; switch (Utils.getVersion(plugin.getServer())) { - case "v1_8_R1": jb = new JsonBuilder_1_8_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_1_8_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_1_8_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; - case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)); break; + case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)); break; + case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)); break; + case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)); break; default: return; } jb.sendJson(player); diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index fd08239..cfae811 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -31,8 +31,6 @@ import de.epiceric.shopchest.interfaces.utils.*; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.sql.SQLite; 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.*; import de.epiceric.shopchest.utils.Metrics; import de.epiceric.shopchest.utils.Metrics.Graph; @@ -45,6 +43,7 @@ import net.milkbowl.vault.permission.Permission; public class ShopChest extends JavaPlugin{ private static ShopChest instance; + private static UpdateChecker uc; public static Statement statement; public static Logger logger; @@ -84,7 +83,7 @@ public class ShopChest extends JavaPlugin{ @Override - public void onEnable() { + public void onEnable() { logger = getLogger(); @@ -174,7 +173,7 @@ public class ShopChest extends JavaPlugin{ instance = this; - UpdateChecker uc = new UpdateChecker(this, getDescription().getWebsite()); + if (uc == null) uc = new UpdateChecker(this, getDescription().getWebsite()); logger.info("Checking for Updates"); if(uc.updateNeeded()) { latestVersion = uc.getVersion(); @@ -191,10 +190,10 @@ public class ShopChest extends JavaPlugin{ if (p.isOp() || perm.has(p, "shopchest.notification.update")) { JsonBuilder jb; switch (Utils.getVersion(getServer())) { - case "v1_8_R1": jb = new JsonBuilder_1_8_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_1_8_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_1_8_R3(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break; - case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, downloadLink); break; + case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(latestVersion)); break; + case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(latestVersion)); break; + case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(latestVersion)); break; + case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(latestVersion)); break; default: return; } jb.sendJson(p); diff --git a/src/de/epiceric/shopchest/config/Config.java b/src/de/epiceric/shopchest/config/Config.java index 51154f8..b3e77bb 100644 --- a/src/de/epiceric/shopchest/config/Config.java +++ b/src/de/epiceric/shopchest/config/Config.java @@ -18,6 +18,9 @@ public class Config { public static List blacklist() {return (plugin.getConfig().getStringList("blacklist") == null) ? new ArrayList() : plugin.getConfig().getStringList("blacklist");}; public static boolean buy_greater_or_equal_sell() {return plugin.getConfig().getBoolean("buy-greater-or-equal-sell");} + public static boolean hopper_protection() {return plugin.getConfig().getBoolean("hopper-protection");} + public static boolean explosion_protection() {return plugin.getConfig().getBoolean("explosion-protection)");} + public static double maximal_distance() {return plugin.getConfig().getDouble("maximal-distance");} public static int default_limit() {return plugin.getConfig().getInt("shop-limits.default");} diff --git a/src/de/epiceric/shopchest/event/NotifyUpdate.java b/src/de/epiceric/shopchest/event/NotifyUpdate.java index 0ae9bf4..51ab594 100644 --- a/src/de/epiceric/shopchest/event/NotifyUpdate.java +++ b/src/de/epiceric/shopchest/event/NotifyUpdate.java @@ -10,8 +10,6 @@ import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.interfaces.Utils; import de.epiceric.shopchest.interfaces.jsonbuilder.*; 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 { @@ -30,10 +28,10 @@ public class NotifyUpdate implements Listener { JsonBuilder jb; switch (Utils.getVersion(ShopChest.getInstance().getServer())) { - case "v1_8_R1": jb = new JsonBuilder_1_8_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_1_8_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_1_8_R3(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; - case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); break; + case "v1_8_R1": jb = new JsonBuilder_1_8_R1(Config.update_available(ShopChest.latestVersion)); break; + case "v1_8_R2": jb = new JsonBuilder_1_8_R2(Config.update_available(ShopChest.latestVersion)); break; + case "v1_8_R3": jb = new JsonBuilder_1_8_R3(Config.update_available(ShopChest.latestVersion)); break; + case "v1_9_R1": jb = new JsonBuilder_1_9_R1(Config.update_available(ShopChest.latestVersion)); break; default: return; } jb.sendJson(p); diff --git a/src/de/epiceric/shopchest/event/ProtectChest.java b/src/de/epiceric/shopchest/event/ProtectChest.java index b63140f..db54370 100644 --- a/src/de/epiceric/shopchest/event/ProtectChest.java +++ b/src/de/epiceric/shopchest/event/ProtectChest.java @@ -1,13 +1,20 @@ package de.epiceric.shopchest.event; +import java.util.ArrayList; + import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.inventory.InventoryMoveItemEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.InventoryHolder; import de.epiceric.shopchest.ShopChest; @@ -27,6 +34,30 @@ public class ProtectChest implements Listener { } } + @EventHandler + public void onBlockExplode(BlockExplodeEvent e) { + if (Config.explosion_protection()) { + ArrayList bl = new ArrayList<>(e.blockList()); + for (Block b : bl) { + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + if (ShopUtils.isShop(b.getLocation())) e.blockList().remove(b); + } + } + } + } + + @EventHandler + public void onEntityExplode(EntityExplodeEvent e) { + if (Config.explosion_protection()) { + ArrayList bl = new ArrayList<>(e.blockList()); + for (Block b : bl) { + if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { + if (ShopUtils.isShop(b.getLocation())) e.blockList().remove(b); + } + } + } + } + @EventHandler public void onBlockPlace(BlockPlaceEvent e) { Block b = e.getBlockPlaced(); @@ -70,4 +101,26 @@ public class ProtectChest implements Listener { } } + @EventHandler(priority = EventPriority.HIGH) + public void onItemMove(InventoryMoveItemEvent e) { + if (Config.hopper_protection()) { + if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) { + + if (e.getSource().getHolder() instanceof DoubleChest) { + DoubleChest dc = (DoubleChest) e.getSource().getHolder(); + Chest r = (Chest) dc.getRightSide(); + Chest l = (Chest) dc.getLeftSide(); + + if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) e.setCancelled(true); + + } else if (e.getSource().getHolder() instanceof Chest) { + Chest c = (Chest) e.getSource().getHolder(); + + if (ShopUtils.isShop(c.getLocation())) e.setCancelled(true); + } + + } + } + } + } diff --git a/src/de/epiceric/shopchest/event/RegenerateShopItem.java b/src/de/epiceric/shopchest/event/RegenerateShopItem.java index 363d83f..ddd7828 100644 --- a/src/de/epiceric/shopchest/event/RegenerateShopItem.java +++ b/src/de/epiceric/shopchest/event/RegenerateShopItem.java @@ -6,6 +6,8 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.ItemDespawnEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.event.player.PlayerPickupItemEvent; public class RegenerateShopItem implements Listener { @@ -23,4 +25,11 @@ public class RegenerateShopItem implements Listener { if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true); } + @EventHandler(priority = EventPriority.HIGH) + public void onItemPickup(InventoryPickupItemEvent e) { + if (e.getInventory().getType().equals(InventoryType.HOPPER)) { + if (e.getItem().hasMetadata("shopItem")) e.setCancelled(true); + } + } + } diff --git a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java index 3c79ed2..a1f176f 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java @@ -8,6 +8,8 @@ import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.interfaces.JsonBuilder; import net.minecraft.server.v1_8_R1.ChatSerializer; import net.minecraft.server.v1_8_R1.PacketPlayOutChat; @@ -30,7 +32,7 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder { String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; text = text.replaceAll(regex, "§$1"); if(!Pattern.compile(regex).matcher(text).find()) { - withText(text); + withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); return this; } String[] words = text.split(regex); @@ -39,7 +41,7 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder { for(String word : words) { try { if(index != words[0].length()) - withText(word).withColor("§"+text.charAt(index - 1)); + withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); } catch(Exception e){} index += word.length() + 2; } @@ -48,14 +50,14 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder { @Override public JsonBuilder_1_8_R1 withText(String text) { - extras.add("{text:\"" + text + "\"}"); + extras.add("{\"text\":\"" + text + "\"}"); return this; } @Override public JsonBuilder_1_8_R1 withColor(ChatColor color) { String c = color.name().toLowerCase(); - addSegment(color.isColor() ? "color:" + c : c + ":true"); + addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); return this; } @@ -68,15 +70,15 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder { @Override public JsonBuilder_1_8_R1 withClickEvent(ClickAction action, String value) { - addSegment("clickEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @Override public JsonBuilder_1_8_R1 withHoverEvent(HoverAction action, String value) { - addSegment("hoverEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @@ -90,8 +92,8 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder { @Override 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:["; + 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 + ","; @@ -100,7 +102,7 @@ public class JsonBuilder_1_8_R1 implements JsonBuilder { } @Override - public void sendJson(Player p) { + public void sendJson(Player p) { ((CraftPlayer) p).getHandle().playerConnection.sendPacket( new PacketPlayOutChat(ChatSerializer.a(toString()))); diff --git a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java index eef9746..f4635da 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java @@ -8,6 +8,8 @@ import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; import org.bukkit.entity.Player; +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.interfaces.JsonBuilder; import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R2.PacketPlayOutChat; @@ -30,7 +32,7 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder { String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; text = text.replaceAll(regex, "§$1"); if(!Pattern.compile(regex).matcher(text).find()) { - withText(text); + withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); return this; } String[] words = text.split(regex); @@ -39,7 +41,7 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder { for(String word : words) { try { if(index != words[0].length()) - withText(word).withColor("§"+text.charAt(index - 1)); + withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); } catch(Exception e){} index += word.length() + 2; } @@ -48,14 +50,14 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder { @Override public JsonBuilder_1_8_R2 withText(String text) { - extras.add("{text:\"" + text + "\"}"); + extras.add("{\"text\":\"" + text + "\"}"); return this; } @Override public JsonBuilder_1_8_R2 withColor(ChatColor color) { String c = color.name().toLowerCase(); - addSegment(color.isColor() ? "color:" + c : c + ":true"); + addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); return this; } @@ -68,15 +70,15 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder { @Override public JsonBuilder_1_8_R2 withClickEvent(ClickAction action, String value) { - addSegment("clickEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @Override public JsonBuilder_1_8_R2 withHoverEvent(HoverAction action, String value) { - addSegment("hoverEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @@ -90,8 +92,8 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder { @Override 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:["; + 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 + ","; @@ -100,7 +102,7 @@ public class JsonBuilder_1_8_R2 implements JsonBuilder { } @Override - public void sendJson(Player p) { + public void sendJson(Player p) { ((CraftPlayer) p).getHandle().playerConnection.sendPacket( new PacketPlayOutChat(ChatSerializer.a(toString()))); diff --git a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java index 5f86ee8..b79effe 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java @@ -8,6 +8,8 @@ import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.interfaces.JsonBuilder; import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R3.PacketPlayOutChat; @@ -30,7 +32,7 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder { String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; text = text.replaceAll(regex, "§$1"); if(!Pattern.compile(regex).matcher(text).find()) { - withText(text); + withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); return this; } String[] words = text.split(regex); @@ -39,7 +41,7 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder { for(String word : words) { try { if(index != words[0].length()) - withText(word).withColor("§"+text.charAt(index - 1)); + withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); } catch(Exception e){} index += word.length() + 2; } @@ -48,14 +50,14 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder { @Override public JsonBuilder_1_8_R3 withText(String text) { - extras.add("{text:\"" + text + "\"}"); + extras.add("{\"text\":\"" + text + "\"}"); return this; } @Override public JsonBuilder_1_8_R3 withColor(ChatColor color) { String c = color.name().toLowerCase(); - addSegment(color.isColor() ? "color:" + c : c + ":true"); + addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); return this; } @@ -68,15 +70,15 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder { @Override public JsonBuilder_1_8_R3 withClickEvent(ClickAction action, String value) { - addSegment("clickEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @Override public JsonBuilder_1_8_R3 withHoverEvent(HoverAction action, String value) { - addSegment("hoverEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @@ -90,8 +92,8 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder { @Override 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:["; + 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 + ","; @@ -100,7 +102,7 @@ public class JsonBuilder_1_8_R3 implements JsonBuilder { } @Override - public void sendJson(Player p) { + public void sendJson(Player p) { ((CraftPlayer) p).getHandle().playerConnection.sendPacket( new PacketPlayOutChat(ChatSerializer.a(toString()))); diff --git a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R1.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R1.java index 8f35cda..28a0eb5 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R1.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R1.java @@ -8,6 +8,8 @@ import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; import org.bukkit.entity.Player; +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.interfaces.JsonBuilder; import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_9_R1.PacketPlayOutChat; @@ -30,7 +32,7 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder { String regex = "[&§]{1}([a-fA-Fl-oL-O0-9]){1}"; text = text.replaceAll(regex, "§$1"); if(!Pattern.compile(regex).matcher(text).find()) { - withText(text); + withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); return this; } String[] words = text.split(regex); @@ -39,7 +41,7 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder { for(String word : words) { try { if(index != words[0].length()) - withText(word).withColor("§"+text.charAt(index - 1)); + withText(word).withColor("§"+text.charAt(index - 1)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); } catch(Exception e){} index += word.length() + 2; } @@ -48,14 +50,14 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder { @Override public JsonBuilder_1_9_R1 withText(String text) { - extras.add("{text:\"" + text + "\"}"); + extras.add("{\"text\":\"" + text + "\"}"); return this; } @Override public JsonBuilder_1_9_R1 withColor(ChatColor color) { String c = color.name().toLowerCase(); - addSegment(color.isColor() ? "color:" + c : c + ":true"); + addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); return this; } @@ -68,15 +70,15 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder { @Override public JsonBuilder_1_9_R1 withClickEvent(ClickAction action, String value) { - addSegment("clickEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @Override public JsonBuilder_1_9_R1 withHoverEvent(HoverAction action, String value) { - addSegment("hoverEvent:{action:" + action.toString().toLowerCase() - + ",value:\"" + value + "\"}"); + addSegment("\"hoverEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); return this; } @@ -90,8 +92,8 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder { @Override 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:["; + 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 + ","; @@ -100,7 +102,7 @@ public class JsonBuilder_1_9_R1 implements JsonBuilder { } @Override - public void sendJson(Player p) { + public void sendJson(Player p) { ((CraftPlayer) p).getHandle().playerConnection.sendPacket( new PacketPlayOutChat(ChatSerializer.a(toString()))); diff --git a/src/de/epiceric/shopchest/utils/ShopUtils.java b/src/de/epiceric/shopchest/utils/ShopUtils.java index d1e8567..024ef2d 100644 --- a/src/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/de/epiceric/shopchest/utils/ShopUtils.java @@ -8,7 +8,6 @@ import java.util.UUID; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.OfflinePlayer; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; @@ -103,16 +102,6 @@ public class ShopUtils { shopLocation.remove(shop.getLocation()); } - - public static String getConfigTitle(Location location) { - World w = location.getWorld(); - int x = location.getBlockX(); - int y = location.getBlockY(); - int z = location.getBlockZ(); - - return w.getName() + "_" + String.valueOf(x) + "_" + String.valueOf(y) + "_" + String.valueOf(z); - } - public static int getShopLimit(Player p) { int limit = Config.default_limit();