Advertisement
Camer047

Untitled

Dec 6th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 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. this.getConfig().addDefault("Chest1X", 0);
  28. this.getConfig().addDefault("Chest1Y", 0);
  29. this.getConfig().addDefault("Chest1Z", 0);
  30.  
  31.  
  32. this.getConfig().options().copyDefaults(true);
  33.  
  34. }
  35.  
  36. @Override
  37. public void onDisable() {
  38. saveConfig();
  39. }
  40.  
  41. //Unused 'time' var
  42. public int time = 5;
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. public boolean onCommand(CommandSender sender, Command cmd, String label,
  50. String[] args) {
  51. final Player player = (Player) sender;
  52. final World world = player.getWorld();
  53.  
  54.  
  55. if (cmd.getName().equalsIgnoreCase("timer")) {
  56.  
  57. if (args.length == 1 && args[0].equalsIgnoreCase("start")) {
  58. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  59. public void run() {
  60. if (time != -1) {
  61. if (time != 0) {
  62. Bukkit.getServer().broadcastMessage("" + time);
  63. time--;
  64. } else {
  65.  
  66. //TEMP
  67. Bukkit.broadcastMessage("Time is equal to 0");
  68.  
  69. Random random = new Random();
  70.  
  71.  
  72. //Get chest spawn location (TEMP)
  73. Location loc = player.getLocation();
  74. Block block = loc.getBlock();
  75. //Set as block: Chest
  76. world.getBlockAt(getConfig().getInt("Chest1X"), getConfig().getInt("Chest1Y"), getConfig().getInt("Chest1Z")).setType(Material.CHEST);
  77. Chest chest = (Chest)block.getState();
  78. Inventory inv = chest.getInventory();
  79.  
  80. //Declare Variable "Test Item"
  81. ItemStack testItem1 = new ItemStack(Material.DIAMOND_SWORD);
  82. ItemMeta meta = testItem1.getItemMeta();
  83. //Set Item Name
  84. meta.setDisplayName(ChatColor.BLUE + "" + ChatColor.BOLD + "TEST ITEM!");
  85.  
  86.  
  87. //Set the item lore
  88. ArrayList <String> lore = new ArrayList <String>();
  89. lore.add(ChatColor.GREEN + "" + player.getName() + "'s " + ChatColor.BLUE + "Diamond Sword");
  90. lore.add(ChatColor.WHITE + "Atleast this one works :/");
  91. meta.setLore(lore);
  92. testItem1.setItemMeta(meta);
  93.  
  94. inv.addItem(testItem1);
  95.  
  96.  
  97.  
  98. time--;
  99. }
  100. }
  101. }
  102. }, 0L, 80L);
  103.  
  104.  
  105. }
  106. }
  107. return true;
  108.  
  109. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement