PageRenderTime 127ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/me/insanj/replicator/replicator.java

https://bitbucket.org/insanj/replicator
Java | 1066 lines | 664 code | 193 blank | 209 comment | 229 complexity | bf5f1aa97c198fead756089af11d629f MD5 | raw file
  1. //TODO: Modify this plugin to make MINESHAFTS, become a REPLICATOR, replicate structures, and more.
  2. //TODO: Make Permissions checking at each command better...
  3. /*
  4. * THE REPLICATOR PLUGIN [version 1.4, "TANGENT"]
  5. * The first plugin crafted by INSANJ. (www.insanj.com/replicator)
  6. * CREATED: 5/14/11 LAST EDITED: 6/20/11
  7. *
  8. * To be used with the current CraftBukkit build #860.
  9. *
  10. * Special thanks to:
  11. * Adamki11s for his tips, but, most of all
  12. * the suggestion to use his Zombie mod as a reference.
  13. *
  14. * Yottabyte for simple bug squashing.
  15. *
  16. * Matt (aka: heyredhat) for his incredible implementation
  17. * of a SPHERE. Man, only 9 lines of code for a perfect
  18. * sphere at an instant, with only 30 minutes to come
  19. * up with it.
  20. *
  21. * This plugin's permanent home is in the
  22. * REPLICATOR world on the insanj servers:
  23. * minecraft.insanj.com
  24. *
  25. */
  26. package me.insanj.replicator;
  27. import com.nijiko.permissions.PermissionHandler;
  28. import com.nijikokun.bukkit.Permissions.Permissions;
  29. import org.bukkit.plugin.Plugin;
  30. import java.io.BufferedWriter;
  31. import java.io.File;
  32. import java.io.FileWriter;
  33. import java.io.Writer;
  34. import java.util.ArrayList;
  35. import java.util.Scanner;
  36. import java.util.logging.Logger;
  37. import org.bukkit.ChatColor;
  38. import org.bukkit.Location;
  39. import org.bukkit.block.Block;
  40. import org.bukkit.command.Command;
  41. import org.bukkit.command.CommandSender;
  42. import org.bukkit.entity.Player;
  43. import org.bukkit.plugin.java.JavaPlugin;
  44. import org.bukkit.Material;
  45. //The main method/class.
  46. public class replicator extends JavaPlugin
  47. {
  48. //Sets the console, the "listeners", and such.
  49. private static final Logger log = Logger.getLogger("Minecraft");
  50. public PermissionHandler permissionHandler;
  51. //private final replicatorPlayerListener playerListener = new replicatorPlayerListener(this);
  52. private static final String version = "1.4 [\"TANGENT\"]";
  53. private static Block diamondTarget;
  54. private static Block cageTarget;
  55. private static Block sphereTarget;
  56. private static Block readTarget;
  57. public static boolean permissions;
  58. public static ArrayList<String> text = new ArrayList<String>();
  59. public static String directory = "plugins/Replicator";
  60. private JavaPlugin replicator = this;
  61. private static int sphereRadius;
  62. public boolean isValidId( int id )
  63. {
  64. return id != 0 && Material.getMaterial(id) != null;
  65. }
  66. //When the plugin is enabled, this method is called.
  67. @Override
  68. public void onEnable()
  69. {
  70. //PluginManager pm = getServer().getPluginManager();
  71. //pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, playerListener, Event.Priority.Normal, this);
  72. log.info("{Replicator} plugin version " + version + " has successfully started.");
  73. setupPermissions();
  74. text.add("Use this folder to store your /read files!");
  75. text.add("\nUse the format: [item id], [x additive], [y additive], [z additive].");
  76. text.add("\nFor example, to create a wood block a block above where you're looking:\t5, 0, 1, 0");
  77. text.add("\nMore info in the readme file inside the .jar package!");
  78. //An attempt to create a new directory, with a file, no matter the directory system.
  79. if( !(new File(directory).exists()) )
  80. {
  81. try
  82. {
  83. new File(directory).mkdir();
  84. File file = new File("plugins/Replicator/readme.txt");
  85. Writer output = new BufferedWriter(new FileWriter(file));
  86. for(int i = 0; i < text.size(); i++)
  87. output.write(text.get(i));
  88. output.close();
  89. }
  90. catch (Exception e1)
  91. {
  92. log.info("{Replicator} had a problem creating/storing in the directory! Error: " + e1.getMessage());
  93. }
  94. }//end if
  95. }//end method onEnable()
  96. //When the plugin is disabled, this method is called.
  97. @Override
  98. public void onDisable()
  99. {
  100. log.info("{Replicator} plugin version " + version + " disabled.");
  101. }//end method onDisable()
  102. //For permissions.
  103. private void setupPermissions()
  104. {
  105. Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
  106. if (this.permissionHandler == null)
  107. {
  108. if (permissionsPlugin != null)
  109. this.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
  110. else
  111. {
  112. log.info("{Replictor} could not detect a Permissions system, defaulting to OP usage.");
  113. permissions = false;
  114. }
  115. }
  116. }//end setupPermissions();
  117. @Override
  118. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
  119. {
  120. Player player = (Player)sender;
  121. int currID = 5;
  122. //Runs the command execution method.
  123. if( commandLabel.equalsIgnoreCase("replicator"))
  124. {
  125. if( args.length > 0 )
  126. {
  127. if( args[0].equalsIgnoreCase("diamond") && (sender.isOp() || permissionHandler.has(player, "replicator.diamond") ))
  128. {
  129. if (args.length == 1 )
  130. diamond(player, 5, null);
  131. else if (args.length == 2)
  132. {
  133. if( args[1].equalsIgnoreCase("undo") )
  134. {
  135. if(diamondTarget == null)
  136. player.sendMessage(ChatColor.RED + "First you have to make a diamond, dummy!");
  137. else
  138. undoDiamond( (Player) sender );
  139. }
  140. try
  141. {
  142. currID = Integer.parseInt(args[1]);
  143. if( isValidId(currID) )
  144. diamond(player, currID, null);
  145. else
  146. player.sendMessage(ChatColor.RED + "Not a valid item id #!");
  147. }//end try
  148. catch (NumberFormatException ex)
  149. {
  150. player.sendMessage(ChatColor.RED + "The id must be an integer! " + ChatColor.YELLOW + "/replicator diamond [id#]");
  151. }
  152. }//end else if
  153. else
  154. player.sendMessage(ChatColor.RED + "Incorrect argument! Need help, " + player.getName() + "? Type in /replicator .");
  155. }//end diamond if
  156. else if( args[0].equalsIgnoreCase("cage") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.cage")) ) )
  157. {
  158. if (args.length == 1)
  159. cage(player, 20, null);
  160. else if (args.length == 2)
  161. {
  162. if( args[1].equalsIgnoreCase("undo") )
  163. {
  164. if(cageTarget == null)
  165. player.sendMessage(ChatColor.RED + "First you have to make a cage, dummy!");
  166. else
  167. undoCage( (Player) sender );
  168. }
  169. try
  170. {
  171. currID = Integer.parseInt(args[1]);
  172. if( isValidId(currID) )
  173. cage(player, currID, null);
  174. else
  175. player.sendMessage(ChatColor.RED + "Not a valid item id #!");
  176. }
  177. catch (NumberFormatException ex)
  178. {
  179. player.sendMessage(ChatColor.RED + "The id must be an integer! " + ChatColor.YELLOW + "/replicator cage [id#]");
  180. }
  181. }//end else if
  182. else
  183. player.sendMessage(ChatColor.RED + "Incorrect argument! Need help, " + player.getName() + "? Type in /replicator .");
  184. }//end cage else if
  185. else if( args[0].equalsIgnoreCase("sphere") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.sphere")) ))
  186. {
  187. if( args.length == 2)
  188. {
  189. if( args[1].equalsIgnoreCase("undo") )
  190. {
  191. if(sphereTarget == null)
  192. player.sendMessage(ChatColor.RED + "First you have to make a sphere, dummy!");
  193. else
  194. undoSphere( (Player) sender );
  195. }
  196. else
  197. player.sendMessage(ChatColor.RED + "Incorrect syntax. Type in /replicator for help!");
  198. }
  199. else if (args.length == 3)
  200. {
  201. try
  202. {
  203. currID = Integer.parseInt(args[1]);
  204. int radius = Integer.parseInt(args[2]);
  205. if( isValidId(currID) && radius <= 100)
  206. sphere(player, currID, radius, null);
  207. else
  208. player.sendMessage(ChatColor.RED + "Not a valid item id, or radius > 100!");
  209. }
  210. catch (NumberFormatException ex)
  211. {
  212. player.sendMessage(ChatColor.RED + "Incorrect values! " + ChatColor.YELLOW + "/replicator sphere [id#] [radius#]");
  213. }
  214. }
  215. else
  216. player.sendMessage(ChatColor.RED + "Incorrect syntax. Type in /replicator for help!");
  217. }//end sphere else if
  218. //Reads from an external file and compiles a figure.
  219. else if( args[0].equalsIgnoreCase("read") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.read") )) )
  220. {
  221. boolean checker;
  222. if( args.length == 2)
  223. {
  224. String file = "plugins/Replicator/" + args[1];
  225. Scanner outdoors = null;
  226. try
  227. {
  228. outdoors = new Scanner(new File(file));
  229. checker = true;
  230. }
  231. catch (Exception e)
  232. {
  233. player.sendMessage(ChatColor.RED + "Unexpected exception: File Not Found!");
  234. checker = false;
  235. }
  236. if(checker == true)
  237. {
  238. outdoors.reset();
  239. ArrayList<String> userFile = new ArrayList<String>();
  240. for(int i = 0; outdoors.hasNextLine(); i++)
  241. userFile.add(outdoors.nextLine());
  242. ArrayList<String[]> sortedFile = new ArrayList<String[]>();
  243. for(int i = 0; i < userFile.size(); i++)
  244. sortedFile.add(userFile.get(i).split(", "));
  245. Block target = player.getTargetBlock(null, 250);
  246. try
  247. {
  248. for(int i = 0; i < sortedFile.size(); i++)
  249. stack(player, target.getX(), target.getY(), target.getZ(), Integer.parseInt(sortedFile.get(i)[0]), Integer.parseInt(sortedFile.get(i)[1]), Integer.parseInt(sortedFile.get(i)[2]), Integer.parseInt(sortedFile.get(i)[3]), 0);
  250. readTarget = target;
  251. player.sendMessage(ChatColor.DARK_PURPLE + "Your structure has been replicated successfully!");
  252. }
  253. catch(Exception e)
  254. {
  255. player.sendMessage(ChatColor.RED + "Something's wrong with the file you want me to read!");
  256. }
  257. }//end if
  258. }//end creation branch
  259. else if( args.length == 3 && args[2].equals("undo") )
  260. {
  261. if(readTarget != null)
  262. {
  263. String file = "plugins/Replicator/" + args[1];
  264. Scanner outdoors = null;
  265. try
  266. {
  267. outdoors = new Scanner(new File(file));
  268. checker = true;
  269. }
  270. catch (Exception e)
  271. {
  272. player.sendMessage(ChatColor.RED + "Unexpected exception: File Not Found!");
  273. checker = false;
  274. }
  275. if(checker == true)
  276. {
  277. outdoors.reset();
  278. ArrayList<String> userFile = new ArrayList<String>();
  279. for(int i = 0; outdoors.hasNextLine(); i++)
  280. userFile.add(outdoors.nextLine());
  281. ArrayList<String[]> sortedFile = new ArrayList<String[]>();
  282. for(int i = 0; i < userFile.size(); i++)
  283. sortedFile.add(userFile.get(i).split(", "));
  284. try
  285. {
  286. for(int i = 0; i < sortedFile.size(); i++)
  287. stack(player, readTarget.getX(), readTarget.getY(), readTarget.getZ(), 0, Integer.parseInt(sortedFile.get(i)[1]), Integer.parseInt(sortedFile.get(i)[2]), Integer.parseInt(sortedFile.get(i)[3]), 0);
  288. player.sendMessage(ChatColor.BLUE + "Your structure has been removed successfully!");
  289. }
  290. catch(Exception e)
  291. {
  292. player.sendMessage(ChatColor.RED + "Something's wrong with the file you want me to read!");
  293. }
  294. }
  295. }//end readTarget != null
  296. else
  297. player.sendMessage(ChatColor.RED + "You have to replicate a structure first, dummy!");
  298. }//end undo branch
  299. else
  300. player.sendMessage(ChatColor.RED + "Incorrect syntax. Type in /replicator for help!");
  301. }
  302. else if( args[0].equalsIgnoreCase("disable") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.disable")) ) )
  303. {
  304. player.sendMessage(ChatColor.RED + "You have disabled the Replicator plugin! Reload server to re-enable.");
  305. player.getServer().getPluginManager().disablePlugin(replicator);
  306. }//end disable else if
  307. else if( args[0].equalsIgnoreCase("help") )
  308. {
  309. player.sendMessage(ChatColor.YELLOW + "-----Quick Reference-----");
  310. player.sendMessage(ChatColor.YELLOW + "This plugin allows for the spontaneous creation of");
  311. player.sendMessage(ChatColor.YELLOW + "a chosen/avalible design. Using each command");
  312. player.sendMessage(ChatColor.YELLOW + "correctly can yield powerful results.");
  313. player.sendMessage(ChatColor.YELLOW + "The \"diamond\" command constructs an elegant diamond,");
  314. player.sendMessage(ChatColor.YELLOW + "\"cage\" constructs an alright 5x5 cage,");
  315. player.sendMessage(ChatColor.YELLOW + "and \"sphere\" creates an elegant sphere!");
  316. player.sendMessage(ChatColor.GRAY + "More info avalible at: insanj.com/replicator");
  317. player.sendMessage(ChatColor.RED + "NOTE: Undo works for all objects by deleting. Beware.");
  318. }
  319. else if( !player.isOp() || (permissions == true && !(permissionHandler.has(player, "replicator."))) )
  320. player.sendMessage(ChatColor.DARK_PURPLE + "Sorry! You have to be promoted to use that command! :/");
  321. else
  322. player.sendMessage(ChatColor.RED + "Incorrect argument! Need help, " + player.getName() + "? Type in /replicator .");
  323. }//end diamond branch
  324. else
  325. {
  326. player.sendMessage(ChatColor.RED + "-----Avalible Arguments-----");
  327. player.sendMessage(ChatColor.YELLOW + "/replicator help");
  328. player.sendMessage(ChatColor.RED + "/replicator disable");
  329. player.sendMessage(ChatColor.DARK_AQUA + "/replicator diamond || /replicator diamond [item id]");
  330. player.sendMessage(ChatColor.GRAY + "/replicator cage || /replicator cage [item id]");
  331. player.sendMessage(ChatColor.GREEN + "/replicator sphere [item id] [radius]");
  332. player.sendMessage(ChatColor.GOLD + "/replicator read [filename]");
  333. player.sendMessage(ChatColor.DARK_PURPLE + "FOR ALL COMMANDS: /[command] undo");
  334. player.sendMessage("Also, use (/rd || /rc || /rs) for speed!");
  335. }//end exception branch
  336. }//end total command branch
  337. //Runs the quick-command execution method.
  338. else if( commandLabel.equalsIgnoreCase("rd") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.diamond")) ))
  339. {
  340. if( args.length == 0)
  341. diamond(player, 5, null);
  342. else if( args.length == 1)
  343. {
  344. if( args[0].equals("undo") )
  345. {
  346. undoDiamond( (Player) sender );
  347. return true;
  348. }
  349. try
  350. {
  351. currID = Integer.parseInt(args[0]);
  352. if( isValidId(currID) )
  353. diamond(player, currID, null);
  354. else
  355. player.sendMessage(ChatColor.RED + "Not a valid item id #!");
  356. }
  357. catch (NumberFormatException ex)
  358. {
  359. player.sendMessage(ChatColor.RED + "The id must be an integer! " + ChatColor.YELLOW + "/rd [id#]");
  360. }
  361. }//end else if
  362. else
  363. player.sendMessage(ChatColor.RED + "Incorrect argument! Need help, " + player.getName() + "? Type in /replicator .");
  364. }//end else if
  365. else if( commandLabel.equalsIgnoreCase("rc") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.cage")) ))
  366. {
  367. if( args.length == 0)
  368. cage(player, 20, null);
  369. else if( args.length == 1)
  370. {
  371. if( args[0].equals("undo") )
  372. {
  373. undoCage( (Player) sender );
  374. return true;
  375. }
  376. try
  377. {
  378. currID = Integer.parseInt(args[0]);
  379. if( isValidId(currID) )
  380. cage(player, currID, null);
  381. else
  382. player.sendMessage(ChatColor.RED + "Not a valid item id #!");
  383. }
  384. catch (NumberFormatException ex)
  385. {
  386. player.sendMessage(ChatColor.RED + "The id must be an integer! " + ChatColor.YELLOW + "/rc [id#]");
  387. }
  388. }//end else if
  389. else
  390. player.sendMessage(ChatColor.RED + "Incorrect argument! Need help, " + player.getName() + "? Type in /replicator .");
  391. }//end else if
  392. else if( commandLabel.equalsIgnoreCase("rs") && (sender.isOp() || (permissions == true && permissionHandler.has(player, "replicator.sphere")) ) )
  393. {
  394. if( args.length == 1)
  395. {
  396. if( args[0].equalsIgnoreCase("undo") )
  397. undoSphere( (Player) sender );
  398. else
  399. player.sendMessage(ChatColor.RED + "Incorrect syntax. Type in /replicator for help!");
  400. }
  401. else if (args.length == 2)
  402. {
  403. try
  404. {
  405. currID = Integer.parseInt(args[0]);
  406. int radius = Integer.parseInt(args[1]);
  407. if( isValidId(currID) && radius <= 100)
  408. sphere(player, currID, radius, null);
  409. else
  410. player.sendMessage(ChatColor.RED + "Not a valid item id, or radius > 100!");
  411. }
  412. catch (NumberFormatException ex)
  413. {
  414. player.sendMessage(ChatColor.RED + "Incorrect values! " + ChatColor.YELLOW + "/rs [id#] [radius#]");
  415. }
  416. }
  417. else
  418. player.sendMessage(ChatColor.RED + "Incorrect syntax. Type in /replicator for help!");
  419. }//end sphere else if
  420. else if( !player.isOp() || (permissions == true && !permissionHandler.has(player, "replicator")) )
  421. player.sendMessage(ChatColor.DARK_PURPLE + "Sorry! You have to be promoted to use that command! :/");
  422. //Because the YAMLYAMLYAML.
  423. return true;
  424. }//end method onCommand()
  425. //Crudely constructs the diamond.
  426. public void diamond(Player player, int args, Block helper)
  427. {
  428. if( helper == null && (args != 8 && args != 9 && args != 10 && args != 11 ) )
  429. {
  430. //Makes the diamond form at the current target of the player.
  431. //Arguments are (1) the blocks considered transparent, null if only air.
  432. //(2) The distance the server is willing to take, greater than 100
  433. Block target = player.getTargetBlock(null, 250);
  434. //Makes the inner column.
  435. for(int i = 1; i <= 5; i++)
  436. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, i, 0, 0);
  437. //Makes first cross.
  438. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 2, 1, 5);
  439. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 2, -1, 6);
  440. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, 2, 0, 7);
  441. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, 2, 0, 8);
  442. //Makes second cross.
  443. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 3, 2, 9);
  444. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 3, -2, 10);
  445. stack(player, target.getX(), target.getY(), target.getZ(), args, 2, 3, 0, 11);
  446. stack(player, target.getX(), target.getY(), target.getZ(), args, -2, 3, 0, 12);
  447. //Second cross filler
  448. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 3, 1, 13);
  449. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 3, -1, 14);
  450. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, 3, 0, 15);
  451. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, 3, 0, 16);
  452. //Makes the pretty edges.
  453. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, 3, 1, 17);
  454. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, 3, 1, 18);
  455. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, 3, -1, 19);
  456. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, 3, -1, 20);
  457. //Makes third cross.
  458. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 4, 1, 21);
  459. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 4, -1, 22);
  460. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, 4, 0, 23);
  461. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, 4, 0, 24);
  462. diamondTarget = target;
  463. player.sendMessage(ChatColor.DARK_PURPLE + player.getName().toUpperCase() + "'s diamond of ID#" + args + " completed!");
  464. }//end if
  465. else if( args == 8 || args == 9 || args == 10 || args == 11 )
  466. player.sendMessage(ChatColor.RED + "You can't make liquid diamonds!");
  467. //Undo!
  468. else
  469. {
  470. //Makes the inner column.
  471. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 1, 0, 0);
  472. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 2, 0, 1);
  473. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 3, 0, 2);
  474. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 4, 0, 3);
  475. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, 0, 4);
  476. //Makes first cross.
  477. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 2, 1, 5);
  478. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 2, -1, 6);
  479. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, 2, 0, 7);
  480. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, 2, 0, 8);
  481. //Makes second cross.
  482. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 3, 2, 9);
  483. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 3, -2, 10);
  484. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 2, 3, 0, 11);
  485. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -2, 3, 0, 12);
  486. //Second cross filler
  487. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 3, 1, 13);
  488. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 3, -1, 14);
  489. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, 3, 0, 15);
  490. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, 3, 0, 16);
  491. //Makes the pretty edges.
  492. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, 3, 1, 17);
  493. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, 3, 1, 18);
  494. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, 3, -1, 19);
  495. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, 3, -1, 20);
  496. //Makes third cross.
  497. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 4, 1, 21);
  498. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 4, -1, 22);
  499. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, 4, 0, 23);
  500. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, 4, 0, 24);
  501. player.sendMessage(ChatColor.BLUE + "Diamond undo successful!");
  502. }
  503. }//end method diamond()
  504. //Crudely constructs a cage around current target.
  505. public void cage(Player player, int args, Block helper)
  506. {
  507. //Makes the cage form at the current target of the player.
  508. //Arguments are (1) the blocks considered transparent, null if only air.
  509. //(2) The distance the server is willing to take, greater than 100
  510. Block target = player.getTargetBlock(null, 250);
  511. //Makes the inner column.
  512. if( helper == null && (args != 8 && args != 9 && args != 10 && args != 11) )
  513. {
  514. for(int i = 1; i <= 5; i++)
  515. {
  516. stack(player, target.getX(), target.getY(), target.getZ(), args, 3, i, -2, 0);
  517. stack(player, target.getX(), target.getY(), target.getZ(), args, 3, i, -1, 1);
  518. stack(player, target.getX(), target.getY(), target.getZ(), args, 3, i, 0, 2);
  519. stack(player, target.getX(), target.getY(), target.getZ(), args, 3, i, 1, 3);
  520. stack(player, target.getX(), target.getY(), target.getZ(), args, 3, i, 2, 4);
  521. }
  522. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 5, 0, 5);
  523. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, 5, 0, 6);
  524. stack(player, target.getX(), target.getY(), target.getZ(), args, 2, 5, 0, 7);
  525. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, 5, 0, 8);
  526. stack(player, target.getX(), target.getY(), target.getZ(), args, -2, 5, 0, 9);
  527. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 5, 0, 10);
  528. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 5, 1, 11);
  529. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 5, 2, 12);
  530. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 5, -1, 13);
  531. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, 5, -2, 14);
  532. for(int i = 1; i <= 5; i++)
  533. {
  534. stack(player, target.getX(), target.getY(), target.getZ(), args, -3, i, -2, 15);
  535. stack(player, target.getX(), target.getY(), target.getZ(), args, -3, i, -1, 16);
  536. stack(player, target.getX(), target.getY(), target.getZ(), args, -3, i, 0, 17);
  537. stack(player, target.getX(), target.getY(), target.getZ(), args, -3, i, 1, 18);
  538. stack(player, target.getX(), target.getY(), target.getZ(), args, -3, i, 2, 19);
  539. }
  540. for(int i = 1; i <= 5; i++)
  541. {
  542. stack(player, target.getX(), target.getY(), target.getZ(), args, -2, i, 3, 20);
  543. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, i, 3, 21);
  544. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, i, 3, 22);
  545. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, i, 3, 23);
  546. stack(player, target.getX(), target.getY(), target.getZ(), args, 2, i, 3, 24);
  547. }
  548. for(int i = 1; i <= 5; i++)
  549. {
  550. stack(player, target.getX(), target.getY(), target.getZ(), args, -2, i, -3, 25);
  551. stack(player, target.getX(), target.getY(), target.getZ(), args, -1, i, -3, 26);
  552. stack(player, target.getX(), target.getY(), target.getZ(), args, 0, i, -3, 27);
  553. stack(player, target.getX(), target.getY(), target.getZ(), args, 1, i, -3, 28);
  554. stack(player, target.getX(), target.getY(), target.getZ(), args, 2, i, -3, 29);
  555. }
  556. cageTarget = target;
  557. player.sendMessage(ChatColor.DARK_PURPLE + player.getName().toUpperCase() + "'s cage of ID#" + args + " completed!");
  558. }
  559. else if( args == 8 || args == 9 || args == 10 || args == 11 )
  560. player.sendMessage(ChatColor.RED + "You can't make liquid cages!");
  561. else
  562. {
  563. for(int i = 1; i <= 5; i++)
  564. {
  565. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 3, i, -2, 0);
  566. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 3, i, -1, 1);
  567. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 3, i, 0, 2);
  568. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 3, i, 1, 3);
  569. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 3, i, 2, 4);
  570. }
  571. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, 0, 5);
  572. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, 5, 0, 6);
  573. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 2, 5, 0, 7);
  574. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, 5, 0, 8);
  575. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -2, 5, 0, 9);
  576. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, 0, 10);
  577. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, 1, 11);
  578. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, 2, 12);
  579. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, -1, 13);
  580. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, 5, -2, 14);
  581. for(int i = 1; i <= 5; i++)
  582. {
  583. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -3, i, -2, 15);
  584. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -3, i, -1, 16);
  585. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -3, i, 0, 17);
  586. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -3, i, 1, 18);
  587. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -3, i, 2, 19);
  588. }
  589. for(int i = 1; i <= 5; i++)
  590. {
  591. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -2, i, 3, 20);
  592. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, i, 3, 21);
  593. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, i, 3, 22);
  594. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, i, 3, 23);
  595. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 2, i, 3, 24);
  596. }
  597. for(int i = 1; i <= 5; i++)
  598. {
  599. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -2, i, -3, 25);
  600. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, -1, i, -3, 26);
  601. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 0, i, -3, 27);
  602. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 1, i, -3, 28);
  603. stack(player, helper.getX(), helper.getY(), helper.getZ(), args, 2, i, -3, 29);
  604. }
  605. player.sendMessage(ChatColor.BLUE + "Cage undo successful!");
  606. }
  607. }//end method cage()
  608. //Constructs the most elegant sphere at your target.
  609. public void sphere(Player player, int args, int radius, Block helper)
  610. {
  611. Block target = player.getTargetBlock(null, 250);
  612. //regular sphere
  613. if( args != 8 && args != 9 && args != 10 && args != 11 && args != 0)
  614. {
  615. if( helper == null )
  616. {
  617. int x0 = target.getX();
  618. int y0 = target.getY();
  619. int z0 = target.getZ();
  620. for(int theta = 0; theta < 180; ++theta) {
  621. for(int phi = 0; phi < 360; ++phi) {
  622. double x = x0 + radius*Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi));
  623. double y = y0 + radius*Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi));
  624. double z = z0 + radius*Math.cos(Math.toRadians(theta));
  625. stackSphere(player, (int)x, (int)y, (int)z, args);
  626. }
  627. }
  628. sphereTarget = target;
  629. sphereRadius = radius;
  630. player.sendMessage(ChatColor.DARK_PURPLE + player.getName().toUpperCase() + "'s sphere of ID#" + args + " completed!");
  631. }//end if
  632. }//end regular sphere
  633. //For liquid containing spheres.
  634. else
  635. {
  636. if( helper == null && args == 8 || args == 9 || args == 10 || args == 11)
  637. {
  638. int x0 = target.getX();
  639. int y0 = target.getY();
  640. int z0 = target.getZ();
  641. for(int theta = 0; theta < 180; ++theta) {
  642. for(int phi = 0; phi < 360; ++phi) {
  643. double x = x0 + radius*Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi));
  644. double y = y0 + radius*Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi));
  645. double z = z0 + radius*Math.cos(Math.toRadians(theta));
  646. stackSphere(player, (int)x, (int)y, (int)z, 20);
  647. }
  648. }
  649. for(int theta = 0; theta < 180; ++theta) {
  650. for(int phi = 0; phi < 360; ++phi) {
  651. double x = x0 + (radius-1)*Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi));
  652. double y = y0 + (radius-1)*Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi));
  653. double z = z0 + (radius-1)*Math.cos(Math.toRadians(theta));
  654. stackSphere(player, (int)x, (int)y, (int)z, args);
  655. }
  656. }
  657. sphereTarget = target;
  658. sphereRadius = radius;
  659. player.sendMessage(ChatColor.DARK_PURPLE + player.getName().toUpperCase() + "'s" + ChatColor.AQUA + " LIQUID " + ChatColor.DARK_PURPLE + "sphere of ID#" + args + " completed!");
  660. }//end if
  661. else if( helper == null && args != 8 && args != 9 && args != 10 && args != 11 )
  662. {
  663. int x0 = target.getX();
  664. int y0 = target.getY();
  665. int z0 = target.getZ();
  666. for(int theta = 0; theta < 180; ++theta) {
  667. for(int phi = 0; phi < 360; ++phi) {
  668. double x = x0 + radius*Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi));
  669. double y = y0 + radius*Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi));
  670. double z = z0 + radius*Math.cos(Math.toRadians(theta));
  671. stackSphere(player, (int)x, (int)y, (int)z, args);
  672. }
  673. }
  674. sphereTarget = target;
  675. sphereRadius = radius;
  676. player.sendMessage(ChatColor.DARK_PURPLE + player.getName().toUpperCase() + "'s sphere of ID#" + args + " completed!");
  677. }//end else if
  678. //UNDO!
  679. else
  680. {
  681. int x0 = helper.getX();
  682. int y0 = helper.getY();
  683. int z0 = helper.getZ();
  684. for(int theta = 0; theta < 180; ++theta) {
  685. for(int phi = 0; phi < 360; ++phi) {
  686. double x = x0 + radius*Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi));
  687. double y = y0 + radius*Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi));
  688. double z = z0 + radius*Math.cos(Math.toRadians(theta));
  689. stackSphere(player, (int)x, (int)y, (int)z, args);
  690. }
  691. }
  692. for(int theta = 0; theta < 90; ++theta) {
  693. for(int phi = 0; phi < 180; ++phi) {
  694. double x = x0 + radius*Math.sin(Math.toRadians(theta))*Math.cos(Math.toRadians(phi));
  695. double y = y0 + radius*Math.sin(Math.toRadians(theta))*Math.sin(Math.toRadians(phi));
  696. double z = z0 + radius*Math.cos(Math.toRadians(theta));
  697. stackSphere(player, (int)x, (int)y, (int)z, args);
  698. }
  699. }
  700. player.sendMessage(ChatColor.BLUE + "Sphere undo successful!");
  701. }//end else
  702. }
  703. }//end method sphere()
  704. public void stack(Player player, int x, int y, int z, int id, int additiveX, int additiveY, int additiveZ, int loc)
  705. {
  706. Location temp = new Location( player.getWorld(), (x + additiveX), (y + additiveY), (z + additiveZ) );
  707. Block block = player.getWorld().getBlockAt(temp);
  708. block.setTypeId(id);
  709. }//end method stack()
  710. public void stackSphere(Player player, int x, int y, int z, int id)
  711. {
  712. Location temp = new Location( player.getWorld(), x, y, z);
  713. Block block = player.getWorld().getBlockAt(temp);
  714. block.setTypeId(id);
  715. }//end method stacksphere()
  716. public void undoDiamond(Player player)
  717. {
  718. diamond( player, 0, diamondTarget );
  719. }
  720. public void undoCage(Player player)
  721. {
  722. cage( player, 0, cageTarget );
  723. }
  724. public void undoSphere(Player player)
  725. {
  726. sphere( player, 0, sphereRadius, sphereTarget);
  727. }
  728. }//end class replicator
  729. /***********************************Contents of "plugin.yml":*******************************
  730. name: Replicator
  731. version: 1.4 ["TANGENT"]
  732. author: insanj
  733. main: me.insanj.replicator.replicator
  734. description: Create, destroy, be stupid.
  735. website: http://www.insanj.com/replicator
  736. commands:
  737. replicator:
  738. #Permissions is only for the disable command, the rest is useable by anyone.
  739. permissions: replicator.disable
  740. description: Lists available arguments for the plugin, or disables.
  741. usage: |
  742. /<command>
  743. /<command> disable
  744. /<commnad> help
  745. replicator diamond:
  746. description: Creates a beautiful diamond out of a material (wood by default).
  747. permissions: replicator.diamond
  748. usage: |
  749. /<command>
  750. /<command> [item id#]
  751. /<command> undo
  752. rd:
  753. description: Quick way to create a diamond.
  754. permissions: replicator.diamond
  755. usage: |
  756. /<command>
  757. /<command> [item id]
  758. /<command> undo
  759. replicator cage:
  760. description: Creates a cage of an item id or class.
  761. permissions: replicator.cage
  762. usage: |
  763. /<command>
  764. /<command> [item id]
  765. /<command> undo
  766. rc:
  767. description: Quick way to create a cage.
  768. permissions: replicator.cage
  769. usage: |
  770. /<command>
  771. /<command> [item id]
  772. /<command> undo
  773. replicator sphere:
  774. description: Create the most incredible sphere.
  775. permissions: replicator.sphere
  776. usage: |
  777. /<command> [item id] [radius]
  778. /<command> undo
  779. rs:
  780. description: Quick way to create a sphere.
  781. permissions: replicator.sphere
  782. usage: |
  783. /<command> [item id] [radius]
  784. /<command> undo
  785. replicator read:
  786. permissions: replicator.read
  787. description: Create your own objects! (More info in changelog)
  788. usage: |
  789. /<command> [file_name_in_current_directory.txt]
  790. /<command> [file_name_in_current_directory.txt] undo
  791. ******************************************************************************************/
  792. /**************************************Changelog and Bugs/README***************************
  793. - means feature or issue removed.
  794. + means feature added.
  795. * means bug of feature fixed.
  796. BUGS/TODO:
  797. +Undo works only by deleting/replacing diamonds (with air), and no cages.
  798. CHANGELOG:
  799. 1.0
  800. *Created first plugin, detects portal placement.
  801. +When portal is placed, finally, it is changed into a wood block, and a neat structure takes its place.
  802. +Made complex structure branch off, with partitions.
  803. +Structure finally traps player, almost makes it impossible NOT to die.
  804. *Fixed all bugs associated, especially the infinite loop.
  805. 1.1
  806. -Scrapped killing player/branched idea, and worked on diamond.
  807. *Placing portal will AT LAST create a weird looking diamond out of wood.
  808. +The diamond is jump-insidable (by accident)!
  809. +FIRST PLUGIN OFFICIAL RELEASE!
  810. 1.2
  811. +Added commands! No more stupid portals!
  812. *The "plugin.yml" has a use, and can be easily read and understood.
  813. +Arguments and Quickcommands added! Make diamonds out of glass, use only four total keystrokes!
  814. +Added help menus and a Quick Reference, and a more organized if/else branch system.
  815. *Made the diamonds spawn one block up from current block, waaaay better.
  816. 1.2_01
  817. *Diamond creation more streamlined, only "valid" blocks spawn, no more apparent bugs.
  818. 1.2_02
  819. +Cages added (on request from poolshark)! At your current target, a sloppy about 5x5ish box is made!
  820. 1.2_03
  821. +Added, after hours of tedious work, an undo function, and streamlined code more. Determined the only way to implement undo as of now is to make the undo replace the last Diamond placed with air. But, the "last diamond placed" thingy is still neat, in my books.
  822. +Released changelog/etc online, and made a mental note to create way more structures ASAP, focus more on video-making next Thursday, and have undo be a necessity.
  823. 1.3
  824. *Cleaned up code, again, and added OP support. Permissions coming next update, but sending off to Bukkit Plugin List now!
  825. 1.4
  826. *Finally got approved on the Bukkit list! Cool!
  827. +With much help from my brother, added incredibly perfect spheres (just 9 lines of code)! You get to choose your radius, too.
  828. +Added a "disable" feature, so I can disable the plugin easily, even though I still can't update seamlessly! >:(
  829. *Fixed a wall of the cage spawning one block lower than the rest.
  830. *Doesn't allow undos without a structure creation first. (Almost overlooked this one!)
  831. +Added an awesome feature where the user can create his/her own unique structures from an external file! [½]
  832. +Added support of the all-loving Permissions plugin! [Æ]
  833. -Got rid of cages being made of liquids, as well as diamonds.
  834. *Modified the general layout of the plugin.yml, adding the nodes for Permissions (for fun!).
  835. +Generates a folder on first run, and then stores a temporary "readme" file.
  836. +Added fancy brackets around the log info messages!
  837. *Fixed a bunch of misc. errors, making sure that the plugin handles everything, and no "Internal errors" pop up. Hopefully that's all, but I'm relying on a few forum-testers to prove me wrong!
  838. ½ - By creating a readable, .txt, file in the Replicator-generated directory, you can create your own structures! Every line will be a new block placement, with the following format:
  839. [item id], [x additive], [y additive], [z additive]
  840. Where the additives are the additions to the current block you're looking at. So, to make a three-block high column of woodÉ
  841. 5, 0, 1, 0
  842. 5, 0, 2, 0
  843. 5, 0, 3, 0
  844. Æ - If you have the Permissions plugin enabled, then the nodes are:
  845. replicator.diamond
  846. replicator.cage
  847. replicator.sphere
  848. replicator.read
  849. replicator.disable
  850. Without the Permissions plugin enabled, Replicator will default to OP.
  851. ******************************************************************************************/