diff --git a/src/de/epiceric/shopchest/Commands.java b/src/de/epiceric/shopchest/Commands.java index a1876ba..13cf453 100644 --- a/src/de/epiceric/shopchest/Commands.java +++ b/src/de/epiceric/shopchest/Commands.java @@ -149,6 +149,7 @@ public class Commands extends BukkitCommand { 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; + case "v1_9_R2": jb = new JsonBuilder_1_9_R2(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 64f0f8e..7fdaad7 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -163,6 +163,7 @@ public class ShopChest extends JavaPlugin{ 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; + case "v1_9_R2": utils = new Utils_1_9_R2(); break; default: logger.severe("Incompatible Server Version: " + Utils.getVersion(getServer()) + "!"); getServer().getPluginManager().disablePlugin(this); @@ -206,6 +207,7 @@ public class ShopChest extends JavaPlugin{ 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; + case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(latestVersion)); break; default: return; } jb.sendJson(p); diff --git a/src/de/epiceric/shopchest/event/NotifyUpdate.java b/src/de/epiceric/shopchest/event/NotifyUpdate.java index c63827c..0ccd519 100644 --- a/src/de/epiceric/shopchest/event/NotifyUpdate.java +++ b/src/de/epiceric/shopchest/event/NotifyUpdate.java @@ -32,6 +32,7 @@ public class NotifyUpdate implements Listener { 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; + case "v1_9_R2": jb = new JsonBuilder_1_9_R2(Config.update_available(ShopChest.latestVersion)); break; default: return; } jb.sendJson(p); diff --git a/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_9_R2.java b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_9_R2.java new file mode 100644 index 0000000..ef094e6 --- /dev/null +++ b/src/de/epiceric/shopchest/interfaces/hologram/Hologram_1_9_R2.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_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; + +import de.epiceric.shopchest.interfaces.Hologram; +import net.minecraft.server.v1_9_R2.EntityArmorStand; +import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy; +import net.minecraft.server.v1_9_R2.PacketPlayOutSpawnEntityLiving; + +public class Hologram_1_9_R2 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_R2(String[] text, Location location) { + this.text = text; + this.location = location; + create(); + } + + public Hologram_1_9_R2(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_1_9_R2.java b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R2.java new file mode 100644 index 0000000..d36ab12 --- /dev/null +++ b/src/de/epiceric/shopchest/interfaces/jsonbuilder/JsonBuilder_1_9_R2.java @@ -0,0 +1,111 @@ +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_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_9_R2.IChatBaseComponent.ChatSerializer; +import net.minecraft.server.v1_9_R2.PacketPlayOutChat; + + +public class JsonBuilder_1_9_R2 implements JsonBuilder { + + /* JsonBuilder by FisheyLP */ + + private List extras = new ArrayList(); + + + public JsonBuilder_1_9_R2(String... text) { + for(String extra : text) + parse(extra); + } + + @Override + public JsonBuilder_1_9_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()) { + withText(text).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); + 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)).withHoverEvent(HoverAction.SHOW_TEXT, Config.click_to_download()).withClickEvent(ClickAction.OPEN_URL, ShopChest.downloadLink); + } catch(Exception e){} + index += word.length() + 2; + } + return this; + } + + @Override + public JsonBuilder_1_9_R2 withText(String text) { + extras.add("{\"text\":\"" + text + "\"}"); + return this; + } + + @Override + public JsonBuilder_1_9_R2 withColor(ChatColor color) { + String c = color.name().toLowerCase(); + addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); + return this; + } + + @Override + public JsonBuilder_1_9_R2 withColor(String color) { + while(color.length() != 1) color = color.substring(1).trim(); + withColor(ChatColor.getByChar(color)); + return this; + } + + @Override + public JsonBuilder_1_9_R2 withClickEvent(ClickAction action, String value) { + addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase() + + "\",\"value\":\"" + value + "\"}"); + return this; + } + + @Override + public JsonBuilder_1_9_R2 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_1_9_R2.java b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R2.java new file mode 100644 index 0000000..ea6f872 --- /dev/null +++ b/src/de/epiceric/shopchest/interfaces/utils/Utils_1_9_R2.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_R2.EntityArmorStand; + +public class Utils_1_9_R2 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 91d19b0..7afcccb 100644 --- a/src/de/epiceric/shopchest/shop/Shop.java +++ b/src/de/epiceric/shopchest/shop/Shop.java @@ -156,6 +156,7 @@ public class Shop { 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; + case "v1_9_R2": hologram = new Hologram_1_9_R2(holoText, holoLocation); break; default: return; }