/src/main/java/me/lordlladar/plugins/loworbitioncannon/Loic.java

https://github.com/LordLladar/Low-Orbit-Ion-Cannon · Java · 231 lines · 211 code · 20 blank · 0 comment · 39 complexity · 5fbd359696af4c6cb7483ed04655ddce MD5 · raw file

  1. package me.lordlladar.plugins.loworbitioncannon;
  2. import java.util.Hashtable;
  3. import java.util.List;
  4. import java.util.logging.Logger;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.block.Block;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.Event;
  11. import org.bukkit.event.Event.Priority;
  12. import org.bukkit.event.Event.Type;
  13. import org.bukkit.event.Listener;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15. public class Loic extends JavaPlugin {
  16. private final LoicPlayerListener playerListener
  17. = new LoicPlayerListener(this);
  18. private final LoicBlockListener blockListener
  19. = new LoicBlockListener(this);
  20. private final LoicEventListener eventListener
  21. = new LoicEventListener(this);
  22. public static final Logger log = Logger.getLogger("Minecraft");
  23. public static String name = "Low Orbit Ion Cannon";
  24. public static String codename = "LOIC";
  25. public static String version = "0.5";
  26. public Listener l = new Listener() { } ;
  27. static Hashtable<String, Integer> cannons = new Hashtable();
  28. public boolean execture (CommandSender sender, String[] args) {
  29. return true;
  30. }
  31. public void onEnable() {
  32. log.info("[" + name + "] Low Orbit Ion Cannon V." + version + " ..."); //Log Name + version in console
  33. log.info("[" + name + "] Low Orbit Ion Cannon by LordLladar."); //Log Name + Author in console
  34. log.info("[" + name + "] Low Orbit Ion Cannon ENABLED!"); //Log Name + Toggle in console
  35. registerEvents(); //Register Events
  36. }
  37. public void onDisable() {
  38. log.info("[" + name +"] Low Orbit Ion Cannon DISABLED!");
  39. }
  40. private void registerEvents() {
  41. getServer().getPluginManager().registerEvent
  42. (Event.Type.PLAYER_ANIMATION, this.playerListener,
  43. Priority.Normal, this);
  44. getServer().getPluginManager().registerEvent
  45. (Event.Type.ENTITY_EXPLODE, this.blockListener,
  46. Priority.Normal, this);
  47. getServer().getPluginManager().registerEvent
  48. (Event.Type.ENTITY_EXPLODE, this.eventListener,
  49. Priority.Normal, this);
  50. }
  51. public boolean onCommand(CommandSender sender, Command command,
  52. String commandLabel, String[] args) {
  53. if (sender instanceof Player);
  54. Player player = (Player)sender;
  55. if (command.getName().toString().equalsIgnoreCase("ioncannon")) {
  56. if (player.hasPermission("ioncannon.fire")) {
  57. if (cannons.containsKey(((Player)sender).getName().toString())) {
  58. getServer().broadcastMessage(ChatColor.YELLOW +
  59. "ATTENTION : " + ChatColor.BLUE +
  60. "Ion Cannons has been disabled");
  61. cannons.remove(((Player)sender).getName().toString());
  62. return true;
  63. }
  64. int size = 3;
  65. if (args.length > 0)
  66. size = Integer.parseInt(args[0]);
  67. if (size < 1)
  68. size = 1;
  69. getServer().broadcastMessage(ChatColor.RED + "WARNING : "
  70. + ChatColor.BLUE + "Ion Cannon Primed.");
  71. getServer().broadcastMessage(ChatColor.YELLOW + "ATTENTION : "
  72. + ChatColor.BLUE + "Beam Size Locked at " +ChatColor.GOLD
  73. + size + ".");
  74. cannons.put(((Player)sender).getName().toString(),
  75. Integer.valueOf(size));
  76. return true;
  77. }
  78. log.info("[WARNING] Player " + sender.toString() +
  79. " was denied access to the command: " + command.toString() + ".");
  80. sender.sendMessage(ChatColor.RED +
  81. "You do not have access to that command.");
  82. return true;
  83. }
  84. return false;
  85. }
  86. private void placePoints(int cx, int cz, int x, int z, int y,
  87. int blockType, Player player) {
  88. if (x == 0) {
  89. player.getWorld().getBlockAt(cx, y, cz + z).setTypeId(blockType);
  90. player.getWorld().getBlockAt(cx, y, cz - z).setTypeId(blockType);
  91. player.getWorld().getBlockAt(cx + z, y, cz).setTypeId(blockType);
  92. player.getWorld().getBlockAt(cx - z, y, cz).setTypeId(blockType);
  93. }
  94. else if (x == z) {
  95. player.getWorld().getBlockAt(cx + x, y, cz + z).setTypeId(blockType);
  96. player.getWorld().getBlockAt(cx - x, y, cz + z).setTypeId(blockType);
  97. player.getWorld().getBlockAt(cx + x, y, cz - z).setTypeId(blockType);
  98. player.getWorld().getBlockAt(cx - x, y, cz - z).setTypeId(blockType);
  99. }
  100. else if (x < z) {
  101. player.getWorld().getBlockAt(cx + x, y, cz + z).setTypeId(blockType);
  102. player.getWorld().getBlockAt(cx - x, y, cz + z).setTypeId(blockType);
  103. player.getWorld().getBlockAt(cx + x, y, cz - z).setTypeId(blockType);
  104. player.getWorld().getBlockAt(cx - x, y, cz - z).setTypeId(blockType);
  105. player.getWorld().getBlockAt(cx + z, y, cz + x).setTypeId(blockType);
  106. player.getWorld().getBlockAt(cx - z, y, cz + x).setTypeId(blockType);
  107. player.getWorld().getBlockAt(cx + z, y, cz - x).setTypeId(blockType);
  108. player.getWorld().getBlockAt(cx - z, y, cz - x).setTypeId(blockType);
  109. }
  110. }
  111. private void fillUpwards(int blockType, int x, int y, int z, Player player) {
  112. for (int i = 0; i < 5; i++) {
  113. if (player.getWorld().getBlockAt(x, y + i, z).getTypeId() != 0)
  114. break;
  115. player.getWorld().getBlockAt(x, y + i, z).setTypeId(blockType);
  116. }
  117. }
  118. private void placeCylinderPoints(int cx, int cz, int x, int z, int y,
  119. int blockType, Player player) {
  120. if (x == 0) {
  121. fillUpwards(blockType, cx, y, cz + z, player);
  122. fillUpwards(blockType, cx, y, cz - z, player);
  123. fillUpwards(blockType, cx + z, y, cz, player);
  124. fillUpwards(blockType, cx - z, y, cz, player);
  125. }
  126. else if (x == z) {
  127. fillUpwards(blockType, cx + x, y, cz + z, player);
  128. fillUpwards(blockType, cx - x, y, cz + z, player);
  129. fillUpwards(blockType, cx + x, y, cz - z, player);
  130. fillUpwards(blockType, cx - x, y, cz - z, player);
  131. }
  132. else if (x < z) {
  133. fillUpwards(blockType, cx + x, y, cz + z, player);
  134. fillUpwards(blockType, cx - x, y, cz + z, player);
  135. fillUpwards(blockType, cx + x, y, cz - z, player);
  136. fillUpwards(blockType, cx - x, y, cz - z, player);
  137. fillUpwards(blockType, cx + z, y, cz + x, player);
  138. fillUpwards(blockType, cx - z, y, cz + x, player);
  139. fillUpwards(blockType, cx + z, y, cz - x, player);
  140. fillUpwards(blockType, cx - z, y, cz - x, player);
  141. }
  142. }
  143. public void circleMidpoint(int xCenter, int yCenter, int radius, int y,
  144. int blockType, Player player) {
  145. int x = 0;
  146. int z = radius;
  147. int p = (5 - radius * 4) / 4;
  148. if (z == 2)
  149. p--;
  150. for (int i = z; i >= 0; i--)
  151. placePoints(xCenter, yCenter, x, i, y, blockType, player);
  152. while (x < z) {
  153. x++;
  154. if (p < 0) {
  155. p += 2 * x + 1;
  156. } else {
  157. z--;
  158. p += 2 * (x - z) + 1;
  159. }
  160. for (int i = z; i >= 0; i--)
  161. placePoints(xCenter, yCenter, x, i, y, blockType, player);
  162. }
  163. }
  164. public void cylinderModpoint(int xCenter, int yCenter, int radius, int y,
  165. int blockType, Player player) {
  166. int x = 0;
  167. int z = radius;
  168. int p = (5 - radius * 4) / 4;
  169. if (z == 2)
  170. p--;
  171. placeCylinderPoints(xCenter, yCenter, x, z, y, blockType, player);
  172. while (x < z) {
  173. x++;
  174. if (p < 0) {
  175. p += 2 * x + 1;
  176. } else {
  177. z--;
  178. p += 2 * (x - z) + 1;
  179. }
  180. placeCylinderPoints(xCenter, yCenter, x, z, y, blockType, player);
  181. }
  182. }
  183. public void armSwing(Player player) {
  184. if (cannons.containsKey(player.getName().toString())) {
  185. LoicTargetBlock blox = new LoicTargetBlock(player);
  186. Block block = blox.getTargetBlock();
  187. if (block == null)
  188. return;
  189. getServer().broadcastMessage(ChatColor.YELLOW + "ATTENTION : "
  190. + ChatColor.BLUE + "Ion Cannon Target Locked.");
  191. getServer().broadcastMessage(ChatColor.RED + "WARNING : "
  192. + ChatColor.BLUE + "Ion Cannon Firing...");
  193. int size = ((Integer)cannons.get(player.getName())).intValue();
  194. log.info("[" + name + "] IonCannon fired by: '"
  195. + player.getName().toString() + "' with size: " + size);
  196. cannons.remove(player.getName());
  197. int beamType = 46;
  198. int borderType = 57;
  199. for (int i = 0; i < 128; i++) {
  200. circleMidpoint(block.getX(), block.getZ(), size, i, borderType,
  201. player);
  202. circleMidpoint(block.getX(), block.getZ(), size - 1, i, beamType,
  203. player);
  204. }
  205. circleMidpoint(block.getX(), block.getZ(), size, 0, 7, player);
  206. cylinderModpoint(block.getX(), block.getZ(), size + 1, 0, 7, player);
  207. player.getWorld().getBlockAt(block.getX(), 127,
  208. block.getZ()).setTypeId(51);
  209. }
  210. }
  211. }