From 57af99da1bc7562f838e2792f4de2a7ba8907d14 Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 5 Aug 2016 15:25:24 +0200 Subject: [PATCH] Now using reflection instead of different modules This commit also fixes spawn eggs on 1.8.x --- ShopChest NMS-Abstract/pom.xml | 14 -- .../de/epiceric/shopchest/nms/IHologram.java | 41 ----- .../epiceric/shopchest/nms/IJsonBuilder.java | 94 ---------- .../epiceric/shopchest/nms/ISpawnEggMeta.java | 39 ---- ShopChest NMS-v1_10_R1/pom.xml | 29 --- .../shopchest/nms/v1_10_R1/Hologram.java | 87 --------- .../shopchest/nms/v1_10_R1/JsonBuilder.java | 20 --- .../shopchest/nms/v1_10_R1/SpawnEggMeta.java | 23 --- ShopChest NMS-v1_8_R1/pom.xml | 29 --- .../shopchest/nms/v1_8_R1/Hologram.java | 87 --------- .../shopchest/nms/v1_8_R1/JsonBuilder.java | 20 --- .../shopchest/nms/v1_8_R1/SpawnEggMeta.java | 23 --- ShopChest NMS-v1_8_R2/pom.xml | 30 ---- .../shopchest/nms/v1_8_R2/Hologram.java | 87 --------- .../shopchest/nms/v1_8_R2/JsonBuilder.java | 20 --- .../shopchest/nms/v1_8_R2/SpawnEggMeta.java | 23 --- ShopChest NMS-v1_8_R3/pom.xml | 30 ---- .../shopchest/nms/v1_8_R3/Hologram.java | 87 --------- .../shopchest/nms/v1_8_R3/JsonBuilder.java | 20 --- .../shopchest/nms/v1_8_R3/SpawnEggMeta.java | 23 --- ShopChest NMS-v1_9_R1/pom.xml | 29 --- .../shopchest/nms/v1_9_R1/Hologram.java | 87 --------- .../shopchest/nms/v1_9_R1/JsonBuilder.java | 20 --- .../shopchest/nms/v1_9_R1/SpawnEggMeta.java | 23 --- ShopChest NMS-v1_9_R2/pom.xml | 29 --- .../shopchest/nms/v1_9_R2/Hologram.java | 87 --------- .../shopchest/nms/v1_9_R2/JsonBuilder.java | 20 --- .../shopchest/nms/v1_9_R2/SpawnEggMeta.java | 23 --- ShopChest/dependency-reduced-pom.xml | 73 -------- ShopChest/pom.xml | 52 ------ .../listeners/NotifyUpdateOnJoinListener.java | 62 ------- pom.xml | 41 +---- .../java/de/epiceric/shopchest/ShopChest.java | 26 +-- .../de/epiceric/shopchest/ShopCommand.java | 27 +-- .../de/epiceric/shopchest/config/Config.java | 0 .../config/LanguageConfiguration.java | 0 .../de/epiceric/shopchest/config/Regex.java | 0 .../shopchest/event/ShopBuySellEvent.java | 0 .../shopchest/event/ShopCreateEvent.java | 0 .../epiceric/shopchest/event/ShopEvent.java | 0 .../shopchest/event/ShopInfoEvent.java | 0 .../shopchest/event/ShopPreCreateEvent.java | 0 .../shopchest/event/ShopPreInfoEvent.java | 0 .../shopchest/event/ShopPreRemoveEvent.java | 0 .../shopchest/event/ShopReloadEvent.java | 0 .../shopchest/event/ShopRemoveEvent.java | 0 .../shopchest/language/EnchantmentName.java | 0 .../shopchest/language/EntityName.java | 0 .../epiceric/shopchest/language/ItemName.java | 0 .../shopchest/language/LanguageUtils.java | 30 +--- .../shopchest/language/LocalizedMessage.java | 0 .../shopchest/language/MusicDiscName.java | 0 .../shopchest/language/PotionEffectName.java | 0 .../shopchest/language/PotionName.java | 0 .../listeners/ChestProtectListener.java | 0 .../shopchest/listeners/ClearLagListener.java | 0 .../listeners/HologramUpdateListener.java | 0 .../listeners/ItemCustomNameListener.java | 0 .../listeners/ItemProtectListener.java | 0 .../listeners/LWCMagnetListener.java | 0 .../listeners/NotifyUpdateOnJoinListener.java | 38 ++++ .../listeners/ShopInteractListener.java | 0 .../de/epiceric/shopchest/nms/Hologram.java | 166 ++++++++++++++++++ .../epiceric/shopchest/nms/JsonBuilder.java | 117 ++++++++++++ .../epiceric/shopchest/nms/SpawnEggMeta.java | 72 ++++++++ .../java/de/epiceric/shopchest/shop/Shop.java | 28 +-- .../de/epiceric/shopchest/sql/Database.java | 0 .../java/de/epiceric/shopchest/sql/MySQL.java | 0 .../de/epiceric/shopchest/sql/SQLite.java | 0 .../epiceric/shopchest/utils/ClickType.java | 0 .../de/epiceric/shopchest/utils/Metrics.java | 0 .../epiceric/shopchest/utils/ShopUtils.java | 0 .../shopchest/utils/UpdateChecker.java | 0 .../de/epiceric/shopchest/utils/Utils.java | 26 +++ .../src => src}/main/resources/config.yml | 0 .../src => src}/main/resources/item_names.txt | 0 .../main/resources/lang/de_DE.lang | 0 .../main/resources/lang/en_US.lang | 0 .../src => src}/main/resources/plugin.yml | 0 79 files changed, 432 insertions(+), 1470 deletions(-) delete mode 100644 ShopChest NMS-Abstract/pom.xml delete mode 100644 ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IHologram.java delete mode 100644 ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IJsonBuilder.java delete mode 100644 ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/ISpawnEggMeta.java delete mode 100644 ShopChest NMS-v1_10_R1/pom.xml delete mode 100644 ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/Hologram.java delete mode 100644 ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/JsonBuilder.java delete mode 100644 ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/SpawnEggMeta.java delete mode 100644 ShopChest NMS-v1_8_R1/pom.xml delete mode 100644 ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/Hologram.java delete mode 100644 ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/JsonBuilder.java delete mode 100644 ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/SpawnEggMeta.java delete mode 100644 ShopChest NMS-v1_8_R2/pom.xml delete mode 100644 ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/Hologram.java delete mode 100644 ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/JsonBuilder.java delete mode 100644 ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/SpawnEggMeta.java delete mode 100644 ShopChest NMS-v1_8_R3/pom.xml delete mode 100644 ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/Hologram.java delete mode 100644 ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/JsonBuilder.java delete mode 100644 ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/SpawnEggMeta.java delete mode 100644 ShopChest NMS-v1_9_R1/pom.xml delete mode 100644 ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/Hologram.java delete mode 100644 ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/JsonBuilder.java delete mode 100644 ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/SpawnEggMeta.java delete mode 100644 ShopChest NMS-v1_9_R2/pom.xml delete mode 100644 ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/Hologram.java delete mode 100644 ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/JsonBuilder.java delete mode 100644 ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/SpawnEggMeta.java delete mode 100644 ShopChest/dependency-reduced-pom.xml delete mode 100644 ShopChest/pom.xml delete mode 100644 ShopChest/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/ShopChest.java (85%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/ShopCommand.java (89%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/config/Config.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/config/LanguageConfiguration.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/config/Regex.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopBuySellEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopCreateEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopInfoEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopPreCreateEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopPreInfoEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopPreRemoveEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopReloadEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/event/ShopRemoveEvent.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/EnchantmentName.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/EntityName.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/ItemName.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/LanguageUtils.java (98%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/LocalizedMessage.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/MusicDiscName.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/PotionEffectName.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/language/PotionName.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/HologramUpdateListener.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java (100%) create mode 100644 src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java (100%) create mode 100644 src/main/java/de/epiceric/shopchest/nms/Hologram.java create mode 100644 src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java create mode 100644 src/main/java/de/epiceric/shopchest/nms/SpawnEggMeta.java rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/shop/Shop.java (90%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/sql/Database.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/sql/MySQL.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/sql/SQLite.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/utils/ClickType.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/utils/Metrics.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/utils/ShopUtils.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/utils/UpdateChecker.java (100%) rename {ShopChest/src => src}/main/java/de/epiceric/shopchest/utils/Utils.java (72%) rename {ShopChest/src => src}/main/resources/config.yml (100%) rename {ShopChest/src => src}/main/resources/item_names.txt (100%) rename {ShopChest/src => src}/main/resources/lang/de_DE.lang (100%) rename {ShopChest/src => src}/main/resources/lang/en_US.lang (100%) rename {ShopChest/src => src}/main/resources/plugin.yml (100%) diff --git a/ShopChest NMS-Abstract/pom.xml b/ShopChest NMS-Abstract/pom.xml deleted file mode 100644 index 4f3193e..0000000 --- a/ShopChest NMS-Abstract/pom.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-Abstract - - \ No newline at end of file diff --git a/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IHologram.java b/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IHologram.java deleted file mode 100644 index 233a94d..0000000 --- a/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IHologram.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.epiceric.shopchest.nms; - -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; - -public interface IHologram { - - /** - * @return Location of the hologram - */ - Location getLocation(); - - /** - * @param p Player to which the hologram should be shown - */ - void showPlayer(OfflinePlayer p); - - - /** - * @param p Player from which the hologram should be hidden - */ - void hidePlayer(OfflinePlayer p); - - /** - * @param p Player to check - * @return Whether the hologram is visible to the player - */ - boolean isVisible(OfflinePlayer p); - - /** - * @return Whether the hologram exists and is not dead - */ - boolean exists(); - - /** - * Removes the hologram.
- * IHologram will be hidden from all players and will be killed - */ - void remove(); - -} diff --git a/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IJsonBuilder.java b/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IJsonBuilder.java deleted file mode 100644 index a699792..0000000 --- a/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/IJsonBuilder.java +++ /dev/null @@ -1,94 +0,0 @@ -package de.epiceric.shopchest.nms; - -import com.google.common.collect.ImmutableMap; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - -public abstract class IJsonBuilder { - - public abstract void sendJson(Player p); - - private List extras = new ArrayList<>(); - - public IJsonBuilder parse(String text, String hoverText, String downloadLink) { - 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, hoverText).withClickEvent(ClickAction.OPEN_URL, 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, hoverText).withClickEvent(ClickAction.OPEN_URL, downloadLink); - } catch (Exception e) {} - index += word.length() + 2; - } - return this; - } - - private IJsonBuilder withText(String text) { - extras.add("{\"text\":\"" + text + "\"}"); - return this; - } - - private IJsonBuilder withColor(ChatColor color) { - String c = color.name().toLowerCase(); - addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); - return this; - } - - private IJsonBuilder withColor(String color) { - while (color.length() != 1) color = color.substring(1).trim(); - withColor(ChatColor.getByChar(color)); - return this; - } - - private IJsonBuilder withClickEvent(ClickAction action, String value) { - addSegment("\"clickEvent\":{\"action\":\"" + action.toString().toLowerCase() - + "\",\"value\":\"" + value + "\"}"); - return this; - } - - private IJsonBuilder 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; - } - - private enum ClickAction { - RUN_COMMAND, SUGGEST_COMMAND, OPEN_URL - } - - private enum HoverAction { - SHOW_TEXT - } - -} diff --git a/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/ISpawnEggMeta.java b/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/ISpawnEggMeta.java deleted file mode 100644 index ed86959..0000000 --- a/ShopChest NMS-Abstract/src/main/java/de/epiceric/shopchest/nms/ISpawnEggMeta.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.epiceric.shopchest.nms; - -import org.bukkit.entity.EntityType; - -public abstract class ISpawnEggMeta { - - /** - * @return The NBT Tag EntityTag.id of the Spawn Egg - */ - public abstract String getNBTEntityID(); - - /** - * @param nbtEntityID EntityID returned by {@link #getNBTEntityID()} - * @return The {@link EntityType} the Spawn Egg will spawn or null if nbtEntityID is null - */ - public EntityType getEntityTypeFromNBTEntityID(String nbtEntityID) { - if (nbtEntityID == null) return null; - - switch (nbtEntityID) { - case "PigZombie": - return EntityType.PIG_ZOMBIE; - case "CaveSpider": - return EntityType.CAVE_SPIDER; - case "LavaSlime": - return EntityType.MAGMA_CUBE; - case "MushroomCow": - return EntityType.MUSHROOM_COW; - case "EntityHorse": - return EntityType.HORSE; - case "PolarBear": - return EntityType.POLAR_BEAR; - default: - return EntityType.valueOf(nbtEntityID.toUpperCase()); - - } - } - -} - diff --git a/ShopChest NMS-v1_10_R1/pom.xml b/ShopChest NMS-v1_10_R1/pom.xml deleted file mode 100644 index 4bcb3d5..0000000 --- a/ShopChest NMS-v1_10_R1/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-v1_10_R1 - - - - org.bukkit - craftbukkit - 1.10-R0.1-SNAPSHOT - provided - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - provided - - - - \ No newline at end of file diff --git a/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/Hologram.java b/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/Hologram.java deleted file mode 100644 index 51c7a26..0000000 --- a/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/Hologram.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.epiceric.shopchest.nms.v1_10_R1; - -import de.epiceric.shopchest.nms.IHologram; -import net.minecraft.server.v1_10_R1.EntityArmorStand; -import net.minecraft.server.v1_10_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_10_R1.PacketPlayOutSpawnEntityLiving; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; - -import java.util.ArrayList; -import java.util.List; - -public class Hologram implements IHologram { - - private boolean exists = false; - private int count; - private List entityList = new ArrayList<>(); - private String[] text; - private Location location; - private List visible = new ArrayList<>(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Location getLocation() { - return location; - } - - 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.add(p); - } - - 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.remove(p); - } - - public boolean isVisible(OfflinePlayer p) { - return visible.contains(p); - } - - 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.setNoGravity(true); - entityList.add(entity); - this.location.subtract(0, 0.25, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, 0.25, 0); - } - - count = 0; - exists = true; - } - - public boolean exists() { - return exists; - } - - public void remove() { - for (EntityArmorStand e : entityList) { - e.die(); - } - exists = false; - } - -} diff --git a/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/JsonBuilder.java b/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/JsonBuilder.java deleted file mode 100644 index 3273466..0000000 --- a/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/JsonBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.epiceric.shopchest.nms.v1_10_R1; - -import de.epiceric.shopchest.nms.IJsonBuilder; -import net.minecraft.server.v1_10_R1.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_10_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class JsonBuilder extends IJsonBuilder { - - public JsonBuilder(String text, String hoverText, String downloadLink) { - parse(text, hoverText, downloadLink); - } - - @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/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/SpawnEggMeta.java b/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/SpawnEggMeta.java deleted file mode 100644 index 97f8d4b..0000000 --- a/ShopChest NMS-v1_10_R1/src/main/java/de/epiceric/shopchest/nms/v1_10_R1/SpawnEggMeta.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.epiceric.shopchest.nms.v1_10_R1; - -import de.epiceric.shopchest.nms.ISpawnEggMeta; -import net.minecraft.server.v1_10_R1.NBTTagCompound; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class SpawnEggMeta extends ISpawnEggMeta { - - private ItemStack stack; - - public SpawnEggMeta(ItemStack stack) { - this.stack = stack; - } - - public String getNBTEntityID() { - net.minecraft.server.v1_10_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); - - NBTTagCompound tag = nmsStack.getTag(); - - return tag == null ? null : tag.getCompound("EntityTag").getString("id"); - } -} \ No newline at end of file diff --git a/ShopChest NMS-v1_8_R1/pom.xml b/ShopChest NMS-v1_8_R1/pom.xml deleted file mode 100644 index f399ffa..0000000 --- a/ShopChest NMS-v1_8_R1/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-v1_8_R1 - - - - org.bukkit - craftbukkit - 1.8-R0.1-SNAPSHOT - provided - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - provided - - - - \ No newline at end of file diff --git a/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/Hologram.java b/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/Hologram.java deleted file mode 100644 index c6ce62a..0000000 --- a/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/Hologram.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R1; - -import de.epiceric.shopchest.nms.IHologram; -import net.minecraft.server.v1_8_R1.EntityArmorStand; -import net.minecraft.server.v1_8_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_8_R1.PacketPlayOutSpawnEntityLiving; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_8_R1.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; - -import java.util.ArrayList; -import java.util.List; - -public class Hologram implements IHologram { - - private boolean exists = false; - private int count; - private List entityList = new ArrayList<>(); - private String[] text; - private Location location; - private List visible = new ArrayList<>(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Location getLocation() { - return location; - } - - 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.add(p); - } - - 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.remove(p); - } - - public boolean isVisible(OfflinePlayer p) { - return visible.contains(p); - } - - 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, 0.25, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, 0.25, 0); - } - - count = 0; - exists = true; - } - - public boolean exists() { - return exists; - } - - public void remove() { - for (EntityArmorStand e : entityList) { - e.die(); - } - exists = false; - } - -} diff --git a/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/JsonBuilder.java b/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/JsonBuilder.java deleted file mode 100644 index 0feb56a..0000000 --- a/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/JsonBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R1; - -import de.epiceric.shopchest.nms.IJsonBuilder; -import net.minecraft.server.v1_8_R1.ChatSerializer; -import net.minecraft.server.v1_8_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class JsonBuilder extends IJsonBuilder { - - public JsonBuilder(String text, String hoverText, String downloadLink) { - parse(text, hoverText, downloadLink); - } - - @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/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/SpawnEggMeta.java b/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/SpawnEggMeta.java deleted file mode 100644 index a713267..0000000 --- a/ShopChest NMS-v1_8_R1/src/main/java/de/epiceric/shopchest/nms/v1_8_R1/SpawnEggMeta.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R1; - -import de.epiceric.shopchest.nms.ISpawnEggMeta; -import net.minecraft.server.v1_8_R1.NBTTagCompound; -import org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class SpawnEggMeta extends ISpawnEggMeta { - - private ItemStack stack; - - public SpawnEggMeta(ItemStack stack) { - this.stack = stack; - } - - public String getNBTEntityID() { - net.minecraft.server.v1_8_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); - - NBTTagCompound tag = nmsStack.getTag(); - - return tag == null ? null : tag.getCompound("EntityTag").getString("id"); - } -} \ No newline at end of file diff --git a/ShopChest NMS-v1_8_R2/pom.xml b/ShopChest NMS-v1_8_R2/pom.xml deleted file mode 100644 index e30ab88..0000000 --- a/ShopChest NMS-v1_8_R2/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-v1_8_R2 - - - - org.bukkit - craftbukkit - 1.8.3-R0.1-SNAPSHOT - provided - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - provided - - - - - \ No newline at end of file diff --git a/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/Hologram.java b/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/Hologram.java deleted file mode 100644 index e321026..0000000 --- a/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/Hologram.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R2; - -import de.epiceric.shopchest.nms.IHologram; -import net.minecraft.server.v1_8_R2.EntityArmorStand; -import net.minecraft.server.v1_8_R2.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_8_R2.PacketPlayOutSpawnEntityLiving; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.craftbukkit.v1_8_R2.CraftWorld; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; - -import java.util.ArrayList; -import java.util.List; - -public class Hologram implements IHologram { - - private boolean exists = false; - private int count; - private List entityList = new ArrayList<>(); - private String[] text; - private Location location; - private List visible = new ArrayList<>(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Location getLocation() { - return location; - } - - 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.add(p); - } - - 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.remove(p); - } - - public boolean isVisible(OfflinePlayer p) { - return visible.contains(p); - } - - 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, 0.25, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, 0.25, 0); - } - - count = 0; - exists = true; - } - - public boolean exists() { - return exists; - } - - public void remove() { - for (EntityArmorStand e : entityList) { - e.die(); - } - exists = false; - } - -} diff --git a/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/JsonBuilder.java b/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/JsonBuilder.java deleted file mode 100644 index ed19d5e..0000000 --- a/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/JsonBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R2; - -import de.epiceric.shopchest.nms.IJsonBuilder; -import net.minecraft.server.v1_8_R2.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_8_R2.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class JsonBuilder extends IJsonBuilder { - - public JsonBuilder(String text, String hoverText, String downloadLink) { - parse(text, hoverText, downloadLink); - } - - @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/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/SpawnEggMeta.java b/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/SpawnEggMeta.java deleted file mode 100644 index 3508407..0000000 --- a/ShopChest NMS-v1_8_R2/src/main/java/de/epiceric/shopchest/nms/v1_8_R2/SpawnEggMeta.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R2; - -import de.epiceric.shopchest.nms.ISpawnEggMeta; -import net.minecraft.server.v1_8_R2.NBTTagCompound; -import org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class SpawnEggMeta extends ISpawnEggMeta { - - private ItemStack stack; - - public SpawnEggMeta(ItemStack stack) { - this.stack = stack; - } - - public String getNBTEntityID() { - net.minecraft.server.v1_8_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); - - NBTTagCompound tag = nmsStack.getTag(); - - return tag == null ? null : tag.getCompound("EntityTag").getString("id"); - } -} \ No newline at end of file diff --git a/ShopChest NMS-v1_8_R3/pom.xml b/ShopChest NMS-v1_8_R3/pom.xml deleted file mode 100644 index 12b9bfa..0000000 --- a/ShopChest NMS-v1_8_R3/pom.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-v1_8_R3 - - - - org.bukkit - craftbukkit - 1.8.8-R0.1-SNAPSHOT - provided - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - provided - - - - - \ No newline at end of file diff --git a/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/Hologram.java b/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/Hologram.java deleted file mode 100644 index 088119c..0000000 --- a/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/Hologram.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R3; - -import de.epiceric.shopchest.nms.IHologram; -import net.minecraft.server.v1_8_R3.EntityArmorStand; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_8_R3.PacketPlayOutSpawnEntityLiving; -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 java.util.ArrayList; -import java.util.List; - -public class Hologram implements IHologram { - - private boolean exists = false; - private int count; - private List entityList = new ArrayList<>(); - private String[] text; - private Location location; - private List visible = new ArrayList<>(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Location getLocation() { - return location; - } - - 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.add(p); - } - - 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.remove(p); - } - - public boolean isVisible(OfflinePlayer p) { - return visible.contains(p); - } - - 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, 0.25, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, 0.25, 0); - } - - count = 0; - exists = true; - } - - public boolean exists() { - return exists; - } - - public void remove() { - for (EntityArmorStand e : entityList) { - e.die(); - } - exists = false; - } - -} diff --git a/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/JsonBuilder.java b/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/JsonBuilder.java deleted file mode 100644 index 1d94a36..0000000 --- a/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/JsonBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R3; - -import de.epiceric.shopchest.nms.IJsonBuilder; -import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class JsonBuilder extends IJsonBuilder { - - public JsonBuilder(String text, String hoverText, String downloadLink) { - parse(text, hoverText, downloadLink); - } - - @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/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/SpawnEggMeta.java b/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/SpawnEggMeta.java deleted file mode 100644 index 5b3fd82..0000000 --- a/ShopChest NMS-v1_8_R3/src/main/java/de/epiceric/shopchest/nms/v1_8_R3/SpawnEggMeta.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.epiceric.shopchest.nms.v1_8_R3; - -import de.epiceric.shopchest.nms.ISpawnEggMeta; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class SpawnEggMeta extends ISpawnEggMeta { - - private ItemStack stack; - - public SpawnEggMeta(ItemStack stack) { - this.stack = stack; - } - - public String getNBTEntityID() { - net.minecraft.server.v1_8_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); - - NBTTagCompound tag = nmsStack.getTag(); - - return tag == null ? null : tag.getCompound("EntityTag").getString("id"); - } -} \ No newline at end of file diff --git a/ShopChest NMS-v1_9_R1/pom.xml b/ShopChest NMS-v1_9_R1/pom.xml deleted file mode 100644 index 69a138e..0000000 --- a/ShopChest NMS-v1_9_R1/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-v1_9_R1 - - - - org.bukkit - craftbukkit - 1.9.2-R0.1-SNAPSHOT - provided - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - provided - - - - \ No newline at end of file diff --git a/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/Hologram.java b/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/Hologram.java deleted file mode 100644 index 4d52529..0000000 --- a/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/Hologram.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.epiceric.shopchest.nms.v1_9_R1; - -import de.epiceric.shopchest.nms.IHologram; -import net.minecraft.server.v1_9_R1.EntityArmorStand; -import net.minecraft.server.v1_9_R1.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_9_R1.PacketPlayOutSpawnEntityLiving; -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 java.util.ArrayList; -import java.util.List; - -public class Hologram implements IHologram { - - private boolean exists = false; - private int count; - private List entityList = new ArrayList<>(); - private String[] text; - private Location location; - private List visible = new ArrayList<>(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Location getLocation() { - return location; - } - - 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.add(p); - } - - 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.remove(p); - } - - public boolean isVisible(OfflinePlayer p) { - return visible.contains(p); - } - - 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, 0.25, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, 0.25, 0); - } - - count = 0; - exists = true; - } - - public boolean exists() { - return exists; - } - - public void remove() { - for (EntityArmorStand e : entityList) { - e.die(); - } - exists = false; - } - -} diff --git a/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/JsonBuilder.java b/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/JsonBuilder.java deleted file mode 100644 index 15a19d4..0000000 --- a/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/JsonBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.epiceric.shopchest.nms.v1_9_R1; - -import de.epiceric.shopchest.nms.IJsonBuilder; -import net.minecraft.server.v1_9_R1.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_9_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class JsonBuilder extends IJsonBuilder { - - public JsonBuilder(String text, String hoverText, String downloadLink) { - parse(text, hoverText, downloadLink); - } - - @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/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/SpawnEggMeta.java b/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/SpawnEggMeta.java deleted file mode 100644 index 7e307f0..0000000 --- a/ShopChest NMS-v1_9_R1/src/main/java/de/epiceric/shopchest/nms/v1_9_R1/SpawnEggMeta.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.epiceric.shopchest.nms.v1_9_R1; - -import de.epiceric.shopchest.nms.ISpawnEggMeta; -import net.minecraft.server.v1_9_R1.NBTTagCompound; -import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class SpawnEggMeta extends ISpawnEggMeta { - - private ItemStack stack; - - public SpawnEggMeta(ItemStack stack) { - this.stack = stack; - } - - public String getNBTEntityID() { - net.minecraft.server.v1_9_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); - - NBTTagCompound tag = nmsStack.getTag(); - - return tag == null ? null : tag.getCompound("EntityTag").getString("id"); - } -} \ No newline at end of file diff --git a/ShopChest NMS-v1_9_R2/pom.xml b/ShopChest NMS-v1_9_R2/pom.xml deleted file mode 100644 index d43be7a..0000000 --- a/ShopChest NMS-v1_9_R2/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest_NMS-v1_9_R2 - - - - org.bukkit - craftbukkit - 1.9.4-R0.1-SNAPSHOT - provided - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - provided - - - - \ No newline at end of file diff --git a/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/Hologram.java b/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/Hologram.java deleted file mode 100644 index 9f0a404..0000000 --- a/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/Hologram.java +++ /dev/null @@ -1,87 +0,0 @@ -package de.epiceric.shopchest.nms.v1_9_R2; - -import de.epiceric.shopchest.nms.IHologram; -import net.minecraft.server.v1_9_R2.EntityArmorStand; -import net.minecraft.server.v1_9_R2.PacketPlayOutEntityDestroy; -import net.minecraft.server.v1_9_R2.PacketPlayOutSpawnEntityLiving; -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 java.util.ArrayList; -import java.util.List; - -public class Hologram implements IHologram { - - private boolean exists = false; - private int count; - private List entityList = new ArrayList<>(); - private String[] text; - private Location location; - private List visible = new ArrayList<>(); - - public Hologram(String[] text, Location location) { - this.text = text; - this.location = location; - create(); - } - - public Location getLocation() { - return location; - } - - 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.add(p); - } - - 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.remove(p); - } - - public boolean isVisible(OfflinePlayer p) { - return visible.contains(p); - } - - 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, 0.25, 0); - count++; - } - - for (int i = 0; i < count; i++) { - this.location.add(0, 0.25, 0); - } - - count = 0; - exists = true; - } - - public boolean exists() { - return exists; - } - - public void remove() { - for (EntityArmorStand e : entityList) { - e.die(); - } - exists = false; - } - -} diff --git a/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/JsonBuilder.java b/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/JsonBuilder.java deleted file mode 100644 index 7c5c1d9..0000000 --- a/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/JsonBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.epiceric.shopchest.nms.v1_9_R2; - -import de.epiceric.shopchest.nms.IJsonBuilder; -import net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer; -import net.minecraft.server.v1_9_R2.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - -public class JsonBuilder extends IJsonBuilder { - - public JsonBuilder(String text, String hoverText, String downloadLink) { - parse(text, hoverText, downloadLink); - } - - @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/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/SpawnEggMeta.java b/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/SpawnEggMeta.java deleted file mode 100644 index 8e1e799..0000000 --- a/ShopChest NMS-v1_9_R2/src/main/java/de/epiceric/shopchest/nms/v1_9_R2/SpawnEggMeta.java +++ /dev/null @@ -1,23 +0,0 @@ -package de.epiceric.shopchest.nms.v1_9_R2; - -import de.epiceric.shopchest.nms.ISpawnEggMeta; -import net.minecraft.server.v1_9_R2.NBTTagCompound; -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; -import org.bukkit.inventory.ItemStack; - -public class SpawnEggMeta extends ISpawnEggMeta { - - private ItemStack stack; - - public SpawnEggMeta(ItemStack stack) { - this.stack = stack; - } - - public String getNBTEntityID() { - net.minecraft.server.v1_9_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack); - - NBTTagCompound tag = nmsStack.getTag(); - - return tag == null ? null : tag.getCompound("EntityTag").getString("id"); - } -} \ No newline at end of file diff --git a/ShopChest/dependency-reduced-pom.xml b/ShopChest/dependency-reduced-pom.xml deleted file mode 100644 index 9b29adb..0000000 --- a/ShopChest/dependency-reduced-pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - ShopChest - - - org.spigotmc - spigot-api - 1.10.2-R0.1-SNAPSHOT - provided - - - commons-lang - commons-lang - - - json-simple - com.googlecode.json-simple - - - guava - com.google.guava - - - gson - com.google.code.gson - - - ebean - org.avaje - - - snakeyaml - org.yaml - - - bungeecord-chat - net.md-5 - - - - - net.milkbowl.vault - VaultAPI - 1.6 - provided - - - bukkit - org.bukkit - - - - - me.minebuilders - clearlag - 2.9.1 - provided - - - com.griefcraft.lwc - lwc-entity-locking - 1.7.3 - provided - - - - diff --git a/ShopChest/pom.xml b/ShopChest/pom.xml deleted file mode 100644 index 0c91a31..0000000 --- a/ShopChest/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - ShopChest-Root - de.epiceric - 1.9.1 - - 4.0.0 - - ShopChest - - - - de.epiceric - ShopChest_NMS-Abstract - ${project.parent.version} - - - de.epiceric - ShopChest_NMS-v1_8_R1 - ${project.parent.version} - - - de.epiceric - ShopChest_NMS-v1_8_R2 - ${project.parent.version} - - - de.epiceric - ShopChest_NMS-v1_8_R3 - ${project.parent.version} - - - de.epiceric - ShopChest_NMS-v1_9_R1 - ${project.parent.version} - - - de.epiceric - ShopChest_NMS-v1_9_R2 - ${project.parent.version} - - - de.epiceric - ShopChest_NMS-v1_10_R1 - ${project.parent.version} - - - - \ No newline at end of file diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java b/ShopChest/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java deleted file mode 100644 index 90d46b4..0000000 --- a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java +++ /dev/null @@ -1,62 +0,0 @@ -package de.epiceric.shopchest.listeners; - -import de.epiceric.shopchest.ShopChest; -import de.epiceric.shopchest.config.Regex; -import de.epiceric.shopchest.language.LanguageUtils; -import de.epiceric.shopchest.language.LocalizedMessage; -import de.epiceric.shopchest.nms.IJsonBuilder; -import de.epiceric.shopchest.utils.Utils; -import net.milkbowl.vault.permission.Permission; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class NotifyUpdateOnJoinListener implements Listener { - - private ShopChest plugin; - private Permission perm; - - public NotifyUpdateOnJoinListener(ShopChest plugin) { - this.plugin = plugin; - perm = plugin.getPermission(); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - - Player p = e.getPlayer(); - - if (plugin.isUpdateNeeded()) { - if (p.isOp() || perm.has(p, "shopchest.notification.update")) { - IJsonBuilder jb; - - switch (Utils.getServerVersion()) { - case "v1_8_R1": - jb = new de.epiceric.shopchest.nms.v1_8_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); - break; - case "v1_8_R2": - jb = new de.epiceric.shopchest.nms.v1_8_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); - break; - case "v1_8_R3": - jb = new de.epiceric.shopchest.nms.v1_8_R3.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); - break; - case "v1_9_R1": - jb = new de.epiceric.shopchest.nms.v1_9_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); - break; - case "v1_9_R2": - jb = new de.epiceric.shopchest.nms.v1_9_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); - break; - case "v1_10_R1": - jb = new de.epiceric.shopchest.nms.v1_10_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); - break; - default: - return; - } - jb.sendJson(p); - } - } - - } - -} diff --git a/pom.xml b/pom.xml index 3f65f79..8e441d4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,11 +5,12 @@ 4.0.0 de.epiceric - ShopChest-Root - pom + ShopChest + jar 1.9.1 ShopChest https://www.spigotmc.org/resources/shopchest.11431/ + Let your players create their own nice-looking shops to sell their stuff to other players! 1.7 @@ -18,17 +19,6 @@ github - - ShopChest - ShopChest NMS-Abstract - ShopChest NMS-v1_8_R1 - ShopChest NMS-v1_8_R2 - ShopChest NMS-v1_8_R3 - ShopChest NMS-v1_9_R1 - ShopChest NMS-v1_9_R2 - ShopChest NMS-v1_10_R1 - - spigot-repo @@ -89,37 +79,12 @@ - - org.apache.maven.plugins - maven-shade-plugin - 2.4.3 - - - package - - shade - - - - org.apache.maven.plugins maven-javadoc-plugin 2.10.4 - aggregate - - aggregate - - site - - ShopChest ${project.version} API - ShopChest ${project.version} API - - - - jar jar diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java b/src/main/java/de/epiceric/shopchest/ShopChest.java similarity index 85% rename from ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java rename to src/main/java/de/epiceric/shopchest/ShopChest.java index a09cf0a..81799c1 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/ShopChest.java +++ b/src/main/java/de/epiceric/shopchest/ShopChest.java @@ -6,7 +6,7 @@ import de.epiceric.shopchest.event.ShopReloadEvent; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LocalizedMessage; import de.epiceric.shopchest.listeners.*; -import de.epiceric.shopchest.nms.IJsonBuilder; +import de.epiceric.shopchest.nms.JsonBuilder; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.sql.Database; @@ -255,29 +255,7 @@ public class ShopChest extends JavaPlugin { for (Player p : getServer().getOnlinePlayers()) { if (p.isOp() || perm.has(p, "shopchest.notification.update")) { - IJsonBuilder jb; - switch (Utils.getServerVersion()) { - case "v1_8_R1": - jb = new de.epiceric.shopchest.nms.v1_8_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); - break; - case "v1_8_R2": - jb = new de.epiceric.shopchest.nms.v1_8_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); - break; - case "v1_8_R3": - jb = new de.epiceric.shopchest.nms.v1_8_R3.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); - break; - case "v1_9_R1": - jb = new de.epiceric.shopchest.nms.v1_9_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); - break; - case "v1_9_R2": - jb = new de.epiceric.shopchest.nms.v1_9_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); - break; - case "v1_10_R1": - jb = new de.epiceric.shopchest.nms.v1_10_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); - break; - default: - return; - } + JsonBuilder jb = new JsonBuilder(ShopChest.this, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, latestVersion)), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), downloadLink); jb.sendJson(p); } } diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/ShopCommand.java b/src/main/java/de/epiceric/shopchest/ShopCommand.java similarity index 89% rename from ShopChest/src/main/java/de/epiceric/shopchest/ShopCommand.java rename to src/main/java/de/epiceric/shopchest/ShopCommand.java index d2f55d8..b0da1e2 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/ShopCommand.java +++ b/src/main/java/de/epiceric/shopchest/ShopCommand.java @@ -7,7 +7,7 @@ import de.epiceric.shopchest.event.ShopPreRemoveEvent; import de.epiceric.shopchest.event.ShopReloadEvent; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LocalizedMessage; -import de.epiceric.shopchest.nms.IJsonBuilder; +import de.epiceric.shopchest.nms.JsonBuilder; import de.epiceric.shopchest.shop.Shop; import de.epiceric.shopchest.shop.Shop.ShopType; import de.epiceric.shopchest.utils.ClickType; @@ -15,7 +15,6 @@ import de.epiceric.shopchest.utils.ClickType.EnumClickType; import de.epiceric.shopchest.utils.ShopUtils; import de.epiceric.shopchest.utils.UpdateChecker; import de.epiceric.shopchest.utils.UpdateChecker.UpdateCheckerResult; -import de.epiceric.shopchest.utils.Utils; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -195,29 +194,7 @@ class ShopCommand extends BukkitCommand { plugin.setDownloadLink(uc.getLink()); plugin.setUpdateNeeded(true); - IJsonBuilder jb; - switch (Utils.getServerVersion()) { - case "v1_8_R1": - jb = new de.epiceric.shopchest.nms.v1_8_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); - break; - case "v1_8_R2": - jb = new de.epiceric.shopchest.nms.v1_8_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); - break; - case "v1_8_R3": - jb = new de.epiceric.shopchest.nms.v1_8_R3.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); - break; - case "v1_9_R1": - jb = new de.epiceric.shopchest.nms.v1_9_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); - break; - case "v1_9_R2": - jb = new de.epiceric.shopchest.nms.v1_9_R2.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); - break; - case "v1_10_R1": - jb = new de.epiceric.shopchest.nms.v1_10_R1.JsonBuilder(LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); - break; - default: - return; - } + JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, uc.getVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), uc.getLink()); jb.sendJson(player); } else if (result == UpdateCheckerResult.FALSE) { diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/config/Config.java b/src/main/java/de/epiceric/shopchest/config/Config.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/config/Config.java rename to src/main/java/de/epiceric/shopchest/config/Config.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/config/LanguageConfiguration.java b/src/main/java/de/epiceric/shopchest/config/LanguageConfiguration.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/config/LanguageConfiguration.java rename to src/main/java/de/epiceric/shopchest/config/LanguageConfiguration.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/config/Regex.java b/src/main/java/de/epiceric/shopchest/config/Regex.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/config/Regex.java rename to src/main/java/de/epiceric/shopchest/config/Regex.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopBuySellEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopBuySellEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopBuySellEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopBuySellEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopCreateEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopCreateEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopCreateEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopCreateEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopInfoEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopInfoEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopInfoEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopInfoEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopPreCreateEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopPreCreateEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopPreCreateEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopPreCreateEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopPreInfoEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopPreInfoEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopPreInfoEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopPreInfoEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopPreRemoveEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopPreRemoveEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopPreRemoveEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopPreRemoveEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopReloadEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopReloadEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopReloadEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopReloadEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/event/ShopRemoveEvent.java b/src/main/java/de/epiceric/shopchest/event/ShopRemoveEvent.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/event/ShopRemoveEvent.java rename to src/main/java/de/epiceric/shopchest/event/ShopRemoveEvent.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/EnchantmentName.java b/src/main/java/de/epiceric/shopchest/language/EnchantmentName.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/EnchantmentName.java rename to src/main/java/de/epiceric/shopchest/language/EnchantmentName.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/EntityName.java b/src/main/java/de/epiceric/shopchest/language/EntityName.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/EntityName.java rename to src/main/java/de/epiceric/shopchest/language/EntityName.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/ItemName.java b/src/main/java/de/epiceric/shopchest/language/ItemName.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/ItemName.java rename to src/main/java/de/epiceric/shopchest/language/ItemName.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java similarity index 98% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java rename to src/main/java/de/epiceric/shopchest/language/LanguageUtils.java index 6fb45eb..cc37898 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java +++ b/src/main/java/de/epiceric/shopchest/language/LanguageUtils.java @@ -3,7 +3,7 @@ package de.epiceric.shopchest.language; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.LanguageConfiguration; import de.epiceric.shopchest.config.Regex; -import de.epiceric.shopchest.nms.ISpawnEggMeta; +import de.epiceric.shopchest.nms.SpawnEggMeta; import de.epiceric.shopchest.utils.Utils; import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; @@ -995,33 +995,7 @@ public class LanguageUtils { for (ItemName itemName : itemNames) { if (itemName.getMaterial() == Material.MONSTER_EGG && material == Material.MONSTER_EGG) { - ISpawnEggMeta spawnEggMeta; - - switch (Utils.getServerVersion()) { - case "v1_8_R1": - spawnEggMeta = new de.epiceric.shopchest.nms.v1_8_R1.SpawnEggMeta(stack); - break; - case "v1_8_R2": - spawnEggMeta = new de.epiceric.shopchest.nms.v1_8_R2.SpawnEggMeta(stack); - break; - case "v1_8_R3": - spawnEggMeta = new de.epiceric.shopchest.nms.v1_8_R3.SpawnEggMeta(stack); - break; - case "v1_9_R1": - spawnEggMeta = new de.epiceric.shopchest.nms.v1_9_R1.SpawnEggMeta(stack); - break; - case "v1_9_R2": - spawnEggMeta = new de.epiceric.shopchest.nms.v1_9_R2.SpawnEggMeta(stack); - break; - case "v1_10_R1": - spawnEggMeta = new de.epiceric.shopchest.nms.v1_10_R1.SpawnEggMeta(stack); - break; - default: - return itemName.getLocalizedName(); - - } - - EntityType spawnedType = spawnEggMeta.getEntityTypeFromNBTEntityID(spawnEggMeta.getNBTEntityID()); + EntityType spawnedType = SpawnEggMeta.getEntityTypeFromItemStack(plugin, stack); for (EntityName entityName : entityNames) { if (entityName.getEntityType() == spawnedType) { diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java b/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java rename to src/main/java/de/epiceric/shopchest/language/LocalizedMessage.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/MusicDiscName.java b/src/main/java/de/epiceric/shopchest/language/MusicDiscName.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/MusicDiscName.java rename to src/main/java/de/epiceric/shopchest/language/MusicDiscName.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/PotionEffectName.java b/src/main/java/de/epiceric/shopchest/language/PotionEffectName.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/PotionEffectName.java rename to src/main/java/de/epiceric/shopchest/language/PotionEffectName.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/language/PotionName.java b/src/main/java/de/epiceric/shopchest/language/PotionName.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/language/PotionName.java rename to src/main/java/de/epiceric/shopchest/language/PotionName.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java rename to src/main/java/de/epiceric/shopchest/listeners/ChestProtectListener.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java b/src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java rename to src/main/java/de/epiceric/shopchest/listeners/ClearLagListener.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/HologramUpdateListener.java b/src/main/java/de/epiceric/shopchest/listeners/HologramUpdateListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/HologramUpdateListener.java rename to src/main/java/de/epiceric/shopchest/listeners/HologramUpdateListener.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java b/src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java rename to src/main/java/de/epiceric/shopchest/listeners/ItemCustomNameListener.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java b/src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java rename to src/main/java/de/epiceric/shopchest/listeners/ItemProtectListener.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java b/src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java rename to src/main/java/de/epiceric/shopchest/listeners/LWCMagnetListener.java diff --git a/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java b/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java new file mode 100644 index 0000000..a17770f --- /dev/null +++ b/src/main/java/de/epiceric/shopchest/listeners/NotifyUpdateOnJoinListener.java @@ -0,0 +1,38 @@ +package de.epiceric.shopchest.listeners; + +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.config.Regex; +import de.epiceric.shopchest.language.LanguageUtils; +import de.epiceric.shopchest.language.LocalizedMessage; +import de.epiceric.shopchest.nms.JsonBuilder; +import de.epiceric.shopchest.utils.Utils; +import net.milkbowl.vault.permission.Permission; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class NotifyUpdateOnJoinListener implements Listener { + + private ShopChest plugin; + private Permission perm; + + public NotifyUpdateOnJoinListener(ShopChest plugin) { + this.plugin = plugin; + perm = plugin.getPermission(); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + + if (plugin.isUpdateNeeded()) { + if (p.isOp() || perm.has(p, "shopchest.notification.update")) { + JsonBuilder jb = new JsonBuilder(plugin, LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_AVAILABLE, new LocalizedMessage.ReplacedRegex(Regex.VERSION, plugin.getLatestVersion())), LanguageUtils.getMessage(LocalizedMessage.Message.UPDATE_CLICK_TO_DOWNLOAD), plugin.getDownloadLink()); + jb.sendJson(p); + } + } + + } + +} diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java rename to src/main/java/de/epiceric/shopchest/listeners/ShopInteractListener.java diff --git a/src/main/java/de/epiceric/shopchest/nms/Hologram.java b/src/main/java/de/epiceric/shopchest/nms/Hologram.java new file mode 100644 index 0000000..1ef2858 --- /dev/null +++ b/src/main/java/de/epiceric/shopchest/nms/Hologram.java @@ -0,0 +1,166 @@ +package de.epiceric.shopchest.nms; + +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.utils.Utils; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +public class Hologram { + + private Class entityArmorStandClass; + private boolean exists = false; + private int count; + private List entityList = new ArrayList<>(); + private String[] text; + private Location location; + private List visible = new ArrayList<>(); + private ShopChest plugin; + + public Hologram(ShopChest plugin, String[] text, Location location) { + this.plugin = plugin; + this.text = text; + this.location = location; + + try { + entityArmorStandClass = Class.forName("net.minecraft.server." + Utils.getServerVersion() + ".EntityArmorStand"); + } catch (ClassNotFoundException e) { + plugin.debug("Could not find EntityArmorStand class"); + plugin.debug(e); + e.printStackTrace(); + return; + } + + create(); + } + + private void create() { + for (String text : this.text) { + try { + Class nmsWorldClass = Class.forName("net.minecraft.server." + Utils.getServerVersion() + ".World"); + + Object craftWorld = this.location.getWorld().getClass().cast(this.location.getWorld()); + Object nmsWorld = nmsWorldClass.cast(craftWorld.getClass().getMethod("getHandle").invoke(craftWorld)); + + Constructor entityArmorStandConstructor = entityArmorStandClass.getConstructor(nmsWorldClass, double.class, double.class, double.class); + Object entityArmorStand = entityArmorStandConstructor.newInstance(nmsWorld, this.location.getX(), this.location.getY(), this.getLocation().getZ()); + + entityArmorStandClass.getMethod("setCustomName", String.class).invoke(entityArmorStand, text); + entityArmorStandClass.getMethod("setCustomNameVisible", boolean.class).invoke(entityArmorStand, true); + entityArmorStandClass.getMethod("setInvisible", boolean.class).invoke(entityArmorStand, true); + + if (Utils.getMajorVersion() < 10) { + entityArmorStandClass.getMethod("setGravity", boolean.class).invoke(entityArmorStand, false); + } else { + entityArmorStandClass.getMethod("setNoGravity", boolean.class).invoke(entityArmorStand, true); + } + + entityList.add(entityArmorStand); + this.location.subtract(0, 0.25, 0); + count++; + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) { + plugin.debug("Could not create Hologram with reflection"); + plugin.debug(e); + e.printStackTrace(); + } + + + } + + for (int i = 0; i < count; i++) { + this.location.add(0, 0.25, 0); + } + + count = 0; + exists = true; + } + + /** + * @return Location of the hologram + */ + public Location getLocation() { + return location; + } + + /** + * @param p Player to which the hologram should be shown + */ + public void showPlayer(Player p) { + for (Object o : entityList) { + try { + Class packetClass = Class.forName("net.minecraft.server." + Utils.getServerVersion() + ".PacketPlayOutSpawnEntityLiving"); + Class entityLivingClass = Class.forName("net.minecraft.server." + Utils.getServerVersion() + ".EntityLiving"); + + Object entityLiving = entityLivingClass.cast(o); + Object packet = packetClass.getConstructor(entityLivingClass).newInstance(entityLiving); + + Utils.sendPacket(plugin, packet, p); + } catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { + plugin.debug("Could not show Hologram to player with reflection"); + plugin.debug(e); + e.printStackTrace(); + } + } + visible.add(p); + } + + /** + * @param p Player from which the hologram should be hidden + */ + public void hidePlayer(Player p) { + for (Object o : entityList) { + try { + Class packetClass = Class.forName("net.minecraft.server." + Utils.getServerVersion() + ".PacketPlayOutEntityDestroy"); + + int id = (int) entityArmorStandClass.getMethod("getId").invoke(o); + + Object packet = packetClass.getConstructor(int[].class).newInstance((Object) new int[] {id}); + + Utils.sendPacket(plugin, packet, p); + } catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException | ClassNotFoundException e) { + plugin.debug("Could not hide Hologram from player with reflection"); + plugin.debug(e); + e.printStackTrace(); + } + } + visible.remove(p); + } + + /** + * @param p Player to check + * @return Whether the hologram is visible to the player + */ + public boolean isVisible(Player p) { + return visible.contains(p); + } + + /** + * @return Whether the hologram exists and is not dead + */ + public boolean exists() { + return exists; + } + + /** + * Removes the hologram.
+ * IHologram will be hidden from all players and will be killed + */ + public void remove() { + for (Object o : entityList) { + try { + o.getClass().getMethod("die").invoke(o); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + plugin.debug("Could not remove Hologram with reflection"); + plugin.debug(e); + e.printStackTrace(); + } + } + exists = false; + } + +} diff --git a/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java b/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java new file mode 100644 index 0000000..752d37e --- /dev/null +++ b/src/main/java/de/epiceric/shopchest/nms/JsonBuilder.java @@ -0,0 +1,117 @@ +package de.epiceric.shopchest.nms; + +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.utils.Utils; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Pattern; + +public class JsonBuilder { + + private List extras = new ArrayList<>(); + private ShopChest plugin; + + public JsonBuilder(ShopChest plugin, String text, String hoverText, String downloadLink) { + this.plugin = plugin; + + parse(text, hoverText, downloadLink); + } + + private JsonBuilder parse(String text, String hoverText, String downloadLink) { + 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(hoverText).withClickEvent(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(hoverText).withClickEvent(downloadLink); + } catch (Exception e) {} + index += word.length() + 2; + } + return this; + } + + private JsonBuilder withText(String text) { + extras.add("{\"text\":\"" + text + "\"}"); + return this; + } + + private JsonBuilder withColor(ChatColor color) { + String c = color.name().toLowerCase(); + addSegment(color.isColor() ? "\"color\":\"" + c + "\"" : "\"" + c + "\"" + ":true"); + return this; + } + + private JsonBuilder withColor(String color) { + while (color.length() != 1) color = color.substring(1).trim(); + withColor(ChatColor.getByChar(color)); + return this; + } + + private JsonBuilder withClickEvent(String value) { + addSegment("\"clickEvent\":{\"action\":\"open_url" + + "\",\"value\":\"" + value + "\"}"); + return this; + } + + private JsonBuilder withHoverEvent(String value) { + addSegment("\"hoverEvent\":{\"action\":\"show_text" + + "\",\"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) { + try { + String version = Utils.getServerVersion(); + + Class iChatBaseComponentClass = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent"); + Class packetPlayOutChatClass = Class.forName("net.minecraft.server." + version + ".PacketPlayOutChat"); + Class chatSerializerClass; + + if (version.equals("v1_8_R1")) { + chatSerializerClass = Class.forName("net.minecraft.server." + version + ".ChatSerializer"); + } else { + chatSerializerClass = Class.forName("net.minecraft.server." + version + ".IChatBaseComponent$ChatSerializer"); + } + + Object iChatBaseComponent = chatSerializerClass.getMethod("a", String.class).invoke(null, toString()); + Object packetPlayOutChat = packetPlayOutChatClass.getConstructor(iChatBaseComponentClass).newInstance(iChatBaseComponent); + + Utils.sendPacket(plugin, packetPlayOutChat, p); + } catch (InstantiationException | InvocationTargetException | + IllegalAccessException | NoSuchMethodException | ClassNotFoundException e) { + plugin.debug("Failed to send packet with reflection"); + plugin.debug(e); + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/de/epiceric/shopchest/nms/SpawnEggMeta.java b/src/main/java/de/epiceric/shopchest/nms/SpawnEggMeta.java new file mode 100644 index 0000000..521dd57 --- /dev/null +++ b/src/main/java/de/epiceric/shopchest/nms/SpawnEggMeta.java @@ -0,0 +1,72 @@ +package de.epiceric.shopchest.nms; + +import de.epiceric.shopchest.ShopChest; +import de.epiceric.shopchest.utils.Utils; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +import java.lang.reflect.InvocationTargetException; + +public class SpawnEggMeta { + + private static String getNBTEntityID(ShopChest plugin, ItemStack stack) { + try { + Class craftItemStackClass = Class.forName("org.bukkit.craftbukkit." + Utils.getServerVersion() + ".inventory.CraftItemStack"); + + Object nmsStack = craftItemStackClass.getMethod("asNMSCopy", ItemStack.class).invoke(null, stack); + + Object nbtTagCompound = nmsStack.getClass().getMethod("getTag").invoke(nmsStack); + if (nbtTagCompound == null) return null; + + Object entityTagCompound = nbtTagCompound.getClass().getMethod("getCompound", String.class).invoke(nbtTagCompound, "EntityTag"); + if (entityTagCompound == null) return null; + + Object id = entityTagCompound.getClass().getMethod("getString", String.class).invoke(entityTagCompound, "id"); + if (id instanceof String) return (String) id; + + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { + plugin.debug("Could not get NBTEntityID with reflection"); + plugin.debug(e); + e.printStackTrace(); + } + + return null; + } + + /** + * @param stack {@link ItemStack} (Spawn Egg) of which the Entity should be gotten + * @return The {@link EntityType} the Spawn Egg will spawn or null if nbtEntityID is null + */ + public static EntityType getEntityTypeFromItemStack(ShopChest plugin, ItemStack stack) { + if (Utils.getMajorVersion() == 8) { + for (EntityType entityType : EntityType.values()) { + if (entityType.getTypeId() == stack.getDurability()) { + return entityType; + } + } + } + + String nbtEntityID = getNBTEntityID(plugin, stack); + + if (nbtEntityID == null) return null; + + switch (nbtEntityID) { + case "PigZombie": + return EntityType.PIG_ZOMBIE; + case "CaveSpider": + return EntityType.CAVE_SPIDER; + case "LavaSlime": + return EntityType.MAGMA_CUBE; + case "MushroomCow": + return EntityType.MUSHROOM_COW; + case "EntityHorse": + return EntityType.HORSE; + case "PolarBear": + return EntityType.POLAR_BEAR; + default: + return EntityType.valueOf(nbtEntityID.toUpperCase()); + + } + } + +} diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/shop/Shop.java b/src/main/java/de/epiceric/shopchest/shop/Shop.java similarity index 90% rename from ShopChest/src/main/java/de/epiceric/shopchest/shop/Shop.java rename to src/main/java/de/epiceric/shopchest/shop/Shop.java index 290b064..410e815 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/shop/Shop.java +++ b/src/main/java/de/epiceric/shopchest/shop/Shop.java @@ -4,7 +4,7 @@ import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Regex; import de.epiceric.shopchest.language.LanguageUtils; import de.epiceric.shopchest.language.LocalizedMessage; -import de.epiceric.shopchest.nms.IHologram; +import de.epiceric.shopchest.nms.Hologram; import de.epiceric.shopchest.utils.Utils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -31,7 +31,7 @@ public class Shop { private OfflinePlayer vendor; private ItemStack product; private Location location; - private IHologram hologram; + private Hologram hologram; private Item item; private double buyPrice; private double sellPrice; @@ -210,27 +210,7 @@ public class Shop { else holoText[1] = LanguageUtils.getMessage(LocalizedMessage.Message.HOLOGRAM_BUY_SELL, new LocalizedMessage.ReplacedRegex(Regex.BUY_PRICE, String.valueOf(buyPrice)), new LocalizedMessage.ReplacedRegex(Regex.SELL_PRICE, String.valueOf(sellPrice))); - switch (Utils.getServerVersion()) { - case "v1_8_R1": - hologram = new de.epiceric.shopchest.nms.v1_8_R1.Hologram(holoText, holoLocation); - break; - case "v1_8_R2": - hologram = new de.epiceric.shopchest.nms.v1_8_R2.Hologram(holoText, holoLocation); - break; - case "v1_8_R3": - hologram = new de.epiceric.shopchest.nms.v1_8_R3.Hologram(holoText, holoLocation); - break; - case "v1_9_R1": - hologram = new de.epiceric.shopchest.nms.v1_9_R1.Hologram(holoText, holoLocation); - break; - case "v1_9_R2": - hologram = new de.epiceric.shopchest.nms.v1_9_R2.Hologram(holoText, holoLocation); - break; - case "v1_10_R1": - hologram = new de.epiceric.shopchest.nms.v1_10_R1.Hologram(holoText, holoLocation); - break; - } - + hologram = new Hologram(plugin, holoText, holoLocation); } /** @@ -285,7 +265,7 @@ public class Shop { /** * @return Hologram of the shop */ - public IHologram getHologram() { + public Hologram getHologram() { return hologram; } diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/sql/Database.java b/src/main/java/de/epiceric/shopchest/sql/Database.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/sql/Database.java rename to src/main/java/de/epiceric/shopchest/sql/Database.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/sql/MySQL.java b/src/main/java/de/epiceric/shopchest/sql/MySQL.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/sql/MySQL.java rename to src/main/java/de/epiceric/shopchest/sql/MySQL.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/sql/SQLite.java b/src/main/java/de/epiceric/shopchest/sql/SQLite.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/sql/SQLite.java rename to src/main/java/de/epiceric/shopchest/sql/SQLite.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/utils/ClickType.java b/src/main/java/de/epiceric/shopchest/utils/ClickType.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/utils/ClickType.java rename to src/main/java/de/epiceric/shopchest/utils/ClickType.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/utils/Metrics.java b/src/main/java/de/epiceric/shopchest/utils/Metrics.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/utils/Metrics.java rename to src/main/java/de/epiceric/shopchest/utils/Metrics.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java b/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/utils/ShopUtils.java rename to src/main/java/de/epiceric/shopchest/utils/ShopUtils.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/utils/UpdateChecker.java b/src/main/java/de/epiceric/shopchest/utils/UpdateChecker.java similarity index 100% rename from ShopChest/src/main/java/de/epiceric/shopchest/utils/UpdateChecker.java rename to src/main/java/de/epiceric/shopchest/utils/UpdateChecker.java diff --git a/ShopChest/src/main/java/de/epiceric/shopchest/utils/Utils.java b/src/main/java/de/epiceric/shopchest/utils/Utils.java similarity index 72% rename from ShopChest/src/main/java/de/epiceric/shopchest/utils/Utils.java rename to src/main/java/de/epiceric/shopchest/utils/Utils.java index 6643e17..ca76da1 100644 --- a/ShopChest/src/main/java/de/epiceric/shopchest/utils/Utils.java +++ b/src/main/java/de/epiceric/shopchest/utils/Utils.java @@ -1,12 +1,15 @@ package de.epiceric.shopchest.utils; +import de.epiceric.shopchest.ShopChest; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.xml.bind.DatatypeConverter; +import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -50,6 +53,29 @@ public class Utils { return amount; } + /** + * Send a packet to a player + * @param packet Packet to send + * @param player Player to which the packet should be sent + * @return {@code true} if the packet was sent, or {@code false} if an exception was thrown + */ + public static boolean sendPacket(ShopChest plugin, Object packet, Player player) { + try { + Class packetClass = Class.forName("net.minecraft.server." + getServerVersion() + ".Packet"); + Object nmsPlayer = player.getClass().getMethod("getHandle").invoke(player); + Object playerConnection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer); + + playerConnection.getClass().getMethod("sendPacket", packetClass).invoke(playerConnection, packet); + + return true; + } catch (ClassNotFoundException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException | InvocationTargetException e) { + plugin.debug("Failed to send packet " + packet.getClass().getName()); + plugin.debug(e); + e.printStackTrace(); + return false; + } + } + /** * @return The current server version with revision number (e.g. v1_9_R2, v1_10_R1) */ diff --git a/ShopChest/src/main/resources/config.yml b/src/main/resources/config.yml similarity index 100% rename from ShopChest/src/main/resources/config.yml rename to src/main/resources/config.yml diff --git a/ShopChest/src/main/resources/item_names.txt b/src/main/resources/item_names.txt similarity index 100% rename from ShopChest/src/main/resources/item_names.txt rename to src/main/resources/item_names.txt diff --git a/ShopChest/src/main/resources/lang/de_DE.lang b/src/main/resources/lang/de_DE.lang similarity index 100% rename from ShopChest/src/main/resources/lang/de_DE.lang rename to src/main/resources/lang/de_DE.lang diff --git a/ShopChest/src/main/resources/lang/en_US.lang b/src/main/resources/lang/en_US.lang similarity index 100% rename from ShopChest/src/main/resources/lang/en_US.lang rename to src/main/resources/lang/en_US.lang diff --git a/ShopChest/src/main/resources/plugin.yml b/src/main/resources/plugin.yml similarity index 100% rename from ShopChest/src/main/resources/plugin.yml rename to src/main/resources/plugin.yml