diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..5fd5124 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,214 @@ + + + 4.0.0 + com.trophonix + TradePlus + 3.84 + + ${basedir}/src/main/java/ + + + . + true + ${basedir}/src/main/resources/ + + + ${project.artifactId}-${revision} + + + org.projectlombok + lombok-maven-plugin + 1.18.20.0 + + + generate-sources + + + + + maven-compiler-plugin + 3.2 + + 17 + 17 + + + + maven-shade-plugin + 3.5.1 + + + package + + shade + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + com.google.common + com.trophonix.tradeplus.shaded.guava + + + co.aikar.taskchain + com.trophonix.tradeplus.shaded.taskchain + + + net.wesjd.anvilgui + com.trophonix.tradeplus.shaded.anvilgui + + + org.codemc.worldguardwrapper + com.trophonix.tradeplus.shaded.worldguardwrapper + + + true + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + bungeecord-repo + https://oss.sonatype.org/content/repositories/snapshots + + + vault-repo + https://jitpack.io + + + minebench-repo + https://repo.minebench.de/ + + + jitpack.io + https://jitpack.io + + + savagefactions-repo + https://cdn.jsdelivr.net/gh/ProSavage/SavageFactions@1.6.x/ + + + aikar + https://repo.aikar.co/content/groups/aikar/ + + + codemc-repo + https://repo.codemc.org/repository/maven-public/ + + + + + org.spigotmc + spigot-api + 1.21-R0.1-SNAPSHOT + provided + + + org.projectlombok + lombok + 1.18.30 + provided + + + net.milkbowl.vault + VaultAPI + 1.7 + provided + + + com.github.ProSavage + SavageFactions + 1.6.3-RC + provided + + + com.github.Angeschossen + LandsAPI + 4.5.2.0 + provided + + + com.github.TechFortress + GriefPrevention + 16.7.1 + system + ${res}/GriefPrevention.jar + + + org.black_ixx + PlayerPoints + 3.1.0 + system + ${res}/PlayerPointsNew.jar + + + BeastTokens + BeastTokens + 2.0 + system + ${res}/BeastTokensAPI.jar + + + com.enjin.mc + enjin-mc-plugin + 3.4.3 + system + ${res}/EnjinMinecraftPlugin.jar + + + com.vk2gpz.tokenenchant + api + 10.0.0 + system + ${res}/TokenEnchantAPI.jar + + + com.github.kicjow + Crazy-Crates + v1.8.5 + system + ${res}/CrazyCrates.jar + + + com.github.Realizedd + TokenManager + 3.2.2 + system + ${res}/TokenManager.jar + + + com.github.Ben12345rocks + VotingPlugin + 6.6.2 + system + ${res}/VotingPlugin.jar + + + com.earth2me + essentials + 2.18.0.0 + system + ${res}/EssentialsX-2.18.0.0.jar + + + + ${project.basedir}/res/ + 3.84.5 + + diff --git a/pom.xml b/pom.xml index 574e307..cad298f 100644 --- a/pom.xml +++ b/pom.xml @@ -26,12 +26,7 @@ vault-repo - http://nexus.hc.to/content/repositories/pub_releases - - - - dakani - https://repo.dakanilabs.com/repository/maven-public/ + https://jitpack.io @@ -64,7 +59,7 @@ org.spigotmc spigot-api - 1.17.1-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT provided @@ -83,9 +78,9 @@ - com.github.WesJD.AnvilGUI + net.wesjd anvilgui - 478e0c196e + 1.10.2-SNAPSHOT compile @@ -99,7 +94,7 @@ org.projectlombok lombok - 1.18.20 + 1.18.30 provided @@ -218,7 +213,7 @@ org.projectlombok lombok-maven-plugin - 1.18.12.0 + 1.18.20.0 generate-sources @@ -231,15 +226,15 @@ maven-compiler-plugin 3.2 - 1.8 - 1.8 + 17 + 17 org.apache.maven.plugins maven-shade-plugin - 3.2.0 + 3.5.1 package diff --git a/src/main/java/com/trophonix/tradeplus/trade/Trade.java b/src/main/java/com/trophonix/tradeplus/trade/Trade.java index afe7966..30cc883 100644 --- a/src/main/java/com/trophonix/tradeplus/trade/Trade.java +++ b/src/main/java/com/trophonix/tradeplus/trade/Trade.java @@ -1049,14 +1049,17 @@ private boolean isBlocked(ItemStack item) { String type = item.getType().toString(); List checks = new ArrayList<>(); if (Sounds.version < 113) { + @SuppressWarnings("deprecation") byte data = item.getData().getData(); checks.add(type + ":" + data); checks.add(type.replace("_", "") + ":" + data); checks.add(type.replace("_", " ") + ":" + data); - try { // Throws exception for materials added after the flattening - checks.add(item.getType().getId() + ":" + data); - checks.add(Integer.toString(item.getType().getId())); - } catch (IllegalArgumentException ignored) { + try { + @SuppressWarnings("deprecation") + int materialId = item.getType().getId(); + checks.add(materialId + ":" + data); + checks.add(Integer.toString(materialId)); + } catch (IllegalArgumentException | NoSuchMethodError ignored) { } } checks.add(type); diff --git a/src/main/java/com/trophonix/tradeplus/util/InvUtils.java b/src/main/java/com/trophonix/tradeplus/util/InvUtils.java index fcd5d4b..a1b241b 100644 --- a/src/main/java/com/trophonix/tradeplus/util/InvUtils.java +++ b/src/main/java/com/trophonix/tradeplus/util/InvUtils.java @@ -56,7 +56,7 @@ public static Inventory getTradeInventory(Player player1, Player player2) { public static Inventory getSpectatorInventory(Player player1, Player player2) { String title = MsgUtils.color(pl.getTradeConfig().getSpectatorTitle()); - if (Sounds.version > 1.8) + if (Sounds.version > 18) title = title.replace("%PLAYER1%", player1.getName()).replace("%PLAYER2%", player2.getName()); Inventory inv = Bukkit.createInventory(new MenuInventoryHolder(), 54, title); ItemStack separator = pl.getTradeConfig().getSeparator().build(); diff --git a/src/main/java/com/trophonix/tradeplus/util/ItemFactory.java b/src/main/java/com/trophonix/tradeplus/util/ItemFactory.java index 0a8e21e..f4d512f 100644 --- a/src/main/java/com/trophonix/tradeplus/util/ItemFactory.java +++ b/src/main/java/com/trophonix/tradeplus/util/ItemFactory.java @@ -52,15 +52,33 @@ public ItemFactory(String parsable, Material fallback) { } if (data > 0) { - this.stack = new ItemStack(mat, 1, data, data); + if (Sounds.version >= 113) { + this.stack = new ItemStack(mat, 1); + ItemMeta meta = this.stack.getItemMeta(); + if (meta instanceof org.bukkit.inventory.meta.Damageable) { + ((org.bukkit.inventory.meta.Damageable) meta).setDamage(data); + this.stack.setItemMeta(meta); + } + } else { + this.stack = new ItemStack(mat, 1, data, data); + } } else { this.stack = new ItemStack(mat); } } } + @SuppressWarnings("deprecation") public ItemFactory damage(short damage) { - stack.setDurability(damage); + if (Sounds.version >= 113) { + ItemMeta meta = stack.getItemMeta(); + if (meta instanceof org.bukkit.inventory.meta.Damageable) { + ((org.bukkit.inventory.meta.Damageable) meta).setDamage(damage); + stack.setItemMeta(meta); + } + } else { + stack.setDurability(damage); + } return this; } diff --git a/src/main/java/com/trophonix/tradeplus/util/NMSManager.java b/src/main/java/com/trophonix/tradeplus/util/NMSManager.java index 46e6be5..1adb9d9 100644 --- a/src/main/java/com/trophonix/tradeplus/util/NMSManager.java +++ b/src/main/java/com/trophonix/tradeplus/util/NMSManager.java @@ -43,12 +43,22 @@ public static boolean classListEqual(Class[] Value1, Class[] Value2) { return true; } + public static boolean isModernNMS() { + return Sounds.isModernNMS; + } + public static String getVersion() { + if (isModernNMS()) { + return ""; + } String V = Bukkit.getServer().getClass().getPackage().getName(); return V.substring(V.lastIndexOf('.') + 1) + "."; } public static boolean useNewVersion() { + if (isModernNMS()) { + return true; + } try { Class.forName("net.minecraft.server." + getVersion() + "ContainerAccess"); return true; @@ -57,6 +67,18 @@ public static boolean useNewVersion() { } } + public static Class getCraftBukkitClass(String className) { + try { + if (isModernNMS()) { + return Class.forName("org.bukkit.craftbukkit." + className); + } + return Class.forName("org.bukkit.craftbukkit." + getVersion() + className); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static Field getField(Class Class, String Field) { try { Field F = Class.getDeclaredField(Field); @@ -69,13 +91,15 @@ public static Field getField(Class Class, String Field) { } public static Class getNMSClass(String ClassName) { - Class C = null; try { + if (isModernNMS()) { + return Class.forName("net.minecraft.server." + ClassName); + } return Class.forName("net.minecraft.server." + getVersion() + ClassName); } catch (Exception e) { e.printStackTrace(); + return null; } - return C; } public static Method getMethod(Class Class, String ClassName, Class... Parameters) { diff --git a/src/main/java/com/trophonix/tradeplus/util/Sounds.java b/src/main/java/com/trophonix/tradeplus/util/Sounds.java index 6012456..a978495 100644 --- a/src/main/java/com/trophonix/tradeplus/util/Sounds.java +++ b/src/main/java/com/trophonix/tradeplus/util/Sounds.java @@ -8,6 +8,7 @@ public class Sounds { public static final int version; + public static final boolean isModernNMS; private static Sound pling; private static Sound click; private static Sound levelUp; @@ -15,10 +16,35 @@ public class Sounds { private static Sound villagerHmm; static { - String[] split = - Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3].split("_"); - version = Integer.parseInt(split[0].replace("v", "") + split[1]); -// System.out.println("You appear to be running version " + version); + int ver = 0; + boolean modern = false; + + try { + String bukkitVersion = Bukkit.getBukkitVersion(); + String[] parts = bukkitVersion.split("-")[0].split("\\."); + int major = Integer.parseInt(parts[0]); + int minor = Integer.parseInt(parts[1]); + ver = major * 100 + minor; + + String packageName = Bukkit.getServer().getClass().getPackage().getName(); + modern = !packageName.contains("v1_"); + } catch (Exception e) { + try { + String packageName = Bukkit.getServer().getClass().getPackage().getName(); + if (packageName.contains("v1_")) { + String[] split = packageName.split("\\.")[3].split("_"); + ver = Integer.parseInt(split[0].replace("v", "") + split[1]); + } else { + ver = 120; + modern = true; + } + } catch (Exception ex) { + ver = 117; + } + } + + version = ver; + isModernNMS = modern; } public static void loadSounds() { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 01e76e3..8eb31f5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -3,7 +3,7 @@ version: ${project.version} author: Trophonix main: com.trophonix.tradeplus.TradePlus softdepend: [Vault,EnjinMinecraftPlugin,GriefPrevention,PlayerPoints,TokenManager,BeastTokens,TokenEnchant,WorldGuard,VotingPlugin] -api-version: "1.16" +api-version: "1.20" commands: trade: description: Trade command