From d62349badc46dc884d1b061b39e7ab851c08dbe1 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Wed, 28 Aug 2019 18:20:27 +0200 Subject: [PATCH] Fixed issue when used the enchanted books, then can't enchanted properly - Added argument for signUpdate command - Removed hack for removing items from inventory when in browse GUI - Version up for player gliding, because not exists in the API --- .../jobs/commands/list/signupdate.java | 21 ++++++++++++++----- .../gamingmesh/jobs/container/JobItems.java | 15 +++++++++---- .../jobs/listeners/JobsListener.java | 7 ++++--- .../jobs/listeners/JobsPaymentListener.java | 5 +++-- .../com/gamingmesh/jobs/stuff/GiveItem.java | 16 +++++++++++--- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java b/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java index 03490449..d09484e1 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/signupdate.java @@ -21,16 +21,27 @@ public class signupdate implements Cmd { return true; } + if (args[0].equalsIgnoreCase("all")) { + Jobs.getJobs().forEach(Jobs.getSignUtil()::SignUpdate); + return true; + } + Job oldjob = Jobs.getJob(args[0]); - - SignTopType type = SignTopType.getType(args[0]); - - if (type == SignTopType.toplist && oldjob == null) { + if (oldjob == null) { sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); return true; } - Jobs.getSignUtil().SignUpdate(oldjob, type); + if (args.length == 2) { + SignTopType type = SignTopType.getType(args[1]); + if (type != null) { + Jobs.getSignUtil().SignUpdate(oldjob, type); + } + + return true; + } + + Jobs.getSignUtil().SignUpdate(oldjob); return true; } diff --git a/src/main/java/com/gamingmesh/jobs/container/JobItems.java b/src/main/java/com/gamingmesh/jobs/container/JobItems.java index f722b32e..a5db950c 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobItems.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobItems.java @@ -59,7 +59,7 @@ public class JobItems { if (enchants != null) { if (mat == CMIMaterial.ENCHANTED_BOOK) { EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) meta; - for (Entry oneEnch : bookMeta.getEnchants().entrySet()) { + for (Entry oneEnch : enchants.entrySet()) { bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true); } } else { @@ -100,13 +100,20 @@ public class JobItems { meta.setLore(TranslatedLore); } if (enchants != null) { - for (Entry OneEnchant : enchants.entrySet()) { - meta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true); + if (item.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) { + EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) meta; + for (Entry oneEnch : enchants.entrySet()) { + bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true); + } + } else { + for (Entry OneEnchant : enchants.entrySet()) { + meta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true); + } } } item.setItemMeta(meta); return item; - } catch (Throwable e) { + } catch (Exception e) { } return null; } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 735fec7f..6bc34810 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -238,7 +238,7 @@ public class JobsListener implements Listener { return; event.setCancelled(true); - final ItemStack clicked = event.getCurrentItem(); + //final ItemStack clicked = event.getCurrentItem(); GuiInfoList joblist = Jobs.getGUIManager().GuiList.get(player.getUniqueId()); @@ -272,14 +272,15 @@ public class JobsListener implements Listener { } player.updateInventory(); - if (event.getClick().isShiftClick() && clicked != null && !clicked.getType().equals(Material.AIR)) + // hack, we don't need to remove items + /*if (event.getClick().isShiftClick() && clicked != null && !clicked.getType().equals(Material.AIR)) Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { @Override public void run() { player.getInventory().remove(clicked); player.updateInventory(); } - }, 1L); + }, 1L);*/ } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 48564514..bdb3c5fb 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -479,6 +479,7 @@ public class JobsPaymentListener implements Listener { JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); if (jPlayer == null) return; + Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.PLACE), block); } @@ -1009,7 +1010,7 @@ public class JobsPaymentListener implements Listener { UUID uuid = null; try { uuid = UUID.fromString(playerName); - } catch (Throwable e) { + } catch (IllegalArgumentException e) { } if (uuid == null) return; @@ -1702,7 +1703,7 @@ public class JobsPaymentListener implements Listener { if (Jobs.getGCManager().disablePaymentIfRiding && player.isInsideVehicle()) return; - if (Jobs.getVersionCheckManager().getVersion().isEqualOrHigher(Version.v1_9_R1) + if (Jobs.getVersionCheckManager().getVersion().isEqualOrHigher(Version.v1_9_R2) && !Jobs.getGCManager().payExploringWhenGliding && player.isGliding()) return; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java b/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java index 3990604a..6716d96e 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java @@ -9,13 +9,14 @@ import org.bukkit.ChatColor; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import com.gamingmesh.jobs.CMILib.ItemManager.CMIMaterial; public class GiveItem { public static void GiveItemForPlayer(Player player, int id, int meta, int qty, String name, List lore, - HashMap hashMap) { + HashMap enchants) { ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack(); itemStack.setAmount(qty); ItemMeta ItemMeta = itemStack.getItemMeta(); @@ -29,8 +30,17 @@ public class GiveItem { ItemMeta.setLore(TranslatedLore); } - for (Entry OneEnchant : hashMap.entrySet()) { - ItemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true); + if (enchants != null) { + if (itemStack.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) { + EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) ItemMeta; + for (Entry oneEnch : enchants.entrySet()) { + bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), false); + } + } else { + for (Entry OneEnchant : enchants.entrySet()) { + ItemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true); + } + } } if (name != null)