Fixed left click adventure issues

This commit is contained in:
stijnb1234 2020-02-25 16:40:31 +01:00
parent 34a69f2461
commit fb2f6da9cf

View file

@ -15,23 +15,22 @@ import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Iterator; import java.util.*;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
public class PlayerInteractListener implements Listener { public class PlayerInteractListener implements Listener {
private ArrayList<UUID> rightClicked = new ArrayList<>();
//BUTTON CLICK //BUTTON CLICK
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteractButton(PlayerInteractEvent e) { public void onPlayerInteractButton(PlayerInteractEvent e) {
@ -71,10 +70,8 @@ public class PlayerInteractListener implements Listener {
//Gamemode adventure left click fix //Gamemode adventure left click fix
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerLeftClickSign(EntityDamageByEntityEvent e) { public void onPlayerLeftClickSign(PlayerAnimationEvent e) {
Entity ent = e.getDamager(); Player p = e.getPlayer();
if (!(ent instanceof Player)) return;
Player p = (Player) e.getDamager();
if (p.getGameMode() != GameMode.ADVENTURE) return; if (p.getGameMode() != GameMode.ADVENTURE) return;
@ -83,6 +80,11 @@ public class PlayerInteractListener implements Listener {
BlockState bs = lookingBlock.getState(); BlockState bs = lookingBlock.getState();
if (!(bs instanceof Sign)) return; if (!(bs instanceof Sign)) return;
if (rightClicked.contains(p.getUniqueId())) {
rightClicked.remove(p.getUniqueId());
return;
}
Sign sign = (Sign) bs; Sign sign = (Sign) bs;
if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) return; if (!sign.getLine(0).equalsIgnoreCase(ConfigUtil.getColored("SignText"))) return;
@ -129,6 +131,8 @@ public class PlayerInteractListener implements Listener {
//BLOCK ADD //BLOCK ADD
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent e) { public void onPlayerInteract(PlayerInteractEvent e) {
rightClicked.add(e.getPlayer().getUniqueId());
if (e.getHand() != EquipmentSlot.OFF_HAND && e.getClickedBlock() != null) { if (e.getHand() != EquipmentSlot.OFF_HAND && e.getClickedBlock() != null) {
Player p = e.getPlayer(); Player p = e.getPlayer();
if (DataManager.containsPlayer(p.getUniqueId())) { if (DataManager.containsPlayer(p.getUniqueId())) {