Facebook
From Coral Lechwe, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 47
  1. package me.dev.nux;
  2.  
  3. import java.util.Set;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.EventHandler;
  11. import org.bukkit.event.Listener;
  12. import org.bukkit.event.player.PlayerInteractEvent;
  13. import org.bukkit.inventory.ItemStack;
  14.  
  15. public class WandClickListener implements Listener {
  16.  
  17.         private Block block;
  18.  
  19.         private ProWandPlugin main;
  20.  
  21.         public WandClickListener(ProWandPlugin main) {
  22.                 this.main = main;
  23.         }
  24.        
  25.  
  26.         @EventHandler
  27.         public void onPlayerInteract(PlayerInteractEvent e) {
  28.  
  29.                 Player p = e.getPlayer();
  30.  
  31.                 if (p.getInventory().getItemInMainHand().equals(new ItemStack(Material.STICK).getItemMeta().getDisplayName().contains(ChatColor.GREEN + "Wand"))) {
  32.  
  33.                         int startx = p.getTargetBlock((Set<Material>) null, 2147483647).getX();
  34.                         int starty = p.getTargetBlock((Set<Material>) null, 2147483647).getY();
  35.                         int startz = p.getTargetBlock((Set<Material>) null, 2147483647).getZ();
  36.  
  37.                         int endx = p.getTargetBlock((Set<Material>) null, 2147483647).getX() + main.radius.get(e.getPlayer());
  38.                         int endy = p.getTargetBlock((Set<Material>) null, 2147483647).getY() + 1;
  39.                         int endz = p.getTargetBlock((Set<Material>) null, 2147483647).getZ() + main.radius.get(e.getPlayer()); // Radius
  40.  
  41.                         for (int x = startx; x < endx; x++) {
  42.                                 for (int y = starty; y < endy; y++) {
  43.                                         for (int z = startz; z < endz; z++) {
  44.                                                 block = p.getWorld().getBlockAt(x, y, z);
  45.  
  46.                                                 if (!block.getType().equals(Material.AIR)) {
  47.  
  48.                                                         block.setType(main.block.setType(main.blockType.get(e.getPlayer())));
  49.  
  50.                                                 }
  51.                                         }
  52.                                 }
  53.                         }
  54.                         main.timesUsed.put(e.getPlayer(), main.used + 1);
  55.  
  56.                         if (block.getType().equals(Material.AIR)) {
  57.                                 p.sendMessage(ChatColor.RED + "This wand can only be used on blocks.");
  58.                         }
  59.                 }
  60.         }
  61. }