Idiot-proof some player listeners against Citizens; resolves #772

This commit is contained in:
Daniel Saukel 2020-05-02 01:16:59 +02:00
parent e46fb89349
commit 8658f49730
5 changed files with 32 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DGlobalPlayer;
import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.player.DPlayerListener;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
@ -105,6 +106,10 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
Block block = event.getBlockClicked();
if (DPortal.getByBlock(plugin, block) != null) {
event.setCancelled(true);
@ -140,6 +145,9 @@ public class GlobalProtectionListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
DPortal dPortal = DPortal.getByLocation(plugin, player.getEyeLocation());
if (dPortal == null) {
return;
@ -181,7 +189,11 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPortalCreation(PlayerInteractEvent event) {
DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(event.getPlayer());
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
DGlobalPlayer dPlayer = (DGlobalPlayer) plugin.getPlayerCache().get(player);
if (!dPlayer.isCreatingPortal()) {
return;
}
@ -213,7 +225,7 @@ public class GlobalProtectionListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (plugin.getPlayerCache().get(player).isInBreakMode()) {
if (DPlayerListener.isCitizensNPC(player) || plugin.getPlayerCache().get(player).isInBreakMode()) {
return;
}
Block clickedBlock = event.getClickedBlock();

View File

@ -21,6 +21,7 @@ import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.player.GlobalPlayer;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.player.DPlayerListener;
import de.erethon.dungeonsxl.util.ContainerAdapter;
import de.erethon.dungeonsxl.world.DGameWorld;
import de.erethon.dungeonsxl.world.block.RewardChest;
@ -114,6 +115,9 @@ public class RewardListener implements Listener {
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
GlobalPlayer dPlayer = plugin.getPlayerCache().get(player);
if (plugin.getInstanceWorld(player.getWorld()) != null) {
return;

View File

@ -25,6 +25,7 @@ import de.erethon.dungeonsxl.api.sign.DungeonSign;
import de.erethon.dungeonsxl.api.world.EditWorld;
import de.erethon.dungeonsxl.config.DMessage;
import de.erethon.dungeonsxl.player.DPermission;
import de.erethon.dungeonsxl.player.DPlayerListener;
import de.erethon.dungeonsxl.trigger.InteractTrigger;
import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.ChatColor;
@ -52,6 +53,9 @@ public class DSignListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
Block clickedBlock = event.getClickedBlock();
if (clickedBlock == null) {
return;

View File

@ -19,6 +19,7 @@ package de.erethon.dungeonsxl.trigger;
import de.erethon.caliburn.item.VanillaItem;
import de.erethon.dungeonsxl.DungeonsXL;
import de.erethon.dungeonsxl.api.world.GameWorld;
import de.erethon.dungeonsxl.player.DPlayerListener;
import de.erethon.dungeonsxl.world.DGameWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -57,6 +58,9 @@ public class TriggerListener implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(player.getWorld());
if (gameWorld == null) {
return;

View File

@ -28,6 +28,7 @@ import de.erethon.dungeonsxl.api.dungeon.GameRuleContainer;
import de.erethon.dungeonsxl.api.world.EditWorld;
import de.erethon.dungeonsxl.api.world.GameWorld;
import de.erethon.dungeonsxl.api.world.InstanceWorld;
import de.erethon.dungeonsxl.player.DPlayerListener;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@ -35,6 +36,7 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -99,6 +101,10 @@ public class DWorldListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onBlockInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (DPlayerListener.isCitizensNPC(player)) {
return;
}
Block block = event.getClickedBlock();
GameWorld gameWorld = plugin.getGameWorld(block.getWorld());
if (gameWorld == null || gameWorld.isPlaying()) {