diff --git a/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java b/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java index a2132dd6..9f0a7841 100644 --- a/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java +++ b/src/main/java/com/gamingmesh/jobs/CMILib/ItemManager.java @@ -970,7 +970,7 @@ public class ItemManager { GREEN_GLAZED_TERRACOTTA(248, 0, 6958, "Green Glazed Terracotta"), GREEN_SHULKER_BOX(232, 0, 9377, "Green Shulker Box"), GREEN_STAINED_GLASS(95, 13, 22503, "Green Stained Glass"), - GREEN_STAINED_GLASS_PANE(160, 13, 4767, "Green Stained Glass Pane"), + GREEN_STAINED_GLASS_PANE(160, 13, 4767, "Green Stained Glass Pane", "STAINED_GLASS_PANE"), GREEN_TERRACOTTA(159, 13, 4105, "Green Terracotta"), GREEN_WALL_BANNER(117, 2, 15046, "Green Banner"), GREEN_WOOL(35, 13, 25085, "Green Wool"), diff --git a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java index 103b207c..71fd1f7d 100644 --- a/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java +++ b/src/main/java/com/gamingmesh/jobs/config/GeneralConfigManager.java @@ -890,12 +890,8 @@ public class GeneralConfigManager { "This is update for same job signs, to avoid huge lag if you have bunch of same type signs. Keep it from 1 to as many sec you want"); InfoUpdateInterval = c.get("Signs.InfoUpdateInterval", 5); - if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { - ShowToplistInScoreboard = false; - } else { - c.getW().addComment("Scoreboard.ShowToplist", "This will enables to show top list in scoreboard instead of chat"); - ShowToplistInScoreboard = c.get("Scoreboard.ShowToplist", true); - } + c.getW().addComment("Scoreboard.ShowToplist", "This will enables to show top list in scoreboard instead of chat"); + ShowToplistInScoreboard = c.get("Scoreboard.ShowToplist", true); c.getW().addComment("Scoreboard.interval", "For how long to show scoreboard"); ToplistInScoreboardInterval = c.get("Scoreboard.interval", 10); diff --git a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java index 17e58357..797aa222 100644 --- a/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java +++ b/src/main/java/com/gamingmesh/jobs/listeners/JobsPaymentListener.java @@ -309,7 +309,7 @@ public class JobsPaymentListener implements Listener { if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) return; Block block = event.getBlock(); - if (block == null) + if (!Jobs.getGCManager().isBrewingStandsReassign()) return; if (!block.hasMetadata(brewingOwnerMetadata)) return; @@ -368,9 +368,9 @@ public class JobsPaymentListener implements Listener { if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) return; - if (CMIMaterial.get(block).equals(CMIMaterial.FURNACE) && block.hasMetadata(furnaceOwnerMetadata)) + if (Jobs.getGCManager().isFurnacesReassign() && CMIMaterial.get(block).equals(CMIMaterial.FURNACE) && block.hasMetadata(furnaceOwnerMetadata)) FurnaceBrewingHandling.removeFurnace(block); - if (CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND) && block.hasMetadata(brewingOwnerMetadata)) + if (Jobs.getGCManager().isBrewingStandsReassign() && CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND) && block.hasMetadata(brewingOwnerMetadata)) FurnaceBrewingHandling.removeBrewing(block); BlockActionInfo bInfo = new BlockActionInfo(block, ActionType.BREAK); @@ -898,7 +898,7 @@ public class JobsPaymentListener implements Listener { if (event.getBlock() != null && !Jobs.getGCManager().canPerformActionInWorld(event.getBlock().getWorld())) return; Block block = event.getBlock(); - if (block == null) + if (!Jobs.getGCManager().isFurnacesReassign()) return; if (!block.hasMetadata(furnaceOwnerMetadata)) @@ -1431,6 +1431,9 @@ public class JobsPaymentListener implements Listener { return; if (CMIMaterial.get(block).equals(CMIMaterial.FURNACE) || CMIMaterial.get(block).equals(CMIMaterial.LEGACY_BURNING_FURNACE)) { + if (!Jobs.getGCManager().isFurnacesReassign()) + return; + ownershipFeedback done = FurnaceBrewingHandling.registerFurnaces(event.getPlayer(), block); if (done.equals(ownershipFeedback.tooMany)) { boolean report = false; @@ -1456,6 +1459,9 @@ public class JobsPaymentListener implements Listener { "[max]", jPlayer.getMaxFurnacesAllowed() == 0 ? "-" : jPlayer.getMaxFurnacesAllowed())); } } else if (CMIMaterial.get(block).equals(CMIMaterial.BREWING_STAND)) { + if (!Jobs.getGCManager().isBrewingStandsReassign()) + return; + ownershipFeedback done = FurnaceBrewingHandling.registerBrewingStand(event.getPlayer(), block); if (done.equals(ownershipFeedback.tooMany)) { boolean report = false; diff --git a/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java b/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java index e93bfa9a..8d12acea 100644 --- a/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java +++ b/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java @@ -16,9 +16,11 @@ import org.bukkit.entity.Player; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.container.ScoreboardInfo; + import com.gamingmesh.jobs.CMILib.VersionChecker.Version; public class CMIScoreboardManager { @@ -76,23 +78,28 @@ public class CMIScoreboardManager { Object boards = boardClass.getConstructor().newInstance(); if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { + Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); + board.clearSlot(DisplaySlot.SIDEBAR); + board.registerNewObjective("Scoreboards", "dummy"); -// Class enums = getNMSClass("IScoreboardCriteria$EnumScoreboardHealthDisplay"); -// Class chatbase = getNMSClass("IChatBaseComponent$ChatSerializer"); -//// Class ser = getNMSClass("IChatBaseComponent$ChatSerializer"); -// Method mm = chatbase.getMethod("a", String.class); -// Object serealized = mm.invoke(chatbase, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', "JobsDummy") + "\"}"); -// Object e = enums.getEnumConstants()[0]; -// Class IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); -// Constructor IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); -// Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("JobsDummy"); -// Method m = boards.getClass().getMethod("registerNewObjective", String.class, getNMSClass("IScoreboardCriteria"), chatbase, enums); -// Object obj = m.invoke(boards, objName, "JobsDummy", IScoreboardCriteria, serealized, e); -// -// Class p1 = getNMSClass("PacketPlayOutScoreboardObjective"); -// Constructor p11 = p1.getConstructor(obj.getClass(), int.class); -// Object pp1 = p11.newInstance(obj, 1); -// sendPacket(player, pp1); + player.setScoreboard(board); + + // TODO We using soon the scoreboard packets +/** Class enums = getNMSClass("IScoreboardCriteria$EnumScoreboardHealthDisplay"); + Class chatbase = getNMSClass("IChatBaseComponent$ChatSerializer"); + Method mm = chatbase.getMethod("a", String.class); + Object serealized = mm.invoke(chatbase, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', "JobsDummy") + "\"}"); + Object e = enums.getEnumConstants()[0]; + Class IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); + Constructor IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); + Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("JobsDummy"); + Method m = boards.getClass().getMethod("registerNewObjective", String.class, getNMSClass("IScoreboardCriteria"), chatbase, enums); + Object obj = m.invoke(boards, objName, "JobsDummy", IScoreboardCriteria, serealized, e); + + Class p1 = getNMSClass("PacketPlayOutScoreboardObjective"); + Constructor p11 = p1.getConstructor(obj.getClass(), int.class); + Object pp1 = p11.newInstance(obj, 1); + sendPacket(player, pp1);*/ } else { Method m = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria")); @@ -117,58 +124,103 @@ public class CMIScoreboardManager { Class boardClass = getNMSClass("Scoreboard"); Object boards = boardClass.getConstructor().newInstance(); if (Version.isCurrentEqualOrHigher(Version.v1_13_R1)) { -// -// Class enums = getNMSClass("IScoreboardCriteria$EnumScoreboardHealthDisplay"); -// -// Class chatbase = getNMSClass("IChatBaseComponent$ChatSerializer"); -//// Class ser = getNMSClass("IChatBaseComponent$ChatSerializer"); -// Method mm2 = chatbase.getMethod("a", String.class); -// Object serealized = mm2.invoke(chatbase, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', "JobsDummy") + "\"}"); -// Object e = enums.getEnumConstants()[0]; -// Class IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); -// Constructor IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); -// Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("JobsDummy"); -// Method m = boards.getClass().getMethod("registerNewObjective", String.class, getNMSClass("IScoreboardCriteria"), chatbase, enums); -// Object obj = m.invoke(boards, objName, "JobsDummy", IScoreboardCriteria, serealized, e); -// -// -// Method mm = obj.getClass().getMethod("setDisplayName", String.class); -// mm.invoke(obj, ChatColor.translateAlternateColorCodes('&', displayName)); -// -// Class p1 = getNMSClass("PacketPlayOutScoreboardObjective"); -// Constructor p11 = p1.getConstructor(obj.getClass(), int.class); -// Object pp1 = p11.newInstance(obj, 1); -// sendPacket(player, pp1); -// -// Class p2 = getNMSClass("PacketPlayOutScoreboardObjective"); -// Constructor p12 = p2.getConstructor(obj.getClass(), int.class); -// Object pp2 = p12.newInstance(obj, 0); -// sendPacket(player, pp2); -// -// Class packetClass = getNMSClass("PacketPlayOutScoreboardDisplayObjective"); -// Constructor packetConstructor = packetClass.getConstructor(int.class, getNMSClass("ScoreboardObjective")); -// Object packet = packetConstructor.newInstance(1, obj); -// sendPacket(player, packet); -// -// for (int i = 0; i < 15; i++) { -// if (i >= lines.size()) -// break; -// -// String ln = ChatColor.translateAlternateColorCodes('&', lines.get(i)); -// Class ScoreboardScoreClass = getNMSClass("ScoreboardScore"); -// Constructor packetConstructor2 = ScoreboardScoreClass.getConstructor(getNMSClass("Scoreboard"), getNMSClass("ScoreboardObjective"), String.class); -// Object packet2 = packetConstructor2.newInstance(boards, obj, ln); -// Method mc = packet2.getClass().getMethod("setScore", int.class); -// mc.invoke(packet2, 15 - i); -// -// Class PacketPlayOutScoreboardScoreClass = getNMSClass("PacketPlayOutScoreboardScore"); -// Constructor PacketPlayOutScoreboardScoreConstructor = PacketPlayOutScoreboardScoreClass.getConstructor(getNMSClass("ScoreboardScore")); -// Object PacketPlayOutScoreboardScore = PacketPlayOutScoreboardScoreConstructor.newInstance(packet2); -// -// sendPacket(player, PacketPlayOutScoreboardScore); -// -// } + Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard(); + Objective sidebar = board.registerNewObjective("sidebar", "dummy"); + sidebar.setDisplaySlot(DisplaySlot.SIDEBAR); + player.setScoreboard(board); + + for (int i = 1; i <= 15; i++) { + Team team = board.registerNewTeam("SLOT_" + i); + team.addEntry(getSlotColor(i)); + } + + if (displayName.length() > 32) + displayName = displayName.substring(0, 32); + + if (!sidebar.getDisplayName().equals(displayName)) + sidebar.setDisplayName(displayName); + + for (int i = 0; i < 15; i++) { + if (i >= lines.size()) + break; + + int slot = lines.size(); + + if (slot < 15) { + for (int x = (slot +1); x <= 15; x++) { + String entry = getSlotColor(x); + if (board.getEntries().contains(entry)) + board.resetScores(entry); + } + } + + for (String line : lines) { + Team team = board.getTeam("SLOT_" + slot); + String entry = getSlotColor(slot); + if (!board.getEntries().contains(entry)) + sidebar.getScore(entry).setScore(slot); + + String pre = getMaxLengthofDName(line); + String suf = getMaxLengthofDName(ChatColor.getLastColors(pre) + getSecondMaxLengthofList(line)); + if (!team.getPrefix().equals(pre)) + team.setPrefix(pre); + + if (!team.getSuffix().equals(suf)) + team.setSuffix(suf); + + slot--; + } + } + + // TODO We using soon the scoreboard packets +/** Class enums = getNMSClass("IScoreboardCriteria$EnumScoreboardHealthDisplay"); + + Class chatbase = getNMSClass("IChatBaseComponent$ChatSerializer"); + Method mm2 = chatbase.getMethod("a", String.class); + Object serealized = mm2.invoke(chatbase, "{\"text\": \"" + ChatColor.translateAlternateColorCodes('&', "JobsDummy") + "\"}"); + Object e = enums.getEnumConstants()[0]; + Class IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); + Constructor IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); + Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("JobsDummy"); + Method m = boards.getClass().getMethod("registerNewObjective", String.class, getNMSClass("IScoreboardCriteria"), chatbase, enums); + Object obj = m.invoke(boards, objName, "JobsDummy", IScoreboardCriteria, serealized, e); + + Method mm = obj.getClass().getMethod("setDisplayName", String.class); + mm.invoke(obj, ChatColor.translateAlternateColorCodes('&', displayName)); + + Class p1 = getNMSClass("PacketPlayOutScoreboardObjective"); + Constructor p11 = p1.getConstructor(obj.getClass(), int.class); + Object pp1 = p11.newInstance(obj, 1); + sendPacket(player, pp1); + + Class p2 = getNMSClass("PacketPlayOutScoreboardObjective"); + Constructor p12 = p2.getConstructor(obj.getClass(), int.class); + Object pp2 = p12.newInstance(obj, 0); + sendPacket(player, pp2); + + Class packetClass = getNMSClass("PacketPlayOutScoreboardDisplayObjective"); + Constructor packetConstructor = packetClass.getConstructor(int.class, getNMSClass("ScoreboardObjective")); + Object packet = packetConstructor.newInstance(1, obj); + sendPacket(player, packet); + + for (int i = 0; i < 15; i++) { + if (i >= lines.size()) + break; + + String ln = ChatColor.translateAlternateColorCodes('&', lines.get(i)); + Class ScoreboardScoreClass = getNMSClass("ScoreboardScore"); + Constructor packetConstructor2 = ScoreboardScoreClass.getConstructor(getNMSClass("Scoreboard"), getNMSClass("ScoreboardObjective"), String.class); + Object packet2 = packetConstructor2.newInstance(boards, obj, ln); + Method mc = packet2.getClass().getMethod("setScore", int.class); + mc.invoke(packet2, 15 - i); + + Class PacketPlayOutScoreboardScoreClass = getNMSClass("PacketPlayOutScoreboardScore"); + Constructor PacketPlayOutScoreboardScoreConstructor = PacketPlayOutScoreboardScoreClass.getConstructor(getNMSClass("ScoreboardScore")); + Object PacketPlayOutScoreboardScore = PacketPlayOutScoreboardScoreConstructor.newInstance(packet2); + + sendPacket(player, PacketPlayOutScoreboardScore); + }*/ } else { Method m = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria")); @@ -242,4 +294,19 @@ public class CMIScoreboardManager { Object con = conField.get(nmsPlayer); return con; } + + private String getMaxLengthofDName(String s) { + return s.length() > 16 ? s.substring(0, 16) : s; + } + + private String getSecondMaxLengthofList(String s) { + if (s.length() > 32) { + s = s.substring(0, 32); + } + return s.length() > 16 ? s.substring(16, s.length()) : ""; + } + + private String getSlotColor(int slot) { + return ChatColor.values()[slot].toString(); + } }