Advertisement
Guest User

Untitled

a guest
Apr 30th, 2014
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.61 KB | None | 0 0
  1. package me.Dablakbandit.Lobby.Players;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Set;
  6.  
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.scoreboard.DisplaySlot;
  10. import org.bukkit.scoreboard.Objective;
  11. import org.bukkit.scoreboard.Score;
  12. import org.bukkit.scoreboard.Scoreboard;
  13. import org.bukkit.scoreboard.Team;
  14.  
  15. @SuppressWarnings("deprecation")
  16. public class ScoreBoardHandler
  17. {
  18. private final String boardName;
  19. private final String mainObjectiveName;
  20. private final Scoreboard scoreBoard;
  21. private Objective mainObjective;
  22. private final List<String> players = new ArrayList<String>();
  23. private DisplaySlot slot;
  24.  
  25. public ScoreBoardHandler(String scoreBoardName, String mainObjectiveName, DisplaySlot slot)
  26. {
  27. this(scoreBoardName, mainObjectiveName, slot, null);
  28. }
  29.  
  30. public ScoreBoardHandler(String scoreBoardName, String mainObjectiveName, DisplaySlot slot, String[] lines)
  31. {
  32. this.boardName = scoreBoardName;
  33. this.mainObjectiveName = mainObjectiveName;
  34. this.slot = slot;
  35. this.scoreBoard = Bukkit.getScoreboardManager().getNewScoreboard();
  36. this.mainObjective = this.scoreBoard.registerNewObjective("main",
  37. ObjectiveCriteria.DUMMY.getName());
  38.  
  39. this.mainObjective.setDisplayName(mainObjectiveName);
  40. this.mainObjective.setDisplaySlot(slot);
  41. if (lines != null) {
  42. for (int i = 0; i < lines.length; i++) {
  43. addObjectiveScore(lines[i], i);
  44. }
  45. }
  46. }
  47.  
  48. public Scoreboard getScoreBoard()
  49. {
  50. return this.scoreBoard;
  51. }
  52.  
  53. public String getBoardName()
  54. {
  55. return this.boardName;
  56. }
  57.  
  58. public String getMainObjectiveName()
  59. {
  60. return this.mainObjectiveName;
  61. }
  62.  
  63. public Objective getMainObjective(){
  64. return this.mainObjective;
  65. }
  66.  
  67. public void setScoreboardName(String name)
  68. {
  69. this.mainObjective.setDisplayName(name);
  70. updatePlayersOnScoreboardNameChange();
  71. }
  72.  
  73. public void changeCriteria(ObjectiveCriteria criteria)
  74. {
  75. this.mainObjective.unregister();
  76. this.mainObjective = null;
  77. this.mainObjective = this.scoreBoard.registerNewObjective("main",
  78. criteria.getName());
  79. this.mainObjective.setDisplayName(this.mainObjectiveName);
  80. this.mainObjective.setDisplaySlot(this.slot);
  81. }
  82.  
  83. public void changeCriteria(Stat criteria, int id)
  84. {
  85. this.mainObjective.unregister();
  86. this.mainObjective = null;
  87. this.mainObjective = this.scoreBoard.registerNewObjective("main",
  88. Stat.getStatWithID(criteria, id));
  89. this.mainObjective.setDisplayName(this.mainObjectiveName);
  90. this.mainObjective.setDisplaySlot(this.slot);
  91. }
  92.  
  93. public DisplaySlot getDisplaySlot()
  94. {
  95. return this.slot;
  96. }
  97.  
  98. public void setDisplaySlot(DisplaySlot slot)
  99. {
  100. this.slot = slot;
  101. }
  102.  
  103. private void updatePlayersOnScoreboardNameChange()
  104. {
  105. for (String playerName : this.players)
  106. {
  107. Player player = Bukkit.getPlayer(playerName);
  108. if (player != null) {
  109. player.setScoreboard(this.scoreBoard);
  110. }
  111. }
  112. }
  113.  
  114. public void checkPlayers()
  115. {
  116. for (String playerName : this.players)
  117. {
  118. Player player = Bukkit.getPlayer(playerName);
  119. if (player != null)
  120. {
  121. if (!player.getScoreboard().equals(this.scoreBoard)) {
  122. this.players.remove(playerName);
  123. }
  124. }
  125. else {
  126. this.players.remove(playerName);
  127. }
  128. }
  129. }
  130.  
  131. public List<String> getPlayers()
  132. {
  133. checkPlayers();
  134. return this.players;
  135. }
  136.  
  137. public Set<Team> getTeams()
  138. {
  139. return this.scoreBoard.getTeams();
  140. }
  141.  
  142. public Team getTeam(String teamName)
  143. {
  144. return this.scoreBoard.getTeam(teamName);
  145. }
  146.  
  147. public void registerTeam(String teamName)
  148. {
  149. this.scoreBoard.registerNewTeam(teamName);
  150. }
  151.  
  152. public Set<Objective> getObjectives()
  153. {
  154. return this.scoreBoard.getObjectives();
  155. }
  156.  
  157. public Objective getObjective(String objectiveName)
  158. {
  159. return this.scoreBoard.getObjective(objectiveName);
  160. }
  161.  
  162. public void registerObjective(String objective, ObjectiveCriteria criteria)
  163. {
  164. this.scoreBoard.registerNewObjective(objective, criteria.getName());
  165. }
  166.  
  167. public Objective getObjectiveInSlot(DisplaySlot slot)
  168. {
  169. return this.scoreBoard.getObjective(slot);
  170. }
  171.  
  172. public void setScoreboard(Player player)
  173. {
  174. player.setScoreboard(this.scoreBoard);
  175. this.players.add(player.getName());
  176. }
  177.  
  178. public void setScoreboard(Player player, Scoreboard otherScoreboard)
  179. {
  180. player.setScoreboard(otherScoreboard);
  181. this.players.remove(player.getName());
  182. }
  183.  
  184. public void removeScoreboard(Player player, boolean blank)
  185. {
  186. if (blank) {
  187. player.setScoreboard(Bukkit.getScoreboardManager()
  188. .getNewScoreboard());
  189. } else {
  190. player.setScoreboard(Bukkit.getScoreboardManager()
  191. .getMainScoreboard());
  192. }
  193. }
  194.  
  195. public void addObjectiveScore(String scoreName, int score)
  196. {
  197. this.mainObjective.getScore(Bukkit.getOfflinePlayer(scoreName)).setScore(
  198. score);
  199. }
  200.  
  201. public void addObjectiveScore(Objective objective, String scoreName, int score)
  202. {
  203. objective.getScore(Bukkit.getOfflinePlayer(scoreName)).setScore(score);
  204. }
  205.  
  206. public Score getObjectiveScore(String score)
  207. {
  208. return this.mainObjective.getScore(Bukkit.getOfflinePlayer(score));
  209. }
  210.  
  211. public Score getObjectiveScore(Objective objective, String score)
  212. {
  213. return objective.getScore(Bukkit.getOfflinePlayer(score));
  214. }
  215.  
  216. public void setObjectiveScore(String scoreName, int setScore)
  217. {
  218. getObjectiveScore(scoreName).setScore(setScore);
  219. }
  220.  
  221. public void setObjectiveScore(Objective objective, String scoreName, int setScore)
  222. {
  223. getObjectiveScore(objective, scoreName).setScore(setScore);
  224. }
  225.  
  226. public Set<Score> getScores(String score)
  227. {
  228. return this.scoreBoard.getScores(Bukkit.getOfflinePlayer(score));
  229. }
  230.  
  231. public static enum ObjectiveCriteria
  232. {
  233. DUMMY(
  234. "dummy"), DEATH_COUNT("deathCount"), HEALTH("health"), PLAYER_KILL_COUNT(
  235. "playerKillCount"), TOTAL_KILL_COUNT("totalKillCount"), achievement_MAKE_BREAD(
  236. "achievement.makeBread"), achievement_BAKE_CAKE(
  237. "achievement.bakeCake"), achievement_DIAMONDS_TO_YOU(
  238. "achievement.diamondsToYou"), achievement_KILL_COW(
  239. "achievement.killCow"), achievement_PORTAL("achievement.portal"), achievement_BUILD_FURNACE(
  240. "achievement.buildFurnace"), achievement_BUILD_SWORD(
  241. "achievement.buildSword"), achievement_COOK_FISH(
  242. "achievement.cookFish"), achievement_ENCHANTMENTS(
  243. "achievement.enchantments"), achievement_MINE_WOOD(
  244. "achievement.mineWood"), achievement_OPEN_INVENTORY(
  245. "achievement.openInventory"), achievement_EXPLORE_ALL_BIOMES(
  246. "achievement.exploreAllBiomes"), achievement_BUILD_WORKBENCH(
  247. "achievement.buildWorkBench"), achievement_THE_END(
  248. "achievement.theEnd"), achievement_BLAZE_ROD(
  249. "achievement.blazeRod"), achievement_SPAWN_WITHER(
  250. "achievement.spawnWither"), achievement_BUILD_BETTER_PICKAXE(
  251. "achievement.buildBetterPickaxe"), achievement_ACQUIRE_IRON(
  252. "achievement.acquireIron"), achievement_THE_END2(
  253. "achievement.theEnd2"), achievement_BOOKCASE(
  254. "achievement.bookcase"), achievement_FLYING_PIG(
  255. "achievement.flyPig"), achievement_GHAST("achievement.ghast"), achievement_SNIPE_SKELETON(
  256. "achievement.snipeSkeleton"), achievement_DIAMONDS(
  257. "achievement.diamonds"), achievement_KILL_WITHER(
  258. "achievement.killWither"), achievement_FULL_BEACON(
  259. "achievement.fullBeacon"), achievement_BUILD_HOE(
  260. "achievement.buildHoe"), achievement_BREED_COW(
  261. "achievement.breedCow"), achievement_ON_A_RAIL(
  262. "achievement.onARail"), achievement_OVERKILL(
  263. "achievement.overkill"), achievement_KILL_ENEMY(
  264. "achievement.killEnemy"), achievement_POTION(
  265. "achievement.potion"), achievement_BUILD_PICKAXE(
  266. "achievement.buildPickaxe"), stat_DAMAGE_DEALT("stat.damageDealt"), stat_DAMAGE_TAKE(
  267. "stat.damageTaken"), stat_LEAVE_GAME("stat.leaveGame"), stat_MINECART_ONE_CM(
  268. "stat.minecartOneCm"), stat_SWIM_ONE_CM("stat.swimOneCm"), stat_WALK_ONE_CM(
  269. "stat.walkOneCm"), stat_HORSE_ONE_CM("stat.horseOneCm"), stat_PIG_ONE_CM(
  270. "stat.pigOneCm"), stat_FLY_ONE_CM("stat.flyOneCm"), stat_BOAT_ONE_CM(
  271. "stat.boatOneCm"), stat_FALL_ONE_CM("stat.fallOneCm"), stat_CLIMB_ONE_CM(
  272. "stat.climbOneCm"), stat_DIVE_ONE_CM("stat.diveOneCm"), stat_FISH_CAUGHT(
  273. "stat.fishCaught"), stat_JUNK_FISHED("stat.junkFished"), stat_TREASURE_FISHED(
  274. "stat.treasureFished"), stat_PLAY_ONE_MINUE(
  275. "stat.playOneMinute"), stat_PLAYER_KILLS("stat.playerKills"), stat_MOB_KILLS(
  276. "stat.mobKills"), stat_ANIMALS_BRED("stat.animalsBred"), stat_JUMP(
  277. "stat.jump"), stat_DROP("stat.drop"), stat_DEATHS("stat.deaths"), stat_killEntity_SILVERFISH("stat.killEntity.Silverfish"), stat_killEntity_ZOMBIE(
  278. "stat.killEntity.Zombie"), stat_killEntity_BLAZE(
  279. "stat.killEntity.Blaze"), stat_killEntity_PIG(
  280. "stat.killEntity.Pig"), stat_killEntity_CREEPER(
  281. "stat.killEntity.Creeper"), stat_killEntity_COW(
  282. "stat.killEntity.Cow"), stat_killEntity_GHAS(
  283. "stat.killEntity.Ghast"), stat_killEntity_WHICH(
  284. "stat.killEntity.Witch"), stat_killEntity_SQUID(
  285. "stat.killEntity.Squid"), stat_killEntity_SPIDER(
  286. "stat.killEntity.Spider"), stat_killEntity_VILLATER(
  287. "stat.killEntity.Villager"), stat_killEntity_ENDERMAN(
  288. "stat.killEntity.Enderman"), stat_killEntity_LAVA_SLIME(
  289. "stat.killEntity.LavaSlime"), stat_killEntity_PIG_ZOMBIE(
  290. "stat.killEntity.PigZombie"), stat_killEntity_WOLF(
  291. "stat.killEntity.Wolf"), stat_killEntity_SHEEP(
  292. "stat.killEntity.Sheep"), stat_killEntity_CHIKEN(
  293. "stat.killEntity.Chicken"), stat_killEntity_SLIME(
  294. "stat.killEntity.Slime"), stat_killEntity_SLELETON(
  295. "stat.killEntity.Skeleton"), stat_killEntity_BAT(
  296. "stat.killEntity.Bat"), stat_killEntity_MUSHROOM_COW(
  297. "stat.killEntity.MushroomCow"), stat_killEntity_CAVE_SPIDER(
  298. "stat.killEntity.CaveSpider"), stat_killEntity_HORSE(
  299. "stat.killEntity.EntityHorse"), stat_killEntity_OCELOT("stat.killEntity.Ozelot"), stat_entityKilledBy_WOLF("stat.entityKilledBy.Wolf"), stat_entityKilledBy_ENDERMAN(
  300. "stat.entityKilledBy.Enderman"), stat_entityKilledBy_SLIME(
  301. "stat.entityKilledBy.Slime"), stat_entityKilledBy_LAVA_SLIME(
  302. "stat.entityKilledBy.LavaSlime"), stat_entityKilledBy_SPIDER(
  303. "stat.entityKilledBy.Spider"), stat_entityKilledBy_CREEPER(
  304. "stat.entityKilledBy.Creeper"), stat_entityKilledBy_BAT(
  305. "stat.entityKilledBy.Bat"), stat_entityKilledBy_SQUID(
  306. "stat.entityKilledBy.Squid"), stat_entityKilledBy_PIG_ZOMBIE(
  307. "stat.entityKilledBy.PigZombie"), stat_entityKilledBy_SILVERHIST(
  308. "stat.entityKilledBy.Silverfish"), stat_entityKilledBy_SKELETON(
  309. "stat.entityKilledBy.Skeleton"), stat_entityKilledBy_WHICH(
  310. "stat.entityKilledBy.Witch"), stat_entityKilledBy_PIG(
  311. "stat.entityKilledBy.Pig"), stat_entityKilledBy_BLAZE(
  312. "stat.entityKilledBy.Blaze"), stat_entityKilledBy_SHEEP(
  313. "stat.entityKilledBy.Sheep"), stat_entityKilledBy_MUSHROOM_COW(
  314. "stat.entityKilledBy.MushroomCow"), stat_entityKilledBy_CAVE_SPIDER(
  315. "stat.entityKilledBy.CaveSpider"), stat_entityKilledBy_VILLAGER(
  316. "stat.entityKilledBy.Villager"), stat_entityKilledBy_ZOMBIE(
  317. "stat.entityKilledBy.Zombie"), stat_entityKilledBy_CHICKEN(
  318. "stat.entityKilledBy.Chicken"), stat_entityKilledBy_COW(
  319. "stat.entityKilledBy.Cow"), stat_entityKilledBy_GHAST(
  320. "stat.entityKilledBy.Ghast"), stat_entityKilledBy_HORSE(
  321. "stat.entityKilledBy.EntityHorse"), stat_entityKilledBy_OCELOT("stat.entityKilledBy.Ozelot");
  322.  
  323. private final String name;
  324.  
  325. private ObjectiveCriteria(String name)
  326. {
  327. this.name = name;
  328. }
  329.  
  330. public String getName()
  331. {
  332. return this.name;
  333. }
  334.  
  335. public static String getCriteriaWithID(ObjectiveCriteria crit, int id)
  336. {
  337. return crit.getName() + "." + id;
  338. }
  339. }
  340.  
  341. public static enum Stat
  342. {
  343. CRAFT_ITEM("stat.craftItem"), USE_ITEM("stat.useItem"), BREAK_ITEM(
  344. "stat.breakItem"), MINE_BLOCK("stat.mineBlock");
  345.  
  346. private final String name;
  347.  
  348. private Stat(String name)
  349. {
  350. this.name = name;
  351. }
  352.  
  353. public String getName()
  354. {
  355. return this.name;
  356. }
  357.  
  358. public static String getStatWithID(Stat stat, int id)
  359. {
  360. return stat.getName() + "." + id;
  361. }
  362. }
  363. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement