From 1413662c19532ea79010aedebb034285623247fb Mon Sep 17 00:00:00 2001 From: montlikadani Date: Fri, 26 Feb 2021 08:45:14 +0100 Subject: [PATCH] Prepare for kyori component --- .../com/gamingmesh/jobs/Gui/GuiManager.java | 31 ++++--- src/main/java/com/gamingmesh/jobs/Jobs.java | 47 ++++++---- .../com/gamingmesh/jobs/PlayerManager.java | 10 +-- .../com/gamingmesh/jobs/Signs/SignUtil.java | 14 +-- .../jobs/config/ScheduleManager.java | 10 +-- .../jobs/container/JobLimitedItems.java | 7 +- .../jobs/listeners/JobsListener.java | 36 ++++---- .../jobs/listeners/JobsPaymentListener.java | 18 ++-- .../com/gamingmesh/jobs/stuff/GiveItem.java | 17 ++-- .../jobs/stuff/complement/Complement.java | 47 ++++++++++ .../jobs/stuff/complement/Complement1.java | 65 ++++++++++++++ .../jobs/stuff/complement/Complement2.java | 88 +++++++++++++++++++ 12 files changed, 304 insertions(+), 86 deletions(-) create mode 100644 src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java create mode 100644 src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java create mode 100644 src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java diff --git a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java index b78620ca..bf82e847 100644 --- a/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java +++ b/src/main/java/com/gamingmesh/jobs/Gui/GuiManager.java @@ -4,7 +4,6 @@ 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; @@ -133,8 +132,8 @@ public class GuiManager { ItemStack guiItem = job.getGuiItem(); ItemMeta meta = guiItem.getItemMeta(); - meta.setDisplayName(job.getNameWithColor()); - meta.setLore(lore); + Jobs.getInstance().getComplement().setDisplayName(meta, job.getNameWithColor()); + Jobs.getInstance().getComplement().setLore(meta, lore); guiItem.setItemMeta(meta); int lastPos = job.getGuiSlot() >= 0 ? job.getGuiSlot() : pos; @@ -190,7 +189,7 @@ public class GuiManager { } public void openJobsBrowseGUI(Player player, Job job, boolean fromCommand) { - Inventory tempInv = Bukkit.createInventory(player, 54, ""); + Inventory tempInv = Jobs.getInstance().getComplement().createInventory(player, 54, ""); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job); @@ -263,8 +262,8 @@ public class GuiManager { continue; ItemMeta meta = guiItem.getItemMeta(); - meta.setDisplayName(job.getNameWithColor()); - meta.setLore(lore); + Jobs.getInstance().getComplement().setDisplayName(meta, job.getNameWithColor()); + Jobs.getInstance().getComplement().setLore(meta, lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); @@ -283,8 +282,8 @@ public class GuiManager { } ItemMeta meta = guiItem.getItemMeta(); - meta.setDisplayName(job.getNameWithColor()); - meta.setLore(lore); + Jobs.getInstance().getComplement().setDisplayName(meta, job.getNameWithColor()); + Jobs.getInstance().getComplement().setLore(meta, lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); i++; @@ -315,7 +314,7 @@ public class GuiManager { ItemStack back = Jobs.getGCManager().guiBackButton; ItemMeta meta = back.getItemMeta(); - meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back")); + Jobs.getInstance().getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.info.gui.back")); back.setItemMeta(meta); gui.addButton(new CMIGuiButton(backButton, back) { @@ -330,7 +329,7 @@ public class GuiManager { ItemStack next = Jobs.getGCManager().guiNextButton; ItemMeta meta = next.getItemMeta(); - meta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.next")); + Jobs.getInstance().getComplement().setDisplayName(meta, Jobs.getLanguage().getMessage("command.info.gui.next")); next.setItemMeta(meta); gui.addButton(new CMIGuiButton(nextButton, next) { @@ -346,7 +345,7 @@ public class GuiManager { } private void openJobsBrowseGUI(Player player, Job job, List jobsRemained) { - Inventory tempInv = Bukkit.createInventory(player, 54, ""); + Inventory tempInv = Jobs.getInstance().getComplement().createInventory(player, 54, ""); JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player); Boost boost = Jobs.getPlayerManager().getFinalBonus(jPlayer, job); @@ -414,8 +413,8 @@ public class GuiManager { } ItemMeta meta = guiItem.getItemMeta(); - meta.setDisplayName(job.getNameWithColor()); - meta.setLore(lore); + Jobs.getInstance().getComplement().setDisplayName(meta, job.getNameWithColor()); + Jobs.getInstance().getComplement().setLore(meta, lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); @@ -433,8 +432,8 @@ public class GuiManager { } ItemMeta meta = guiItem.getItemMeta(); - meta.setDisplayName(job.getNameWithColor()); - meta.setLore(lore); + Jobs.getInstance().getComplement().setDisplayName(meta, job.getNameWithColor()); + Jobs.getInstance().getComplement().setLore(meta, lore); guiItem.setItemMeta(meta); tempInv.setItem(i, guiItem.clone()); i++; @@ -465,7 +464,7 @@ public class GuiManager { ItemStack skull = Jobs.getGCManager().guiBackButton; ItemMeta skullMeta = skull.getItemMeta(); - skullMeta.setDisplayName(Jobs.getLanguage().getMessage("command.info.gui.back")); + Jobs.getInstance().getComplement().setDisplayName(skullMeta, 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 c59a1258..0628cfcb 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -48,8 +48,12 @@ import com.gamingmesh.jobs.listeners.JobsPaymentListener; import com.gamingmesh.jobs.listeners.PistonProtectionListener; import com.gamingmesh.jobs.selection.SelectionManager; import com.gamingmesh.jobs.stuff.*; +import com.gamingmesh.jobs.stuff.complement.Complement; +import com.gamingmesh.jobs.stuff.complement.Complement1; +import com.gamingmesh.jobs.stuff.complement.Complement2; import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; + import org.bukkit.Bukkit; import org.bukkit.block.Block; import org.bukkit.command.CommandSender; @@ -72,7 +76,6 @@ public class Jobs extends JavaPlugin { private static Language lManager; private static LanguageManager lmManager; private static SignUtil signManager; - private CMIScoreboardManager cmiScoreboardManager; private static ScheduleManager scheduleManager; private static NameTranslatorManager nameTranslatorManager; private static GuiManager guiManager; @@ -85,15 +88,18 @@ public class Jobs extends JavaPlugin { private static Loging loging; private static BlockProtectionManager bpManager; private static JobsManager dbManager; + private static ConfigManager configManager; + private static GeneralConfigManager gConfigManager; + private static PistonProtectionListener pistonProtectionListener; + private static CMIReflections reflections; + private static BufferedEconomy economy; + private static PermissionHandler permissionHandler; + private static PermissionManager permissionManager; private final Set blockOwnerShips = new HashSet<>(); - private static PistonProtectionListener pistonProtectionListener; - - private static ConfigManager configManager; - private static GeneralConfigManager gConfigManager; - - private static CMIReflections reflections; + private CMIScoreboardManager cmiScoreboardManager; + private Complement complement; private static JobsDAO dao; private static List jobs; @@ -101,10 +107,6 @@ public class Jobs extends JavaPlugin { private static WeakHashMap usedSlots = new WeakHashMap<>(); private static Map jobsIds = new HashMap<>(); - private static BufferedEconomy economy; - private static PermissionHandler permissionHandler; - private static PermissionManager permissionManager; - public static BufferedPaymentThread paymentThread; private static DatabaseSaveThread saveTask; @@ -113,12 +115,15 @@ public class Jobs extends JavaPlugin { private static NMS nms; protected static VersionChecker versionCheckManager; - protected static SelectionManager smanager; private static PointsData pointsDatabase; - /** + public Complement getComplement() { + return complement; + } + + /** * Returns the block owner ship for specific {@link CMIMaterial} type. * * @param type {@link CMIMaterial} @@ -730,17 +735,25 @@ public class Jobs extends JavaPlugin { getServer().getPluginManager().registerEvents(getPistonProtectionListener(), this); } + boolean kyoriSupported = false; + try { + Class.forName("net.kyori.adventure.text.Component"); + kyoriSupported = true; + } catch (ClassNotFoundException e) { + } + + complement = (Version.isCurrentEqualOrHigher(Version.v1_16_R3) && kyoriSupported) ? new Complement2() + : new Complement1(); + // register economy Bukkit.getScheduler().runTask(this, new HookEconomyTask(this)); dao.loadBlockProtection(); getExplore().load(); + getCommandManager().fillCommands(); + getDBManager().getDB().triggerTableIdUpdate(); consoleMsg("&e[Jobs] Plugin has been enabled successfully."); - - getCommandManager().fillCommands(); - - getDBManager().getDB().triggerTableIdUpdate(); } catch (Throwable e) { e.printStackTrace(); System.out.println("There was some issues when starting plugin. Please contact dev about this. Plugin will be disabled."); diff --git a/src/main/java/com/gamingmesh/jobs/PlayerManager.java b/src/main/java/com/gamingmesh/jobs/PlayerManager.java index 4180a493..ca177781 100644 --- a/src/main/java/com/gamingmesh/jobs/PlayerManager.java +++ b/src/main/java/com/gamingmesh/jobs/PlayerManager.java @@ -633,7 +633,7 @@ public class PlayerManager { String message = Jobs.getLanguage().getMessage("message.leveldown.message"); message = message.replace("%jobname%", job.getNameWithColor()); - message = message.replace("%playername%", player != null ? player.getDisplayName() : jPlayer.getName()); + message = message.replace("%playername%", player != null ? Jobs.getInstance().getComplement().getDisplayName(player) : jPlayer.getName()); message = message.replace("%joblevel%", "" + prog.getLevel()); message = message.replace("%lostLevel%", "" + oldLevel); @@ -786,13 +786,13 @@ public class PlayerManager { message = message.replace("%titlename%", levelUpEvent.getOldTitle() .getChatColor().toString() + levelUpEvent.getOldTitle().getName()); - message = message.replace("%playername%", player != null ? player.getDisplayName() : jPlayer.getName()); + message = message.replace("%playername%", player != null ? Jobs.getInstance().getComplement().getDisplayName(player) : jPlayer.getName()); message = message.replace("%joblevel%", "" + prog.getLevel()); for (String line : message.split("\n")) { if (Jobs.getGCManager().isBroadcastingLevelups()) { if (Jobs.getGCManager().BroadcastingLevelUpLevels.contains(oldLevel + 1) || Jobs.getGCManager().BroadcastingLevelUpLevels.contains(0)) - Bukkit.getServer().broadcastMessage(line); + Jobs.getInstance().getComplement().broadcastMessage(line); } else if (player != null) { if (Jobs.getGCManager().LevelChangeActionBar) ActionBarManager.send(player, line); @@ -817,14 +817,14 @@ public class PlayerManager { message = Jobs.getLanguage().getMessage("message.skillup." + (Jobs.getGCManager().isBroadcastingSkillups() ? "broadcast" : "nobroadcast")); - message = message.replace("%playername%", player != null ? player.getDisplayName() : jPlayer.getName()); + message = message.replace("%playername%", player != null ? Jobs.getInstance().getComplement().getDisplayName(player) : jPlayer.getName()); message = message.replace("%titlename%", levelUpEvent.getNewTitle() .getChatColor().toString() + levelUpEvent.getNewTitle().getName()); message = message.replace("%jobname%", job.getNameWithColor()); for (String line : message.split("\n")) { if (Jobs.getGCManager().isBroadcastingSkillups()) { - Bukkit.getServer().broadcastMessage(line); + Jobs.getInstance().getComplement().broadcastMessage(line); } else if (player != null) { if (Jobs.getGCManager().TitleChangeActionBar) ActionBarManager.send(player, line); diff --git a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java index a91b9dd2..4c4d054e 100644 --- a/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java +++ b/src/main/java/com/gamingmesh/jobs/Signs/SignUtil.java @@ -225,7 +225,7 @@ public class SignUtil { if (!jSign.isSpecial()) { for (int i = 0; i < 4; i++) { if (i + number >= playerList.size()) { - sign.setLine(i, ""); + Jobs.getInstance().getComplement().setLine(sign, i, ""); continue; } @@ -250,7 +250,7 @@ public class SignUtil { } if (!line.isEmpty()) - sign.setLine(i, line); + Jobs.getInstance().getComplement().setLine(sign, i, line); } sign.update(); if (!UpdateHead(sign, playerList.get(0).getPlayerInfo().getName(), timelapse)) { @@ -267,22 +267,22 @@ public class SignUtil { } int no = jSign.getNumber() + number + 1; - 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)); + Jobs.getInstance().getComplement().setLine(sign, 0, translateSignLine("signs.SpecialList.p" + jSign.getNumber(), no, playerName, pl.getLevel(), signJobName)); + Jobs.getInstance().getComplement().setLine(sign, 1, translateSignLine("signs.SpecialList.name", no, playerName, pl.getLevel(), signJobName)); switch (type) { case toplist: case gtoplist: - sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.level", "[number]", no, "[player]", playerName, "[level]", pl.getLevel(), "[job]", signJobName)); + Jobs.getInstance().getComplement().setLine(sign, 2, Jobs.getLanguage().getMessage("signs.SpecialList.level", "[number]", no, "[player]", playerName, "[level]", pl.getLevel(), "[job]", signJobName)); break; case questtoplist: - sign.setLine(2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); + Jobs.getInstance().getComplement().setLine(sign, 2, Jobs.getLanguage().getMessage("signs.SpecialList.quests", "[number]", no, "[player]", playerName, "[quests]", pl.getLevel(), "[job]", signJobName)); break; default: break; } - sign.setLine(3, translateSignLine("signs.SpecialList.bottom", no, playerName, pl.getLevel(), signJobName)); + Jobs.getInstance().getComplement().setLine(sign, 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/ScheduleManager.java b/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java index 956c8711..452658ce 100644 --- a/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/ScheduleManager.java @@ -69,7 +69,7 @@ public class ScheduleManager { if (one.isStarted() && one.getBroadcastInfoOn() < System.currentTimeMillis() && one.getBroadcastInterval() > 0) { one.setBroadcastInfoOn(System.currentTimeMillis() + one.getBroadcastInterval() * 60 * 1000); - one.getMessageToBroadcast().forEach(Bukkit::broadcastMessage); + Jobs.getInstance().getComplement().broadcastMessage(one.getMessageToBroadcast()); } if (((one.isNextDay() && (Current >= From && Current < Until || Current >= one.getNextFrom() && Current < one.getNextUntil()) && !one @@ -84,9 +84,9 @@ public class ScheduleManager { if (one.isBroadcastOnStart()) if (one.getMessageOnStart().isEmpty()) - Bukkit.broadcastMessage(Jobs.getLanguage().getMessage("message.boostStarted")); + Jobs.getInstance().getComplement().broadcastMessage(Jobs.getLanguage().getMessage("message.boostStarted")); else - one.getMessageOnStart().forEach(Bukkit::broadcastMessage); + Jobs.getInstance().getComplement().broadcastMessage(one.getMessageOnStart()); for (Job onejob : one.getJobs()) { onejob.setBoost(one.getBoost()); @@ -107,9 +107,9 @@ public class ScheduleManager { if (one.isBroadcastOnStop()) if (one.getMessageOnStop().isEmpty()) - Bukkit.broadcastMessage(Jobs.getLanguage().getMessage("message.boostStoped")); + Jobs.getInstance().getComplement().broadcastMessage(Jobs.getLanguage().getMessage("message.boostStoped")); else - one.getMessageOnStop().forEach(Bukkit::broadcastMessage); + Jobs.getInstance().getComplement().broadcastMessage(one.getMessageOnStop()); for (Job onejob : one.getJobs()) { onejob.setBoost(new BoostMultiplier()); diff --git a/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java b/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java index 5391e8be..65450c03 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobLimitedItems.java @@ -28,6 +28,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; @@ -70,8 +71,8 @@ public class JobLimitedItems { return item; } - if (this.name != null) - meta.setDisplayName(CMIChatColor.translate(name)); + if (name != null) + Jobs.getInstance().getComplement().setDisplayName(meta, CMIChatColor.translate(name)); if (lore != null && !lore.isEmpty()) { List translatedLore = new ArrayList<>(); @@ -79,7 +80,7 @@ public class JobLimitedItems { translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); } - meta.setLore(translatedLore); + Jobs.getInstance().getComplement().setLore(meta, translatedLore); } if (enchants != null) diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java index 69d0bb99..aa47ddc6 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsListener.java @@ -215,12 +215,12 @@ public class JobsListener implements Listener { return; Sign sign = (Sign) block.getState(); - String FirstLine = sign.getLine(0); + String FirstLine = Jobs.getInstance().getComplement().getLine(sign, 0); if (!CMIChatColor.stripColor(FirstLine).equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline")))) return; - String command = CMIChatColor.stripColor(sign.getLine(1)); + String command = CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(sign, 1)); for (String key : Jobs.getGCManager().keys) { if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { command = key; @@ -228,7 +228,8 @@ public class JobsListener implements Listener { } } - player.performCommand("jobs " + command + " " + CMIChatColor.stripColor(sign.getLine(2)) + " " + CMIChatColor.stripColor(sign.getLine(3))); + player.performCommand("jobs " + command + " " + CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(sign, 2)) + + " " + CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(sign, 3))); } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @@ -242,7 +243,7 @@ public class JobsListener implements Listener { Player player = event.getPlayer(); Sign sign = (Sign) block.getState(); - String firstLine = sign.getLine(0); + String firstLine = Jobs.getInstance().getComplement().getLine(sign, 0); if (firstLine.contains(Jobs.getLanguage().getMessage("signs.topline")) && !player.hasPermission("jobs.command.signs")) { event.setCancelled(true); player.sendMessage(Jobs.getLanguage().getMessage("signs.cantdestroy")); @@ -274,10 +275,10 @@ public class JobsListener implements Listener { Sign sign = (Sign) block.getState(); - if (!CMIChatColor.stripColor(event.getLine(0)).equalsIgnoreCase("[Jobs]")) + if (!CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(event, 0)).equalsIgnoreCase("[Jobs]")) return; - final SignTopType type = SignTopType.getType(CMIChatColor.stripColor(event.getLine(1))); + final SignTopType type = SignTopType.getType(CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(event, 1))); if (type == null) return; @@ -288,7 +289,7 @@ public class JobsListener implements Listener { return; } - String jobname = CMIChatColor.stripColor(event.getLine(2)).toLowerCase(); + String jobname = CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(sign, 2)).toLowerCase(); final Job job = Jobs.getJob(jobname); if (type == SignTopType.toplist && job == null) { player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob")); @@ -296,7 +297,7 @@ public class JobsListener implements Listener { } boolean special = false; - String numberString = CMIChatColor.stripColor(event.getLine(3)).toLowerCase(); + String numberString = CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(sign, 3)).toLowerCase(); if (numberString.contains("s")) { numberString = numberString.replace("s", ""); special = true; @@ -334,10 +335,11 @@ public class JobsListener implements Listener { if (!Jobs.getGCManager().SignsEnabled) return; - if (CMIChatColor.stripColor(event.getLine(0)).equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor(event - .getLine(1)) + if (CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(event, 0)) + .equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.topline"))) && !CMIChatColor.stripColor( + Jobs.getInstance().getComplement().getLine(event, 1)) .equalsIgnoreCase("toplist")) - event.setLine(0, convert(Jobs.getLanguage().getMessage("signs.topline"))); + Jobs.getInstance().getComplement().setLine(event, 0, convert(Jobs.getLanguage().getMessage("signs.topline"))); else return; @@ -347,20 +349,20 @@ public class JobsListener implements Listener { return; } - String command = CMIChatColor.stripColor(event.getLine(1)).toLowerCase(); + String command = CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(event, 1)).toLowerCase(); for (String key : Jobs.getGCManager().keys) { if (command.equalsIgnoreCase(CMIChatColor.stripColor(Jobs.getLanguage().getMessage("signs.secondline." + key)))) { - event.setLine(1, convert(Jobs.getLanguage().getMessage("signs.secondline." + key))); + Jobs.getInstance().getComplement().setLine(event, 1, convert(Jobs.getLanguage().getMessage("signs.secondline." + key))); break; } } - Job job = Jobs.getJob(CMIChatColor.stripColor(event.getLine(2))); + Job job = Jobs.getJob(CMIChatColor.stripColor(Jobs.getInstance().getComplement().getLine(event, 2))); if (job == null) return; String color = Jobs.getGCManager().SignsColorizeJobName ? job.getChatColor().toString() : ""; - event.setLine(2, convert(color + job.getName())); + Jobs.getInstance().getComplement().setLine(event, 2, convert(color + job.getName())); } private String convert(String line) { @@ -454,9 +456,9 @@ public class JobsListener implements Listener { if (iih.hasItemMeta()) { ItemMeta meta = iih.getItemMeta(); if (meta.hasDisplayName()) - name = meta.getDisplayName(); + name = Jobs.getInstance().getComplement().getDisplayName(meta); if (meta.hasLore()) - lore = meta.getLore(); + lore = Jobs.getInstance().getComplement().getLore(meta); } String meinOk = null; diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index f80dc4a5..d868cee4 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -180,8 +180,8 @@ public class JobsPaymentListener implements Listener { ItemStack currentItem = event.getCurrentItem(); if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) { - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta() - .getDisplayName()), ActionType.VTRADE)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE)); } else if (currentItem != null) { Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.VTRADE)); } @@ -203,7 +203,8 @@ public class JobsPaymentListener implements Listener { while (newItemsCount >= 1) { newItemsCount--; if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.VTRADE)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.VTRADE)); else Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.VTRADE)); } @@ -703,8 +704,8 @@ public 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(resultStack.getItemMeta() - .getDisplayName()), ActionType.CRAFT)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.CRAFT)); } else if (currentItem != null) { Jobs.action(jPlayer, new ItemActionInfo(currentItem, ActionType.CRAFT)); } @@ -726,7 +727,8 @@ public class JobsPaymentListener implements Listener { while (newItemsCount >= 1) { newItemsCount--; if (resultStack.hasItemMeta() && resultStack.getItemMeta().hasDisplayName()) - Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(resultStack.getItemMeta().getDisplayName()), ActionType.CRAFT)); + Jobs.action(jPlayer, new ItemNameActionInfo(CMIChatColor.stripColor(Jobs.getInstance() + .getComplement().getDisplayName(resultStack.getItemMeta())), ActionType.CRAFT)); else Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.CRAFT)); } @@ -855,10 +857,10 @@ public class JobsPaymentListener implements Listener { String originalName = null; String newName = null; if (firstSlot.hasItemMeta()) - originalName = firstSlot.getItemMeta().getDisplayName(); + originalName = Jobs.getInstance().getComplement().getDisplayName(firstSlot.getItemMeta()); if (resultStack.hasItemMeta()) - newName = resultStack.getItemMeta().getDisplayName(); + newName = Jobs.getInstance().getComplement().getDisplayName(resultStack.getItemMeta()); if (originalName != null && !originalName.equals(newName) && inv.getItem(1) == null && !Jobs.getGCManager().PayForRenaming) return; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java b/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java index 5561f0f1..8caf03e2 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/GiveItem.java @@ -11,6 +11,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; +import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.CMILib.CMIChatColor; import com.gamingmesh.jobs.CMILib.CMIMaterial; @@ -19,34 +20,34 @@ public class GiveItem { HashMap enchants) { ItemStack itemStack = CMIMaterial.get(id, meta).newItemStack(); itemStack.setAmount(qty); - ItemMeta ItemMeta = itemStack.getItemMeta(); + ItemMeta itemMeta = itemStack.getItemMeta(); if (lore != null && !lore.isEmpty()) { - List TranslatedLore = new ArrayList<>(); + List translatedLore = new ArrayList<>(); for (String oneLore : lore) { - TranslatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); + translatedLore.add(CMIChatColor.translate(oneLore.replace("[player]", player.getName()))); } - ItemMeta.setLore(TranslatedLore); + Jobs.getInstance().getComplement().setLore(itemMeta, translatedLore); } if (enchants != null) { if (itemStack.getType() == CMIMaterial.ENCHANTED_BOOK.getMaterial()) { - EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) ItemMeta; + EnchantmentStorageMeta bookMeta = (EnchantmentStorageMeta) itemMeta; for (Entry oneEnch : enchants.entrySet()) { bookMeta.addStoredEnchant(oneEnch.getKey(), oneEnch.getValue(), true); } } else { for (Entry OneEnchant : enchants.entrySet()) { - ItemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true); + itemMeta.addEnchant(OneEnchant.getKey(), OneEnchant.getValue(), true); } } } if (name != null) - ItemMeta.setDisplayName(CMIChatColor.translate(name)); + Jobs.getInstance().getComplement().setDisplayName(itemMeta, CMIChatColor.translate(name)); - itemStack.setItemMeta(ItemMeta); + itemStack.setItemMeta(itemMeta); GiveItemForPlayer(player, itemStack); } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java new file mode 100644 index 00000000..ca480a6f --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement.java @@ -0,0 +1,47 @@ +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.InventoryHolder; +import org.bukkit.inventory.meta.ItemMeta; + +public interface Complement { + + String getDisplayName(ItemMeta meta); + + String getDisplayName(Player player); + + String getLine(SignChangeEvent event, int line); + + String getLine(Sign sign, int line); + + void setLine(SignChangeEvent event, int line, String text); + + 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) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendMessage(message); + } + } + + default void broadcastMessage(List messages) { + for (String msg : messages) { + for (Player player : Bukkit.getOnlinePlayers()) { + player.sendMessage(msg); + } + } + } +} diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java new file mode 100644 index 00000000..83ddc326 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java @@ -0,0 +1,65 @@ +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); + } + + @Override + public void setLine(SignChangeEvent event, int line, String text) { + event.setLine(line, text); + } + + @Override + public String getLine(Sign sign, int line) { + 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(); + } + + @Override + 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 new file mode 100644 index 00000000..6426e628 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java @@ -0,0 +1,88 @@ +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.serializer.plain.PlainComponentSerializer; + +public final class Complement2 implements Complement { + + private String serialize(Component component) { + return PlainComponentSerializer.plain().serialize(component); + } + + private Component deserialize(String t) { + return PlainComponentSerializer.plain().deserialize(t); + } + + @Override + public String getDisplayName(ItemMeta meta) { + return serialize(meta.displayName()); + } + + @Override + public String getLine(SignChangeEvent event, int line) { + return serialize(event.line(line)); + } + + @Override + public void setLine(SignChangeEvent event, int line, String text) { + event.line(line, deserialize(text)); + } + + @Override + public String getLine(Sign sign, int line) { + 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()); + } + + @Override + public void setLine(Sign sign, int line, String text) { + sign.line(line, deserialize(text)); + } + + @Override + public List getLore(ItemMeta meta) { + List lore = new ArrayList<>(); + + for (Component comp : meta.lore()) { + lore.add(serialize(comp)); + } + + return lore; + } +}