SHARE
TWEET

Untitled

a guest Nov 14th, 2017 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.grimlytwisted.serverplugin.custom.alchemy;
  2.  
  3. import org.bukkit.Location;
  4. import org.bukkit.Material;
  5. import org.bukkit.entity.Entity;
  6. import org.bukkit.entity.Item;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.Listener;
  10. import org.bukkit.event.block.Action;
  11. import org.bukkit.event.player.PlayerInteractEvent;
  12. import org.bukkit.inventory.EquipmentSlot;
  13. import org.bukkit.inventory.ItemStack;
  14.  
  15. import java.util.ArrayList;
  16. import java.util.List;
  17.  
  18. public class CauldronUse implements Listener {
  19.  
  20.     @EventHandler
  21.     public void onClick(PlayerInteractEvent event) {
  22.  
  23.         //List<Entity> test = new ArrayList<>(); //Trying to create lists of item entities
  24.         //test.add(new Item(Material.DIAMOND)); //Failing right now, woo!
  25.  
  26.         List<Item> entities = new ArrayList<>();
  27.         Item alpha;
  28.  
  29.         EquipmentSlot equip = event.getHand(); // Defines the equipment slot of hand, the main RIGHT hand.
  30.  
  31.         ItemStack item = new ItemStack(Material.STICK); // Declaring item, stick, as wand
  32.         Player player = event.getPlayer(); // Getting event initiator, the player
  33.  
  34.         if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
  35.             System.out.println("Failed at event.getAction() != Action.RIGHT_CLICK_BLOCK");
  36.             return;
  37.         }
  38.         if (event.getClickedBlock().getType() != Material.CAULDRON) {
  39.             System.out.println("Failed at event.getClickedBlock().getType() != Material.CAULDRON");
  40.             return;
  41.         }
  42.         if (!player.getInventory().getItemInMainHand().equals(item)) {
  43.             System.out.println("Failed at !player.getInventory().getItemInMainHand().equals(item)");
  44.             return;
  45.         }
  46.         if (equip != EquipmentSlot.HAND) {
  47.             System.out.println("Failed at equip != EquipmentSlot.HAND");
  48.             return;
  49.         }
  50.  
  51.         int val = event.getClickedBlock().getData(); // Gets byte value
  52.         if (val == 1 || val == 2 || val == 3) { // Tests if it has a value between 1 and 3
  53.  
  54.             System.out.println(player.getName() + " clicked a cauldron with " + event.getClickedBlock().getData() + " bytes.");
  55.             event.getClickedBlock().setData((byte) (event.getClickedBlock().getData() - 1)); // Changes the byte value, removing 1 increment of water
  56.             Location cauldronLoc = event.getClickedBlock().getLocation();
  57.             for (Entity entity : event.getClickedBlock().getWorld().getNearbyEntities(new Location(player.getWorld(), cauldronLoc.getX() + 0.5, cauldronLoc.getY(), cauldronLoc.getZ() + 0.5), 0.5, 1, 0.5)) {
  58.  
  59.                 if (entity instanceof Item) {
  60.  
  61.                     entities.add(entity);
  62.                     //if(entities.containsAll(diamond)) {
  63.                     //if(((Item) entity).getItemStack().getType().equals(Material.DIAMOND)) {
  64.                     player.sendMessage("DIAMOND DETECTED");
  65.                     entity.remove();
  66.                 }
  67.             }
  68.         }
  69.     }
  70.     public void diamondFunction() {
  71.         System.out.println();
  72.     }
  73. }
RAW Paste Data
Top