h31ix

Untitled

May 11th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.48 KB | None | 0 0
  1. /*
  2. * AntiCheat for Bukkit.
  3. * Copyright (C) 2012 H31IX http://h31ix.net
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. package net.h31ix.anticheat.xray;
  20.  
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import org.bukkit.ChatColor;
  24. import org.bukkit.command.CommandSender;
  25. import org.bukkit.entity.Player;
  26.  
  27. public class XRayTracker {
  28. private Map<Player,Integer> diamond = new HashMap<Player,Integer>();
  29. private Map<Player,Integer> gold = new HashMap<Player,Integer>();
  30. private Map<Player,Integer> iron = new HashMap<Player,Integer>();
  31. private Map<Player,Integer> coal = new HashMap<Player,Integer>();
  32. private Map<Player,Integer> lapis = new HashMap<Player,Integer>();
  33. private Map<Player,Integer> redstone = new HashMap<Player,Integer>();
  34. private Map<Player,Integer> block = new HashMap<Player,Integer>();
  35. private Map<Player,Integer> totalblock = new HashMap<Player,Integer>();
  36. private static final ChatColor GREEN = ChatColor.GREEN;
  37. private static final ChatColor WHITE = ChatColor.WHITE;
  38. private static final ChatColor RED = ChatColor.RED;
  39. private static final ChatColor GRAY = ChatColor.GRAY;
  40. private static final int DIVISOR = 100;
  41. private static final int RATIO_DIVISOR = 3;
  42. private static final int POWER = 10;
  43. private static final int MIN_BLOCK_COUNT = 10;
  44.  
  45. public XRayTracker()
  46. {
  47.  
  48. }
  49.  
  50. public boolean sufficientData(Player player)
  51. {
  52. return totalblock.get(player) != null && totalblock.get(player) >= MIN_BLOCK_COUNT;
  53. }
  54.  
  55. public void sendStats(CommandSender cs, Player player)
  56. {
  57. double t = 1;
  58. double d = 0;
  59. double g = 0;
  60. double i = 0;
  61. double c = 0;
  62. double la = 0;
  63. double r = 0;
  64. double b = 0;
  65. if(totalblock.get(player) != null)
  66. {
  67. t = totalblock.get(player);
  68. }
  69. if(diamond.get(player) != null)
  70. {
  71. d = (diamond.get(player)/t)*DIVISOR;
  72. }
  73. if(gold.get(player) != null)
  74. {
  75. g = (gold.get(player)/t)*DIVISOR;
  76. }
  77. if(iron.get(player) != null)
  78. {
  79. i = (iron.get(player)/t)*DIVISOR;
  80. }
  81. if(coal.get(player) != null)
  82. {
  83. c = (coal.get(player)/t)*DIVISOR;
  84. }
  85. if(lapis.get(player) != null)
  86. {
  87. la = (lapis.get(player)/t)*DIVISOR;
  88. }
  89. if(redstone.get(player) != null)
  90. {
  91. r = (redstone.get(player)/t)*DIVISOR;
  92. }
  93. if(block.get(player) != null)
  94. {
  95. b = (block.get(player)/t)*DIVISOR;
  96. }
  97. cs.sendMessage("--------------------["+GREEN+"X-Ray Stats"+WHITE+"]---------------------");
  98. ChatColor color = WHITE;
  99. if(d >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
  100. {
  101. color = RED;
  102. }
  103. cs.sendMessage(GRAY+"Player: "+WHITE+player.getName());
  104. cs.sendMessage(GRAY+"Total blocks broken: "+WHITE+t);
  105. cs.sendMessage(GRAY+"Percent diamond ore: "+color+round(d)+"%");
  106. color = WHITE;
  107. if(g >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
  108. {
  109. color = RED;
  110. }
  111. cs.sendMessage(GRAY+"Percent gold ore: "+color+round(g)+"%");
  112. color = WHITE;
  113. if(i >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
  114. {
  115. color = RED;
  116. }
  117. cs.sendMessage(GRAY+"Percent iron ore: "+color+round(i)+"%");
  118. color = WHITE;
  119. if(c >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
  120. {
  121. color = RED;
  122. }
  123. cs.sendMessage(GRAY+"Percent coal ore: "+color+round(c)+"%");
  124. color = WHITE;
  125. if(la >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
  126. {
  127. color = RED;
  128. }
  129. cs.sendMessage(GRAY+"Percent lapis ore: "+color+round(la)+"%");
  130. color = WHITE;
  131. if(r >= b/RATIO_DIVISOR && t > MIN_BLOCK_COUNT)
  132. {
  133. color = RED;
  134. }
  135. cs.sendMessage(GRAY+"Percent redstone ore: "+color+round(r)+"%");
  136. cs.sendMessage(GRAY+"Percent all other blocks: "+WHITE+round(b)+"%");
  137. cs.sendMessage("-----------------------------------------------------");
  138. }
  139.  
  140. public void addDiamond(Player player)
  141. {
  142. addOre(player,diamond);
  143. }
  144.  
  145. public void addGold(Player player)
  146. {
  147. addOre(player,gold);
  148. }
  149.  
  150. public void addCoal(Player player)
  151. {
  152. addOre(player,coal);
  153. }
  154.  
  155. public void addIron(Player player)
  156. {
  157. addOre(player,iron);
  158. }
  159.  
  160. public void addLapis(Player player)
  161. {
  162. addOre(player,lapis);
  163. }
  164.  
  165. public void addRedstone(Player player)
  166. {
  167. addOre(player,redstone);
  168. }
  169.  
  170. public void addBlock(Player player)
  171. {
  172. addOre(player,block);
  173. }
  174.  
  175. public void addTotal(Player player)
  176. {
  177. addOre(player,totalblock);
  178. }
  179.  
  180. private void addOre(Player player, Map<Player,Integer> map)
  181. {
  182. if(map.get(player) == null || map.get(player) == 0)
  183. {
  184. map.put(player,1);
  185. }
  186. else
  187. {
  188. int playerLevel = map.get(player);
  189. map.put(player, playerLevel+1);
  190. }
  191. }
  192.  
  193. private float round(double num)
  194. {
  195. float p = (float)Math.pow(10,1);
  196. num*=p;
  197. float tmp = Math.round(num);
  198. return (float)tmp/p;
  199. }
  200.  
  201. public void reset(Player player)
  202. {
  203. totalblock.put(player,1);
  204. diamond.put(player,0);
  205. iron.put(player,0);
  206. gold.put(player,0);
  207. coal.put(player,0);
  208. redstone.put(player,0);
  209. lapis.put(player,0);
  210. totalblock.put(player,0);
  211. }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment