diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index 082014d..a88313b 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -17,9 +17,7 @@ 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.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.utils.ClickType; import de.epiceric.shopchest.utils.ClickType.EnumClickType; import de.epiceric.shopchest.utils.ShopUtils; @@ -181,9 +179,10 @@ public class Commands extends BukkitCommand { 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; + 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; default: return; } jb.sendJson(player); diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index 0eff2f0..fd08239 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -27,17 +27,13 @@ import de.epiceric.shopchest.event.RegenerateShopItem; import de.epiceric.shopchest.event.RegenerateShopItemAfterRemove; import de.epiceric.shopchest.event.UpdateHolograms; 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.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.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.utils.Metrics; import de.epiceric.shopchest.utils.Metrics.Graph; import de.epiceric.shopchest.utils.Metrics.Plotter; @@ -150,11 +146,12 @@ public class ShopChest extends JavaPlugin{ 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; + case "v1_8_R1": utils = new Utils_1_8_R1(); break; + case "v1_8_R2": utils = new Utils_1_8_R2(); break; + case "v1_8_R3": utils = new Utils_1_8_R3(); break; + case "v1_9_R1": utils = new Utils_1_9_R1(); break; default: - logger.severe("Incompatible Server Version!"); + logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!"); getServer().getPluginManager().disablePlugin(this); return; } @@ -194,9 +191,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_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; + 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; default: return; } jb.sendJson(p); diff --git a/src/de/epiceric/shopchest/event/InteractShop.java b/src/de/epiceric/shopchest/event/InteractShop.java index df02214..2bf5b58 100644 --- a/src/de/epiceric/shopchest/event/InteractShop.java +++ b/src/de/epiceric/shopchest/event/InteractShop.java @@ -16,7 +16,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.yi.acru.bukkit.Lockette.Lockette; @@ -248,9 +247,7 @@ public class InteractShop implements Listener{ sqlite.removeShop(shop); - for (Player player : plugin.getServer().getOnlinePlayers()) { - shop.getHologram().hidePlayer(player); - } + shop.removeHologram(); executor.sendMessage(Config.shop_removed()); diff --git a/src/de/epiceric/shopchest/event/NotifyUpdate.java b/src/de/epiceric/shopchest/event/NotifyUpdate.java index 7158666..0ae9bf4 100644 --- a/src/de/epiceric/shopchest/event/NotifyUpdate.java +++ b/src/de/epiceric/shopchest/event/NotifyUpdate.java @@ -8,9 +8,7 @@ import org.bukkit.event.player.PlayerJoinEvent; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; 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; import de.epiceric.shopchest.interfaces.JsonBuilder.ClickAction; import de.epiceric.shopchest.interfaces.JsonBuilder.HoverAction; @@ -32,9 +30,10 @@ public class NotifyUpdate implements Listener { 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; + 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; default: return; } jb.sendJson(p); diff --git a/src/de/epiceric/shopchest/event/ProtectChest.java b/src/de/epiceric/shopchest/event/ProtectChest.java index c2f413c..b63140f 100644 --- a/src/de/epiceric/shopchest/event/ProtectChest.java +++ b/src/de/epiceric/shopchest/event/ProtectChest.java @@ -31,7 +31,7 @@ public class ProtectChest implements Listener { public void onBlockPlace(BlockPlaceEvent e) { Block b = e.getBlockPlaced(); if (b.getType().equals(Material.CHEST) || b.getType().equals(Material.TRAPPED_CHEST)) { - + Chest c = (Chest) b.getState(); InventoryHolder ih = c.getInventory().getHolder(); @@ -40,23 +40,28 @@ public class ProtectChest implements Listener { Chest r = (Chest) dc.getRightSide(); Chest l = (Chest) dc.getLeftSide(); - if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) { + if (ShopUtils.isShop(r.getLocation()) || ShopUtils.isShop(l.getLocation())) { Shop shop; if (b.getLocation().equals(r.getLocation())) { shop = ShopUtils.getShop(l.getLocation()); ShopUtils.removeShop(shop); + ShopChest.sqlite.removeShop(shop); } else if (b.getLocation().equals(l.getLocation())) { shop = ShopUtils.getShop(r.getLocation()); ShopUtils.removeShop(shop); + ShopChest.sqlite.removeShop(shop); } else { return; } - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); Shop newShop = new Shop(ShopChest.getInstance(), shop.getVendor(), shop.getProduct(), shop.getLocation(), shop.getBuyPrice(), shop.getSellPrice(), shop.isInfinite()); + newShop.createHologram(); + newShop.createItem(); ShopUtils.addShop(newShop); + ShopChest.sqlite.addShop(newShop); } diff --git a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_R1.java b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R1.java similarity index 94% rename from src/de/epiceric/shopchest/interfaces/hologram/Hologram_R1.java rename to src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R1.java index ba90fed..00dca7c 100644 --- a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_R1.java +++ b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R1.java @@ -14,7 +14,7 @@ import net.minecraft.server.v1_8_R1.EntityArmorStand; import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving; -public class Hologram_R1 implements Hologram { +public class Hologram_1_8_R1 implements Hologram { private List entitylist = new ArrayList(); private String[] text; @@ -24,13 +24,13 @@ public class Hologram_R1 implements Hologram { private HashMap visible = new HashMap(); - public Hologram_R1(String[] text, Location location) { + public Hologram_1_8_R1(String[] text, Location location) { this.text = text; this.location = location; create(); } - public Hologram_R1(String text, Location location) { + public Hologram_1_8_R1(String text, Location location) { this.text = new String[] {text}; this.location = location; create(); diff --git a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_R2.java b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R2.java similarity index 94% rename from src/de/epiceric/shopchest/interfaces/hologram/Hologram_R2.java rename to src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R2.java index ec27bdb..1701357 100644 --- a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_R2.java +++ b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R2.java @@ -14,7 +14,7 @@ import net.minecraft.server.v1_8_R2.EntityArmorStand; import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy; import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving; -public class Hologram_R2 implements Hologram { +public class Hologram_1_8_R2 implements Hologram { private List entitylist = new ArrayList(); private String[] text; @@ -24,13 +24,13 @@ public class Hologram_R2 implements Hologram { private HashMap visible = new HashMap(); - public Hologram_R2(String[] text, Location location) { + public Hologram_1_8_R2(String[] text, Location location) { this.text = text; this.location = location; create(); } - public Hologram_R2(String text, Location location) { + public Hologram_1_8_R2(String text, Location location) { this.text = new String[] {text}; this.location = location; create(); diff --git a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_R3.java b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R3.java similarity index 94% rename from src/de/epiceric/shopchest/interfaces/hologram/Hologram_R3.java rename to src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R3.java index d4e61ef..5ae6cac 100644 --- a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_R3.java +++ b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_8_R3.java @@ -14,7 +14,7 @@ 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_R3 implements Hologram { +public class Hologram_1_8_R3 implements Hologram { private List entitylist = new ArrayList(); private String[] text; @@ -24,13 +24,13 @@ public class Hologram_R3 implements Hologram { private HashMap visible = new HashMap(); - public Hologram_R3(String[] text, Location location) { + public Hologram_1_8_R3(String[] text, Location location) { this.text = text; this.location = location; create(); } - public Hologram_R3(String text, Location location) { + public Hologram_1_8_R3(String text, Location location) { this.text = new String[] {text}; this.location = location; create(); diff --git a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_9_R1.java b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_9_R1.java new file mode 100644 index 0000000..c933662 --- /dev/null +++ b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_9_R1.java @@ -0,0 +1,87 @@ +package de.epiceric.shopchest.interfaces.hologram; + +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_9_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; + +import de.epiceric.shopchest.interfaces.Hologram; +import net.minecraft.server.v1_9_R1.EntityArmorStand; +import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving; + +public class Hologram_1_9_R1 implements 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_1_9_R1(String[] text, Location location) { + this.text = text; + this.location = location; + create(); + } + + public Hologram_1_9_R1(String text, Location location) { + this.text = new String[] {text}; + this.location = location; + create(); + } + + public Location getLocation() { + return location; + } + + public List getEntities() { + return entitylist; + } + + public void showPlayer(OfflinePlayer p) { + for (Object o : entitylist) { + EntityArmorStand armor = (EntityArmorStand) o; + PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving(armor); + ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet); + } + visible.put(p, true); + } + + public void hidePlayer(OfflinePlayer p) { + for (Object o : entitylist) { + EntityArmorStand armor = (EntityArmorStand) o; + 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/interfaces/jsonbuilder/JsonBuilder_R1.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java similarity index 86% rename from src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R1.java rename to src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java index 8d6754e..3c79ed2 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R1.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R1.java @@ -13,20 +13,20 @@ import net.minecraft.server.v1_8_R1.ChatSerializer; import net.minecraft.server.v1_8_R1.PacketPlayOutChat; -public class JsonBuilder_R1 implements JsonBuilder { +public class JsonBuilder_1_8_R1 implements JsonBuilder { /* JsonBuilder by FisheyLP */ private List extras = new ArrayList(); - public JsonBuilder_R1(String... text) { + public JsonBuilder_1_8_R1(String... text) { for(String extra : text) parse(extra); } @Override - public JsonBuilder_R1 parse(String text) { + public JsonBuilder_1_8_R1 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()) { @@ -47,34 +47,34 @@ public class JsonBuilder_R1 implements JsonBuilder { } @Override - public JsonBuilder_R1 withText(String text) { + public JsonBuilder_1_8_R1 withText(String text) { extras.add("{text:\"" + text + "\"}"); return this; } @Override - public JsonBuilder_R1 withColor(ChatColor color) { + public JsonBuilder_1_8_R1 withColor(ChatColor color) { String c = color.name().toLowerCase(); addSegment(color.isColor() ? "color:" + c : c + ":true"); return this; } @Override - public JsonBuilder_R1 withColor(String color) { + public JsonBuilder_1_8_R1 withColor(String color) { while(color.length() != 1) color = color.substring(1).trim(); withColor(ChatColor.getByChar(color)); return this; } @Override - public JsonBuilder_R1 withClickEvent(ClickAction action, String value) { + public JsonBuilder_1_8_R1 withClickEvent(ClickAction action, String value) { addSegment("clickEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); return this; } @Override - public JsonBuilder_R1 withHoverEvent(HoverAction action, String value) { + public JsonBuilder_1_8_R1 withHoverEvent(HoverAction action, String value) { addSegment("hoverEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); return this; diff --git a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R2.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java similarity index 86% rename from src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R2.java rename to src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java index e509d18..eef9746 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R2.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R2.java @@ -13,20 +13,20 @@ import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R2.PacketPlayOutChat; -public class JsonBuilder_R2 implements JsonBuilder { +public class JsonBuilder_1_8_R2 implements JsonBuilder { /* JsonBuilder by FisheyLP */ private List extras = new ArrayList(); - public JsonBuilder_R2(String... text) { + public JsonBuilder_1_8_R2(String... text) { for(String extra : text) parse(extra); } @Override - public JsonBuilder_R2 parse(String text) { + public JsonBuilder_1_8_R2 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()) { @@ -47,34 +47,34 @@ public class JsonBuilder_R2 implements JsonBuilder { } @Override - public JsonBuilder_R2 withText(String text) { + public JsonBuilder_1_8_R2 withText(String text) { extras.add("{text:\"" + text + "\"}"); return this; } @Override - public JsonBuilder_R2 withColor(ChatColor color) { + public JsonBuilder_1_8_R2 withColor(ChatColor color) { String c = color.name().toLowerCase(); addSegment(color.isColor() ? "color:" + c : c + ":true"); return this; } @Override - public JsonBuilder_R2 withColor(String color) { + public JsonBuilder_1_8_R2 withColor(String color) { while(color.length() != 1) color = color.substring(1).trim(); withColor(ChatColor.getByChar(color)); return this; } @Override - public JsonBuilder_R2 withClickEvent(ClickAction action, String value) { + public JsonBuilder_1_8_R2 withClickEvent(ClickAction action, String value) { addSegment("clickEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); return this; } @Override - public JsonBuilder_R2 withHoverEvent(HoverAction action, String value) { + public JsonBuilder_1_8_R2 withHoverEvent(HoverAction action, String value) { addSegment("hoverEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); return this; diff --git a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R3.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java similarity index 86% rename from src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R3.java rename to src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java index 05f8a1f..5f86ee8 100644 --- a/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_R3.java +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_8_R3.java @@ -13,20 +13,20 @@ import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -public class JsonBuilder_R3 implements JsonBuilder { +public class JsonBuilder_1_8_R3 implements JsonBuilder { /* JsonBuilder by FisheyLP */ private List extras = new ArrayList(); - public JsonBuilder_R3(String... text) { + public JsonBuilder_1_8_R3(String... text) { for(String extra : text) parse(extra); } @Override - public JsonBuilder_R3 parse(String text) { + public JsonBuilder_1_8_R3 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()) { @@ -47,34 +47,34 @@ public class JsonBuilder_R3 implements JsonBuilder { } @Override - public JsonBuilder_R3 withText(String text) { + public JsonBuilder_1_8_R3 withText(String text) { extras.add("{text:\"" + text + "\"}"); return this; } @Override - public JsonBuilder_R3 withColor(ChatColor color) { + public JsonBuilder_1_8_R3 withColor(ChatColor color) { String c = color.name().toLowerCase(); addSegment(color.isColor() ? "color:" + c : c + ":true"); return this; } @Override - public JsonBuilder_R3 withColor(String color) { + public JsonBuilder_1_8_R3 withColor(String color) { while(color.length() != 1) color = color.substring(1).trim(); withColor(ChatColor.getByChar(color)); return this; } @Override - public JsonBuilder_R3 withClickEvent(ClickAction action, String value) { + public JsonBuilder_1_8_R3 withClickEvent(ClickAction action, String value) { addSegment("clickEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); return this; } @Override - public JsonBuilder_R3 withHoverEvent(HoverAction action, String value) { + public JsonBuilder_1_8_R3 withHoverEvent(HoverAction action, String value) { addSegment("hoverEvent:{action:" + action.toString().toLowerCase() + ",value:\"" + value + "\"}"); return this; 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 new file mode 100644 index 0000000..8f35cda --- /dev/null +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R1.java @@ -0,0 +1,109 @@ +package de.epiceric.shopchest.interfaces.jsonbuilder; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +import org.bukkit.ChatColor; +import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + +import de.epiceric.shopchest.interfaces.JsonBuilder; +import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer; +import net.minecraft.server.v1_9_R1.PacketPlayOutChat; + + +public class JsonBuilder_1_9_R1 implements JsonBuilder { + + /* JsonBuilder by FisheyLP */ + + private List extras = new ArrayList(); + + + public JsonBuilder_1_9_R1(String... text) { + for(String extra : text) + parse(extra); + } + + @Override + public JsonBuilder_1_9_R1 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; + } + + @Override + public JsonBuilder_1_9_R1 withText(String 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"); + return this; + } + + @Override + public JsonBuilder_1_9_R1 withColor(String color) { + while(color.length() != 1) color = color.substring(1).trim(); + withColor(ChatColor.getByChar(color)); + return this; + } + + @Override + public JsonBuilder_1_9_R1 withClickEvent(ClickAction action, String 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 + "\"}"); + 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); + } + + @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:["; + extras.remove(0);; + for (String extra : extras) + text = text + extra + ","; + text = text.substring(0, text.length() - 1) + "]}"; + return text; + } + + @Override + 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/interfaces/utils/Utils_R1.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R1.java similarity index 93% rename from src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java rename to src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R1.java index 9256d00..de72972 100644 --- a/src/de/epiceric/shopchest/interfaces/utils/Utils_R1.java +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R1.java @@ -11,7 +11,7 @@ import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.utils.ShopUtils; import net.minecraft.server.v1_8_R1.EntityArmorStand; -public class Utils_R1 extends Utils { +public class Utils_1_8_R1 extends Utils { @Override public void reload(Player player) { @@ -19,7 +19,7 @@ public class Utils_R1 extends Utils { for (Shop shop : ShopUtils.getShops()) { Hologram hologram = shop.getHologram(); - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); ShopUtils.removeShop(shop); for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) { @@ -75,7 +75,7 @@ public class Utils_R1 extends Utils { } - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); } } diff --git a/src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R2.java similarity index 93% rename from src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java rename to src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R2.java index 61dace4..222c3c9 100644 --- a/src/de/epiceric/shopchest/interfaces/utils/Utils_R2.java +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R2.java @@ -12,7 +12,7 @@ import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.utils.ShopUtils; import net.minecraft.server.v1_8_R2.EntityArmorStand; -public class Utils_R2 extends Utils { +public class Utils_1_8_R2 extends Utils { @Override public void reload(Player player) { @@ -20,7 +20,7 @@ public class Utils_R2 extends Utils { for (Shop shop : ShopUtils.getShops()) { Hologram hologram = shop.getHologram(); - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); ShopUtils.removeShop(shop); for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) { @@ -78,7 +78,7 @@ public class Utils_R2 extends Utils { } - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); } } diff --git a/src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R3.java similarity index 93% rename from src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java rename to src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R3.java index 554d286..f7916bb 100644 --- a/src/de/epiceric/shopchest/interfaces/utils/Utils_R3.java +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_8_R3.java @@ -11,7 +11,7 @@ import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.utils.ShopUtils; import net.minecraft.server.v1_8_R3.EntityArmorStand; -public class Utils_R3 extends Utils { +public class Utils_1_8_R3 extends Utils { @Override public void reload(Player player) { @@ -19,7 +19,7 @@ public class Utils_R3 extends Utils { for (Shop shop : ShopUtils.getShops()) { Hologram hologram = shop.getHologram(); - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); ShopUtils.removeShop(shop); for (Player p : ShopChest.getInstance().getServer().getOnlinePlayers()) { @@ -76,7 +76,7 @@ public class Utils_R3 extends Utils { } - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); } } diff --git a/src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R1.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R1.java new file mode 100644 index 0000000..994833d --- /dev/null +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R1.java @@ -0,0 +1,86 @@ +package de.epiceric.shopchest.interfaces.utils; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerMoveEvent; +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.config.Config; +import de.epiceric.shopchest.interfaces.Utils; +import de.epiceric.shopchest.interfaces.Hologram; +import de.epiceric.shopchest.shop.Shop; +import de.epiceric.shopchest.utils.ShopUtils; +import net.minecraft.server.v1_9_R1.EntityArmorStand; + +public class Utils_1_9_R1 extends Utils { + + @Override + public void reload(Player player) { + + for (Shop shop : ShopUtils.getShops()) { + Hologram hologram = shop.getHologram(); + + if (shop.hasItem()) 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); + } + + + } + + int count = 0; + + for (int id = 1; id < ShopChest.sqlite.getHighestID() + 1; id++) { + + try { + Shop shop = ShopChest.sqlite.getShop(id); + shop.createHologram(); + shop.createItem(); + ShopUtils.addShop(shop); + } catch (NullPointerException e) { + continue; + } + + count++; + + } + + if (player != null) player.sendMessage(Config.reloaded_shops(count)); + + for (Player p : Bukkit.getOnlinePlayers()) { + Bukkit.getPluginManager().callEvent(new PlayerMoveEvent(p, p.getLocation(), p.getLocation())); + } + + + } + + + @Override + public void removeShops() { + for (Shop shop : ShopUtils.getShops()) { + Hologram hologram = shop.getHologram(); + + for (Player p : Bukkit.getOnlinePlayers()) { + hologram.hidePlayer(p); + } + + for (Object o : hologram.getEntities()) { + EntityArmorStand e = (EntityArmorStand) o; + e.getWorld().removeEntity(e); + } + + + if (shop.hasItem()) shop.getItem().remove(); + + } + } + + + +} diff --git a/src/de/epiceric/shopchest/shop/Shop.java b/src/de/epiceric/shopchest/shop/Shop.java index 276b5c5..55d7807 100644 --- a/src/de/epiceric/shopchest/shop/Shop.java +++ b/src/de/epiceric/shopchest/shop/Shop.java @@ -10,6 +10,7 @@ import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -20,9 +21,7 @@ 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.interfaces.hologram.*; import de.epiceric.shopchest.utils.ItemNames; public class Shop { @@ -47,6 +46,12 @@ public class Shop { this.infinite = infinite; } + public void removeHologram() { + for (Player player : plugin.getServer().getOnlinePlayers()) { + getHologram().hidePlayer(player); + } + } + public void createItem() { Item item; @@ -141,9 +146,10 @@ public class Shop { else holoText[1] = Config.hologram_buy_sell(buyPrice, sellPrice); 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; + case "v1_8_R1": hologram = new Hologram_1_8_R1(holoText, holoLocation); break; + case "v1_8_R2": hologram = new Hologram_1_8_R2(holoText, holoLocation); break; + case "v1_8_R3": hologram = new Hologram_1_8_R3(holoText, holoLocation); break; + case "v1_9_R1": hologram = new Hologram_1_9_R1(holoText, holoLocation); break; default: return; } @@ -181,4 +187,8 @@ public class Shop { return item; } + public boolean hasItem() { + return item != null; + } + } diff --git a/src/de/epiceric/shopchest/sql/Database.java b/src/de/epiceric/shopchest/sql/Database.java index 8eb7e19..d90dded 100644 --- a/src/de/epiceric/shopchest/sql/Database.java +++ b/src/de/epiceric/shopchest/sql/Database.java @@ -123,7 +123,7 @@ public abstract class Database { int id = getShopID(shop); if (id == 0) return; - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); Connection conn = null; PreparedStatement ps = null; diff --git a/src/de/epiceric/shopchest/utils/ShopUtils.java b/src/de/epiceric/shopchest/utils/ShopUtils.java index e0b8406..d1e8567 100644 --- a/src/de/epiceric/shopchest/utils/ShopUtils.java +++ b/src/de/epiceric/shopchest/utils/ShopUtils.java @@ -91,7 +91,8 @@ public class ShopUtils { Chest r = (Chest) dc.getRightSide(); Chest l = (Chest) dc.getLeftSide(); - shop.getItem().remove(); + if (shop.hasItem()) shop.getItem().remove(); + shop.removeHologram(); shopLocation.remove(r.getLocation()); shopLocation.remove(l.getLocation()); return;