From ba16c1a68e12af3c579bbcd018016fd0eace0644 Mon Sep 17 00:00:00 2001 From: Zrips Date: Tue, 8 Mar 2022 16:19:52 +0200 Subject: [PATCH] Cleanup --- .../gamingmesh/jobs/container/JobsPlayer.java | 16 +- .../jobs/stuff/complement/Complement1.java | 80 +++++----- .../jobs/stuff/complement/Complement2.java | 142 +++++++++--------- .../jobs/stuff/complement/JobsChatEvent.java | 86 +++++------ 4 files changed, 159 insertions(+), 165 deletions(-) diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index b97001af..9b2f505f 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -98,7 +98,7 @@ public class JobsPlayer { this.userName = player.getName() == null ? "Unknown" : player.getName(); this.playerUUID = player.getUniqueId(); } - + public JobsPlayer(Player player) { this.userName = player.getName() == null ? "Unknown" : player.getName(); this.playerUUID = player.getUniqueId(); @@ -398,16 +398,10 @@ public class JobsPlayer { } public int getPlayerMaxQuest(String jobName) { - int m1 = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true); - int max = m1; - - m1 = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true); - - if (m1 != 0 && (m1 > max || m1 < max)) { - max = m1; - } - - return max; + int m1 = (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest.all", false, true); + if (m1 != 0) + return m1; + return (int) Jobs.getPermissionManager().getMaxPermission(this, "jobs.maxquest." + jobName, false, true); } /** 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 83ddc326..6f29b56f 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement1.java @@ -13,53 +13,53 @@ 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 getDisplayName(ItemMeta meta) { + return meta.getDisplayName(); + } - @Override - public String getLine(SignChangeEvent event, int line) { - return event.getLine(line); - } + @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 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 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 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 setLore(ItemMeta meta, List lore) { + meta.setLore(lore); + } - @Override - public void setDisplayName(ItemMeta meta, String name) { - meta.setDisplayName(name); - } + @Override + public void setDisplayName(ItemMeta meta, String name) { + meta.setDisplayName(name); + } - @Override - public String getDisplayName(Player player) { - return player.getDisplayName(); - } + @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 void setLine(Sign sign, int line, String text) { + sign.setLine(line, text); + } - @Override - public List getLore(ItemMeta meta) { - return meta.getLore(); - } + @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 db0d9e8f..a2a4f24e 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/Complement2.java @@ -17,83 +17,83 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public class Complement2 implements Complement { - protected String serialize(Component component) { - return LegacyComponentSerializer.legacyAmpersand().serialize(component); + protected String serialize(Component component) { + return LegacyComponentSerializer.legacyAmpersand().serialize(component); + } + + 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) { } - protected TextComponent deserialize(String t) { - return LegacyComponentSerializer.legacyAmpersand().deserialize(t); + return dName == null ? "" : serialize(dName); + } + + @Override + public String getLine(SignChangeEvent event, int line) { + Component l = event.line(line); + return l == null ? "" : serialize(l); + } + + @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)); } - @Override - public String getDisplayName(ItemMeta meta) { - Component dName = null; + meta.lore(l); + } - try { - dName = meta.displayName(); - } catch (NoSuchMethodError e) { - } + @Override + public void setDisplayName(ItemMeta meta, String name) { + meta.displayName(deserialize(name)); + } - return dName == null ? "" : serialize(dName); + @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<>(); + + if (meta.hasLore()) { + for (Component comp : meta.lore()) { + lore.add(serialize(comp)); + } } - @Override - public String getLine(SignChangeEvent event, int line) { - Component l = event.line(line); - return l == null ? "" : serialize(l); - } - - @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<>(); - - if (meta.hasLore()) { - for (Component comp : meta.lore()) { - lore.add(serialize(comp)); - } - } - - return lore; - } + return lore; + } } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java b/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java index 263b17de..d50e8301 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/complement/JobsChatEvent.java @@ -12,56 +12,56 @@ import com.gamingmesh.jobs.stuff.Util; @SuppressWarnings("deprecation") public class JobsChatEvent implements Listener { - private Jobs plugin; + private Jobs plugin; - public JobsChatEvent(Jobs plugin) { - this.plugin = plugin; + public JobsChatEvent(Jobs plugin) { + this.plugin = plugin; + } + + @EventHandler(priority = EventPriority.NORMAL) + public void asyncPlayerChatEvent(final AsyncPlayerChatEvent event) { + if (event.isCancelled() || Util.getJobsEditorMap().isEmpty()) + return; + + final String msg = Util.getJobsEditorMap().remove(event.getPlayer().getUniqueId()); + if (msg != null) { + plugin.getServer().getScheduler().runTask(plugin, + () -> event.getPlayer().performCommand(msg + event.getMessage())); + event.setCancelled(true); } + } - @EventHandler(priority = EventPriority.NORMAL) - public void asyncPlayerChatEvent(final AsyncPlayerChatEvent event) { - if (event.isCancelled() || Util.getJobsEditorMap().isEmpty()) - return; + // Adding to chat prefix job name + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onPlayerChat(AsyncPlayerChatEvent event) { + if (!Jobs.getGCManager().getModifyChat()) + return; - final String msg = Util.getJobsEditorMap().remove(event.getPlayer().getUniqueId()); - if (msg != null) { - plugin.getServer().getScheduler().runTask(plugin, - () -> event.getPlayer().performCommand(msg + event.getMessage())); - event.setCancelled(true); - } - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); + String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; + if (honorific.equals(" ")) + honorific = ""; - // Adding to chat prefix job name - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onPlayerChat(AsyncPlayerChatEvent event) { - if (!Jobs.getGCManager().getModifyChat()) - return; + event.setFormat(event.getFormat().replace("%1$s", honorific + "%1$s")); + } - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); - String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equals(" ")) - honorific = ""; + // Changing chat prefix variable to job name + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onPlayerChatLow(AsyncPlayerChatEvent event) { + onPlayerChatHigh(event); + } - event.setFormat(event.getFormat().replace("%1$s", honorific + "%1$s")); - } + // Changing chat prefix variable to job name + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onPlayerChatHigh(AsyncPlayerChatEvent event) { + if (Jobs.getGCManager().getModifyChat()) + return; - // Changing chat prefix variable to job name - @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) - public void onPlayerChatLow(AsyncPlayerChatEvent event) { - onPlayerChatHigh(event); - } + JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); + String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; + if (honorific.equals(" ")) + honorific = ""; - // Changing chat prefix variable to job name - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onPlayerChatHigh(AsyncPlayerChatEvent event) { - if (Jobs.getGCManager().getModifyChat()) - return; - - JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer()); - String honorific = jPlayer != null ? jPlayer.getDisplayHonorific() : ""; - if (honorific.equals(" ")) - honorific = ""; - - event.setFormat(event.getFormat().replace("{jobs}", honorific)); - } + event.setFormat(event.getFormat().replace("{jobs}", honorific)); + } }