From da807bef5e67b532449789565926c5e25c151779 Mon Sep 17 00:00:00 2001 From: Zrips Date: Sun, 20 Jun 2021 11:47:03 +0300 Subject: [PATCH] Removing NMS dependencies, more future version friendly --- .../gamingmesh/jobs/CMILib/CMIItemStack.java | 3 +- src/main/java/com/gamingmesh/jobs/Jobs.java | 36 ++---- src/main/java/com/gamingmesh/jobs/NMS.java | 29 ----- .../com/gamingmesh/jobs/PlayerManager.java | 2 +- .../jobs/actions/EntityActionInfo.java | 5 +- .../jobs/commands/list/edititembonus.java | 8 +- .../jobs/commands/list/editjobs.java | 2 +- .../jobs/commands/list/editquests.java | 2 +- .../jobs/commands/list/itembonus.java | 3 +- .../jobs/commands/list/iteminfo.java | 3 +- .../gamingmesh/jobs/config/ShopManager.java | 7 +- .../jobs/listeners/JobsListener.java | 5 +- .../jobs/listeners/JobsPaymentListener.java | 21 ++-- .../listeners/PistonProtectionListener.java | 3 +- .../com/gamingmesh/jobs/nmsUtil/v1_10.java | 94 ---------------- .../com/gamingmesh/jobs/nmsUtil/v1_11.java | 56 ---------- .../com/gamingmesh/jobs/nmsUtil/v1_12.java | 57 ---------- .../com/gamingmesh/jobs/nmsUtil/v1_13.java | 57 ---------- .../com/gamingmesh/jobs/nmsUtil/v1_14.java | 57 ---------- .../com/gamingmesh/jobs/nmsUtil/v1_15.java | 57 ---------- .../com/gamingmesh/jobs/nmsUtil/v1_16.java | 57 ---------- .../com/gamingmesh/jobs/nmsUtil/v1_7.java | 86 -------------- .../com/gamingmesh/jobs/nmsUtil/v1_8.java | 90 --------------- .../com/gamingmesh/jobs/nmsUtil/v1_9.java | 90 --------------- .../java/com/gamingmesh/jobs/stuff/Util.java | 105 +++++++++++++++++- 25 files changed, 147 insertions(+), 788 deletions(-) delete mode 100644 src/main/java/com/gamingmesh/jobs/NMS.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_10.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_13.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_14.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_15.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_16.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java delete mode 100644 src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/CMIItemStack.java b/src/main/java/com/gamingmesh/jobs/CMILib/CMIItemStack.java index 41de66f7..544d691e 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/CMIItemStack.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/CMIItemStack.java @@ -20,6 +20,7 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.stuff.Util; public class CMIItemStack { @@ -94,7 +95,7 @@ public class CMIItemStack { } public short getDurability() { - return Jobs.getNms().getDurability(getItemStack()); + return Util.getDurability(getItemStack()); } public short getMaxDurability() { diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index cb683338..5538291b 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -113,8 +113,6 @@ public class Jobs extends JavaPlugin { public static final Map FASTPAYMENT = new HashMap<>(); - private static NMS nms; - protected static VersionChecker versionCheckManager; protected static SelectionManager smanager; @@ -128,13 +126,13 @@ public class Jobs extends JavaPlugin { return kyoriSupported; } - /** - * Returns the block owner ship for specific {@link CMIMaterial} type. - * - * @param type {@link CMIMaterial} - * @see #getBlockOwnerShip(CMIMaterial, boolean) - * @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()} - */ + /** + * Returns the block owner ship for specific {@link CMIMaterial} type. + * + * @param type {@link CMIMaterial} + * @see #getBlockOwnerShip(CMIMaterial, boolean) + * @return {@link BlockOwnerShip}, otherwise {@link Optional#empty()} + */ public Optional getBlockOwnerShip(CMIMaterial type) { return getBlockOwnerShip(type, true); } @@ -275,10 +273,6 @@ public class Jobs extends JavaPlugin { return gConfigManager; } - public static NMS getNms() { - return nms; - } - /** * @return {@link PlayerManager} */ @@ -692,22 +686,6 @@ public class Jobs extends JavaPlugin { public void onEnable() { instance = this; - try { - Class nmsClass = Class.forName("com.gamingmesh.jobs.nmsUtil." + Version.getCurrent().getShortVersion()); - if (NMS.class.isAssignableFrom(nmsClass)) { - nms = (NMS) nmsClass.getConstructor().newInstance(); - } else { - System.out.println("Something went wrong, please note down version and contact author, version: " + Version.getCurrent().toString()); - setEnabled(false); - return; - } - } catch (Exception e) { - System.out.println("Your server version is not compatible with this plugins version! Plugin will be disabled: " + Version.getCurrent().toString()); - setEnabled(false); - e.printStackTrace(); - return; - } - try { Class.forName("net.kyori.adventure.text.Component"); org.bukkit.inventory.meta.ItemMeta.class.getDeclaredMethod("displayName"); diff --git a/src/main/java/com/gamingmesh/jobs/NMS.java b/src/main/java/com/gamingmesh/jobs/NMS.java deleted file mode 100644 index 1acf1330..00000000 --- a/src/main/java/com/gamingmesh/jobs/NMS.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.gamingmesh.jobs; - -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -public interface NMS { - - List getPistonRetractBlocks(BlockPistonRetractEvent event); - - String getRealType(Entity entity); - - ItemStack getItemInMainHand(Player player); - - void setItemInMainHand(Player player, ItemStack item); - - double getMaxHealth(LivingEntity entity); - - short getDurability(ItemStack item); - - void setSkullOwner(SkullMeta meta, OfflinePlayer player); -} diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 77183629..8831f461 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -956,7 +956,7 @@ public class PlayerManager { // Check mainhand slot if (Jobs.getGCManager().boostedItemsInMainHand) { - jitems.add(getJobsItemByNbt(Jobs.getNms().getItemInMainHand(player))); + jitems.add(getJobsItemByNbt(Util.getItemInMainHand(player))); } // Check offhand slot diff --git a/src/main/java/com/gamingmesh/jobs/actions/EntityActionInfo.java b/src/main/java/com/gamingmesh/jobs/actions/EntityActionInfo.java index e56db4d6..779cf775 100644 --- a/src/main/java/com/gamingmesh/jobs/actions/EntityActionInfo.java +++ b/src/main/java/com/gamingmesh/jobs/actions/EntityActionInfo.java @@ -19,9 +19,10 @@ package com.gamingmesh.jobs.actions; import org.bukkit.entity.Entity; -import com.gamingmesh.jobs.Jobs; + import com.gamingmesh.jobs.container.ActionType; import com.gamingmesh.jobs.container.BaseActionInfo; +import com.gamingmesh.jobs.stuff.Util; public class EntityActionInfo extends BaseActionInfo { private Entity entity; @@ -33,7 +34,7 @@ public class EntityActionInfo extends BaseActionInfo { @Override public String getName() { - return Jobs.getNms().getRealType(entity); + return Util.getRealType(entity); } @Override diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java index 622921e9..57783c9d 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/edititembonus.java @@ -15,11 +15,13 @@ import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.Util; public class edititembonus implements Cmd { private enum actions { list, add, remove; + public static actions getByname(String name) { for (actions one : actions.values()) { if (one.name().equalsIgnoreCase(name)) @@ -68,7 +70,7 @@ public class edititembonus implements Cmd { if (jPlayer == null) return false; - ItemStack iih = Jobs.getNms().getItemInMainHand(player); + ItemStack iih = Util.getItemInMainHand(player); if (iih == null || iih.getType() == Material.AIR) return false; @@ -77,13 +79,13 @@ public class edititembonus implements Cmd { if (jobitem == null) return false; iih = CMIReflections.setNbt(iih, "JobsItemBoost", jobitem.getNode()); - Jobs.getNms().setItemInMainHand(player, iih); + Util.setItemInMainHand(player, iih); break; case list: break; case remove: iih = Jobs.getReflections().removeNbt(iih, "JobsItemBoost"); - Jobs.getNms().setItemInMainHand(player, iih); + Util.setItemInMainHand(player, iih); break; default: break; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java index 7e4be811..d71c5c11 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editjobs.java @@ -335,7 +335,7 @@ public class editjobs implements Cmd { String key = args[3]; switch (args[3]) { case "hand": - ItemStack item = Jobs.getNms().getItemInMainHand(player); + ItemStack item = Util.getItemInMainHand(player); key = item.getType().name() + "-" + item.getData().getData(); break; case "offhand": diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java index d7d50779..5e68f167 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/editquests.java @@ -318,7 +318,7 @@ public class editquests implements Cmd { String key = args[4]; switch (args[4]) { case "hand": - ItemStack item = Jobs.getNms().getItemInMainHand(player); + ItemStack item = Util.getItemInMainHand(player); key = item.getType().name() + "-" + item.getData().getData(); break; case "offhand": diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java index f40e1623..22dfe6e2 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/itembonus.java @@ -16,6 +16,7 @@ import com.gamingmesh.jobs.container.Job; import com.gamingmesh.jobs.container.JobItems; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; import com.gamingmesh.jobs.CMILib.RawMessage; @@ -35,7 +36,7 @@ public class itembonus implements Cmd { if (jPlayer == null) return false; - ItemStack iih = Jobs.getNms().getItemInMainHand(player); + ItemStack iih = Util.getItemInMainHand(player); List items = new ArrayList<>(); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java b/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java index 46f4039f..f109c180 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/iteminfo.java @@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.Version; import com.gamingmesh.jobs.commands.Cmd; +import com.gamingmesh.jobs.stuff.Util; public class iteminfo implements Cmd { @@ -24,7 +25,7 @@ public class iteminfo implements Cmd { return true; } - ItemStack iih = Jobs.getNms().getItemInMainHand((Player) sender); + ItemStack iih = Util.getItemInMainHand((Player) sender); if (iih == null || iih.getType() == Material.AIR) return true; diff --git a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java index f8459c4a..1e2cbdf9 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java @@ -37,6 +37,7 @@ import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsPlayer; import com.gamingmesh.jobs.container.ShopItem; import com.gamingmesh.jobs.stuff.GiveItem; +import com.gamingmesh.jobs.stuff.Util; @SuppressWarnings("deprecation") public class ShopManager { @@ -192,12 +193,12 @@ public class ShopManager { skullMeta.setLore(lore); if (item.isHeadOwner()) { - Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer()); + Util.setSkullOwner(skullMeta, jPlayer.getPlayer()); } else { try { - Jobs.getNms().setSkullOwner(skullMeta, Bukkit.getOfflinePlayer(UUID.fromString(item.getCustomHead()))); + Util.setSkullOwner(skullMeta, Bukkit.getOfflinePlayer(UUID.fromString(item.getCustomHead()))); } catch (IllegalArgumentException ex) { - Jobs.getNms().setSkullOwner(skullMeta, Bukkit.getOfflinePlayer(item.getCustomHead())); + Util.setSkullOwner(skullMeta, Bukkit.getOfflinePlayer(item.getCustomHead())); } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index c605814f..ddd9b0a0 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -81,6 +81,7 @@ import com.gamingmesh.jobs.container.JobLimitedItems; import com.gamingmesh.jobs.container.JobProgression; import com.gamingmesh.jobs.container.JobsArmorChangeEvent; import com.gamingmesh.jobs.container.JobsArmorChangeEvent.EquipMethod; +import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.container.JobsPlayer; public class JobsListener implements Listener { @@ -117,7 +118,7 @@ public class JobsListener implements Listener { return; Player player = event.getPlayer(); - if (Jobs.getNms().getItemInMainHand(player).getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial()) + if (Util.getItemInMainHand(player).getType() != CMIMaterial.get(Jobs.getGCManager().getSelectionTool()).getMaterial()) return; if (!Jobs.getGCManager().canPerformActionInWorld(event.getPlayer().getWorld()) || !player.hasPermission("jobs.area.select")) @@ -369,7 +370,7 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onLimitedItemInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - ItemStack iih = Jobs.getNms().getItemInMainHand(player); + ItemStack iih = Util.getItemInMainHand(player); if (iih.getType() == Material.AIR) return; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 92169563..29244ff1 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -28,6 +28,7 @@ import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip; import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip.ownershipFeedback; import com.gamingmesh.jobs.hooks.HookManager; import com.gamingmesh.jobs.hooks.JobsHook; +import com.gamingmesh.jobs.stuff.Util; import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.util.player.UserManager; @@ -215,7 +216,7 @@ public final class JobsPaymentListener implements Listener { Player player = event.getPlayer(); - ItemStack itemInHand = Jobs.getNms().getItemInMainHand(player); + ItemStack itemInHand = Util.getItemInMainHand(player); if (itemInHand.getType() != Material.BUCKET && itemInHand.getType() != Material.BOWL) { return; } @@ -398,7 +399,7 @@ public final class JobsPaymentListener implements Listener { // Protection for block break with silktouch if (Jobs.getGCManager().useSilkTouchProtection) { - ItemStack item = Jobs.getNms().getItemInMainHand(player); + ItemStack item = Util.getItemInMainHand(player); if (item.getType() != Material.AIR && Jobs.getBpManager().isInBp(block)) { for (Enchantment one : item.getEnchantments().keySet()) { @@ -777,7 +778,7 @@ public final class JobsPaymentListener implements Listener { CMIMaterial mat1 = CMIMaterial.get(a), mat2 = CMIMaterial.get(b); - return mat1 == mat2 && Jobs.getNms().getDurability(a) == Jobs.getNms().getDurability(b) && Objects.equal(a.getData(), b.getData()) && + return mat1 == mat2 && Util.getDurability(a) == Util.getDurability(b) && Objects.equal(a.getData(), b.getData()) && Objects.equal(a.getEnchantments(), b.getEnchantments()); } @@ -1149,7 +1150,7 @@ public final class JobsPaymentListener implements Listener { Double damage = damageDealtByPlayers.getIfPresent(lVictimUUID); if (damage != null) { - double perc = (damage * 100D) / Jobs.getNms().getMaxHealth(lVictim); + double perc = (damage * 100D) / Util.getMaxHealth(lVictim); damageDealtByPlayers.invalidate(lVictimUUID); @@ -1331,7 +1332,7 @@ public final class JobsPaymentListener implements Listener { continue; Player p = (Player) one; - if (!Jobs.getNms().getItemInMainHand(p).getType().toString().equalsIgnoreCase("ARMOR_STAND")) + if (!Util.getItemInMainHand(p).getType().toString().equalsIgnoreCase("ARMOR_STAND")) continue; double d = p.getLocation().distance(loc); @@ -1476,7 +1477,7 @@ public final class JobsPaymentListener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new ItemActionInfo(Jobs.getNms().getItemInMainHand(player), ActionType.EAT)); + Jobs.action(Jobs.getPlayerManager().getJobsPlayer(player), new ItemActionInfo(Util.getItemInMainHand(player), ActionType.EAT)); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @@ -1557,7 +1558,7 @@ public final class JobsPaymentListener implements Listener { CMIMaterial cmat = CMIMaterial.get(block); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(p); - Material hand = Jobs.getNms().getItemInMainHand(p).getType(); + Material hand = Util.getItemInMainHand(p).getType(); if (event.useInteractedBlock() != org.bukkit.event.Event.Result.DENY && event.getAction() == Action.RIGHT_CLICK_BLOCK && jPlayer != null && !p.isSneaking()) { @@ -1629,7 +1630,7 @@ public final class JobsPaymentListener implements Listener { // Prevent item durability loss if (!Jobs.getGCManager().payItemDurabilityLoss && hand.getMaxDurability() - - Jobs.getNms().getDurability(Jobs.getNms().getItemInMainHand(p)) != hand.getMaxDurability()) + - Util.getDurability(Util.getItemInMainHand(p)) != hand.getMaxDurability()) return; // either it's version 1.13+ and we're trying to strip a normal log like oak, @@ -1706,13 +1707,13 @@ public final class JobsPaymentListener implements Listener { if (Jobs.getGCManager().payItemDurabilityLoss) return true; - ItemStack hand = Jobs.getNms().getItemInMainHand(p); + ItemStack hand = Util.getItemInMainHand(p); java.util.Map got = Jobs.getGCManager().whiteListedItems.get(CMIMaterial.get(hand)); if (got == null) return false; - if (Jobs.getNms().getDurability(hand) == 0) + if (Util.getDurability(hand) == 0) return true; for (Map.Entry oneG : got.entrySet()) { diff --git a/src/main/java/com/gamingmesh/jobs/listeners/PistonProtectionListener.java b/src/main/java/com/gamingmesh/jobs/listeners/PistonProtectionListener.java index 77899065..9e32b171 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/PistonProtectionListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/PistonProtectionListener.java @@ -12,6 +12,7 @@ import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.stuff.Util; public class PistonProtectionListener implements Listener { @@ -46,7 +47,7 @@ public class PistonProtectionListener implements Listener { y = dir.getModY(), z = dir.getModZ(); - List blocks = Jobs.getNms().getPistonRetractBlocks(event); + List blocks = Util.getPistonRetractBlocks(event); for (int i = blocks.size() - 1; i >= 0; i--) { Location oldLoc = blocks.get(i).getLocation(); Location newLoc = oldLoc.clone().add(x, y, z); diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_10.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_10.java deleted file mode 100644 index 2d7e749c..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_10.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Guardian; -import org.bukkit.entity.Horse; -import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Zombie; -import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -@SuppressWarnings("deprecation") -public class v1_10 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - String name = entity.getType().name(); - switch (entity.getType()) { - case GUARDIAN: - Guardian g = (Guardian) entity; - if (g.isElder()) - name = "GuardianElder"; - break; - case HORSE: - Horse horse = (Horse) entity; - if (horse.getVariant() == Variant.UNDEAD_HORSE) - name = "HorseZombie"; - if (horse.getVariant() == Variant.SKELETON_HORSE) - name = "HorseSkeleton"; - break; - case SKELETON: - Skeleton skeleton = (Skeleton) entity; - if (skeleton.getSkeletonType() == SkeletonType.WITHER) - name = "SkeletonWither"; - if (skeleton.getSkeletonType() == SkeletonType.STRAY) - name = "SkeletonStray"; - break; - case ZOMBIE: - Zombie zombie = (Zombie) entity; - if (zombie.isVillager() && zombie.getVillagerProfession().toString().equals("HUSK")) - return "ZombieVillager"; - if (zombie.getVillagerProfession().toString().equals("HUSK")) - return "ZombieHusk"; - break; - default: - break; - } - - return name; - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getMaxHealth(); - } - - @Override - public short getDurability(ItemStack item) { - return item.getDurability(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwner(player.getName()); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java deleted file mode 100644 index c92c8b15..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import com.gamingmesh.jobs.NMS; - -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("deprecation") -public class v1_11 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - return entity.getType().name(); - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getMaxHealth(); - } - - @Override - public short getDurability(ItemStack item) { - return item.getDurability(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwner(player.getName()); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java deleted file mode 100644 index ccbfb08f..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import com.gamingmesh.jobs.NMS; - -import org.bukkit.OfflinePlayer; -import org.bukkit.attribute.Attribute; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import java.util.ArrayList; -import java.util.List; - -@SuppressWarnings("deprecation") -public class v1_12 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - return entity.getType().name(); - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); - } - - @Override - public short getDurability(ItemStack item) { - return item.getDurability(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwner(player.getName()); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_13.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_13.java deleted file mode 100644 index 66356192..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_13.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.attribute.Attribute; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -public class v1_13 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - return entity.getType().name(); - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); - } - - @Override - public short getDurability(ItemStack item) { - return (short) ((Damageable) item.getItemMeta()).getDamage(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwningPlayer(player); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_14.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_14.java deleted file mode 100644 index 2734dd20..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_14.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.attribute.Attribute; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -public class v1_14 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - return entity.getType().name(); - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); - } - - @Override - public short getDurability(ItemStack item) { - return (short) ((Damageable) item.getItemMeta()).getDamage(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwningPlayer(player); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_15.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_15.java deleted file mode 100644 index e95f129f..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_15.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.attribute.Attribute; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -public class v1_15 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - return entity.getType().name(); - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); - } - - @Override - public short getDurability(ItemStack item) { - return (short) ((Damageable) item.getItemMeta()).getDamage(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwningPlayer(player); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_16.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_16.java deleted file mode 100644 index 52590113..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_16.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.attribute.Attribute; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -public class v1_16 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - return entity.getType().name(); - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInMainHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); - } - - @Override - public short getDurability(ItemStack item) { - return (short) ((Damageable) item.getItemMeta()).getDamage(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwningPlayer(player); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java deleted file mode 100644 index 77e707bb..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Horse; -import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Zombie; -import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -@SuppressWarnings("deprecation") -public class v1_7 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - List blocks = new ArrayList<>(); - blocks.add(event.getBlock()); - return blocks; - } - - @Override - public String getRealType(Entity entity) { - String name = entity.getType().name(); - switch (entity.getType()) { - case HORSE: - Horse horse = (Horse) entity; - if (horse.getVariant() == Variant.UNDEAD_HORSE) - name = "HorseZombie"; - if (horse.getVariant() == Variant.SKELETON_HORSE) - name = "HorseSkeleton"; - break; - case SKELETON: - Skeleton skeleton = (Skeleton) entity; - if (skeleton.getSkeletonType() == SkeletonType.WITHER) - name = "SkeletonWither"; - break; - case ZOMBIE: - Zombie zombie = (Zombie) entity; - if (zombie.isVillager()) - return "ZombieVillager"; - break; - default: - break; - } - - return name; - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getMaxHealth(); - } - - @Override - public short getDurability(ItemStack item) { - return item.getDurability(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwner(player.getName()); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java deleted file mode 100644 index 2c3accb6..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Guardian; -import org.bukkit.entity.Horse; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Zombie; -import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -@SuppressWarnings("deprecation") -public class v1_8 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - String name = entity.getType().name(); - switch (entity.getType()) { - case GUARDIAN: - Guardian g = (Guardian) entity; - if (g.isElder()) - name = "GuardianElder"; - break; - case HORSE: - Horse horse = (Horse) entity; - if (horse.getVariant() == Variant.UNDEAD_HORSE) - name = "HorseZombie"; - if (horse.getVariant() == Variant.SKELETON_HORSE) - name = "HorseSkeleton"; - break; - case SKELETON: - Skeleton skeleton = (Skeleton) entity; - if (skeleton.getSkeletonType() == SkeletonType.WITHER) - name = "SkeletonWither"; - break; - case ZOMBIE: - Zombie zombie = (Zombie) entity; - if (zombie.isVillager()) - return "ZombieVillager"; - break; - default: - break; - } - - return name; - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getMaxHealth(); - } - - @Override - public short getDurability(ItemStack item) { - return item.getDurability(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwner(player.getName()); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java deleted file mode 100644 index 416dc478..00000000 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.gamingmesh.jobs.nmsUtil; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.OfflinePlayer; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Guardian; -import org.bukkit.entity.Horse; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Skeleton; -import org.bukkit.entity.Zombie; -import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.Skeleton.SkeletonType; -import org.bukkit.event.block.BlockPistonRetractEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; - -import com.gamingmesh.jobs.NMS; - -@SuppressWarnings("deprecation") -public class v1_9 implements NMS { - - @Override - public List getPistonRetractBlocks(BlockPistonRetractEvent event) { - return new ArrayList<>(event.getBlocks()); - } - - @Override - public String getRealType(Entity entity) { - String name = entity.getType().name(); - switch (entity.getType()) { - case GUARDIAN: - Guardian g = (Guardian) entity; - if (g.isElder()) - name = "GuardianElder"; - break; - case HORSE: - Horse horse = (Horse) entity; - if (horse.getVariant() == Variant.UNDEAD_HORSE) - name = "HorseZombie"; - if (horse.getVariant() == Variant.SKELETON_HORSE) - name = "HorseSkeleton"; - break; - case SKELETON: - Skeleton skeleton = (Skeleton) entity; - if (skeleton.getSkeletonType() == SkeletonType.WITHER) - name = "SkeletonWither"; - break; - case ZOMBIE: - Zombie zombie = (Zombie) entity; - if (zombie.isVillager()) - return "ZombieVillager"; - break; - default: - break; - } - - return name; - } - - @Override - public ItemStack getItemInMainHand(Player player) { - return player.getInventory().getItemInMainHand(); - } - - @Override - public void setItemInMainHand(Player player, ItemStack item) { - player.getInventory().setItemInHand(item); - } - - @Override - public double getMaxHealth(LivingEntity entity) { - return entity.getMaxHealth(); - } - - @Override - public short getDurability(ItemStack item) { - return item.getDurability(); - } - - @Override - public void setSkullOwner(SkullMeta meta, OfflinePlayer player) { - if (meta != null && player != null) { - meta.setOwner(player.getName()); - } - } -} diff --git a/src/main/java/com/gamingmesh/jobs/stuff/Util.java b/src/main/java/com/gamingmesh/jobs/stuff/Util.java index 3f0113f9..5c199937 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/Util.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/Util.java @@ -9,24 +9,33 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.World; +import org.bukkit.attribute.Attribute; import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Horse; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.entity.Skeleton; +import org.bukkit.entity.Zombie; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.potion.PotionType; import org.bukkit.util.BlockIterator; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.CMIMaterial; +import com.gamingmesh.jobs.CMILib.Version; import com.gamingmesh.jobs.container.JobsWorld; public class Util { @@ -37,6 +46,98 @@ public class Util { public static final List LEAVECONFIRM = new ArrayList<>(); + public static List getPistonRetractBlocks(BlockPistonRetractEvent event) { + if (Version.isCurrentEqualOrHigher(Version.v1_8_R1)) { + return new ArrayList<>(event.getBlocks()); + } + List blocks = new ArrayList<>(); + blocks.add(event.getBlock()); + return blocks; + } + + public static String getRealType(Entity entity) { + + if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) { + return entity.getType().name(); + } + + String name = entity.getType().name(); + switch (entity.getType().toString()) { + case "GUARDIAN": + org.bukkit.entity.Guardian g = (org.bukkit.entity.Guardian) entity; + if (g.isElder()) + name = "GuardianElder"; + break; + case "HORSE": + Horse horse = (Horse) entity; + if (horse.getVariant().toString().equals("UNDEAD_HORSE")) + name = "HorseZombie"; + if (horse.getVariant().toString().equals("SKELETON_HORSE")) + name = "HorseSkeleton"; + break; + case "SKELETON": + Skeleton skeleton = (Skeleton) entity; + if (skeleton.getSkeletonType().toString().equals("WITHER")) + name = "SkeletonWither"; + if (Version.isCurrentEqualOrHigher(Version.v1_10_R1) && skeleton.getSkeletonType().toString().equals("STRAY")) + name = "SkeletonStray"; + break; + case "ZOMBIE": + Zombie zombie = (Zombie) entity; + if (Version.isCurrentEqualOrHigher(Version.v1_10_R1)) { + if (zombie.isVillager() && zombie.getVillagerProfession().toString().equals("HUSK")) + return "ZombieVillager"; + if (zombie.getVillagerProfession().toString().equals("HUSK")) + return "ZombieHusk"; + } else { + if (zombie.isVillager()) + return "ZombieVillager"; + } + break; + default: + break; + } + + return name; + } + + public static double getMaxHealth(LivingEntity entity) { + if (Version.isCurrentEqualOrHigher(Version.v1_12_R1)) { + return entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); + } + return entity.getMaxHealth(); + } + + public static short getDurability(ItemStack item) { + if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { + return (short) ((Damageable) item.getItemMeta()).getDamage(); + } + return item.getDurability(); + } + + public static void setSkullOwner(SkullMeta meta, OfflinePlayer player) { + if (meta != null && player != null) { + if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { + meta.setOwningPlayer(player); + } else { + meta.setOwner(player.getName()); + } + } + } + + public static ItemStack getItemInMainHand(Player player) { + if (Version.isCurrentHigher(Version.v1_8_R3)) + return player.getInventory().getItemInMainHand(); + return player.getItemInHand(); + } + + public static void setItemInMainHand(Player player, ItemStack item) { + if (Version.isCurrentHigher(Version.v1_8_R3)) + player.getInventory().setItemInMainHand(item); + else + player.setItemInHand(item); + } + @SuppressWarnings("deprecation") public static ItemStack getSkull(String skullOwner) { ItemStack item = CMIMaterial.PLAYER_HEAD.newItemStack(); @@ -45,7 +146,7 @@ public class Util { if (skullOwner.length() == 36) { try { OfflinePlayer offPlayer = Bukkit.getOfflinePlayer(UUID.fromString(skullOwner)); - Jobs.getNms().setSkullOwner(skullMeta, offPlayer); + setSkullOwner(skullMeta, offPlayer); } catch (IllegalArgumentException e) { } } else