Advertisement
Guest User

Untitled

a guest
Dec 11th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. package com.zeeveener.Test;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  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.block.Block;
  11. import org.bukkit.enchantments.Enchantment;
  12. import org.bukkit.entity.Item;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.Action;
  17. import org.bukkit.event.block.BlockDamageEvent;
  18. import org.bukkit.event.block.BlockPlaceEvent;
  19. import org.bukkit.event.player.PlayerInteractEvent;
  20. import org.bukkit.inventory.ItemStack;
  21. import org.bukkit.inventory.meta.ItemMeta;
  22. import org.bukkit.plugin.java.JavaPlugin;
  23. import org.bukkit.util.Vector;
  24.  
  25. public class Main extends JavaPlugin implements Listener {
  26.  
  27. private List<Location> plate = new ArrayList<Location>();
  28.  
  29. public void onEnable() {
  30. getServer().getPluginManager().registerEvents(this, this);
  31. }
  32.  
  33. public void onDisable() {
  34.  
  35. }
  36.  
  37. @EventHandler
  38. public void onInteract(PlayerInteractEvent e) {
  39. Player p = e.getPlayer();
  40. if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
  41. Bukkit.broadcastMessage("1");
  42. if (p.getItemInHand().getType().equals(Material.STONE_PLATE)) {
  43. Bukkit.broadcastMessage("2");
  44. if (true) {
  45. Bukkit.broadcastMessage("3");
  46. if (e.getClickedBlock() != null
  47. && e.getClickedBlock().getType() != null) {
  48. Bukkit.broadcastMessage("4");
  49. Location l = e.getClickedBlock().getLocation();
  50. plate.add(l.add(0, 1, 0));
  51. l.add(0, 1, 0).getBlock().setType(Material.STONE_PLATE);
  52. if (p.getItemInHand().getAmount() == 1) {
  53. p.setItemInHand(null);
  54. } else {
  55. p.getItemInHand().setAmount(
  56. p.getItemInHand().getAmount() - 1);
  57. }
  58. }
  59. }
  60. }
  61. } else if (e.getAction().equals(Action.RIGHT_CLICK_AIR)) {
  62. if (p.getItemInHand().getType().equals(Material.FIREBALL)) {
  63. if (true) {
  64. e.setCancelled(true);
  65. final Item i = p
  66. .getLocation()
  67. .getWorld()
  68. .dropItemNaturally(p.getLocation(),
  69. new ItemStack(Material.FIREBALL));
  70. i.setVelocity(new Vector(p.getVelocity().getX(), p
  71. .getVelocity().getY() + 4, p.getVelocity().getZ()));
  72. i.setVelocity(p.getLocation().getDirection());
  73. i.setPickupDelay(100000);
  74. if (p.getItemInHand().getAmount() == 1) {
  75. p.setItemInHand(null);
  76. } else {
  77. p.getItemInHand().setAmount(
  78. p.getItemInHand().getAmount() - 1);
  79. }
  80. Bukkit.getScheduler().runTaskLater(this, new Runnable() {
  81. public void run() {
  82. i.getWorld().createExplosion(i.getLocation(), 2,
  83. false);
  84. i.remove();
  85. }
  86. }, 100L);
  87. }
  88. }
  89. } else if (e.getAction().equals(Action.PHYSICAL)) {
  90. if (e.getClickedBlock().getType().equals(Material.STONE_PLATE)) {
  91. if (plate.contains(e.getClickedBlock().getLocation())) {
  92. if (true) {
  93. e.getClickedBlock().setType(Material.AIR);
  94. plate.remove(e.getClickedBlock().getLocation());
  95. e.getClickedBlock()
  96. .getWorld()
  97. .createExplosion(
  98. e.getClickedBlock().getLocation(), 2,
  99. false);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. @EventHandler
  106. public void onPlace(BlockPlaceEvent e)
  107. {
  108. Player p = e.getPlayer();
  109. Block b = e.getBlock();
  110. if(b.getType().equals(Material.STONE_PLATE))
  111. {
  112. if(true)
  113. {
  114. plate.add(b.getLocation());
  115. p.sendMessage("You create a land mine! Punch it to remove it!");
  116. }
  117. }
  118. }
  119. @EventHandler
  120. public void onDe(BlockDamageEvent e)
  121. {
  122. Player p = e.getPlayer();
  123. Block b = e.getBlock();
  124. if(b.getType().equals(Material.STONE_PLATE))
  125. {
  126. if(plate.contains(e.getBlock().getLocation()))
  127. {
  128. if(true)
  129. {
  130. e.getBlock().setType(Material.AIR);
  131. plate.remove(e.getBlock().getLocation());
  132. p.sendMessage("You removed a land mine!");
  133. p.getInventory().addItem(setNameAndLore(Material.STONE_PLATE, 1, "&bLand Mine", Enchantment.WATER_WORKER, 10));
  134. }
  135. }
  136. }
  137. }
  138. public ItemStack setNameAndLore(Material material, int amount, String name, Enchantment enchant, int enchantamount, String... lore)
  139. {
  140. ItemStack item = new ItemStack(material, amount);
  141. item.addUnsafeEnchantment(enchant, enchantamount);
  142. ItemMeta meta = item.getItemMeta();
  143. meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
  144. ArrayList<String> lorez = new ArrayList<String>();
  145. for(String mylores : lore)
  146. {
  147. lorez.add(ChatColor.translateAlternateColorCodes('&', mylores));
  148. }
  149. meta.setLore(lorez);
  150. item.setItemMeta(meta);
  151. return item;
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement