From 54fe26647abbf8d51da376c175ca191b70ae8aca Mon Sep 17 00:00:00 2001 From: stijnb1234 Date: Sat, 1 Feb 2020 14:12:54 +0100 Subject: [PATCH] Started with PlayerInteractListener --- .../Listeners/PlayerInteractListener.java | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java b/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java index 1291c2d..1cc2bf9 100644 --- a/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java +++ b/src/main/java/nl/SBDeveloper/V10Lift/Listeners/PlayerInteractListener.java @@ -1,20 +1,63 @@ package nl.SBDeveloper.V10Lift.Listeners; +import nl.SBDeveloper.V10Lift.API.Objects.Lift; +import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; +import nl.SBDeveloper.V10Lift.Managers.DataManager; +import nl.SBDeveloper.V10Lift.Utils.XMaterial; +import nl.SBDeveloper.V10Lift.V10LiftPlugin; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; + +import javax.xml.crypto.Data; +import java.util.Map; public class PlayerInteractListener implements Listener { //BUTTON CLICK @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteractButton(PlayerInteractEvent e) { - + Action action = e.getAction(); + Block block = e.getClickedBlock(); + if (block == null) return; + Material button = block.getType(); + if (action == Action.RIGHT_CLICK_BLOCK + && e.getHand() != EquipmentSlot.OFF_HAND + && (button.toString().contains("BUTTON") || button == XMaterial.LEVER.parseMaterial())) { + String world = block.getWorld().getName(); + int x = block.getX(); + int y = block.getY(); + int z = block.getZ(); + for (Map.Entry entry : DataManager.getLifts().entrySet()) { + Lift lift = entry.getValue(); + for (LiftBlock lb : lift.getOfflineInputs()) { + if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) { + lb.setActive(!lb.isActive()); + V10LiftPlugin.getAPI().setDefective(entry.getKey(), lb.isActive()); + return; + } + } + } + } } //BLOCK ADD @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent e) { + if (e.getHand() != EquipmentSlot.OFF_HAND) { + Player p = e.getPlayer(); + if (DataManager.containsPlayer(p.getUniqueId())) { + if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return; + e.setCancelled(true); + //TODO Fix hashmap for player -> lift (because I need it here) + int res = V10LiftPlugin.getAPI().switchBlockAtLift(DataManager.getPlayer(p.getUniqueId()), e.getClickedBlock()); + } + } } }