diff --git a/.classpath b/.classpath index f3b20d9c..8e6499f1 100644 --- a/.classpath +++ b/.classpath @@ -2,34 +2,30 @@ - - + + - + - - + + - + - + - + - + - + - + - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index bbcbc934..c788ee34 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,5 +1,8 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.source=1.7 diff --git a/src/main/java/com/gamingmesh/jobs/Jobs.java b/src/main/java/com/gamingmesh/jobs/Jobs.java index e936f126..34e4ece2 100644 --- a/src/main/java/com/gamingmesh/jobs/Jobs.java +++ b/src/main/java/com/gamingmesh/jobs/Jobs.java @@ -60,7 +60,6 @@ import com.gamingmesh.jobs.config.LanguageManager; import com.gamingmesh.jobs.config.NameTranslatorManager; import com.gamingmesh.jobs.config.RestrictedAreaManager; import com.gamingmesh.jobs.config.RestrictedBlockManager; -import com.gamingmesh.jobs.config.ScboardManager; import com.gamingmesh.jobs.config.ScheduleManager; import com.gamingmesh.jobs.config.ShopManager; import com.gamingmesh.jobs.config.TitleManager; @@ -93,6 +92,7 @@ import com.gamingmesh.jobs.stuff.JobsClassLoader; import com.gamingmesh.jobs.stuff.Loging; import com.gamingmesh.jobs.stuff.TabComplete; import com.gamingmesh.jobs.stuff.VersionChecker; +import com.gamingmesh.jobs.stuff.CMIScoreboardManager; import com.gamingmesh.jobs.tasks.BufferedPaymentThread; import com.gamingmesh.jobs.tasks.DatabaseSaveThread; @@ -104,7 +104,7 @@ public class Jobs extends JavaPlugin { private static Language lManager = null; private static LanguageManager lmManager = null; private static SignUtil signManager = null; - private static ScboardManager scboardManager = null; + private CMIScoreboardManager CMIScoreboardManager = null; private static ScheduleManager scheduleManager = null; private static NameTranslatorManager NameTranslatorManager = null; private static GuiManager GUIManager = null; @@ -370,12 +370,15 @@ public class Jobs extends JavaPlugin { * Returns scoreboard manager * @return the scoreboard manager */ - public static ScboardManager getScboard() { - return scboardManager; + public CMIScoreboardManager getCMIScoreboardManager() { + if (CMIScoreboardManager == null) + CMIScoreboardManager = new CMIScoreboardManager(this); + return CMIScoreboardManager; } - public void setScboard() { - scboardManager = new ScboardManager(this); + protected static Jobs instance; + public static Jobs getInstance() { + return instance; } /** @@ -507,6 +510,7 @@ public class Jobs extends JavaPlugin { * @throws IOException */ public void startup() { + instance = this; try { reload(); } catch (IOException e1) { @@ -767,7 +771,6 @@ public class Jobs extends JavaPlugin { setPermissionHandler(new PermissionHandler(this)); setJobsClassloader(); setPlayerManager(); - setScboard(); setLanguage(); setGUIManager(); setExplore(); diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java b/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java index 8568c601..13ba5b31 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/entitylist.java @@ -1,13 +1,12 @@ package com.gamingmesh.jobs.commands.list; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.EntityType; import com.gamingmesh.jobs.Jobs; import com.gamingmesh.jobs.commands.Cmd; import com.gamingmesh.jobs.commands.JobCommand; -import net.md_5.bungee.api.ChatColor; - public class entitylist implements Cmd { @Override diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java index d0e925ab..df30114c 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/gtop.java @@ -1,5 +1,6 @@ package com.gamingmesh.jobs.commands.list; +import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; @@ -65,23 +66,17 @@ public class gtop implements Cmd { } } else { - Jobs.getScboard().addNew(player); - Scoreboard board = player.getScoreboard(); - Objective objective = board.getObjective("JobsTopPlayers"); - if (objective == null) - objective = board.registerNewObjective("JobsTopPlayers", "dummy"); - objective.setDisplaySlot(DisplaySlot.SIDEBAR); - objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.gtopline")); + List ls = new ArrayList(); + int i = page * 15 - 15; - int line = 16; - for (TopList One : FullList) { + for (TopList one : FullList) { i++; - line--; - String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; - Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", One.getLevel())); - score.setScore(line); + String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown"; + ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", one.getLevel())); } - player.setScoreboard(board); + + plugin.getCMIScoreboardManager().setScoreBoard(player, Jobs.getLanguage().getMessage("scoreboard.gtopline"), ls); + plugin.getCMIScoreboardManager().addNew(player); int prev = page < 2 ? 1 : page - 1; int next = page + 1; diff --git a/src/main/java/com/gamingmesh/jobs/commands/list/top.java b/src/main/java/com/gamingmesh/jobs/commands/list/top.java index e7592772..f73aadfc 100644 --- a/src/main/java/com/gamingmesh/jobs/commands/list/top.java +++ b/src/main/java/com/gamingmesh/jobs/commands/list/top.java @@ -1,5 +1,6 @@ package com.gamingmesh.jobs.commands.list; +import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; @@ -78,26 +79,38 @@ public class top implements Cmd { One.getExp())); } } else { - Jobs.getScboard().addNew(player); - Scoreboard board = player.getScoreboard(); - Objective objective = board.getObjective("JobsTopPlayers"); - if (objective == null) - objective = board.registerNewObjective("JobsTopPlayers", "dummy"); - objective.setDisplaySlot(DisplaySlot.SIDEBAR); - objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName)); - int i = start; - int line = 16; - for (TopList One : FullList) { + + List ls = new ArrayList(); + + int i = (start + 1) * 15 - 15; + for (TopList one : FullList) { i++; - line--; - String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; - - Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", One.getLevel())); - score.setScore(line); - + String playername = one.getPlayerName() != null ? one.getPlayerName() : "Unknown"; + ls.add(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", one.getLevel())); } - player.setScoreboard(board); + plugin.getCMIScoreboardManager().setScoreBoard(player, Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName), ls); + + plugin.getCMIScoreboardManager().addNew(player); + +// Scoreboard board = player.getScoreboard(); +// Objective objective = board.getObjective("JobsTopPlayers"); +// if (objective == null) +// objective = board.registerNewObjective("JobsTopPlayers", "dummy"); +// objective.setDisplaySlot(DisplaySlot.SIDEBAR); +// objective.setDisplayName(Jobs.getLanguage().getMessage("scoreboard.topline", "%jobname%", jobName)); +// int i = start; +// int line = 16; +// for (TopList One : FullList) { +// i++; +// line--; +// String playername = One.getPlayerName() != null ? One.getPlayerName() : "Unknown"; +// +// Score score = objective.getScore(Jobs.getLanguage().getMessage("scoreboard.line", "%number%", i, "%playername%", playername, "%level%", One.getLevel())); +// score.setScore(line); +// +// } +// player.setScoreboard(board); int from = start; if (start >= 15) diff --git a/src/main/java/com/gamingmesh/jobs/config/ScboardManager.java b/src/main/java/com/gamingmesh/jobs/config/ScboardManager.java deleted file mode 100644 index 64a6fa5e..00000000 --- a/src/main/java/com/gamingmesh/jobs/config/ScboardManager.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.gamingmesh.jobs.config; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; - -import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.container.ScoreboardInfo; - -public class ScboardManager { - - private ConcurrentHashMap timerMap = new ConcurrentHashMap(); - private Jobs plugin; - - public ScboardManager(Jobs plugin) { - this.plugin = plugin; - } - - private void RunScheduler() { - Iterator> MeinMapIter = timerMap.entrySet().iterator(); - while (MeinMapIter.hasNext()) { - Entry Map = MeinMapIter.next(); - - if (System.currentTimeMillis() > Map.getValue().getTime() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) { - Player player = Bukkit.getPlayer(Map.getKey()); - if (player != null) { - player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); - if (Map.getValue().getObj() != null) { - Objective obj = player.getScoreboard().getObjective(Map.getValue().getObj().getName()); - if (obj != null) - obj.setDisplaySlot(DisplaySlot.SIDEBAR); - } - } - timerMap.remove(Map.getKey()); - } - } - - if (timerMap.size() > 0) - Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - RunScheduler(); - return; - } - }, 20L); - return; - } - - public void addNew(Player player) { - Scoreboard scoreBoard = player.getScoreboard(); - timerMap.put(player.getUniqueId(), new ScoreboardInfo(scoreBoard, DisplaySlot.SIDEBAR)); - RunScheduler(); - } - -} diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java index 124c2dc6..6b51cc63 100644 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java +++ b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_11.java @@ -35,5 +35,4 @@ public class v1_11 implements NMS { public Block getTargetBlock(Player player, int range) { return player.getTargetBlock((Set) null, range); } - } diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java index adc8876b..8c5e3b65 100644 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java +++ b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_12.java @@ -35,5 +35,4 @@ public class v1_12 implements NMS { public Block getTargetBlock(Player player, int range) { return player.getTargetBlock((Set) null, range); } - } diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java index e3bf3523..62e3f2b1 100644 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java +++ b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_7.java @@ -3,6 +3,7 @@ package com.gamingmesh.jobs.nmsUtil; import java.util.ArrayList; import java.util.HashSet; import java.util.List; + import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.Horse; @@ -56,7 +57,7 @@ public class v1_7 implements NMS { public ItemStack getItemInMainHand(Player player) { return player.getInventory().getItemInHand(); } - + @SuppressWarnings("deprecation") @Override public Block getTargetBlock(Player player, int range) { diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java index 8c42e6a2..ced77033 100644 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java +++ b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_8.java @@ -58,13 +58,13 @@ public class v1_8 implements NMS { } return name; } - + @SuppressWarnings("deprecation") @Override public ItemStack getItemInMainHand(Player player) { return player.getInventory().getItemInHand(); } - + @Override public Block getTargetBlock(Player player, int range) { return player.getTargetBlock((Set) null, range); diff --git a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java index 7952f7f2..f1ba62c7 100644 --- a/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java +++ b/src/main/java/com/gamingmesh/jobs/nmsUtil/v1_9.java @@ -68,5 +68,4 @@ public class v1_9 implements NMS { public Block getTargetBlock(Player player, int range) { return player.getTargetBlock((Set) null, range); } - } diff --git a/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java b/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java new file mode 100644 index 00000000..f339bae0 --- /dev/null +++ b/src/main/java/com/gamingmesh/jobs/stuff/CMIScoreboardManager.java @@ -0,0 +1,168 @@ +package com.gamingmesh.jobs.stuff; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; + +import com.gamingmesh.jobs.Jobs; +import com.gamingmesh.jobs.container.ScoreboardInfo; + +public class CMIScoreboardManager { + + private ConcurrentHashMap timerMap = new ConcurrentHashMap(); + private Jobs plugin; + + public CMIScoreboardManager(Jobs plugin) { + this.plugin = plugin; + } + + private void RunScheduler() { + Iterator> MeinMapIter = timerMap.entrySet().iterator(); + while (MeinMapIter.hasNext()) { + Entry Map = MeinMapIter.next(); + + if (System.currentTimeMillis() > Map.getValue().getTime() + (Jobs.getGCManager().ToplistInScoreboardInterval * 1000)) { + Player player = Bukkit.getPlayer(Map.getKey()); + if (player != null) { + removeScoreBoard(player); + player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); + if (Map.getValue().getObj() != null) { + Objective obj = player.getScoreboard().getObjective(Map.getValue().getObj().getName()); + if (obj != null) + obj.setDisplaySlot(DisplaySlot.SIDEBAR); + } + } + timerMap.remove(Map.getKey()); + } + } + + if (timerMap.size() > 0) + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + RunScheduler(); + return; + } + }, 20L); + return; + } + + public void addNew(Player player) { + Scoreboard scoreBoard = player.getScoreboard(); + timerMap.put(player.getUniqueId(), new ScoreboardInfo(scoreBoard, DisplaySlot.SIDEBAR)); + RunScheduler(); + } + + private final String objName = "CMIScoreboard"; + + public void removeScoreBoard(Player player) { + try { + + Class boardClass = getNMSClass("Scoreboard"); + Object boards = boardClass.getConstructor().newInstance(); + + Method m = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria")); + + Class IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); + Constructor IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); + Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("dummy"); + + Object obj = m.invoke(boards, objName, IScoreboardCriteria); + Class p1 = getNMSClass("PacketPlayOutScoreboardObjective"); + Constructor p11 = p1.getConstructor(obj.getClass(), int.class); + Object pp1 = p11.newInstance(obj, 1); + sendPacket(player, pp1); + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + public void setScoreBoard(Player player, String displayName, List lines) { + + try { + Class boardClass = getNMSClass("Scoreboard"); + Object boards = boardClass.getConstructor().newInstance(); + + Method m = boards.getClass().getMethod("registerObjective", String.class, getNMSClass("IScoreboardCriteria")); + + Class IScoreboardCriterias = getNMSClass("ScoreboardBaseCriteria"); + Constructor IScoreboardCriteriasConst = IScoreboardCriterias.getConstructor(String.class); + Object IScoreboardCriteria = IScoreboardCriteriasConst.newInstance("dummy"); + + Object obj = m.invoke(boards, objName, IScoreboardCriteria); + + 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; + + Class ScoreboardScoreClass = getNMSClass("ScoreboardScore"); + Constructor packetConstructor2 = ScoreboardScoreClass.getConstructor(getNMSClass("Scoreboard"), getNMSClass("ScoreboardObjective"), String.class); + Object packet2 = packetConstructor2.newInstance(boards, obj, lines.get(i)); + 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); + + } + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + e.printStackTrace(); + } + } + + private static void sendPacket(Player player, Object packet) { + Method sendPacket; + try { + sendPacket = getNMSClass("PlayerConnection").getMethod("sendPacket", getNMSClass("Packet")); + sendPacket.invoke(getConnection(player), packet); + } catch (NoSuchMethodException | SecurityException | ClassNotFoundException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchFieldException e) { + e.printStackTrace(); + } + } + + private static Class getNMSClass(String nmsClassString) throws ClassNotFoundException { + return Class.forName("net.minecraft.server." + Jobs.getVersionCheckManager().getVersion() + "." + nmsClassString); + } + + private static Object getConnection(Player player) throws SecurityException, NoSuchMethodException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InvocationTargetException { + Method getHandle = player.getClass().getMethod("getHandle"); + Object nmsPlayer = getHandle.invoke(player); + Field conField = nmsPlayer.getClass().getField("playerConnection"); + Object con = conField.get(nmsPlayer); + return con; + } +}