Advertisement
skela

Untitled

Dec 12th, 2014
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. package simplearena;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.configuration.file.FileConfiguration;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.EventHandler;
  12. import org.bukkit.event.Listener;
  13. import org.bukkit.event.inventory.InventoryClickEvent;
  14. import org.bukkit.inventory.Inventory;
  15. import org.bukkit.inventory.ItemStack;
  16. import org.bukkit.inventory.meta.ItemMeta;
  17. import org.bukkit.plugin.java.JavaPlugin;
  18.  
  19.  
  20. public class Arena extends JavaPlugin implements Listener{
  21. private FileConfiguration cfg;
  22.  
  23. public void onEnable(){
  24. getServer().getPluginManager().registerEvents(this, this);
  25. cfg = getConfig();
  26. }
  27.  
  28. public void onDisable(){
  29.  
  30. }
  31.  
  32. private void chooseArena(Player player){
  33. Inventory arenas = Bukkit.createInventory(null,9, ChatColor.RED
  34. + "Arena Selector");
  35. ItemStack arena1 = new ItemStack(Material.WOOD_SWORD);
  36. ItemMeta arena1Meta = arena1.getItemMeta();
  37.  
  38. ItemStack arena2 = new ItemStack(Material.STONE_SWORD);
  39. ItemMeta arena2Meta = arena2.getItemMeta();
  40.  
  41. ItemStack arena3 = new ItemStack(Material.IRON_SWORD);
  42. ItemMeta arena3Meta = arena3.getItemMeta();
  43.  
  44. ItemStack arena4 = new ItemStack(Material.GOLD_SWORD);
  45. ItemMeta arena4Meta = arena4.getItemMeta();
  46.  
  47. ItemStack arena5 = new ItemStack(Material.DIAMOND_SWORD);
  48. ItemMeta arena5Meta = arena5.getItemMeta();
  49.  
  50. arena1Meta.setDisplayName(ChatColor.DARK_RED + "Arena #1");
  51. arena1.setItemMeta(arena1Meta);
  52.  
  53. arena2Meta.setDisplayName(ChatColor.DARK_RED + "Arena #2");
  54. arena2.setItemMeta(arena2Meta);
  55.  
  56. arena3Meta.setDisplayName(ChatColor.DARK_RED + "Arena #3");
  57. arena3.setItemMeta(arena3Meta);
  58.  
  59. arena4Meta.setDisplayName(ChatColor.DARK_RED + "Arena #4");
  60. arena4.setItemMeta(arena4Meta);
  61.  
  62. arena5Meta.setDisplayName(ChatColor.DARK_RED + "Arena #5");
  63. arena5.setItemMeta(arena5Meta);
  64.  
  65. arenas.setItem(0, arena1);
  66. arenas.setItem(2, arena2);
  67. arenas.setItem(4, arena3);
  68. arenas.setItem(6, arena4);
  69. arenas.setItem(8, arena5);
  70.  
  71. player.openInventory(arenas);
  72. }
  73.  
  74. @EventHandler
  75. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
  76. Player p = (Player) sender;
  77.  
  78. if(commandLabel.equalsIgnoreCase("pvp") && args.length == 0 && p.hasPermission("simple.arena.pvp")){
  79. chooseArena(p);
  80. }
  81.  
  82. if(commandLabel.equalsIgnoreCase("setarena1") && args.length == 0 && p.hasPermission("simple.arena.set")){
  83. cfg.set("Arenas.Arena1.world", p.getWorld().getName());
  84. cfg.set("Arenas.Arena1.x" , p.getLocation().getBlockX());
  85. cfg.set("Arenas.Arena1.y" , p.getLocation().getBlockY());
  86. cfg.set("Arenas.Arena1.z" , p.getLocation().getBlockZ());
  87. saveConfig();
  88.  
  89. p.sendMessage(String.format("%sYou have set %sArena 1", ChatColor.DARK_GREEN, ChatColor.DARK_RED));
  90. return true;
  91. }
  92.  
  93. if(commandLabel.equalsIgnoreCase("setarena2") && args.length == 0 && p.hasPermission("simple.arena.set")){
  94. cfg.set("Arenas.Arena2.world", p.getWorld().getName());
  95. cfg.set("Arenas.Arena2.x" , p.getLocation().getBlockX());
  96. cfg.set("Arenas.Arena2.y" , p.getLocation().getBlockY());
  97. cfg.set("Arenas.Arena2.z" , p.getLocation().getBlockZ());
  98. saveConfig();
  99.  
  100. p.sendMessage(String.format("%sYou have set %sArena 2", ChatColor.DARK_GREEN, ChatColor.DARK_RED));
  101. return true;
  102. }
  103.  
  104. if(commandLabel.equalsIgnoreCase("setarena3") && args.length == 0 && p.hasPermission("simple.arena.set")){
  105. cfg.set("Arenas.Arena3.world", p.getWorld().getName());
  106. cfg.set("Arenas.Arena3.x" , p.getLocation().getBlockX());
  107. cfg.set("Arenas.Arena3.y" , p.getLocation().getBlockY());
  108. cfg.set("Arenas.Arena3.z" , p.getLocation().getBlockZ());
  109. saveConfig();
  110.  
  111. p.sendMessage(String.format("%sYou have set %sArena 3", ChatColor.DARK_GREEN, ChatColor.DARK_RED));
  112. return true;
  113. }
  114.  
  115. if(commandLabel.equalsIgnoreCase("setarena4") && args.length == 0 && p.hasPermission("simple.arena.set")){
  116. cfg.set("Arenas.Arena4.world", p.getWorld().getName());
  117. cfg.set("Arenas.Arena4.x" , p.getLocation().getBlockX());
  118. cfg.set("Arenas.Arena4.y" , p.getLocation().getBlockY());
  119. cfg.set("Arenas.Arena4.z" , p.getLocation().getBlockZ());
  120. saveConfig();
  121.  
  122. p.sendMessage(String.format("%sYou have set %sArena 4", ChatColor.DARK_GREEN, ChatColor.DARK_RED));
  123. return true;
  124. }
  125.  
  126. if(commandLabel.equalsIgnoreCase("setarena5") && args.length == 0 && p.hasPermission("simple.arena.set")){
  127. cfg.set("Arenas.Arena5.world", p.getWorld().getName());
  128. cfg.set("Arenas.Arena5.x" , p.getLocation().getBlockX());
  129. cfg.set("Arenas.Arena5.y" , p.getLocation().getBlockY());
  130. cfg.set("Arenas.Arena5.z" , p.getLocation().getBlockZ());
  131. saveConfig();
  132.  
  133. p.sendMessage(String.format("%sYou have set %sArena 5", ChatColor.DARK_GREEN, ChatColor.DARK_RED));
  134. return true;
  135. }
  136.  
  137.  
  138. return false;
  139. }
  140.  
  141. @EventHandler
  142. public void arenaselected(InventoryClickEvent event){
  143. if (!ChatColor.stripColor(event.getInventory().getName())
  144. .equalsIgnoreCase("Arena Selector")){
  145. return;
  146. }
  147. Player player = (Player) event.getWhoClicked();
  148. event.setCancelled(true);
  149.  
  150. if (event.getCurrentItem() == null
  151. || event.getCurrentItem().getType() == Material.AIR
  152. || !event.getCurrentItem().hasItemMeta()){
  153. player.closeInventory();
  154. return;
  155. }
  156.  
  157. switch (event.getCurrentItem().getType()){
  158. case WOOD_SWORD:
  159. player.closeInventory();
  160. int x = cfg.getInt("Arenas.Arena1.x");
  161. int y = cfg.getInt("Arenas.Arena1.y");
  162. int z = cfg.getInt("Arenas.Arena1.z");
  163. player.teleport(new Location(player.getWorld(), x, y, z));
  164. player.sendMessage(String.format("%sTeleported to %sArena 1", ChatColor.DARK_GREEN, ChatColor.GOLD));
  165. break;
  166. case STONE_SWORD:
  167. player.closeInventory();
  168. int x2 = cfg.getInt("Arenas.Arena2.x");
  169. int y2 = cfg.getInt("Arenas.Arena2.y");
  170. int z2 = cfg.getInt("Arenas.Arena2.z");
  171. player.teleport(new Location(player.getWorld(), x2, y2, z2));
  172. player.sendMessage(String.format("%sTeleported to %sArena 2", ChatColor.DARK_GREEN, ChatColor.GOLD));
  173. break;
  174. case IRON_SWORD:
  175. player.closeInventory();
  176. int x3 = cfg.getInt("Arenas.Arena3.x");
  177. int y3 = cfg.getInt("Arenas.Arena3.y");
  178. int z3 = cfg.getInt("Arenas.Arena3.z");
  179. player.teleport(new Location(player.getWorld(), x3, y3, z3));
  180. player.sendMessage(String.format("%sTeleported to %sArena 3", ChatColor.DARK_GREEN, ChatColor.GOLD));
  181. break;
  182. case GOLD_SWORD:
  183. player.closeInventory();
  184. int x4 = cfg.getInt("Arenas.Arena4.x");
  185. int y4 = cfg.getInt("Arenas.Arena4.y");
  186. int z4 = cfg.getInt("Arenas.Arena4.z");
  187. player.teleport(new Location(player.getWorld(), x4, y4, z4));
  188. player.sendMessage(String.format("%sTeleported to %sArena 4", ChatColor.DARK_GREEN, ChatColor.GOLD));
  189. break;
  190. case DIAMOND_SWORD:
  191. player.closeInventory();
  192. int x5 = cfg.getInt("Arenas.Arena5.x");
  193. int y5 = cfg.getInt("Arenas.Arena5.y");
  194. int z5 = cfg.getInt("Arenas.Arena5.z");
  195. player.teleport(new Location(player.getWorld(), x5, y5, z5));
  196. player.sendMessage(String.format("%sTeleported to %sArena 5", ChatColor.DARK_GREEN, ChatColor.GOLD));
  197. break;
  198. default:
  199. player.closeInventory();
  200. break;
  201. }
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement