private static boolean isSetException(Score score) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException { Object craftScore = CRAFT_SCORE.cast(score); Object craftObjective = CRAFT_OBJECTIVE.cast(score.getObjective()); Method craftHandle = CRAFT_OBJECTIVE.getDeclaredMethod("getHandle"); craftHandle.setAccessible(true); Object craftObjectiveHandle = craftHandle.invoke(craftObjective); Field objective = CRAFT_SCORE.getDeclaredField("objective"); objective.setAccessible(true); Object craftScoreboard = checkState(objective.get(craftScore)); Field craftBoard = CRAFT_SCOREBOARD.getDeclaredField("board"); craftBoard.setAccessible(true); Object scoreboard = craftBoard.get(craftScoreboard); Method playerObjectives = SCOREBOARD.getDeclaredMethod("getPlayerObjectives", String.class); playerObjectives.setAccessible(true); Field playerField = CRAFT_SCORE.getDeclaredField("entry"); playerField.setAccessible(true); String playerName = (String) playerField.get(craftScore); Map map = (Map) playerObjectives.invoke(scoreboard, playerName); // return // objective.checkState().board.getPlayerObjectives(playerName).containsKey(objective.getHandle()); return map.containsKey(craftObjectiveHandle); }
public void subKarma(int givKarma) { this.karma = this.karma - givKarma; if (this.karma < -1200) { this.karma = -1200; } Score curScore = HGGodWars.kBoard.karmaObj.getScore(this.playerName); curScore.setScore(this.karma); realignKarma(); }
public void setBoard(Player player, int time) { this.objective.setDisplaySlot(DisplaySlot.SIDEBAR); this.objective.setDisplayName("TNT Tag"); Score money = this.objective.getScore("Players:"); money.setScore(this.players.size()); Score Tags = this.objective.getScore("Time:"); Tags.setScore(time); player.setScoreboard(this.board); }
public Scoreboard Initialize(Player p) throws IllegalStateException, IllegalArgumentException { ScoreboardManager manager = Bukkit.getScoreboardManager(); Scoreboard board = manager.getNewScoreboard(); Objective objective = board.registerNewObjective("test", "dummy"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); objective.setDisplayName( ChatColor.GOLD + "" + ChatColor.BOLD + " _Esti" + ChatColor.DARK_AQUA + "" + ChatColor.BOLD + "Net_ "); Score score2 = objective.getScore(ChatColor.DARK_BLUE + "Online:"); // Get a fake offline player score2.setScore(4); Score score3 = objective.getScore( ChatColor.BOLD + "" + Integer.toString( Bukkit.getServer().getOnlinePlayers().size())); // Get a fake offline player score3.setScore(3); Score score = objective.getScore( ChatColor.AQUA + "Time before game starts:"); // Get a fake offline player score.setScore(2); Score score5 = objective.getScore( ChatColor.BOLD + "" + Basic.countdown + " "); // Get a fake offline player score5.setScore(1); return board; }
public void scoreboard() { boardClass.setDisplaySlot(DisplaySlot.SIDEBAR); Score rank = boardClass.getScore(ChatColor.GREEN + "Rank:"); Score power = boardClass.getScore(ChatColor.GOLD + "Power:"); rank.setScore(userSkillClass.getRank()); power.setScore(userSkillClass.getPower()); Score[] score = new Score[userSkillClass.getSkillClass().getSkills().size()]; for (int i = 0; i < userSkillClass.getSkillClass().getSkills().size(); i++) { Skill skill = userSkillClass.getSkillClass().getSkills().get(i); score[i] = boardClass.getScore(ChatColor.GREEN + skill.getScoreboardName() + ":"); score[i].setScore(userSkillClass.getLevel(skill)); } player.setScoreboard(board); }
private void prepareScoreboard() { Objective objective = this.scoreboard.registerNewObjective("queue", "dummy"); objective.setDisplayName(FortressSiege.msgPrefix); objective.setDisplaySlot(DisplaySlot.SIDEBAR); Score players = objective.getScore("Spieler: "); players.setScore(0); Score timeleft = objective.getScore("Restzeit: "); timeleft.setScore(0); Objective score = this.scoreboard.registerNewObjective("score", "dummy"); score.setDisplaySlot(DisplaySlot.PLAYER_LIST); score.setDisplayName("Score"); }
private void initialize() { if (!Settings.getInstance().dummyEnable) return; Scoreboard scoreboard = this.user.getScoreboard(); Objective objective = scoreboard.getObjective(NAME); if (objective == null || !objective.getName().equals(NAME)) { objective = scoreboard.registerNewObjective(NAME, "dummy"); objective.setDisplaySlot(DisplaySlot.BELOW_NAME); objective.setDisplayName(Settings.getInstance().dummySuffix); } for (Player player : Bukkit.getOnlinePlayers()) { User user = User.get(player); @SuppressWarnings("deprecation") Score score = objective.getScore(user.getOfflineUser()); score.setScore(user.getRank().getPoints()); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onDamage(EntityDamageByEntityEvent e) { if (e.isCancelled()) { System.out.println("Event is cancelled. Ignoring..."); return; } if (e.getEntity() instanceof Player && e.getDamager() instanceof Player) { final Player damaged = (Player) e.getEntity(); final Player damager = (Player) e.getDamager(); if (!inCombat.containsKey(damaged.getName())) { damaged.sendMessage(ChatColor.RED + "You are now in combat!"); final Scoreboard scoreboard = damaged.getScoreboard(); Objective objective = scoreboard.getObjective("timers") == null ? scoreboard.registerNewObjective("timers", "dummy") : scoreboard.getObjective("timers"); objective.setDisplayName("§6Timers"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); final Score combatTag = objective.getScore("§aCombat Tag"); combatTag.setScore(60); // damaged.setScoreboard(scoreboard); inCombatTag.put( damaged.getName(), new BukkitRunnable() { @Override public void run() { if (inCombat.get(damaged.getName()) != null) { if (inCombat.get(damaged.getName()) > 0) { inCombat.put(damaged.getName(), inCombat.get(damaged.getName()) - 1); combatTag.setScore(inCombat.get(damaged.getName())); } else { inCombat.remove(damaged.getName()); damaged.sendMessage(ChatColor.GREEN + "You are no longer in combat."); scoreboard.resetScores("§aCombat Tag"); this.cancel(); inCombatTag.remove(damager.getName()); } } } }); inCombatTag .get(damaged.getName()) .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L); } if (!inCombat.containsKey(damager.getName())) { damager.sendMessage(ChatColor.RED + "You are now in combat!"); final Scoreboard scoreboard2 = damager.getScoreboard(); Objective objective2 = scoreboard2.getObjective("timers") == null ? scoreboard2.registerNewObjective("timers", "dummy") : scoreboard2.getObjective("timers"); objective2.setDisplayName("§6Timers"); objective2.setDisplaySlot(DisplaySlot.SIDEBAR); final Score combatTag2 = objective2.getScore("§aCombat Tag"); combatTag2.setScore(60); // damager.setScoreboard(scoreboard2); inCombatTag.put( damager.getName(), new BukkitRunnable() { @Override public void run() { if (inCombat.get(damager.getName()) != null) { if (inCombat.get(damager.getName()) > 0) { inCombat.put(damager.getName(), inCombat.get(damager.getName()) - 1); combatTag2.setScore(inCombat.get(damager.getName())); } else { inCombat.remove(damager.getName()); damager.sendMessage(ChatColor.GREEN + "You are no longer in combat."); scoreboard2.resetScores("§aCombat Tag"); this.cancel(); inCombatTag.remove(damager.getName()); } } } }); inCombatTag .get(damager.getName()) .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L); } inCombat.put(damaged.getName(), 60); inCombat.put(damager.getName(), 60); } if (e.getEntity() instanceof Player && e.getDamager() instanceof Projectile) { final Player damaged = (Player) e.getEntity(); Projectile projectile = (Projectile) e.getDamager(); if (projectile.getShooter() instanceof Player) { final Player damager = (Player) projectile.getShooter(); if (damager.equals(damaged)) { return; } if (!inCombat.containsKey(damaged.getName())) { damaged.sendMessage(ChatColor.RED + "You are now in combat!"); final Scoreboard scoreboard = damaged.getScoreboard(); Objective objective = scoreboard.getObjective("ct") == null ? scoreboard.registerNewObjective("ct", "dummy") : scoreboard.getObjective("ct"); objective.setDisplayName("§6Timers"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); final Score combatTag = objective.getScore("§aCombat Tag"); combatTag.setScore(60); // damaged.setScoreboard(scoreboard); inCombatTag.put( damaged.getName(), new BukkitRunnable() { @Override public void run() { if (inCombat.get(damaged.getName()) != null) { if (inCombat.get(damaged.getName()) > 0) { inCombat.put(damaged.getName(), inCombat.get(damaged.getName()) - 1); combatTag.setScore(inCombat.get(damaged.getName())); } else { inCombat.remove(damaged.getName()); damaged.sendMessage(ChatColor.GREEN + "You are no longer in combat."); scoreboard.resetScores("§aCombat Tag"); this.cancel(); inCombatTag.remove(damager.getName()); } } } }); inCombatTag .get(damaged.getName()) .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L); } if (!inCombat.containsKey(damager.getName())) { damager.sendMessage(ChatColor.RED + "You are now in combat!"); final Scoreboard scoreboard2 = damager.getScoreboard(); Objective objective2 = scoreboard2.getObjective("ct") == null ? scoreboard2.registerNewObjective("ct", "dummy") : scoreboard2.getObjective("ct"); objective2.setDisplayName("§6Timers"); objective2.setDisplaySlot(DisplaySlot.SIDEBAR); final Score combatTag2 = objective2.getScore("§aCombat Tag"); combatTag2.setScore(60); // damager.setScoreboard(scoreboard2); inCombatTag.put( damager.getName(), new BukkitRunnable() { @Override public void run() { if (inCombat.get(damager.getName()) != null) { if (inCombat.get(damager.getName()) > 0) { inCombat.put(damager.getName(), inCombat.get(damager.getName()) - 1); combatTag2.setScore(inCombat.get(damager.getName())); } else { inCombat.remove(damager.getName()); damager.sendMessage(ChatColor.GREEN + "You are no longer in combat."); scoreboard2.resetScores("§aCombat Tag"); this.cancel(); inCombatTag.remove(damager.getName()); } } } }); inCombatTag .get(damager.getName()) .runTaskTimerAsynchronously(Hardcore.getPlugin(Hardcore.class), 20L, 20L); } inCombat.put(damaged.getName(), 60); inCombat.put(damager.getName(), 60); } } }
public void updateBoard() { for (Player p : playerBoards.keySet()) { if (p == null || !p.isOnline()) { return; } if (GameManager.seekers.contains(p.getName())) { Objective ob = playerBoards.get(p).getObjective("seekerboard"); if (ob == null) { ob = playerBoards.get(p).registerNewObjective("seekerboard", "dummy"); } Score score = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + plugin.ST.seeker_Translate + ":")); score.setScore(GameManager.seekers.size()); Score score1 = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + plugin.ST.hider_Translate + ":")); score1.setScore(GameManager.hiders.size()); Score score2 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.WHITE + plugin.ST.time_Left_Translate + ":")); score2.setScore(GameManager.timeleft); } if (GameManager.hiders.contains(p.getName())) { Objective ob = playerBoards.get(p).getObjective("hiderboard"); if (ob == null) { ob = playerBoards.get(p).registerNewObjective("hiderboard", "dummy"); } if (PropHunt.dc.isDisguised(p)) { ob.setDisplayName( ChatColor.AQUA + DisguiseManager.parseDisguiseToName(PropHunt.dc.getDisguise(p))); } Score score = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + plugin.ST.seeker_Translate + ":")); score.setScore(GameManager.seekers.size()); Score score1 = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + plugin.ST.hider_Translate + ":")); score1.setScore(GameManager.hiders.size()); Score score2 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.WHITE + plugin.ST.time_Left_Translate + ":")); score2.setScore(GameManager.timeleft); if (GameManager.usingSolidBlock) { Score score3 = ob.getScore( Bukkit.getOfflinePlayer( ChatColor.GREEN + "" + ChatColor.ITALIC + plugin.ST.solid_Time_Translate + ":")); if (SolidBlockTracker.solidBlocks.containsKey(p.getName())) { p.getScoreboard() .resetScores( Bukkit.getOfflinePlayer( ChatColor.GREEN + "" + ChatColor.ITALIC + plugin.ST.solid_Time_Translate + ":")); Score newscore = ob.getScore( Bukkit.getOfflinePlayer( ChatColor.GOLD + "" + ChatColor.BOLD + plugin.ST.solid_Translate + "")); newscore.setScore(1); } else { p.getScoreboard() .resetScores( Bukkit.getOfflinePlayer( ChatColor.GOLD + "" + ChatColor.BOLD + plugin.ST.solid_Translate + "")); score3.setScore( GameManager.solidBlockTime - SolidBlockTracker.movementTracker.get(p.getName())); } } } if (GameManager.playersWaiting.contains(p.getName())) { Objective ob = playerBoards.get(p).getObjective("lobbyboard"); if (ob == null) { ob = playerBoards.get(p).registerNewObjective("lobbyboard", "dummy"); } if (!GameManager.gameStatus) { Score scorey = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.GREEN + plugin.ST.starting_In_Translate + "")); scorey.setScore(GameManager.currentLobbyTime); } else { p.getScoreboard() .resetScores( Bukkit.getOfflinePlayer(ChatColor.GREEN + plugin.ST.starting_In_Translate + "")); } Score score = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + plugin.ST.seeker_Translate + ":")); score.setScore(GameManager.seekers.size()); Score score1 = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + plugin.ST.hider_Translate + ":")); score1.setScore(GameManager.hiders.size()); Score score2 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.WHITE + plugin.ST.time_Left_Translate + ":")); score2.setScore(GameManager.timeleft); Score score3 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.YELLOW + plugin.ST.player_Translate + ":")); score3.setScore(GameManager.playersWaiting.size()); Score score4 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.GRAY + plugin.ST.spectator_Translate + ":")); score4.setScore(GameManager.spectators.size()); } if (GameManager.spectators.contains(p.getName())) { Objective ob = playerBoards.get(p).getObjective("lobbyboard"); if (ob == null) { ob = playerBoards.get(p).registerNewObjective("lobbyboard", "dummy"); } Score score = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + plugin.ST.seeker_Translate + ":")); score.setScore(GameManager.seekers.size()); Score score1 = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + plugin.ST.hider_Translate + ":")); score1.setScore(GameManager.hiders.size()); Score score2 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.WHITE + plugin.ST.time_Left_Translate + ":")); score2.setScore(GameManager.timeleft); Score score3 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.YELLOW + plugin.ST.player_Translate + ":")); score3.setScore(GameManager.playersWaiting.size()); Score score4 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.GRAY + plugin.ST.spectator_Translate + ":")); score4.setScore(GameManager.spectators.size()); } } }
public void addPlayerToGame(PropHunt plugin, Player p) { if (p == null || !p.isOnline()) { return; } if (GameManager.seekers.contains(p.getName())) { Scoreboard sb = plugin.getServer().getScoreboardManager().getNewScoreboard(); Objective ob = sb.registerNewObjective("seekerboard", "dummy"); ob.setDisplaySlot(DisplaySlot.SIDEBAR); ob.setDisplayName(ChatColor.GOLD + "PropHunt Stats"); Score score = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + plugin.ST.seeker_Translate + ":")); score.setScore(GameManager.seekers.size()); Score score1 = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + plugin.ST.hider_Translate + ":")); score1.setScore(GameManager.hiders.size()); Score score2 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.WHITE + plugin.ST.time_Left_Translate + ":")); score2.setScore(GameManager.timeleft); p.setScoreboard(sb); playerBoards.put(p, sb); } if (GameManager.hiders.contains(p.getName())) { Scoreboard sb = plugin.getServer().getScoreboardManager().getNewScoreboard(); Objective ob = sb.registerNewObjective("hiderboard", "dummy"); ob.setDisplaySlot(DisplaySlot.SIDEBAR); ob.setDisplayName( ChatColor.AQUA + DisguiseManager.parseDisguiseToName(PropHunt.dc.getDisguise(p))); Score score = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + plugin.ST.seeker_Translate + ":")); score.setScore(GameManager.seekers.size()); Score score1 = ob.getScore(Bukkit.getOfflinePlayer(ChatColor.AQUA + plugin.ST.hider_Translate + ":")); score1.setScore(GameManager.hiders.size()); Score score2 = ob.getScore( Bukkit.getOfflinePlayer(ChatColor.WHITE + plugin.ST.time_Left_Translate + ":")); score2.setScore(GameManager.timeleft); p.setScoreboard(sb); playerBoards.put(p, sb); } }
public void setKarma(int givKarma) { this.karma = givKarma; Score curScore = HGGodWars.kBoard.karmaObj.getScore(this.playerName); curScore.setScore(this.karma); realignKarma(); }
private static void resetException(Score score) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException { Object craftScore = CRAFT_SCORE.cast(score); Object craftObjective = CRAFT_OBJECTIVE.cast(score.getObjective()); Method craftHandle = CRAFT_OBJECTIVE.getDeclaredMethod("getHandle"); craftHandle.setAccessible(true); Object craftObjectiveHandle = craftHandle.invoke(craftObjective); Field objective = CRAFT_SCORE.getDeclaredField("objective"); objective.setAccessible(true); Object craftScoreboard = checkState(objective.get(craftScore)); /* Method checkState = CRAFT_OBJECTIVE.getDeclaredMethod("checkState"); checkState.setAccessible(true); craftScoreboard = checkState.invoke(CRAFT_SCORE.getDeclaredField("objective").get(craftScore)); */ Field scoreboardField = CRAFT_SCOREBOARD.getDeclaredField("board"); scoreboardField.setAccessible(true); Object scoreboard = scoreboardField.get(craftScoreboard); Method playerObjectives = SCOREBOARD.getDeclaredMethod("getPlayerObjectives", String.class); playerObjectives.setAccessible(true); Field playerField = CRAFT_SCORE.getDeclaredField("playerName"); playerField.setAccessible(true); String playerName = (String) playerField.get(craftScore); Map map = (Map) playerObjectives.invoke(scoreboard, playerName); if (map.remove(craftObjectiveHandle) == null) { // If they don't have a score to delete, don't delete it. return; } Method resetScores = SCOREBOARD.getDeclaredMethod("resetPlayerScores", String.class); resetScores.setAccessible(true); resetScores.invoke(scoreboard, playerName); for (Object key : map.keySet()) { Object value = map.get(key); Method playerScoreMethod = SCOREBOARD.getDeclaredMethod( "getPlayerScoreForObjective", String.class, SCOREBOARD_OBJECTIVE); playerScoreMethod.setAccessible(true); Object scoreboardScore = playerScoreMethod.invoke(scoreboard, playerName, key); Method getScore = SCOREBOARD_SCORE.getDeclaredMethod("getScore"); getScore.setAccessible(true); int setScoreTo = (int) getScore.invoke(value); Method setScore = SCOREBOARD_SCORE.getDeclaredMethod("setScore", int.class); setScore.setAccessible(true); setScore.invoke(scoreboardScore, setScoreTo); } /* CraftScoreboard myBoard = objective.checkState(); Map<ScoreboardObjective, ScoreboardScore> savedScores = myBoard.board.getPlayerObjectives(playerName); if(savedScores.remove(objective.getHandle()) == null) { // If they don't have a score to delete, don't delete it. return; } myBoard.board.resetPlayerScores(playerName); for(Map.Entry<ScoreboardObjective, ScoreboardScore> e : savedScores.entrySet()) { myBoard.board.getPlayerScoreForObjective(playerName, e.getKey()).setScore(e.getValue().getScore()); } */ }
public void updatePlayers() { Objective objective = this.scoreboard.getObjective("queue"); Score timeleft = objective.getScore("Spieler: "); timeleft.setScore(FortressSiege.gameHandler.queueList.size()); }
public void updateTimeleft() { Objective objective = this.scoreboard.getObjective("queue"); Score timeleft = objective.getScore("Restzeit: "); timeleft.setScore(FortressSiege.queueTask.getRemaining()); }