mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-27 21:27:44 +01:00
Made declaring the player mandatory when calling FlagListener#checkIsland(...) (#543)
* WIP - See FlagListener.java for changes Makes declaring the player mandatory for checkIsland method so it cannot be forgotten and will be fresh every check. See BlockInteractionListener for how it will look. * Update src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java Co-Authored-By: tastybento <tastybento@users.noreply.github.com> * Update src/main/java/world/bentobox/bentobox/api/flags/FlagListener.java Co-Authored-By: tastybento <tastybento@users.noreply.github.com> * Adjusted all the flags to new API
This commit is contained in:
parent
3ca0c440e4
commit
f89419f3d8
@ -1,6 +1,5 @@
|
||||
package world.bentobox.bentobox.api.flags;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Location;
|
||||
@ -69,37 +68,6 @@ public abstract class FlagListener implements Listener {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player associated with this event.
|
||||
* If the user is a fake player, they are not counted.
|
||||
* @param e - event
|
||||
* @return true if found, otherwise false
|
||||
*/
|
||||
private boolean createEventUser(@NonNull Event e) {
|
||||
try {
|
||||
// Use reflection to get the getPlayer method if it exists
|
||||
Method getPlayer = e.getClass().getMethod("getPlayer");
|
||||
if (getPlayer != null) {
|
||||
setUser(User.getInstance((Player)getPlayer.invoke(e)));
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e1) { // Do nothing
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Explicitly set the user for the next {@link #checkIsland(Event, Location, Flag)} or {@link #checkIsland(Event, Location, Flag, boolean)}
|
||||
* @param user - the User
|
||||
*/
|
||||
@NonNull
|
||||
public FlagListener setUser(@NonNull User user) {
|
||||
if (!plugin.getSettings().getFakePlayers().contains(user.getName())) {
|
||||
this.user = user;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following methods cover the cancellable events and enable a simple noGo(e) to be used to cancel and send the error message
|
||||
*/
|
||||
@ -132,25 +100,29 @@ public abstract class FlagListener implements Listener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if flag is allowed at location
|
||||
* Check if flag is allowed at location. Uses player object because Bukkit events provide player.
|
||||
* @param e - event
|
||||
* @param player - player affected by this flag, or null if none
|
||||
* @param loc - location
|
||||
* @param flag - flag {@link world.bentobox.bentobox.lists.Flags}
|
||||
* @return true if allowed, false if not
|
||||
*/
|
||||
public boolean checkIsland(@NonNull Event e, @NonNull Location loc, @NonNull Flag flag) {
|
||||
return checkIsland(e, loc, flag, false);
|
||||
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull Location loc, @NonNull Flag flag) {
|
||||
return checkIsland(e, player, loc, flag, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if flag is allowed at location
|
||||
* @param e - event
|
||||
* @param player - player affected by this flag, or null if none
|
||||
* @param loc - location
|
||||
* @param flag - flag {@link world.bentobox.bentobox.lists.Flags}
|
||||
* @param silent - if true, no attempt is made to tell the user
|
||||
* @return true if the check is okay, false if it was disallowed
|
||||
*/
|
||||
public boolean checkIsland(@NonNull Event e, @NonNull Location loc, @NonNull Flag flag, boolean silent) {
|
||||
public boolean checkIsland(@NonNull Event e, @Nullable Player player, @NonNull Location loc, @NonNull Flag flag, boolean silent) {
|
||||
// Set user
|
||||
user = User.getInstance(player);
|
||||
// If this is not an Island World or a standard Nether or End, skip
|
||||
if (!plugin.getIWM().inWorld(loc)) {
|
||||
report(user, e, loc, flag, Why.UNPROTECTED_WORLD);
|
||||
@ -171,15 +143,6 @@ public abstract class FlagListener implements Listener {
|
||||
}
|
||||
|
||||
// Protection flag
|
||||
// If the user is not set already, try to get it from the event
|
||||
// Set the user associated with this event
|
||||
// The user is not set, and the event does not hold a getPlayer, so return false
|
||||
// TODO: is this the correct handling here?
|
||||
if (user == null && !createEventUser(e)) {
|
||||
plugin.logError("Check island had no associated user! " + e.getEventName());
|
||||
report(user, e, loc, flag, Why.ERROR_NO_ASSOCIATED_USER);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ops or "bypass everywhere" moderators can do anything
|
||||
if (user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".everywhere")) {
|
||||
@ -188,7 +151,6 @@ public abstract class FlagListener implements Listener {
|
||||
} else {
|
||||
report(user, e, loc, flag, Why.BYPASS_EVERYWHERE);
|
||||
}
|
||||
user = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -196,13 +158,11 @@ public abstract class FlagListener implements Listener {
|
||||
if (flag.getType().equals(Flag.Type.WORLD_SETTING)) {
|
||||
if (flag.isSetForWorld(loc.getWorld())) {
|
||||
report(user, e, loc, flag, Why.ALLOWED_IN_WORLD);
|
||||
user = null;
|
||||
return true;
|
||||
}
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_IN_WORLD);
|
||||
noGo(e, flag, silent);
|
||||
// Clear the user for the next time
|
||||
user = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -213,28 +173,23 @@ public abstract class FlagListener implements Listener {
|
||||
// If it is not allowed on the island, "bypass island" moderators can do anything
|
||||
if (island.get().isAllowed(user, flag)) {
|
||||
report(user, e, loc, flag, Why.RANK_ALLOWED);
|
||||
user = null;
|
||||
return true;
|
||||
} else if (user.hasPermission(getIWM().getPermissionPrefix(loc.getWorld()) + ".mod.bypass." + flag.getID() + ".island")) {
|
||||
report(user, e, loc, flag, Why.BYPASS_ISLAND);
|
||||
user = null;
|
||||
return true;
|
||||
}
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_ON_ISLAND);
|
||||
noGo(e, flag, silent);
|
||||
// Clear the user for the next time
|
||||
user = null;
|
||||
return false;
|
||||
}
|
||||
// The player is in the world, but not on an island, so general world settings apply
|
||||
if (flag.isSetForWorld(loc.getWorld())) {
|
||||
report(user, e, loc, flag, Why.ALLOWED_IN_WORLD);
|
||||
user = null;
|
||||
return true;
|
||||
} else {
|
||||
report(user, e, loc, flag, Why.NOT_ALLOWED_IN_WORLD);
|
||||
noGo(e, flag, silent);
|
||||
user = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -10,10 +11,10 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
* Handle interaction with blocks
|
||||
* @author tastybento
|
||||
*/
|
||||
public class BlockInteractionListener extends FlagListener {
|
||||
@ -27,7 +28,7 @@ public class BlockInteractionListener extends FlagListener {
|
||||
// For some items, we need to do a specific check for RIGHT_CLICK_BLOCK
|
||||
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)
|
||||
&& e.getClickedBlock().getType().equals(Material.ITEM_FRAME)) {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ITEM_FRAME);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.ITEM_FRAME);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -35,23 +36,21 @@ public class BlockInteractionListener extends FlagListener {
|
||||
if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
|
||||
return;
|
||||
}
|
||||
// Set user
|
||||
this.setUser(User.getInstance(e.getPlayer()));
|
||||
// Check clicked block
|
||||
checkClickedBlock(e, e.getClickedBlock().getLocation(), e.getClickedBlock().getType());
|
||||
checkClickedBlock(e, e.getPlayer(), e.getClickedBlock().getLocation(), e.getClickedBlock().getType());
|
||||
|
||||
// Now check for in-hand items
|
||||
if (e.getItem() != null) {
|
||||
if (e.getItem().getType().name().contains("BOAT")) {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
return;
|
||||
}
|
||||
switch (e.getItem().getType()) {
|
||||
case ENDER_PEARL:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.ENDER_PEARL);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.ENDER_PEARL);
|
||||
break;
|
||||
case BONE_MEAL:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
break;
|
||||
case BAT_SPAWN_EGG:
|
||||
case BLAZE_SPAWN_EGG:
|
||||
@ -104,7 +103,7 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case ZOMBIE_PIGMAN_SPAWN_EGG:
|
||||
case ZOMBIE_SPAWN_EGG:
|
||||
case ZOMBIE_VILLAGER_SPAWN_EGG:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.SPAWN_EGGS);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.SPAWN_EGGS);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -116,21 +115,22 @@ public class BlockInteractionListener extends FlagListener {
|
||||
/**
|
||||
* Check if an action can occur on a clicked block
|
||||
* @param e - event called
|
||||
* @param player - player
|
||||
* @param loc - location of clicked block
|
||||
* @param type - material type of clicked block
|
||||
*/
|
||||
private void checkClickedBlock(Event e, Location loc, Material type) {
|
||||
private void checkClickedBlock(Event e, Player player, Location loc, Material type) {
|
||||
// Handle pots
|
||||
if (type.name().startsWith("POTTED")) {
|
||||
checkIsland(e, loc, Flags.CONTAINER);
|
||||
checkIsland(e, player, loc, Flags.CONTAINER);
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case ANVIL:
|
||||
checkIsland(e, loc, Flags.ANVIL);
|
||||
checkIsland(e, player, loc, Flags.ANVIL);
|
||||
break;
|
||||
case BEACON:
|
||||
checkIsland(e, loc, Flags.BEACON);
|
||||
checkIsland(e, player, loc, Flags.BEACON);
|
||||
break;
|
||||
case BLACK_BED:
|
||||
case BLUE_BED:
|
||||
@ -148,11 +148,11 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case RED_BED:
|
||||
case WHITE_BED:
|
||||
case YELLOW_BED:
|
||||
checkIsland(e, loc, Flags.BED);
|
||||
checkIsland(e, player, loc, Flags.BED);
|
||||
break;
|
||||
case BREWING_STAND:
|
||||
case CAULDRON:
|
||||
checkIsland(e, loc, Flags.BREWING);
|
||||
checkIsland(e, player, loc, Flags.BREWING);
|
||||
break;
|
||||
case CHEST:
|
||||
case CHEST_MINECART:
|
||||
@ -175,17 +175,17 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case YELLOW_SHULKER_BOX:
|
||||
case SHULKER_BOX:
|
||||
case FLOWER_POT:
|
||||
checkIsland(e, loc, Flags.CONTAINER);
|
||||
checkIsland(e, player, loc, Flags.CONTAINER);
|
||||
break;
|
||||
case DISPENSER:
|
||||
checkIsland(e, loc, Flags.DISPENSER);
|
||||
checkIsland(e, player, loc, Flags.DISPENSER);
|
||||
break;
|
||||
case DROPPER:
|
||||
checkIsland(e, loc, Flags.DROPPER);
|
||||
checkIsland(e, player, loc, Flags.DROPPER);
|
||||
break;
|
||||
case HOPPER:
|
||||
case HOPPER_MINECART:
|
||||
checkIsland(e, loc, Flags.HOPPER);
|
||||
checkIsland(e, player, loc, Flags.HOPPER);
|
||||
break;
|
||||
case ACACIA_DOOR:
|
||||
case BIRCH_DOOR:
|
||||
@ -194,7 +194,7 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case JUNGLE_DOOR:
|
||||
case SPRUCE_DOOR:
|
||||
case OAK_DOOR:
|
||||
checkIsland(e, loc, Flags.DOOR);
|
||||
checkIsland(e, player, loc, Flags.DOOR);
|
||||
break;
|
||||
case ACACIA_TRAPDOOR:
|
||||
case BIRCH_TRAPDOOR:
|
||||
@ -203,7 +203,7 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case JUNGLE_TRAPDOOR:
|
||||
case SPRUCE_TRAPDOOR:
|
||||
case IRON_TRAPDOOR:
|
||||
checkIsland(e, loc, Flags.TRAPDOOR);
|
||||
checkIsland(e, player, loc, Flags.TRAPDOOR);
|
||||
break;
|
||||
case ACACIA_FENCE_GATE:
|
||||
case BIRCH_FENCE_GATE:
|
||||
@ -211,25 +211,25 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case OAK_FENCE_GATE:
|
||||
case JUNGLE_FENCE_GATE:
|
||||
case SPRUCE_FENCE_GATE:
|
||||
checkIsland(e, loc, Flags.GATE);
|
||||
checkIsland(e, player, loc, Flags.GATE);
|
||||
break;
|
||||
case FURNACE:
|
||||
checkIsland(e, loc, Flags.FURNACE);
|
||||
checkIsland(e, player, loc, Flags.FURNACE);
|
||||
break;
|
||||
case ENCHANTING_TABLE:
|
||||
checkIsland(e, loc, Flags.ENCHANTING);
|
||||
checkIsland(e, player, loc, Flags.ENCHANTING);
|
||||
break;
|
||||
case ENDER_CHEST:
|
||||
checkIsland(e, loc, Flags.ENDER_CHEST);
|
||||
checkIsland(e, player, loc, Flags.ENDER_CHEST);
|
||||
break;
|
||||
case JUKEBOX:
|
||||
checkIsland(e, loc, Flags.JUKEBOX);
|
||||
checkIsland(e, player, loc, Flags.JUKEBOX);
|
||||
break;
|
||||
case NOTE_BLOCK:
|
||||
checkIsland(e, loc, Flags.NOTE_BLOCK);
|
||||
checkIsland(e, player, loc, Flags.NOTE_BLOCK);
|
||||
break;
|
||||
case CRAFTING_TABLE:
|
||||
checkIsland(e, loc, Flags.CRAFTING);
|
||||
checkIsland(e, player, loc, Flags.CRAFTING);
|
||||
break;
|
||||
case STONE_BUTTON:
|
||||
case ACACIA_BUTTON:
|
||||
@ -238,24 +238,24 @@ public class BlockInteractionListener extends FlagListener {
|
||||
case JUNGLE_BUTTON:
|
||||
case OAK_BUTTON:
|
||||
case SPRUCE_BUTTON:
|
||||
checkIsland(e, loc, Flags.BUTTON);
|
||||
checkIsland(e, player, loc, Flags.BUTTON);
|
||||
break;
|
||||
case LEVER:
|
||||
checkIsland(e, loc, Flags.LEVER);
|
||||
checkIsland(e, player, loc, Flags.LEVER);
|
||||
break;
|
||||
case REPEATER:
|
||||
case COMPARATOR:
|
||||
case DAYLIGHT_DETECTOR:
|
||||
checkIsland(e, loc, Flags.REDSTONE);
|
||||
checkIsland(e, player, loc, Flags.REDSTONE);
|
||||
break;
|
||||
case DRAGON_EGG:
|
||||
checkIsland(e, loc, Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, player, loc, Flags.BREAK_BLOCKS);
|
||||
break;
|
||||
case END_PORTAL_FRAME:
|
||||
checkIsland(e, loc, Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, player, loc, Flags.PLACE_BLOCKS);
|
||||
break;
|
||||
case ITEM_FRAME:
|
||||
checkIsland(e, loc, Flags.ITEM_FRAME);
|
||||
checkIsland(e, player, loc, Flags.ITEM_FRAME);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -273,7 +273,6 @@ public class BlockInteractionListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent e) {
|
||||
setUser(User.getInstance(e.getPlayer()));
|
||||
checkClickedBlock(e, e.getBlock().getLocation(), e.getBlock().getType());
|
||||
checkClickedBlock(e, e.getPlayer(), e.getBlock().getLocation(), e.getBlock().getType());
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ import org.bukkit.event.vehicle.VehicleDamageEvent;
|
||||
import org.bukkit.util.BlockIterator;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
public class BreakBlocksListener extends FlagListener {
|
||||
@ -29,7 +28,7 @@ public class BreakBlocksListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onBlockBreak(final BlockBreakEvent e) {
|
||||
setUser(User.getInstance(e.getPlayer())).checkIsland(e, e.getBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +39,7 @@ public class BreakBlocksListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBreakHanging(final HangingBreakByEntityEvent e) {
|
||||
if (e.getRemover() instanceof Player) {
|
||||
setUser(User.getInstance(e.getRemover())).checkIsland(e, e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, (Player)e.getRemover(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +61,7 @@ public class BreakBlocksListener extends FlagListener {
|
||||
while (iterator.hasNext()) {
|
||||
Block lastBlock = iterator.next();
|
||||
if (lastBlock.getType().toString().endsWith("_SKULL") || (lastBlock.getType().toString().endsWith("_HEAD") && !lastBlock.getType().equals(Material.PISTON_HEAD))) {
|
||||
checkIsland(e, lastBlock.getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), lastBlock.getLocation(), Flags.BREAK_BLOCKS);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -74,7 +73,7 @@ public class BreakBlocksListener extends FlagListener {
|
||||
case CAKE:
|
||||
case DRAGON_EGG:
|
||||
case SPAWNER:
|
||||
setUser(User.getInstance(e.getPlayer())).checkIsland(e, e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -88,8 +87,7 @@ public class BreakBlocksListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onVehicleDamageEvent(VehicleDamageEvent e) {
|
||||
if (getIWM().inWorld(e.getVehicle().getLocation()) && e.getAttacker() instanceof Player) {
|
||||
setUser(User.getInstance((Player) e.getAttacker()));
|
||||
checkIsland(e, e.getVehicle().getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, (Player)e.getAttacker(), e.getVehicle().getLocation(), Flags.BREAK_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,11 +104,11 @@ public class BreakBlocksListener extends FlagListener {
|
||||
|
||||
// Get the attacker
|
||||
if (e.getDamager() instanceof Player) {
|
||||
setUser(User.getInstance(e.getDamager())).checkIsland(e, e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, (Player)e.getDamager(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS);
|
||||
} else if (e.getDamager() instanceof Projectile) {
|
||||
// Find out who fired the arrow
|
||||
Projectile p = (Projectile) e.getDamager();
|
||||
if (p.getShooter() instanceof Player && !setUser(User.getInstance((Player)p.getShooter())).checkIsland(e, e.getEntity().getLocation(), Flags.BREAK_BLOCKS)) {
|
||||
if (p.getShooter() instanceof Player && !checkIsland(e, (Player)p.getShooter(), e.getEntity().getLocation(), Flags.BREAK_BLOCKS)) {
|
||||
e.getEntity().setFireTicks(0);
|
||||
e.getDamager().remove();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class BreedingListener extends FlagListener {
|
||||
if (e.getHand().equals(EquipmentSlot.OFF_HAND)) {
|
||||
inHand = e.getPlayer().getInventory().getItemInOffHand();
|
||||
}
|
||||
if (inHand != null && BREEDING_ITEMS.contains(inHand.getType()) && !checkIsland(e, e.getRightClicked().getLocation(), Flags.BREEDING)) {
|
||||
if (inHand != null && BREEDING_ITEMS.contains(inHand.getType()) && !checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.BREEDING)) {
|
||||
((Animals)e.getRightClicked()).setBreed(false);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class BucketListener extends FlagListener {
|
||||
if (e.getBlockClicked() != null) {
|
||||
// This is where the water or lava actually will be dumped
|
||||
Block dumpBlock = e.getBlockClicked().getRelative(e.getBlockFace());
|
||||
checkIsland(e, dumpBlock.getLocation(), Flags.BUCKET);
|
||||
checkIsland(e, e.getPlayer(), dumpBlock.getLocation(), Flags.BUCKET);
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,23 +40,23 @@ public class BucketListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onBucketFill(final PlayerBucketFillEvent e) {
|
||||
// Check filling of various liquids
|
||||
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA))) {
|
||||
if (e.getItemStack().getType().equals(Material.LAVA_BUCKET) && (!checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_LAVA))) {
|
||||
return;
|
||||
}
|
||||
if (e.getItemStack().getType().equals(Material.WATER_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.COLLECT_WATER))) {
|
||||
if (e.getItemStack().getType().equals(Material.WATER_BUCKET) && (!checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.COLLECT_WATER))) {
|
||||
return;
|
||||
}
|
||||
if (e.getItemStack().getType().equals(Material.MILK_BUCKET) && (!checkIsland(e, e.getBlockClicked().getLocation(), Flags.MILKING))) {
|
||||
if (e.getItemStack().getType().equals(Material.MILK_BUCKET) && (!checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.MILKING))) {
|
||||
return;
|
||||
}
|
||||
// Check general bucket use
|
||||
checkIsland(e, e.getBlockClicked().getLocation(), Flags.BUCKET);
|
||||
checkIsland(e, e.getPlayer(), e.getBlockClicked().getLocation(), Flags.BUCKET);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onTropicalFishScooping(final PlayerInteractEntityEvent e) {
|
||||
if (e.getRightClicked() instanceof TropicalFish && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.WATER_BUCKET)) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.FISH_SCOOPING);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.FISH_SCOOPING);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ public class EggListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onEggThrow(PlayerEggThrowEvent e) {
|
||||
if (!checkIsland(e, e.getEgg().getLocation(), Flags.EGGS)) {
|
||||
if (!checkIsland(e, e.getPlayer(), e.getEgg().getLocation(), Flags.EGGS)) {
|
||||
e.setHatching(false);
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class EntityInteractListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onPlayerInteractAtEntity(final PlayerInteractAtEntityEvent e) {
|
||||
if (e.getRightClicked() instanceof ArmorStand) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.ARMOR_STAND);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.ARMOR_STAND);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,24 +35,24 @@ public class EntityInteractListener extends FlagListener {
|
||||
if (e.getRightClicked() instanceof Vehicle) {
|
||||
// Animal riding
|
||||
if (e.getRightClicked() instanceof Animals) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.RIDING);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.RIDING);
|
||||
}
|
||||
// Minecart riding
|
||||
else if (e.getRightClicked() instanceof Minecart) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.MINECART);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.MINECART);
|
||||
}
|
||||
// Boat riding
|
||||
else if (e.getRightClicked() instanceof Boat) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.BOAT);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.BOAT);
|
||||
}
|
||||
}
|
||||
// Villager trading
|
||||
else if (e.getRightClicked().getType().equals(EntityType.VILLAGER)) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.TRADING);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.TRADING);
|
||||
}
|
||||
// Name tags
|
||||
else if (e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.NAME_TAG)) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.NAME_TAG);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.NAME_TAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -20,9 +20,8 @@ public class ExperiencePickupListener extends FlagListener {
|
||||
public void onExperienceOrbTargetPlayer(EntityTargetLivingEntityEvent e) {
|
||||
// Make sure the target is a Player and the entity is an experience orb
|
||||
if (e.getTarget() instanceof Player && e.getEntity() instanceof ExperienceOrb) {
|
||||
setUser(User.getInstance((Player) e.getTarget()));
|
||||
if (!checkIsland(e, e.getEntity().getLocation(), Flags.EXPERIENCE_PICKUP)) {
|
||||
// Cancelling the event won't be enough, we need to explicitly set the target to null
|
||||
if (!checkIsland(e, (Player) e.getTarget(), e.getEntity().getLocation(), Flags.EXPERIENCE_PICKUP)) {
|
||||
// Canceling the event won't be enough, we need to explicitly set the target to null
|
||||
e.setTarget(null);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class FireListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerInteract(PlayerInteractEvent e) {
|
||||
if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getMaterial() != null && e.getMaterial().equals(Material.FLINT_AND_STEEL)) {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.FIRE);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.FIRE);
|
||||
}
|
||||
// Look along player's sight line to see if any blocks are fire. Players can hit fire out quite a long way away.
|
||||
try {
|
||||
@ -85,7 +85,7 @@ public class FireListener extends FlagListener {
|
||||
while (iter.hasNext()) {
|
||||
Block lastBlock = iter.next();
|
||||
if (lastBlock.getType().equals(Material.FIRE)) {
|
||||
checkIsland(e, lastBlock.getLocation(), Flags.FIRE_EXTINGUISH);
|
||||
checkIsland(e, e.getPlayer(), lastBlock.getLocation(), Flags.FIRE_EXTINGUISH);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package world.bentobox.bentobox.listeners.flags.protection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Animals;
|
||||
@ -32,7 +31,6 @@ import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -42,7 +40,7 @@ import world.bentobox.bentobox.lists.Flags;
|
||||
*/
|
||||
public class HurtingListener extends FlagListener {
|
||||
|
||||
private HashMap<Integer, UUID> thrownPotions = new HashMap<>();
|
||||
private HashMap<Integer, Player> thrownPotions = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Handles mob and monster protection
|
||||
@ -72,11 +70,11 @@ public class HurtingListener extends FlagListener {
|
||||
private void respond(EntityDamageByEntityEvent e, Entity damager, Flag flag) {
|
||||
// Get the attacker
|
||||
if (damager instanceof Player) {
|
||||
setUser(User.getInstance(damager)).checkIsland(e, damager.getLocation(), flag);
|
||||
checkIsland(e, (Player)damager, damager.getLocation(), flag);
|
||||
} else if (damager instanceof Projectile) {
|
||||
// Find out who fired the projectile
|
||||
Projectile p = (Projectile) damager;
|
||||
if (p.getShooter() instanceof Player && !setUser(User.getInstance((Player)p.getShooter())).checkIsland(e, damager.getLocation(), flag)) {
|
||||
if (p.getShooter() instanceof Player && !checkIsland(e, (Player)p.getShooter(), damager.getLocation(), flag)) {
|
||||
e.getEntity().setFireTicks(0);
|
||||
damager.remove();
|
||||
}
|
||||
@ -93,14 +91,14 @@ public class HurtingListener extends FlagListener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_ANIMALS))
|
||||
|| ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_MONSTERS))
|
||||
|| (e.getCaught() instanceof Villager && checkIsland(e, e.getCaught().getLocation(), Flags.HURT_VILLAGERS))) {
|
||||
if (((e.getCaught() instanceof Animals || e.getCaught() instanceof IronGolem || e.getCaught() instanceof Snowman) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_ANIMALS))
|
||||
|| ((e.getCaught() instanceof Monster || e.getCaught() instanceof Squid || e.getCaught() instanceof Slime) && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_MONSTERS))
|
||||
|| (e.getCaught() instanceof Villager && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.HURT_VILLAGERS))) {
|
||||
e.getHook().remove();
|
||||
}
|
||||
|
||||
// Handle Armor stands that can be pulled using a rod
|
||||
if (e.getCaught() instanceof ArmorStand && checkIsland(e, e.getCaught().getLocation(), Flags.ARMOR_STAND)) {
|
||||
if (e.getCaught() instanceof ArmorStand && checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), Flags.ARMOR_STAND)) {
|
||||
e.getHook().remove();
|
||||
}
|
||||
}
|
||||
@ -114,7 +112,7 @@ public class HurtingListener extends FlagListener {
|
||||
if (e.getRightClicked() instanceof Parrot
|
||||
&& (e.getHand().equals(EquipmentSlot.HAND) && e.getPlayer().getInventory().getItemInMainHand().getType().equals(Material.COOKIE))
|
||||
|| (e.getHand().equals(EquipmentSlot.OFF_HAND) && e.getPlayer().getInventory().getItemInOffHand().getType().equals(Material.COOKIE))) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.HURT_ANIMALS);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.HURT_ANIMALS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +126,6 @@ public class HurtingListener extends FlagListener {
|
||||
Projectile projectile = e.getEntity();
|
||||
if (projectile.getShooter() instanceof Player) {
|
||||
Player attacker = (Player)projectile.getShooter();
|
||||
setUser(User.getInstance(attacker));
|
||||
// Run through all the affected entities
|
||||
for (LivingEntity entity: e.getAffectedEntities()) {
|
||||
// Self damage
|
||||
@ -137,7 +134,7 @@ public class HurtingListener extends FlagListener {
|
||||
}
|
||||
// Monsters being hurt
|
||||
if ((entity instanceof Monster || entity instanceof Slime || entity instanceof Squid)
|
||||
&& !setUser(User.getInstance(attacker)).checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS)) {
|
||||
&& !checkIsland(e, attacker, entity.getLocation(), Flags.HURT_MONSTERS)) {
|
||||
for (PotionEffect effect : e.getPotion().getEffects()) {
|
||||
entity.removePotionEffect(effect.getType());
|
||||
}
|
||||
@ -145,14 +142,14 @@ public class HurtingListener extends FlagListener {
|
||||
|
||||
// Mobs being hurt
|
||||
if ((entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman)
|
||||
&& !checkIsland(e, entity.getLocation(), Flags.HURT_ANIMALS)) {
|
||||
&& !checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS)) {
|
||||
for (PotionEffect effect : e.getPotion().getEffects()) {
|
||||
entity.removePotionEffect(effect.getType());
|
||||
}
|
||||
}
|
||||
|
||||
// Villagers being hurt
|
||||
if (entity instanceof Villager && !checkIsland(e, entity.getLocation(), Flags.HURT_VILLAGERS)) {
|
||||
if (entity instanceof Villager && !checkIsland(e, attacker, entity.getLocation(), Flags.HURT_VILLAGERS)) {
|
||||
for (PotionEffect effect : e.getPotion().getEffects()) {
|
||||
entity.removePotionEffect(effect.getType());
|
||||
}
|
||||
@ -170,9 +167,8 @@ public class HurtingListener extends FlagListener {
|
||||
// Try to get the shooter
|
||||
Projectile projectile = e.getEntity();
|
||||
if (projectile.getShooter() instanceof Player) {
|
||||
UUID uuid = ((Player)projectile.getShooter()).getUniqueId();
|
||||
// Store it and remove it when the effect is gone
|
||||
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), uuid);
|
||||
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), (Player)projectile.getShooter());
|
||||
getPlugin().getServer().getScheduler().runTaskLater(getPlugin(), () -> thrownPotions.remove(e.getAreaEffectCloud().getEntityId()), e.getAreaEffectCloud().getDuration());
|
||||
}
|
||||
}
|
||||
@ -184,23 +180,23 @@ public class HurtingListener extends FlagListener {
|
||||
}
|
||||
|
||||
if (e.getCause().equals(DamageCause.ENTITY_ATTACK) && thrownPotions.containsKey(e.getDamager().getEntityId())) {
|
||||
UUID attacker = thrownPotions.get(e.getDamager().getEntityId());
|
||||
Player attacker = thrownPotions.get(e.getDamager().getEntityId());
|
||||
// Self damage
|
||||
if (attacker.equals(e.getEntity().getUniqueId())) {
|
||||
if (attacker == null || attacker.equals(e.getEntity())) {
|
||||
return;
|
||||
}
|
||||
Entity entity = e.getEntity();
|
||||
// Monsters being hurt
|
||||
if (entity instanceof Monster || entity instanceof Slime || entity instanceof Squid) {
|
||||
checkIsland(e, entity.getLocation(), Flags.HURT_MONSTERS);
|
||||
checkIsland(e, attacker, entity.getLocation(), Flags.HURT_MONSTERS);
|
||||
}
|
||||
// Mobs being hurt
|
||||
if (entity instanceof Animals || entity instanceof IronGolem || entity instanceof Snowman) {
|
||||
checkIsland(e, entity.getLocation(), Flags.HURT_ANIMALS);
|
||||
checkIsland(e, attacker, entity.getLocation(), Flags.HURT_ANIMALS);
|
||||
}
|
||||
// Villagers being hurt
|
||||
if (entity instanceof Villager) {
|
||||
checkIsland(e, entity.getLocation(), Flags.HURT_VILLAGERS);
|
||||
checkIsland(e, attacker, entity.getLocation(), Flags.HURT_VILLAGERS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,13 +9,13 @@ import org.bukkit.block.Furnace;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.entity.Animals;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -31,34 +31,34 @@ public class InventoryListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
InventoryHolder inventoryHolder = e.getInventory().getHolder();
|
||||
if (inventoryHolder == null) {
|
||||
if (inventoryHolder == null || !(e.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
setUser(User.getInstance(e.getWhoClicked()));
|
||||
Player player = (Player)e.getWhoClicked();
|
||||
if (inventoryHolder instanceof Animals) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.MOUNT_INVENTORY);
|
||||
}
|
||||
else if (inventoryHolder instanceof Chest
|
||||
|| inventoryHolder instanceof ShulkerBox) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.CONTAINER);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.CONTAINER);
|
||||
}
|
||||
else if (inventoryHolder instanceof Dispenser) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.DISPENSER);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.DISPENSER);
|
||||
}
|
||||
else if (inventoryHolder instanceof Dropper) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.DROPPER);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.DROPPER);
|
||||
}
|
||||
else if (inventoryHolder instanceof Hopper) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.HOPPER);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.HOPPER);
|
||||
}
|
||||
else if (inventoryHolder instanceof Furnace) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.FURNACE);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.FURNACE);
|
||||
}
|
||||
else if (inventoryHolder instanceof BrewingStand) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.BREWING);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.BREWING);
|
||||
}
|
||||
else if (inventoryHolder instanceof Beacon) {
|
||||
checkIsland(e, e.getInventory().getLocation(), Flags.BEACON);
|
||||
checkIsland(e, player, e.getInventory().getLocation(), Flags.BEACON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -20,7 +19,7 @@ public class ItemDropPickUpListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onDrop(PlayerDropItemEvent e) {
|
||||
checkIsland(e, e.getItemDrop().getLocation(), Flags.ITEM_DROP);
|
||||
checkIsland(e, e.getPlayer(), e.getItemDrop().getLocation(), Flags.ITEM_DROP);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -29,7 +28,7 @@ public class ItemDropPickUpListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPickup(EntityPickupItemEvent e) {
|
||||
if (e.getEntity() instanceof Player) {
|
||||
setUser(User.getInstance(e.getEntity())).checkIsland(e, e.getItem().getLocation(), Flags.ITEM_PICKUP);
|
||||
checkIsland(e, (Player)e.getEntity(), e.getItem().getLocation(), Flags.ITEM_PICKUP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class LeashListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onLeash(PlayerLeashEntityEvent e) {
|
||||
checkIsland(e, e.getEntity().getLocation(), Flags.LEASH);
|
||||
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.LEASH);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -33,7 +33,7 @@ public class LeashListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onUnleash(PlayerUnleashEntityEvent e) {
|
||||
checkIsland(e, e.getEntity().getLocation(), Flags.LEASH);
|
||||
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.LEASH);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ public class LeashListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerLeashHitch(final HangingPlaceEvent e) {
|
||||
if (e.getEntity() != null && e.getEntity().getType().equals(EntityType.LEASH_HITCH)) {
|
||||
checkIsland(e, e.getEntity().getLocation(), Flags.LEASH);
|
||||
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.LEASH);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.event.entity.EntityInteractEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -31,7 +30,7 @@ public class PhysicalInteractionListener extends FlagListener {
|
||||
switch (e.getClickedBlock().getType()) {
|
||||
case FARMLAND:
|
||||
// Crop trample
|
||||
checkIsland(e, e.getPlayer().getLocation(), Flags.CROP_TRAMPLE);
|
||||
checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.CROP_TRAMPLE);
|
||||
break;
|
||||
|
||||
case ACACIA_PRESSURE_PLATE:
|
||||
@ -44,12 +43,12 @@ public class PhysicalInteractionListener extends FlagListener {
|
||||
case SPRUCE_PRESSURE_PLATE:
|
||||
case STONE_PRESSURE_PLATE:
|
||||
// Pressure plates
|
||||
checkIsland(e, e.getPlayer().getLocation(), Flags.PRESSURE_PLATE);
|
||||
checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PRESSURE_PLATE);
|
||||
break;
|
||||
|
||||
|
||||
case TURTLE_EGG:
|
||||
checkIsland(e, e.getPlayer().getLocation(), Flags.TURTLE_EGGS);
|
||||
break;
|
||||
checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.TURTLE_EGGS);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@ -68,8 +67,6 @@ public class PhysicalInteractionListener extends FlagListener {
|
||||
}
|
||||
Projectile p = (Projectile)e.getEntity();
|
||||
if (p.getShooter() instanceof Player && e.getBlock() != null) {
|
||||
// Set the user to the shooter
|
||||
setUser(User.getInstance((Player)p.getShooter()));
|
||||
|
||||
switch(e.getBlock().getType()) {
|
||||
case ACACIA_BUTTON:
|
||||
@ -79,7 +76,7 @@ public class PhysicalInteractionListener extends FlagListener {
|
||||
case SPRUCE_BUTTON:
|
||||
case STONE_BUTTON:
|
||||
case DARK_OAK_BUTTON:
|
||||
checkIsland(e, e.getBlock().getLocation(), Flags.BUTTON);
|
||||
checkIsland(e, (Player)p.getShooter(), e.getBlock().getLocation(), Flags.BUTTON);
|
||||
break;
|
||||
case ACACIA_PRESSURE_PLATE:
|
||||
case BIRCH_PRESSURE_PLATE:
|
||||
@ -91,7 +88,7 @@ public class PhysicalInteractionListener extends FlagListener {
|
||||
case SPRUCE_PRESSURE_PLATE:
|
||||
case STONE_PRESSURE_PLATE:
|
||||
// Pressure plates
|
||||
checkIsland(e, e.getBlock().getLocation(), Flags.PRESSURE_PLATE);
|
||||
checkIsland(e, (Player)p.getShooter(), e.getBlock().getLocation(), Flags.PRESSURE_PLATE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -30,7 +29,7 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
if (e.getBlock().getType().equals(Material.FIRE)) {
|
||||
return;
|
||||
}
|
||||
checkIsland(e, e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +39,7 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
public void onPlayerHitItemFrame(PlayerInteractEntityEvent e) {
|
||||
if (e.getRightClicked().getType().equals(EntityType.ITEM_FRAME)) {
|
||||
checkIsland(e, e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getRightClicked().getLocation(), Flags.PLACE_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,7 +56,7 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
|
||||
switch (e.getClickedBlock().getType()) {
|
||||
case FIREWORK_ROCKET:
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.PLACE_BLOCKS);
|
||||
return;
|
||||
case RAIL:
|
||||
case POWERED_RAIL:
|
||||
@ -65,7 +64,7 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
case ACTIVATOR_RAIL:
|
||||
if (e.getMaterial() != null && (e.getMaterial() == Material.MINECART || e.getMaterial() == Material.CHEST_MINECART || e.getMaterial() == Material.HOPPER_MINECART
|
||||
|| e.getMaterial() == Material.TNT_MINECART || e.getMaterial() == Material.FURNACE_MINECART)) {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.MINECART);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.MINECART);
|
||||
}
|
||||
return;
|
||||
default:
|
||||
@ -76,10 +75,10 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
|| e.getMaterial().equals(Material.END_CRYSTAL)
|
||||
//|| Tag.DOORS.isTagged(e.getMaterial())
|
||||
|| e.getMaterial().equals(Material.CHEST) || e.getMaterial().equals(Material.TRAPPED_CHEST)) {
|
||||
checkIsland(e, e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.PLACE_BLOCKS);
|
||||
}
|
||||
else if (e.getMaterial().name().contains("BOAT")) {
|
||||
checkIsland(e, e.getPlayer().getLocation(), Flags.BOAT);
|
||||
checkIsland(e, e.getPlayer(), e.getPlayer().getLocation(), Flags.BOAT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,8 +91,7 @@ public class PlaceBlocksListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
|
||||
public void onBlockForm(EntityBlockFormEvent e) {
|
||||
if (e.getNewState().getType().equals(Material.FROSTED_ICE) && e.getEntity() instanceof Player) {
|
||||
setUser(User.getInstance((Player)e.getEntity()));
|
||||
checkIsland(e, e.getBlock().getLocation(), Flags.FROST_WALKER);
|
||||
checkIsland(e, (Player)e.getEntity(), e.getBlock().getLocation(), Flags.FROST_WALKER);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,9 +17,9 @@ public class PortalListener extends FlagListener {
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerPortal(PlayerPortalEvent e) {
|
||||
if (e.getCause().equals(TeleportCause.NETHER_PORTAL)) {
|
||||
checkIsland(e, e.getFrom(), Flags.NETHER_PORTAL);
|
||||
checkIsland(e, e.getPlayer(), e.getFrom(), Flags.NETHER_PORTAL);
|
||||
} else if (e.getCause().equals(TeleportCause.END_PORTAL)) {
|
||||
checkIsland(e, e.getFrom(), Flags.END_PORTAL);
|
||||
checkIsland(e, e.getPlayer(), e.getFrom(), Flags.END_PORTAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class ShearingListener extends FlagListener {
|
||||
// Protect sheep
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onShear(final PlayerShearEntityEvent e) {
|
||||
checkIsland(e, e.getEntity().getLocation(), Flags.SHEARING);
|
||||
checkIsland(e, e.getPlayer(), e.getEntity().getLocation(), Flags.SHEARING);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -37,9 +36,7 @@ public class TNTListener extends FlagListener {
|
||||
Projectile projectile = (Projectile) e.getEntity();
|
||||
// Find out who fired it
|
||||
if (projectile.getShooter() instanceof Player && projectile.getFireTicks() > 0) {
|
||||
Player shooter = (Player)projectile.getShooter();
|
||||
setUser(User.getInstance(shooter));
|
||||
if (!setUser(User.getInstance(shooter)).checkIsland(e, e.getBlock().getLocation(), Flags.BREAK_BLOCKS)) {
|
||||
if (!checkIsland(e, (Player)projectile.getShooter(), e.getBlock().getLocation(), Flags.BREAK_BLOCKS)) {
|
||||
// Remove the arrow
|
||||
projectile.remove();
|
||||
e.setCancelled(true);
|
||||
@ -59,7 +56,7 @@ public class TNTListener extends FlagListener {
|
||||
&& e.getClickedBlock().getType().equals(Material.TNT)
|
||||
&& e.getMaterial() != null
|
||||
&& e.getMaterial().equals(Material.FLINT_AND_STEEL)) {
|
||||
checkIsland(e, e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
checkIsland(e, e.getPlayer(), e.getClickedBlock().getLocation(), Flags.BREAK_BLOCKS);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,9 @@ public class TeleportationListener extends FlagListener {
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent e) {
|
||||
if (e.getCause() != null) {
|
||||
if (e.getCause().equals(TeleportCause.ENDER_PEARL)) {
|
||||
checkIsland(e, e.getTo(), Flags.ENDER_PEARL);
|
||||
checkIsland(e, e.getPlayer(), e.getTo(), Flags.ENDER_PEARL);
|
||||
} else if (e.getCause().equals(TeleportCause.CHORUS_FRUIT)) {
|
||||
checkIsland(e, e.getTo(), Flags.CHORUS_FRUIT);
|
||||
checkIsland(e, e.getPlayer(), e.getTo(), Flags.CHORUS_FRUIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
|
||||
import world.bentobox.bentobox.api.flags.FlagListener;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
|
||||
/**
|
||||
@ -24,10 +23,9 @@ public class ThrowingListener extends FlagListener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerThrowPotion(ProjectileLaunchEvent e) {
|
||||
if (e.getEntity().getShooter() instanceof Player
|
||||
if (e.getEntity().getShooter() instanceof Player
|
||||
&& (e.getEntity() instanceof ThrownPotion || e.getEntity() instanceof ThrownExpBottle)) {
|
||||
setUser(User.getInstance((Player)e.getEntity().getShooter()));
|
||||
checkIsland(e, e.getEntity().getLocation(), Flags.POTION_THROWING);
|
||||
checkIsland(e, (Player)e.getEntity().getShooter(), e.getEntity().getLocation(), Flags.POTION_THROWING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ public class PVPListener extends FlagListener {
|
||||
// Get the attacker
|
||||
if (damager instanceof Player) {
|
||||
User user = User.getInstance(damager);
|
||||
if (!setUser(user).checkIsland((Event)e, damager.getLocation(), flag)) {
|
||||
if (!checkIsland((Event)e, (Player)damager, damager.getLocation(), flag)) {
|
||||
user.notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class PVPListener extends FlagListener {
|
||||
return;
|
||||
}
|
||||
User user = User.getInstance((Player)p.getShooter());
|
||||
if (!setUser(user).checkIsland((Event)e, damager.getLocation(), flag)) {
|
||||
if (!checkIsland((Event)e, (Player)entity, damager.getLocation(), flag)) {
|
||||
damager.setFireTicks(0);
|
||||
hurtEntity.setFireTicks(0);
|
||||
damager.remove();
|
||||
@ -108,7 +108,7 @@ public class PVPListener extends FlagListener {
|
||||
if (protectedVisitor((Player)e.getCaught())) {
|
||||
User.getInstance(e.getPlayer()).notify(Flags.INVINCIBLE_VISITORS.getHintReference());
|
||||
e.setCancelled(true);
|
||||
} else if (!checkIsland(e, e.getCaught().getLocation(), getFlag(e.getCaught().getWorld()))) {
|
||||
} else if (!checkIsland(e, e.getPlayer(), e.getCaught().getLocation(), getFlag(e.getCaught().getWorld()))) {
|
||||
e.getHook().remove();
|
||||
User.getInstance(e.getPlayer()).notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||
e.setCancelled(true);
|
||||
@ -149,7 +149,7 @@ public class PVPListener extends FlagListener {
|
||||
return true;
|
||||
}
|
||||
// Check if PVP is allowed or not
|
||||
if (!checkIsland(e, le.getLocation(), flag)) {
|
||||
if (!checkIsland(e, user.getPlayer(), le.getLocation(), flag)) {
|
||||
user.notify(Flags.PVP_OVERWORLD.getHintReference());
|
||||
return true;
|
||||
}
|
||||
|
@ -469,15 +469,15 @@ public class TestBentoBox {
|
||||
|
||||
// checking events - vistor
|
||||
Event e3 = new BlockBreakEvent(block, visitorToIsland);
|
||||
Assert.assertFalse(fl.checkIsland(e3, location, Flags.BREAK_BLOCKS, true));
|
||||
Assert.assertFalse(fl.checkIsland(e3, visitorToIsland, location, Flags.BREAK_BLOCKS, true));
|
||||
|
||||
// checking events - owner
|
||||
Event e = new BlockBreakEvent(block, ownerOfIsland);
|
||||
Assert.assertTrue(fl.checkIsland(e, location, Flags.BREAK_BLOCKS, true));
|
||||
Assert.assertTrue(fl.checkIsland(e, ownerOfIsland, location, Flags.BREAK_BLOCKS, true));
|
||||
|
||||
// checking events - member
|
||||
Event e2 = new BlockBreakEvent(block, player);
|
||||
Assert.assertTrue(fl.checkIsland(e2, location, Flags.BREAK_BLOCKS, true));
|
||||
Assert.assertTrue(fl.checkIsland(e2, player, location, Flags.BREAK_BLOCKS, true));
|
||||
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,6 @@ public class EnderChestListenerTest {
|
||||
// Enderchest use is okay
|
||||
Flags.ENDER_CHEST.setSetting(world, true);
|
||||
BlockInteractionListener bil = new BlockInteractionListener();
|
||||
bil.setUser(User.getInstance(player));
|
||||
bil.onPlayerInteract(e);
|
||||
assertFalse(e.isCancelled());
|
||||
Mockito.verify(notifier, Mockito.never()).notify(Mockito.anyObject(), Mockito.anyString());
|
||||
|
Loading…
Reference in New Issue
Block a user