Advertisement
Camer047

Untitled

Dec 18th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.16 KB | None | 0 0
  1. package me.Camer047;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Random;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.ChatColor;
  8. import org.bukkit.Location;
  9. import org.bukkit.Material;
  10. import org.bukkit.World;
  11. import org.bukkit.block.Block;
  12. import org.bukkit.block.Chest;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.CommandSender;
  15. import org.bukkit.entity.Player;
  16. import org.bukkit.inventory.Inventory;
  17. import org.bukkit.inventory.ItemStack;
  18. import org.bukkit.inventory.meta.ItemMeta;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20.  
  21.  
  22. public class DefenceClass extends JavaPlugin {
  23.  
  24. @Override
  25. public void onEnable() {
  26. new ListenerClass(this);
  27.  
  28. this.getConfig().addDefault("timer", 5);
  29. this.getConfig().addDefault("Chest1X", 0);
  30. this.getConfig().addDefault("Chest1Y", 0);
  31. this.getConfig().addDefault("Chest1Z", 0);
  32.  
  33.  
  34. this.getConfig().addDefault("Chest2X", 0);
  35. this.getConfig().addDefault("Chest2Y", 0);
  36. this.getConfig().addDefault("Chest2Z", 0);
  37.  
  38. this.getConfig().addDefault("Chest3X", 0);
  39. this.getConfig().addDefault("Chest3Y", 0);
  40. this.getConfig().addDefault("Chest3Z", 0);
  41.  
  42.  
  43.  
  44. this.getConfig().options().copyDefaults(true);
  45.  
  46. //////////
  47. //ITEMS///
  48. //////////
  49.  
  50. //Declare Variable "Chest Item"
  51. ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
  52. ItemMeta meta = chestItem1.getItemMeta();
  53. //Set Item Name
  54. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
  55. //Set the item lore
  56. ArrayList <String> lore = new ArrayList <String>();
  57. lore.add(ChatColor.BLUE + "Diamond Sword");
  58. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  59. meta.setLore(lore);
  60. chestItem1.setItemMeta(meta);
  61.  
  62.  
  63.  
  64. //Declare Variable "Chest Item"
  65. ItemStack chestItem1 = new ItemStack(Material.WEB, 1);
  66. ItemMeta meta = chestItem1.getItemMeta();
  67. //Set Item Name
  68. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item ZERO D:!");
  69.  
  70.  
  71. //Set the item lore
  72. ArrayList <String> lore = new ArrayList <String>();
  73. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
  74. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  75. meta.setLore(lore);
  76. chestItem1.setItemMeta(meta);
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86. }
  87.  
  88. @Override
  89. public void onDisable() {
  90. saveConfig();
  91. }
  92.  
  93.  
  94. public int time = getConfig().getInt("timer");
  95. public int chestnumber = 0;
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. public boolean onCommand(CommandSender sender, Command cmd, String label,
  103. String[] args) {
  104. final Player player = (Player) sender;
  105. final World world = player.getWorld();
  106.  
  107.  
  108. if (cmd.getName().equalsIgnoreCase("timer")) {
  109.  
  110. player.sendMessage("DEFENCE");
  111. player.sendMessage("By Camer047");
  112.  
  113. if (args.length == 1 && args[0].equalsIgnoreCase("start")) {
  114.  
  115. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  116. public void run() {
  117. if (time != -1) {
  118. if (time != 0) {
  119. Bukkit.getServer().broadcastMessage("" + time);
  120. time --;
  121. } else {
  122.  
  123. //TEMP
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. //Create Random function
  132. Random random = new Random();
  133. int spawncords = 4;
  134. final int spawncordsfinal = random.nextInt(spawncords);
  135. time = getConfig().getInt("timer");
  136.  
  137. int chestcontents = 4;
  138. final int chestcontentsf = random.nextInt(chestcontents);
  139.  
  140.  
  141.  
  142. if (spawncordsfinal == 0) {
  143. chestnumber = 0;
  144.  
  145.  
  146.  
  147. inv.addItem(chestItem1);
  148. }}
  149.  
  150.  
  151. if (spawncordsfinal == 1) {
  152.  
  153. chestnumber = 1;
  154.  
  155. //Set as block: Chest
  156. Block block = world.getBlockAt(getConfig().getInt("Chest1X"), getConfig().getInt("Chest1Y"), getConfig().getInt("Chest1Z"));
  157. block.setType(Material.CHEST);
  158. Chest chest = (Chest) block.getState();
  159. if (block.getState() instanceof Chest) {
  160. Inventory inv = chest.getInventory();
  161.  
  162.  
  163.  
  164.  
  165. if (chestcontentsf == 1) {
  166.  
  167. //Declare Variable "Chest Item"
  168. ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
  169. ItemMeta meta = chestItem1.getItemMeta();
  170. //Set Item Name
  171. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
  172.  
  173.  
  174. //Set the item lore
  175. ArrayList <String> lore = new ArrayList <String>();
  176. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
  177. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  178. meta.setLore(lore);
  179. chestItem1.setItemMeta(meta);
  180.  
  181. inv.addItem(chestItem1);
  182. }
  183. if (chestcontentsf == 2) {
  184.  
  185.  
  186. //Declare Variable "Chest Item2"
  187. ItemStack chestItem2 = new ItemStack(Material.IRON_AXE, 1);
  188. ItemMeta meta = chestItem2.getItemMeta();
  189. //Set Item Name
  190. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test item two!");
  191.  
  192.  
  193. //Set the item lore
  194. ArrayList <String> lore = new ArrayList <String>();
  195. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Iron A$$");
  196. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  197. meta.setLore(lore);
  198. chestItem2.setItemMeta(meta);
  199.  
  200. inv.addItem(chestItem2);
  201.  
  202.  
  203. }
  204. if (chestcontentsf == 3) {
  205.  
  206.  
  207. //Declare Variable "Chest Item 3"
  208. ItemStack chestItem3 = new ItemStack(Material.IRON_SWORD, 1);
  209. ItemMeta meta = chestItem3.getItemMeta();
  210. //Set Item Name
  211. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Chest three!");
  212.  
  213.  
  214. //Set the item lore
  215. ArrayList <String> lore = new ArrayList <String>();
  216. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Mystery Item o_0");
  217. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  218. meta.setLore(lore);
  219. chestItem3.setItemMeta(meta);
  220.  
  221. inv.addItem(chestItem3);
  222.  
  223.  
  224.  
  225. }
  226.  
  227.  
  228.  
  229. }}
  230.  
  231. if (spawncordsfinal == 2) {
  232.  
  233. chestnumber = 2;
  234.  
  235. //Set as block: Chest
  236. Block block = world.getBlockAt(getConfig().getInt("Chest2X"), getConfig().getInt("Chest2Y"), getConfig().getInt("Chest2Z"));
  237. block.setType(Material.CHEST);
  238. Chest chest = (Chest) block.getState();
  239. if (block.getState() instanceof Chest) {
  240. Inventory inv = chest.getInventory();
  241.  
  242. if (chestcontentsf == 1) {
  243.  
  244. //Declare Variable "Chest Item"
  245. ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
  246. ItemMeta meta = chestItem1.getItemMeta();
  247. //Set Item Name
  248. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
  249.  
  250.  
  251. //Set the item lore
  252. ArrayList <String> lore = new ArrayList <String>();
  253. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
  254. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  255. meta.setLore(lore);
  256. chestItem1.setItemMeta(meta);
  257.  
  258. inv.addItem(chestItem1);
  259. }
  260. if (chestcontentsf == 2) {
  261.  
  262.  
  263. //Declare Variable "Chest Item2"
  264. ItemStack chestItem2 = new ItemStack(Material.IRON_AXE, 1);
  265. ItemMeta meta = chestItem2.getItemMeta();
  266. //Set Item Name
  267. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test item two!");
  268.  
  269.  
  270. //Set the item lore
  271. ArrayList <String> lore = new ArrayList <String>();
  272. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Iron A$$");
  273. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  274. meta.setLore(lore);
  275. chestItem2.setItemMeta(meta);
  276.  
  277. inv.addItem(chestItem2);
  278.  
  279.  
  280. }
  281. if (chestcontentsf == 3) {
  282.  
  283.  
  284. //Declare Variable "Chest Item 3"
  285. ItemStack chestItem3 = new ItemStack(Material.IRON_SWORD, 1);
  286. ItemMeta meta = chestItem3.getItemMeta();
  287. //Set Item Name
  288. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Chest three!");
  289.  
  290.  
  291. //Set the item lore
  292. ArrayList <String> lore = new ArrayList <String>();
  293. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Mystery Item o_0");
  294. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  295. meta.setLore(lore);
  296. chestItem3.setItemMeta(meta);
  297.  
  298. inv.addItem(chestItem3);
  299.  
  300.  
  301.  
  302. }
  303.  
  304.  
  305. }}
  306.  
  307. if (spawncordsfinal == 3) {
  308.  
  309. chestnumber = 3;
  310.  
  311. //Set as block: Chest
  312. Block block = world.getBlockAt(getConfig().getInt("Chest3X"), getConfig().getInt("Chest3Y"), getConfig().getInt("Chest3Z"));
  313. block.setType(Material.CHEST);
  314. Chest chest = (Chest) block.getState();
  315. if (block.getState() instanceof Chest) {
  316. Inventory inv = chest.getInventory();
  317.  
  318. if (chestcontentsf == 1) {
  319.  
  320. //Declare Variable "Chest Item"
  321. ItemStack chestItem1 = new ItemStack(Material.DIAMOND_SWORD, 1);
  322. ItemMeta meta = chestItem1.getItemMeta();
  323. //Set Item Name
  324. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test Item One!");
  325.  
  326.  
  327. //Set the item lore
  328. ArrayList <String> lore = new ArrayList <String>();
  329. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
  330. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  331. meta.setLore(lore);
  332. chestItem1.setItemMeta(meta);
  333.  
  334. inv.addItem(chestItem1);
  335. }
  336. if (chestcontentsf == 2) {
  337.  
  338.  
  339. //Declare Variable "Chest Item2"
  340. ItemStack chestItem2 = new ItemStack(Material.IRON_AXE, 1);
  341. ItemMeta meta = chestItem2.getItemMeta();
  342. //Set Item Name
  343. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Test item two!");
  344.  
  345.  
  346. //Set the item lore
  347. ArrayList <String> lore = new ArrayList <String>();
  348. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Iron A$$");
  349. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  350. meta.setLore(lore);
  351. chestItem2.setItemMeta(meta);
  352.  
  353. inv.addItem(chestItem2);
  354.  
  355.  
  356. }
  357. if (chestcontentsf == 3) {
  358.  
  359.  
  360. //Declare Variable "Chest Item 3"
  361. ItemStack chestItem3 = new ItemStack(Material.IRON_SWORD, 1);
  362. ItemMeta meta = chestItem3.getItemMeta();
  363. //Set Item Name
  364. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "This is Chest three!");
  365.  
  366.  
  367. //Set the item lore
  368. ArrayList <String> lore = new ArrayList <String>();
  369. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "sexy stick yo");
  370. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  371. meta.setLore(lore);
  372. chestItem3.setItemMeta(meta);
  373.  
  374. inv.addItem(chestItem3);
  375.  
  376.  
  377.  
  378. }
  379.  
  380.  
  381. }
  382. }
  383.  
  384.  
  385.  
  386.  
  387. Bukkit.broadcastMessage("Chest " + chestnumber + " Spawned"); }
  388. }
  389. }
  390. }, 0, 20L);
  391.  
  392.  
  393.  
  394. }
  395.  
  396.  
  397. }
  398. return true; }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement