From 327da4fa3ebddf459381fba8d9b3458a93839d40 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Thu, 6 May 2021 20:45:39 +0200 Subject: [PATCH] Use the deprecated methods to set item name or lore to support CMI's gradient colors --- .../com/gamingmesh/jobs/Gui/GuiManager.java | 26 +++++++++---------- src/main/java/com/gamingmesh/jobs/Jobs.java | 21 +++++++++------ .../com/gamingmesh/jobs/Signs/SignUtil.java | 12 ++++----- .../gamingmesh/jobs/config/ShopManager.java | 24 +++++++---------- .../jobs/container/JobLimitedItems.java | 4 +-- .../gamingmesh/jobs/container/ShopItem.java | 2 +- .../jobs/listeners/JobsListener.java | 15 ++++++----- .../com/gamingmesh/jobs/stuff/GiveItem.java | 8 ++---- .../jobs/stuff/complement/Complement2.java | 6 +++-- src/main/resources/shopItems.yml | 5 ++-- 10 files changed, 61 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index 28109a3d..1123f2ba 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -141,8 +141,8 @@ public class GuiManager { ItemStack guiItem = job.getGuiItem(); ItemMeta meta = guiItem.getItemMeta(); - plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); - plugin.getComplement().setLore(meta, lore); + meta.setDisplayName(job.getJobDisplayName()); + meta.setLore(lore); if (Jobs.getGCManager().hideItemAttributes) { meta.addItemFlags(org.bukkit.inventory.ItemFlag.HIDE_ATTRIBUTES, org.bukkit.inventory.ItemFlag.HIDE_ENCHANTS); @@ -275,8 +275,8 @@ public class GuiManager { continue; ItemMeta meta = guiItem.getItemMeta(); - plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); - plugin.getComplement().setLore(meta, lore); + meta.setDisplayName(job.getJobDisplayName()); + meta.setLore(lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); @@ -295,8 +295,8 @@ public class GuiManager { } ItemMeta meta = guiItem.getItemMeta(); - plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); - plugin.getComplement().setLore(meta, lore); + meta.setDisplayName(job.getJobDisplayName()); + meta.setLore(lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); i++; @@ -327,7 +327,7 @@ public class GuiManager { ItemStack back = Jobs.getGCManager().guiBackButton; ItemMeta meta = back.getItemMeta(); - plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.info.gui.back")); + meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back")); back.setItemMeta(meta); gui.addButton(new CMIGuiButton(backButton, back) { @@ -342,7 +342,7 @@ public class GuiManager { ItemStack next = Jobs.getGCManager().guiNextButton; ItemMeta meta = next.getItemMeta(); - plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.info.gui.next")); + meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.next")); next.setItemMeta(meta); gui.addButton(new CMIGuiButton(nextButton, next) { @@ -426,8 +426,8 @@ public class GuiManager { } ItemMeta meta = guiItem.getItemMeta(); - plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); - plugin.getComplement().setLore(meta, lore); + meta.setDisplayName(job.getJobDisplayName()); + meta.setLore(lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); @@ -445,8 +445,8 @@ public class GuiManager { } ItemMeta meta = guiItem.getItemMeta(); - plugin.getComplement().setDisplayName(meta, job.getJobDisplayName()); - plugin.getComplement().setLore(meta, lore); + meta.setDisplayName(job.getJobDisplayName()); + meta.setLore(lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); i++; @@ -477,7 +477,7 @@ public class GuiManager { ItemStack skull = Jobs.getGCManager().guiBackButton; ItemMeta skullMeta = skull.getItemMeta(); - plugin.getComplement().setDisplayName(skullMeta, Jobs.getLanguage().getMessage("command.info.gui.back")); + skullMeta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back")); skull.setItemMeta(skullMeta); gui.addButton(new CMIGuiButton(backButton, skull) { diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index 83201cd9..51a3f4df 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -97,6 +97,8 @@ public class Jobs extends JavaPlugin { private final Set blockOwnerShips = new HashSet<>(); + private boolean kyoriSupported = false; + private CMIScoreboardManager cmiScoreboardManager; private Complement complement; private GuiManager guiManager; @@ -122,6 +124,10 @@ public class Jobs extends JavaPlugin { return complement; } + public boolean isKyoriSupported() { + return kyoriSupported; + } + /** * Returns the block owner ship for specific {@link CMIMaterial} type. * @@ -246,7 +252,7 @@ public class Jobs extends JavaPlugin { public static ShopManager getShopManager() { if (shopManager == null) { - shopManager = new ShopManager(instance); + shopManager = new ShopManager(); } return shopManager; } @@ -693,6 +699,12 @@ public class Jobs extends JavaPlugin { return; } + try { + Class.forName("net.kyori.adventure.text.Component"); + kyoriSupported = true; + } catch (ClassNotFoundException e) { + } + placeholderAPIEnabled = setupPlaceHolderAPI(); try { @@ -729,13 +741,6 @@ public class Jobs extends JavaPlugin { getServer().getPluginManager().registerEvents(new PistonProtectionListener(), this); } - boolean kyoriSupported = false; - try { - Class.forName("net.kyori.adventure.text.serializer.plain.PlainComponentSerializer"); - kyoriSupported = true; - } catch (ClassNotFoundException e) { - } - if (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) { complement = new Complement2(); //getServer().getPluginManager().registerEvents(new KyoriChatEvent(this), this); diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index e0d46d27..2087052a 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -263,7 +263,7 @@ public class SignUtil { } if (!line.isEmpty()) - plugin.getComplement().setLine(sign, i, line); + sign.setLine(i, line); } sign.update(); if (!updateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) { @@ -280,22 +280,22 @@ public class SignUtil { } int no = jSign.getNumber() + number + 1; - plugin.getComplement().setLine(sign, 0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName)); - plugin.getComplement().setLine(sign, 1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName)); + sign.setLine(0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName)); + sign.setLine(1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName)); switch (type) { case toplist: case gtoplist: - plugin.getComplement().setLine(sign, 2, translateSignLine("signs.SpecialList.level", no, playerName, pl.getLevel(), signJobName)); + sign.setLine(2, translateSignLine("signs.SpecialList.level", no, playerName, pl.getLevel(), signJobName)); break; case questtoplist: - plugin.getComplement().setLine(sign, 2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); + sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); break; default: break; } - plugin.getComplement().setLine(sign, 3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName)); + sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName)); sign.update(); if (!updateHead(sign, pl.getPlayerInfo().getName(), timelapse)) { timelapse--; diff --git a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java index bb721e59..73607326 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ShopManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ShopManager.java @@ -41,14 +41,8 @@ import com.gamingmesh.jobs.stuff.GiveItem; @SuppressWarnings("deprecation") public class ShopManager { - private Jobs plugin; - private final List list = new ArrayList<>(); - public ShopManager(Jobs plugin) { - this.plugin = plugin; - } - public List getShopItemList() { return list; } @@ -144,7 +138,7 @@ public class ShopManager { guiItem.setAmount(item.getIconAmount()); if (item.getIconName() != null) - plugin.getComplement().setDisplayName(meta, item.getIconName()); + meta.setDisplayName(item.getIconName()); lore.addAll(item.getIconLore()); @@ -183,17 +177,19 @@ public class ShopManager { ? Jobs.getLanguage().getMessage("command.shop.info.reqTotalLevelColor") : "") + item.getRequiredTotalLevels())); } - plugin.getComplement().setLore(meta, lore); + meta.setLore(lore); if (item.getCustomHead() != null) { - guiItem = CMIMaterial.PLAYER_HEAD.newItemStack(); + guiItem = CMIMaterial.PLAYER_HEAD.newItemStack(item.getIconAmount()); SkullMeta skullMeta = (SkullMeta) guiItem.getItemMeta(); if (skullMeta == null) continue; - plugin.getComplement().setDisplayName(skullMeta, item.getIconName()); - plugin.getComplement().setLore(skullMeta, lore); + if (item.getIconName() != null) + skullMeta.setDisplayName(item.getIconName()); + + skullMeta.setLore(lore); if (item.isHeadOwner()) { Jobs.getNms().setSkullOwner(skullMeta, jPlayer.getPlayer()); @@ -277,7 +273,7 @@ public class ShopManager { int prevSlot = getPrevButtonSlot(guiSize.getFields(), page); if (prevSlot != -1 && page > 1) { - plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.help.output.prevPage")); + meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.prevPage")); item.setItemMeta(meta); gui.addButton(new CMIGuiButton(prevSlot, item) { @@ -290,7 +286,7 @@ public class ShopManager { int nextSlot = getNextButtonSlot(guiSize.getFields(), page); if (nextSlot != -1 && !getItemsByPage(page + 1).isEmpty()) { - plugin.getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.help.output.nextPage")); + meta.setDisplayName(Jobs.getLanguage().getMessage("command.help.output.nextPage")); item.setItemMeta(meta); gui.addButton(new CMIGuiButton(nextSlot, item) { @Override @@ -342,8 +338,6 @@ public class ShopManager { } sItem.setIconAmount(nameSection.getInt("Icon.Amount", 1)); - - if (nameSection.isString("Icon.Name")) sItem.setIconName(CMIChatColor.translate(nameSection.getString("Icon.Name"))); List lore = nameSection.getStringList("Icon.Lore"); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java b/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java index e833811e..610ee6f5 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java @@ -68,7 +68,7 @@ public class JobLimitedItems { Jobs plugin = org.bukkit.plugin.java.JavaPlugin.getPlugin(Jobs.class); if (name != null) - plugin.getComplement().setDisplayName(meta, CMIChatColor.translate(name)); + meta.setDisplayName(CMIChatColor.translate(name)); if (lore != null && !lore.isEmpty()) { List translatedLore = new ArrayList<>(); @@ -76,7 +76,7 @@ public class JobLimitedItems { translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); } - plugin.getComplement().setLore(meta, translatedLore); + meta.setLore(translatedLore); } if (enchants != null) diff --git a/src/main/java/com/gamingmesh/jobs/container/ShopItem.java b/src/main/java/com/gamingmesh/jobs/container/ShopItem.java index 9a0ad0ad..1f3126f8 100644 --- a/src/main/java/com/gamingmesh/jobs/container/ShopItem.java +++ b/src/main/java/com/gamingmesh/jobs/container/ShopItem.java @@ -11,7 +11,7 @@ public class ShopItem { private int slot = -1, page = -1, iconAmount = 1; - private String nodeName = null, iconMaterial = null, iconName = null; + private String nodeName, iconMaterial, iconName; private boolean hideWithoutPerm = false; private boolean hideNoEnoughPoint = false; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 3bbcceee..7f48d153 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -307,10 +307,11 @@ public class JobsListener implements Listener { if (!Jobs.getGCManager().SignsEnabled) return; + String line1 = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)); + if (CMIChatColor.stripColor(plugin.getComplement().getLine(event, 0)) - .equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor( - plugin.getComplement().getLine(event, 1)).equalsIgnoreCase("toplist")) - plugin.getComplement().setLine(event, 0, convert(Jobs.getLanguage().getMessage("signs.topline"))); + .equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !line1.equalsIgnoreCase("toplist")) + event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline"))); else return; @@ -320,11 +321,11 @@ public class JobsListener implements Listener { return; } - String command = CMIChatColor.stripColor(plugin.getComplement().getLine(event, 1)).toLowerCase(); for (String key : Jobs.getLanguageManager().signKeys) { String secondLine = Jobs.getLanguage().getMessage("signs.secondline." + key); - if (command.equalsIgnoreCase(CMIChatColor.stripColor(secondLine))) { - plugin.getComplement().setLine(event, 1, convert(secondLine)); + + if (line1.equalsIgnoreCase(CMIChatColor.stripColor(secondLine))) { + event.setLine(1, convert(secondLine)); break; } } @@ -334,7 +335,7 @@ public class JobsListener implements Listener { return; String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; - plugin.getComplement().setLine(event, 2, convert(color + job.getName())); + event.setLine(2, convert(color + job.getName())); } private final Pattern pattern = Pattern.compile("&([0-9a-fk-or])"); diff --git a/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java b/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java index 5b356541..5db9267f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java @@ -9,9 +9,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.plugin.java.JavaPlugin; -import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; @@ -26,15 +24,13 @@ public class GiveItem { return; } - Jobs plugin = JavaPlugin.getPlugin(Jobs.class); - if (lore != null && !lore.isEmpty()) { List translatedLore = new ArrayList<>(); for (String oneLore : lore) { translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); } - plugin.getComplement().setLore(itemMeta, translatedLore); + itemMeta.setLore(translatedLore); } if (enchants != null) { @@ -51,7 +47,7 @@ public class GiveItem { } if (name != null) - plugin.getComplement().setDisplayName(itemMeta, CMIChatColor.translate(name)); + itemMeta.setDisplayName(CMIChatColor.translate(name)); itemStack.setItemMeta(itemMeta); giveItemForPlayer(player, itemStack); 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 022beb04..db0d9e8f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java @@ -12,6 +12,7 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.meta.ItemMeta; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public class Complement2 implements Complement { @@ -20,13 +21,14 @@ public class Complement2 implements Complement { return LegacyComponentSerializer.legacyAmpersand().serialize(component); } - protected Component deserialize(String t) { - return Component.text(t); + protected TextComponent deserialize(String t) { + return LegacyComponentSerializer.legacyAmpersand().deserialize(t); } @Override public String getDisplayName(ItemMeta meta) { Component dName = null; + try { dName = meta.displayName(); } catch (NoSuchMethodError e) { diff --git a/src/main/resources/shopItems.yml b/src/main/resources/shopItems.yml index 527a4bfe..cf150bf7 100644 --- a/src/main/resources/shopItems.yml +++ b/src/main/resources/shopItems.yml @@ -20,8 +20,9 @@ Items: HideIfThereIsNoEnoughPoints: false # (Optional) When you want to use Player Head material with skin then use this #CustomHead: - # PlayerName: playerName - # Using the current player (if have job) who opened the gui. The PlayerName string is ignoring if this exist. + # You can specify here valid player name or uuid. + # PlayerName: playerNameOrUUID + # Use the current player who opened the gui, so the head skin will be this player who opened. # UseCurrentPlayer: true # (Optional) List of permissions required to buy this item RequiredPermission: