diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index 93ff25ca..356cbb80 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; @@ -213,7 +214,8 @@ public class GuiManager { } public void openJobsBrowseGUI(Player player, Job job, boolean fromCommand) { - Inventory tempInv = plugin.getComplement().createInventory(player, 54, ""); + + Inventory tempInv = Bukkit.createInventory(player, 54, ""); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job); @@ -369,7 +371,7 @@ public class GuiManager { } private void openJobsBrowseGUI(Player player, Job job, List jobsRemained) { - Inventory tempInv = plugin.getComplement().createInventory(player, 54, ""); + Inventory tempInv = Bukkit.createInventory(player, 54, ""); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job); diff --git a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java index b58ab138..771a10bb 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ConfigManager.java @@ -59,6 +59,7 @@ import net.Zrips.CMILib.Equations.ParseError; import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Version.Version; public class ConfigManager { diff --git a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java index bcc39181..81ee293e 100644 --- a/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/LanguageManager.java @@ -343,7 +343,7 @@ public class LanguageManager { c.get("command.give.help.info", "Gives item by jobs name and item category name. Player name is optional"); c.get("command.give.help.args", "[playername] [jobname] [items/limiteditems] [jobitemname]"); - Jobs.getGCManager().getCommandArgs().put("give", Arrays.asList("[playername]", "[jobname]%%[jobitemname]", "[jobitemname]")); + Jobs.getGCManager().getCommandArgs().put("give", Arrays.asList("[playername]", "[jobname]", "items%%limiteditems","[jobitemname]")); c.get("command.give.output.notonline", "&4Player with that name is not online!"); c.get("command.give.output.noitem", "&4Can't find any item by given name!"); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 1cd9e7cb..7788f524 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -59,6 +59,7 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.world.StructureGrowEvent; import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.ItemMeta; @@ -85,6 +86,7 @@ import net.Zrips.CMILib.Colors.CMIChatColor; import net.Zrips.CMILib.Items.ArmorTypes; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; +import net.Zrips.CMILib.NBT.CMINBT; import net.Zrips.CMILib.Version.Version; public class JobsListener implements Listener { @@ -383,14 +385,23 @@ public class JobsListener implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onLimitedItemInteract(PlayerInteractEvent event) { - if(!Jobs.hasLimitedItems()) - { - return; + if (!Jobs.hasLimitedItems()) { + return; } Player player = event.getPlayer(); - ItemStack iih = CMIItemStack.getItemInMainHand(player); - if (iih.getType() == Material.AIR) + ItemStack iih = null; + try { + if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { + iih = CMIItemStack.getItemInOffHand(player); + } else { + iih = CMIItemStack.getItemInMainHand(player); + } + } catch (Exception e) { + iih = CMIItemStack.getItemInMainHand(player); + } + + if (iih == null || iih.getType() == Material.AIR) return; if (event.getClickedBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getClickedBlock().getWorld())) @@ -401,29 +412,54 @@ public class JobsListener implements Listener { return; Map enchants = new HashMap<>(iih.getEnchantments()); - if (enchants.isEmpty()) + if (enchants.isEmpty()) { return; + } String name = null; List lore = new ArrayList<>(); + CMINBT nbt = new CMINBT(iih); + Integer i = nbt.getInt("JobsLimited"); + if (i != null) { + Job job = Jobs.getJob(i); + if (job != null) { + JobProgression prog = jPlayer.getJobProgression(job); + if (prog != null) { + String node = nbt.getString("JobsLimitedNode"); + if (node != null) { + for (JobLimitedItems oneItem : job.getLimitedItems().values()) { + if (prog.getLevel() >= oneItem.getLevel() || !oneItem.getNode().equalsIgnoreCase(node)) + continue; + event.setCancelled(true); + CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", job.getDisplayName())); + return; + } + } + } + } + } + if (iih.hasItemMeta()) { ItemMeta meta = iih.getItemMeta(); if (meta.hasDisplayName()) - name = plugin.getComplement().getDisplayName(meta); + name = meta.getDisplayName(); if (meta.hasLore()) - lore = plugin.getComplement().getLore(meta); + lore = meta.getLore(); } String meinOk = null; + String itemNode = null; CMIMaterial mat = CMIMaterial.get(iih); + Integer jobId = null; mein: for (JobProgression one : jPlayer.getJobProgression()) { for (JobLimitedItems oneItem : one.getJob().getLimitedItems().values()) { if (one.getLevel() >= oneItem.getLevel() || !isThisItem(oneItem, mat, name, lore, enchants)) continue; - - meinOk = one.getJob().getName(); + jobId = one.getJob().getId(); + meinOk = one.getJob().getDisplayName(); + itemNode = oneItem.getNode(); break mein; } } @@ -431,6 +467,19 @@ public class JobsListener implements Listener { if (meinOk != null) { event.setCancelled(true); CMIActionBar.send(player, Jobs.getLanguage().getMessage("limitedItem.error.levelup", "[jobname]", meinOk)); + + nbt = new CMINBT(iih); + nbt.setInt("JobsLimited", jobId); + iih = (ItemStack) nbt.setString("JobsLimitedNode", itemNode); + try { + if (Version.isCurrentHigher(Version.v1_8_R3) && event.getHand() != EquipmentSlot.HAND) { + CMIItemStack.setItemInOffHand(player, iih); + } else { + CMIItemStack.setItemInMainHand(player, iih); + } + } catch (Exception e) { + CMIItemStack.setItemInMainHand(player, iih); + } } } diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index fa95d0b9..00eb79a0 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -129,7 +129,6 @@ import net.Zrips.CMILib.Entities.CMIEntityType; import net.Zrips.CMILib.Items.CMIItemStack; import net.Zrips.CMILib.Items.CMIMaterial; import net.Zrips.CMILib.Locale.LC; -import net.Zrips.CMILib.Logs.CMIDebug; import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Version.Version; @@ -214,8 +213,7 @@ public final class JobsPaymentListener implements Listener { ItemStack currentItem = event.getCurrentItem(); if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) { - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin - .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.VTRADE)); } else if (currentItem != null) { Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.VTRADE)); } @@ -237,8 +235,7 @@ public final class JobsPaymentListener implements Listener { while (newItemsCount >= 1) { newItemsCount--; if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin - .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.VTRADE)); else Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.VTRADE)); } @@ -749,8 +746,7 @@ public final class JobsPaymentListener implements Listener { PotionMeta potion = (PotionMeta) currentItem.getItemMeta(); Jobs.action(jPlayer, new PotionItemActionInfo(currentItem, ActionType.CRAFT, potion.getBasePotionData().getType())); } else if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) { - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin - .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.CRAFT)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.CRAFT)); } else if (currentItem != null) { Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT)); } @@ -776,8 +772,7 @@ public final class JobsPaymentListener implements Listener { org.bukkit.inventory.meta.ItemMeta resultItemMeta = resultStack.getItemMeta(); if (resultItemMeta != null && resultItemMeta.hasDisplayName()) - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(plugin - .getComplement().getDisplayName(resultItemMeta)), ActionType.CRAFT)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultItemMeta.getDisplayName()), ActionType.CRAFT)); else Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT)); } @@ -967,10 +962,10 @@ public final class JobsPaymentListener implements Listener { String originalName = null; String newName = null; if (firstSlot.hasItemMeta()) - originalName = plugin.getComplement().getDisplayName(firstSlot.getItemMeta()); + originalName = firstSlot.getItemMeta().getDisplayName(); if (resultStack.hasItemMeta()) - newName = plugin.getComplement().getDisplayName(resultStack.getItemMeta()); + newName = resultStack.getItemMeta().getDisplayName(); if (originalName != null && !originalName.equals(newName) && inv.getItem(1) == null && !Jobs.getGCManager().PayForRenaming) return; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java index 2c1fbd02..7bba46c2 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/TabComplete.java @@ -108,7 +108,7 @@ public final class TabComplete implements TabCompleter { } if (args.length > 3 && args[3].equalsIgnoreCase("limiteditems")) { - Job oneJob = Jobs.getJob(args[i - 1]); + Job oneJob = Jobs.getJob(args[i - 2]); if (oneJob != null) for (JobLimitedItems limitedItem : oneJob.getLimitedItems().values()) { diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java index 02359a15..613966ab 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java @@ -6,15 +6,11 @@ import org.bukkit.Bukkit; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.meta.ItemMeta; import net.Zrips.CMILib.Colors.CMIChatColor; public interface Complement { - String getDisplayName(ItemMeta meta); - String getDisplayName(Player player); String getLine(SignChangeEvent event, int line); @@ -25,14 +21,6 @@ public interface Complement { void setLine(Sign sign, int line, String text); - org.bukkit.inventory.Inventory createInventory(InventoryHolder owner, int size, String title); - - void setLore(ItemMeta meta, List lore); - - List getLore(ItemMeta meta); - - void setDisplayName(ItemMeta meta, String name); - default void broadcastMessage(String message) { message = CMIChatColor.translate(message); for (Player player : Bukkit.getOnlinePlayers()) { diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java index 6f29b56f..ceece653 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java @@ -1,23 +1,12 @@ package com.gamingmesh.jobs.stuff.complement; -import java.util.List; - -import org.bukkit.Bukkit; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.meta.ItemMeta; @SuppressWarnings("deprecation") public final class Complement1 implements Complement { - @Override - public String getDisplayName(ItemMeta meta) { - return meta.getDisplayName(); - } - @Override public String getLine(SignChangeEvent event, int line) { return event.getLine(line); @@ -33,21 +22,6 @@ public final class Complement1 implements Complement { return sign.getLine(line); } - @Override - public Inventory createInventory(InventoryHolder owner, int size, String title) { - return Bukkit.createInventory(owner, size, title); - } - - @Override - public void setLore(ItemMeta meta, List lore) { - meta.setLore(lore); - } - - @Override - public void setDisplayName(ItemMeta meta, String name) { - meta.setDisplayName(name); - } - @Override public String getDisplayName(Player player) { return player.getDisplayName(); @@ -57,9 +31,4 @@ public final class Complement1 implements Complement { public void setLine(Sign sign, int line, String text) { sign.setLine(line, text); } - - @Override - public List getLore(ItemMeta meta) { - return meta.getLore(); - } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java index a2a4f24e..c8e58c13 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java @@ -1,15 +1,8 @@ package com.gamingmesh.jobs.stuff.complement; -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.Bukkit; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; -import org.bukkit.inventory.meta.ItemMeta; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextComponent; @@ -25,18 +18,6 @@ public class Complement2 implements Complement { return LegacyComponentSerializer.legacyAmpersand().deserialize(t); } - @Override - public String getDisplayName(ItemMeta meta) { - Component dName = null; - - try { - dName = meta.displayName(); - } catch (NoSuchMethodError e) { - } - - return dName == null ? "" : serialize(dName); - } - @Override public String getLine(SignChangeEvent event, int line) { Component l = event.line(line); @@ -53,27 +34,6 @@ public class Complement2 implements Complement { return serialize(sign.line(line)); } - @Override - public Inventory createInventory(InventoryHolder owner, int size, String title) { - return Bukkit.createInventory(owner, size, deserialize(title)); - } - - @Override - public void setLore(ItemMeta meta, List lore) { - List l = new ArrayList<>(); - - for (String e : lore) { - l.add(deserialize(e)); - } - - meta.lore(l); - } - - @Override - public void setDisplayName(ItemMeta meta, String name) { - meta.displayName(deserialize(name)); - } - @Override public String getDisplayName(Player player) { return serialize(player.displayName()); @@ -84,16 +44,4 @@ public class Complement2 implements Complement { sign.line(line, deserialize(text)); } - @Override - public List getLore(ItemMeta meta) { - List lore = new ArrayList<>(); - - if (meta.hasLore()) { - for (Component comp : meta.lore()) { - lore.add(serialize(comp)); - } - } - - return lore; - } }