diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 5dd04e506..b2f3459b0 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1,5 +1,6 @@ package com.github.intellectualsites.plotsquared.bukkit.listeners; +import com.destroystokyo.paper.MaterialTags; import com.github.intellectualsites.plotsquared.bukkit.BukkitMain; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; @@ -29,7 +30,6 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.item.ItemType; import io.papermc.lib.PaperLib; @@ -37,6 +37,7 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.FluidCollisionMode; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -773,6 +774,7 @@ import java.util.regex.Pattern; PlotPlayer pp = BukkitUtil.getPlayer(player); Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT); org.bukkit.Location to = event.getTo(); + //noinspection ConstantConditions if (to != null) { Location location = BukkitUtil.getLocation(to); PlotArea area = location.getPlotArea(); @@ -839,17 +841,10 @@ import java.util.regex.Pattern; dest = null; } if (dest != null) { - if (passengers != null) { - vehicle.eject(); - vehicle.setVelocity(new Vector(0d, 0d, 0d)); - PaperLib.teleportAsync(vehicle, dest); - passengers.forEach(vehicle::addPassenger); - } else { - vehicle.eject(); - vehicle.setVelocity(new Vector(0d, 0d, 0d)); - PaperLib.teleportAsync(vehicle, dest); - vehicle.addPassenger(player); - } + vehicle.eject(); + vehicle.setVelocity(new Vector(0d, 0d, 0d)); + PaperLib.teleportAsync(vehicle, dest); + passengers.forEach(vehicle::addPassenger); return; } } @@ -1093,20 +1088,17 @@ import java.util.regex.Pattern; .replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT))); } if (!plot.hasOwner()) { - if (Permissions - .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { - return; + if (!Permissions + .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED, true)) { + event.setCancelled(true); } - MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_DESTROY_UNOWNED); - event.setCancelled(true); return; } if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asItemType(block.getType()))) { + .contains(BukkitAdapter.asBlockType(block.getType()))) { return; } if (Permissions @@ -1361,12 +1353,6 @@ import java.util.regex.Pattern; public void onBlockDamage(BlockDamageEvent event) { Player player = event.getPlayer(); Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); - if (player == null) { - if (location.isPlotRoad()) { - event.setCancelled(true); - return; - } - } PlotArea area = location.getPlotArea(); if (area == null) { return; @@ -1388,10 +1374,10 @@ import java.util.regex.Pattern; } PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> destroy = plot.getFlag(Flags.BREAK); + Optional> destroy = plot.getFlag(Flags.BREAK); Block block = event.getBlock(); if (destroy.isPresent() && destroy.get() - .contains(BukkitAdapter.asItemType(block.getType())) || Permissions + .contains(BukkitAdapter.asBlockType(block.getType())) || Permissions .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { return; } @@ -1738,9 +1724,6 @@ import java.util.regex.Pattern; } Block block = player.getTargetBlock(null, 7); org.bukkit.block.BlockState state = block.getState(); - if (state == null) { - return; - } Material stateType = state.getType(); Material itemType = newItem.getType(); if (stateType != itemType) { @@ -1899,7 +1882,7 @@ import java.util.regex.Pattern; return; } if (event.getAction() == Action.RIGHT_CLICK_AIR) { - Material item = event.getItem().getType(); + Material item = event.getMaterial(); if (item.toString().toLowerCase().endsWith("egg")) { event.setCancelled(true); event.setUseItemInHand(Event.Result.DENY); @@ -1907,8 +1890,8 @@ import java.util.regex.Pattern; } ItemStack hand = player.getInventory().getItemInMainHand(); ItemStack offHand = player.getInventory().getItemInOffHand(); - Material type = (hand == null) ? Material.AIR : hand.getType(); - Material offType = (offHand == null) ? Material.AIR : offHand.getType(); + Material type = hand.getType(); + Material offType = offHand.getType(); if (type == Material.AIR) { type = offType; } @@ -1916,10 +1899,8 @@ import java.util.regex.Pattern; Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY); if (block != null && block.getType() != Material.AIR) { Location location = BukkitUtil.getLocation(block.getLocation()); - Material finalType = type; if (!EventUtil.manager - .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asItemType( - finalType), true)) { + .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null, true)) { event.setCancelled(true); event.setUseItemInHand(Event.Result.DENY); } @@ -1937,297 +1918,116 @@ import java.util.regex.Pattern; return; } PlayerBlockEventType eventType = null; - Supplier lazyItem; - Location location; + BlockType blocktype1; + Block block = event.getClickedBlock(); + Location location = BukkitUtil.getLocation(block.getLocation()); Action action = event.getAction(); - switch (action) { + outer: switch (action) { case PHYSICAL: { eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; - Block block = event.getClickedBlock(); - lazyItem = BukkitBlockUtil.supplyItem(block); - location = BukkitUtil.getLocation(block.getLocation()); + blocktype1 = BukkitAdapter.asBlockType(block.getType()); break; } + //todo rearrange the right click code. it is all over the place. case RIGHT_CLICK_BLOCK: { - Block block = event.getClickedBlock(); - location = BukkitUtil.getLocation(block.getLocation()); Material blockType = block.getType(); - switch (blockType) { - case ACACIA_DOOR: - case BIRCH_DOOR: - case DARK_OAK_DOOR: - case IRON_DOOR: - case JUNGLE_DOOR: - case OAK_DOOR: - case SPRUCE_DOOR: - - case ACACIA_TRAPDOOR: - case BIRCH_TRAPDOOR: - case DARK_OAK_TRAPDOOR: - case IRON_TRAPDOOR: - case JUNGLE_TRAPDOOR: - case OAK_TRAPDOOR: - case SPRUCE_TRAPDOOR: - - case CHEST: - case ENDER_CHEST: - case TRAPPED_CHEST: - - case ACACIA_FENCE_GATE: - case BIRCH_FENCE_GATE: - case DARK_OAK_FENCE_GATE: - case OAK_FENCE_GATE: - case JUNGLE_FENCE_GATE: - case SPRUCE_FENCE_GATE: - - case ACACIA_BUTTON: - case BIRCH_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case OAK_BUTTON: - case SPRUCE_BUTTON: - case STONE_BUTTON: - - case BLACK_BED: - case BLUE_BED: - case BROWN_BED: - case CYAN_BED: - case GRAY_BED: - case GREEN_BED: - case LIGHT_BLUE_BED: - case LIGHT_GRAY_BED: - case LIME_BED: - case MAGENTA_BED: - case ORANGE_BED: - case PINK_BED: - case PURPLE_BED: - case RED_BED: - case WHITE_BED: - case YELLOW_BED: - - case BLACK_BANNER: - case BLACK_WALL_BANNER: - case BLUE_BANNER: - case BLUE_WALL_BANNER: - case BROWN_BANNER: - case BROWN_WALL_BANNER: - case CYAN_BANNER: - case CYAN_WALL_BANNER: - case GRAY_BANNER: - case GRAY_WALL_BANNER: - case GREEN_BANNER: - case GREEN_WALL_BANNER: - case LIGHT_BLUE_BANNER: - case LIGHT_BLUE_WALL_BANNER: - case LIGHT_GRAY_BANNER: - case LIGHT_GRAY_WALL_BANNER: - case LIME_BANNER: - case LIME_WALL_BANNER: - case MAGENTA_BANNER: - case MAGENTA_WALL_BANNER: - case ORANGE_BANNER: - case ORANGE_WALL_BANNER: - case PINK_BANNER: - case PINK_WALL_BANNER: - case PURPLE_BANNER: - case PURPLE_WALL_BANNER: - case RED_BANNER: - case RED_WALL_BANNER: - case WHITE_BANNER: - case WHITE_WALL_BANNER: - case YELLOW_BANNER: - case YELLOW_WALL_BANNER: - - case BLACK_SHULKER_BOX: - case BLUE_SHULKER_BOX: - case BROWN_SHULKER_BOX: - case CYAN_SHULKER_BOX: - case GRAY_SHULKER_BOX: - case GREEN_SHULKER_BOX: - case LIGHT_BLUE_SHULKER_BOX: - case LIGHT_GRAY_SHULKER_BOX: - case LIME_SHULKER_BOX: - case MAGENTA_SHULKER_BOX: - case ORANGE_SHULKER_BOX: - case PINK_SHULKER_BOX: - case PURPLE_SHULKER_BOX: - case RED_SHULKER_BOX: - case WHITE_SHULKER_BOX: - case YELLOW_SHULKER_BOX: - - case CHAIN_COMMAND_BLOCK: - case REPEATING_COMMAND_BLOCK: - - case LEGACY_SIGN: - case LEGACY_WALL_SIGN: - case OAK_SIGN: - case ACACIA_SIGN: - case ACACIA_WALL_SIGN: - case BIRCH_SIGN: - case BIRCH_WALL_SIGN: - case DARK_OAK_SIGN: - case DARK_OAK_WALL_SIGN: - case JUNGLE_SIGN: - case JUNGLE_WALL_SIGN: - case OAK_WALL_SIGN: - case SPRUCE_SIGN: - case SPRUCE_WALL_SIGN: - - case REDSTONE_TORCH: - case REDSTONE_WALL_TORCH: - - case TURTLE_EGG: - case TURTLE_HELMET: - case TURTLE_SPAWN_EGG: - - case ANVIL: - case BEACON: - case BREWING_STAND: - case CAKE: - case COMMAND_BLOCK: - case COMPARATOR: - case CRAFTING_TABLE: - //todo re-evaluate adding lectern here - case LECTERN: - case GRINDSTONE: - case LOOM: - case SMOKER: - case STONECUTTER: - case DISPENSER: - case DROPPER: - case ENCHANTING_TABLE: - case FURNACE: - case BLAST_FURNACE: - case HOPPER: - case JUKEBOX: - case LEVER: - case NOTE_BLOCK: - case REDSTONE_ORE: - eventType = PlayerBlockEventType.INTERACT_BLOCK; - break; - case DRAGON_EGG: - eventType = PlayerBlockEventType.TELEPORT_OBJECT; - break; - default: - if (blockType.isInteractable()) { - eventType = PlayerBlockEventType.INTERACT_BLOCK; - } + if (blockType.isInteractable() && player.isSneaking()) { + return; //this returns so the block place event is called } - lazyItem = BukkitBlockUtil.supplyItem(block); - if (eventType != null && (eventType != PlayerBlockEventType.INTERACT_BLOCK - || !player.isSneaking())) { - break; - } - ItemStack hand = player.getInventory().getItemInMainHand(); - ItemStack offHand = player.getInventory().getItemInOffHand(); - Material type = (hand == null) ? Material.AIR : hand.getType(); - Material offType = (offHand == null) ? Material.AIR : offHand.getType(); - if ((type == Material.AIR && offType != Material.AIR && !player.isSneaking() - && blockType.isInteractable()) || (type == Material.AIR - && offType == Material.AIR)) { + if (blockType.isInteractable()) { eventType = PlayerBlockEventType.INTERACT_BLOCK; + } + blocktype1 = BukkitAdapter.asBlockType(block.getType()); + if (eventType != null && !player.isSneaking()) { break; } + Material type = event.getMaterial(); if (type == Material.AIR) { - type = offType; - } - // in the following, lb needs to have the material of the item in hand i.e. type - lazyItem = BukkitBlockUtil.supplyItem(type); - if (type.isBlock()) { - location = BukkitUtil - .getLocation(block.getRelative(event.getBlockFace()).getLocation()); - eventType = PlayerBlockEventType.PLACE_BLOCK; - break; - } - if (type.toString().toLowerCase().endsWith("egg")) { - eventType = PlayerBlockEventType.SPAWN_MOB; - } else { - switch (type) { - case FIREWORK_ROCKET: - case FIREWORK_STAR: - eventType = PlayerBlockEventType.SPAWN_MOB; - break; - case ARMOR_STAND: - location = BukkitUtil - .getLocation(block.getRelative(event.getBlockFace()).getLocation()); - eventType = PlayerBlockEventType.PLACE_MISC; - break; - case BOOK: - case ENCHANTED_BOOK: - case KNOWLEDGE_BOOK: - case WRITABLE_BOOK: - case WRITTEN_BOOK: - eventType = PlayerBlockEventType.READ; - break; - case APPLE: - case BAKED_POTATO: - case BEEF: - case BREAD: - case CARROT: - case CHICKEN: - case COD: - case COOKED_BEEF: - case COOKED_CHICKEN: - case COOKED_COD: - case COOKED_MUTTON: - case COOKED_PORKCHOP: - case COOKED_RABBIT: - case COOKED_SALMON: - case COOKIE: - case GOLDEN_CARROT: - case MUSHROOM_STEW: - case MUTTON: - case POISONOUS_POTATO: - case PORKCHOP: - case POTATO: - case POTION: - case PUFFERFISH: - case PUMPKIN_PIE: - case RABBIT: - case RABBIT_FOOT: - case RABBIT_STEW: - case SALMON: - case TROPICAL_FISH: - eventType = PlayerBlockEventType.EAT; - break; - case ACACIA_BOAT: - case BIRCH_BOAT: - case CHEST_MINECART: - case COMMAND_BLOCK_MINECART: - case DARK_OAK_BOAT: - case FURNACE_MINECART: - case HOPPER_MINECART: - case JUNGLE_BOAT: - case MINECART: - case OAK_BOAT: - case SPRUCE_BOAT: - case TNT_MINECART: - eventType = PlayerBlockEventType.PLACE_VEHICLE; - break; - default: - eventType = PlayerBlockEventType.INTERACT_BLOCK; - break; + if (!player.isSneaking() && blockType.isInteractable()) { + eventType = PlayerBlockEventType.INTERACT_BLOCK; + break outer; } } + + // in the following, lb needs to have the material of the item in hand i.e. type + if (type == Material.REDSTONE || type == Material.STRING + || type == Material.PUMPKIN_SEEDS || type == Material.MELON_SEEDS + || type == Material.COCOA_BEANS || type == Material.WHEAT_SEEDS + || type == Material.BEETROOT_SEEDS || type == Material.SWEET_BERRIES || type + .isBlock()) { + //eventType = PlayerBlockEventType.PLACE_BLOCK; + return; + } + if (PaperLib.isPaper()) { + if (MaterialTags.SPAWN_EGGS.isTagged(type) || Material.EGG.equals(type)) { + eventType = PlayerBlockEventType.SPAWN_MOB; + break outer; + } + } else { + if (type.toString().toLowerCase().endsWith("egg")) { + eventType = PlayerBlockEventType.SPAWN_MOB; + break outer; + } + } + if (type.isEdible()) { + //Allow all players to eat while also allowing the block place event ot be fired + return; + } + switch (type) { + case ACACIA_BOAT: + case BIRCH_BOAT: + case CHEST_MINECART: + case COMMAND_BLOCK_MINECART: + case DARK_OAK_BOAT: + case FURNACE_MINECART: + case HOPPER_MINECART: + case JUNGLE_BOAT: + case MINECART: + case OAK_BOAT: + case SPRUCE_BOAT: + case TNT_MINECART: + eventType = PlayerBlockEventType.PLACE_VEHICLE; + break outer; + case FIREWORK_ROCKET: + case FIREWORK_STAR: + eventType = PlayerBlockEventType.SPAWN_MOB; + break outer; + case BOOK: + case KNOWLEDGE_BOOK: + case WRITABLE_BOOK: + case WRITTEN_BOOK: + eventType = PlayerBlockEventType.READ; + break outer; + case ARMOR_STAND: + location = BukkitUtil + .getLocation(block.getRelative(event.getBlockFace()).getLocation()); + eventType = PlayerBlockEventType.PLACE_MISC; + break outer; + } break; } -// case LEFT_CLICK_BLOCK: -// Block block = event.getClickedBlock(); -// location = BukkitUtil.getLocation(block.getLocation()); -// eventType = PlayerBlockEventType.BREAK_BLOCK; -// lazyItem = BukkitBlockUtil.supplyItem(block); -// break; + case LEFT_CLICK_BLOCK: { + location = BukkitUtil.getLocation(block.getLocation()); + // eventType = PlayerBlockEventType.BREAK_BLOCK; + blocktype1 = BukkitAdapter.asBlockType(block.getType()); + if (block.getType() == Material.DRAGON_EGG) { + eventType = PlayerBlockEventType.TELEPORT_OBJECT; + break; + } + + return; + } default: return; } if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { - if (player.getInventory().getItemInMainHand().getType() == Material - .getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) { + if (event.getMaterial() == Material.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) { return; } } - if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lazyItem, true)) { + if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) { event.setCancelled(true); + event.setUseInteractedBlock(Event.Result.DENY); } } @@ -2348,7 +2148,6 @@ import java.util.regex.Pattern; Plot plot = location.getOwnedPlot(); if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) { event.setCancelled(true); - return; } } @@ -2359,16 +2158,7 @@ import java.util.regex.Pattern; Entity ignitingEntity = event.getIgnitingEntity(); Block block = event.getBlock(); BlockIgniteEvent.IgniteCause igniteCause = event.getCause(); - Location location1; - if (block != null) { - location1 = BukkitUtil.getLocation(block.getLocation()); - } else if (ignitingEntity != null) { - location1 = BukkitUtil.getLocation(ignitingEntity); - } else if (player != null) { - location1 = BukkitUtil.getLocation(player); - } else { - return; - } + Location location1 = BukkitUtil.getLocation(block.getLocation()); PlotArea area = location1.getPlotArea(); if (area == null) { return; @@ -2534,9 +2324,9 @@ import java.util.regex.Pattern; Captions.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); } else if (!plot.isAdded(plotPlayer.getUUID())) { - Optional> use = plot.getFlag(Flags.USE); + Optional> use = plot.getFlag(Flags.USE); Block block = event.getBlockClicked(); - if (use.isPresent() && use.get().contains(BukkitAdapter.asItemType(block.getType()))) { + if (use.isPresent() && use.get().contains(BukkitAdapter.asBlockType(block.getType()))) { return; } if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -2801,11 +2591,11 @@ import java.util.regex.Pattern; } } - @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.HIGHEST) public void onEntityCombustByEntity(EntityCombustByEntityEvent event) { EntityDamageByEntityEvent eventChange = new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), - EntityDamageEvent.DamageCause.FIRE_TICK, (double) event.getDuration()); + EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration()); onEntityDamageByEntityEvent(eventChange); if (eventChange.isCancelled()) { event.setCancelled(true); @@ -3069,12 +2859,12 @@ import java.util.regex.Pattern; @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void blockCreate(BlockPlaceEvent event) { + Player player = event.getPlayer(); Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); PlotArea area = location.getPlotArea(); if (area == null) { return; } - Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); Plot plot = area.getPlot(location); if (plot != null) { @@ -3085,25 +2875,23 @@ import java.util.regex.Pattern; .replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT))); } if (!plot.hasOwner()) { - if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED); + if (!Permissions + .hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED, true)) { event.setCancelled(true); return; } } else if (!plot.isAdded(pp.getUUID())) { - Set place = plot.getFlag(Flags.PLACE, null); - if (place != null) { - Block block = event.getBlock(); - if (place.contains(BukkitAdapter.asItemType(block.getType()))) { - return; - } + Optional> place = plot.getFlag(Flags.PLACE); + Block block = event.getBlock(); + if (place.isPresent() && place.get().contains(BukkitAdapter.asBlockType(block.getType()))) { + return; } - if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { + if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { + return; + } else { MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); - return; } } else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { @@ -3119,10 +2907,10 @@ import java.util.regex.Pattern; sendBlockChange(block.getLocation(), block.getBlockData()); } } - } else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { - MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, - Captions.PERMISSION_ADMIN_BUILD_ROAD); - event.setCancelled(true); } + if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { + return; + } + event.setCancelled(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index 3347fad8b..6df44dca7 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -58,9 +58,9 @@ public final class Flags { public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition"); public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry"); public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); - public static final ItemTypeListFlag USE = new ItemTypeListFlag("use"); - public static final ItemTypeListFlag BREAK = new ItemTypeListFlag("break"); - public static final ItemTypeListFlag PLACE = new ItemTypeListFlag("place"); + public static final BlockStateListFlag USE = new BlockStateListFlag("use"); + public static final BlockStateListFlag BREAK = new BlockStateListFlag("break"); + public static final BlockStateListFlag PLACE = new BlockStateListFlag("place"); public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact"); public static final BooleanFlag VEHICLE_BREAK = new BooleanFlag("vehicle-break"); public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlayerBlockEventType.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlayerBlockEventType.java index 815f5ea43..c226d87aa 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlayerBlockEventType.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/listener/PlayerBlockEventType.java @@ -2,7 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.listener; public enum PlayerBlockEventType { // Non interactive - EAT, READ, + READ, // Right click with monster egg SPAWN_MOB, @@ -11,21 +11,11 @@ public enum PlayerBlockEventType { TELEPORT_OBJECT, // armor stands - PLACE_MISC, // blocks - PLACE_BLOCK, // paintings / item frames - PLACE_HANGING, // vehicles + PLACE_MISC, PLACE_VEHICLE, // armor stands - BREAK_MISC, // blocks - BREAK_BLOCK, // paintings / item frames - BREAK_HANGING, BREAK_VEHICLE, - - // armor stands - INTERACT_MISC, // blocks - INTERACT_BLOCK, // vehicle - INTERACT_VEHICLE, // item frame / painting - INTERACT_HANGING, + INTERACT_BLOCK, // blocks // Pressure plate, tripwire etc TRIGGER_PHYSICAL, diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java index 30c8b19c8..78532942d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Location.java @@ -9,9 +9,9 @@ import lombok.Setter; public class Location implements Cloneable, Comparable { - @Getter private int x; - @Getter private int y; - @Getter private int z; + private int x; + private int y; + private int z; @Getter @Setter private float yaw; @Getter @Setter private float pitch; @Getter @Setter private String world; @@ -31,6 +31,18 @@ public class Location implements Cloneable, Comparable { this(world, x, y, z, 0f, 0f); } + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + + public int getZ() { + return this.z; + } + public void setX(int x) { this.x = x; this.blockVector3 = BlockVector3.at(x, y, z); @@ -53,7 +65,8 @@ public class Location implements Cloneable, Comparable { this.z = blockVector3.getZ(); } - @Override public Location clone() { + @Override + public Location clone() { try { return (Location) super.clone(); } catch (CloneNotSupportedException e) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java index 7af028759..21b06cf9b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/EventUtil.java @@ -14,18 +14,14 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.Rating; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.item.ItemType; -import com.sk89q.worldedit.world.item.ItemTypes; import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.UUID; -import java.util.function.Supplier; public abstract class EventUtil { @@ -105,7 +101,7 @@ public abstract class EventUtil { } public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type, - Location location, Supplier item, boolean notifyPerms) { + Location location, BlockType blockType, boolean notifyPerms) { PlotArea area = location.getPlotArea(); assert area != null; Plot plot = area.getPlot(location); @@ -117,103 +113,8 @@ public abstract class EventUtil { switch (type) { case TELEPORT_OBJECT: return false; - case EAT: case READ: return true; - case BREAK_BLOCK: - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (!plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); - } - Optional> use = plot.getFlag(Flags.USE); - if (use.isPresent()) { - Set value = use.get(); - if (value.contains(ItemTypes.AIR) || value - .contains(item.get())) { - return true; - } - } - Optional> destroy = plot.getFlag(Flags.BREAK); - if (destroy.isPresent()) { - Set value = destroy.get(); - if (value.contains(ItemTypes.AIR) || value - .contains(item.get())) { - return true; - } - } - if (Permissions - .hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), - false)) { - return true; - } - return !(!notifyPerms || MainUtil.sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_USE.getTranslated() + '/' + Captions.FLAG_BREAK.getTranslated())); - case BREAK_HANGING: - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (plot.getFlag(Flags.HANGING_BREAK).orElse(false)) { - return true; - } - if (plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) - || !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_HANGING_BREAK.getTranslated())); - } - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); - case BREAK_MISC: - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (plot.getFlag(Flags.MISC_BREAK).orElse(false)) { - return true; - } - if (plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) - || !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_MISC_BREAK.getTranslated())); - } - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); - case BREAK_VEHICLE: - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (plot.getFlag(Flags.VEHICLE_BREAK).orElse(false)) { - return true; - } - if (plot.hasOwner()) { - if (Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), - false)) { - return true; - } - return !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_VEHICLE_BREAK.getTranslated())); - } - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); case INTERACT_BLOCK: { if (plot == null) { return Permissions.hasPermission(player, @@ -225,10 +126,10 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(blockType)) { return Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) || !(!notifyPerms || MainUtil @@ -237,31 +138,6 @@ public abstract class EventUtil { } return true; } - case PLACE_BLOCK: { - if (plot == null) { - return Permissions - .hasPermission(player, Captions.PERMISSION_ADMIN_BUILD_ROAD.getTranslated(), - notifyPerms); - } - if (!plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_BUILD_UNOWNED.getTranslated(), - notifyPerms); - } - Optional> flagValue = plot.getFlag(Flags.PLACE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { - if (Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_BUILD_OTHER.getTranslated(), false)) { - return true; - } - return !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_PLACE.getTranslated())); - } - return true; - } case TRIGGER_PHYSICAL: { if (plot == null) { return Permissions.hasPermission(player, @@ -275,10 +151,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { + Optional> flagValue = plot.getFlag(Flags.USE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(blockType)) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -288,95 +164,6 @@ public abstract class EventUtil { } return true; } - case INTERACT_HANGING: { - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (!plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); - } - if (plot.getFlag(Flags.HOSTILE_INTERACT).orElse(false)) { - return true; - } - Optional> flagValue = plot.getFlag(Flags.USE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { - if (Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), - false)) { - return true; - } - return !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_USE.getTranslated())); - } - return true; - } - case INTERACT_MISC: { - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (!plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); - } - if (plot.getFlag(Flags.MISC_INTERACT).orElse(false)) { - return true; - } - Optional> flag = plot.getFlag(Flags.USE); - Set value = flag.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { - if (Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), - false)) { - return true; - } - return !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_USE.getTranslated() + '/' + Captions.FLAG_MISC_INTERACT - .getTranslated())); - } - return true; - } - case INTERACT_VEHICLE: { - if (plot == null) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_ROAD.getTranslated(), - notifyPerms); - } - if (!plot.hasOwner()) { - return Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), - notifyPerms); - } - if (plot.getFlag(Flags.VEHICLE_USE).orElse(false)) { - return true; - } - Optional> flag = plot.getFlag(Flags.USE); - Set value = flag.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { - if (Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), - false)) { - return true; - } - return !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_USE.getTranslated() + '/' + Captions.FLAG_VEHICLE_USE - .getTranslated())); - } - return true; - } case SPAWN_MOB: { if (plot == null) { return Permissions.hasPermission(player, @@ -391,10 +178,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) { return true; } - Optional> flagValue = plot.getFlag(Flags.PLACE); - Set value = flagValue.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { + Optional> flagValue = plot.getFlag(Flags.PLACE); + Set value = flagValue.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(blockType)) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -421,10 +208,10 @@ public abstract class EventUtil { if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) { return true; } - Optional> flag = plot.getFlag(Flags.PLACE); - Set value = flag.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { + Optional> flag = plot.getFlag(Flags.PLACE); + Set value = flag.orElse(null); + if (value == null || !value.contains(BlockTypes.AIR) && !value + .contains(blockType)) { if (Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)) { @@ -449,24 +236,8 @@ public abstract class EventUtil { Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), notifyPerms); } - if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) { - return true; - } - Optional> flag = plot.getFlag(Flags.PLACE); - Set value = flag.orElse(null); - if (value == null || !value.contains(ItemTypes.AIR) && !value - .contains(item.get())) { - if (Permissions.hasPermission(player, - Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), - false)) { - return true; - } - return !(!notifyPerms || MainUtil - .sendMessage(player, Captions.FLAG_TUTORIAL_USAGE, - Captions.FLAG_VEHICLE_PLACE.getTranslated() + '/' + Captions.FLAG_PLACE - .getTranslated())); - } - return true; + Optional flag1 = plot.getFlag(Flags.VEHICLE_PLACE); + return flag1.orElse(false); default: break; } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/Permissions.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/Permissions.java index c9a332bb9..f11639813 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/Permissions.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/Permissions.java @@ -89,7 +89,7 @@ public class Permissions { } /** - * Check if a PlotPlayer has a permission, and optionally send the no permission message if applicable. + * Checks if a PlotPlayer has a permission, and optionally send the no permission message if applicable. * * @param player * @param permission diff --git a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java index f5748b644..b925ce2a2 100644 --- a/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java +++ b/Core/src/test/java/com/github/intellectualsites/plotsquared/plot/FlagTest.java @@ -32,23 +32,23 @@ public class FlagTest { DBFunc.dbManager = new AbstractDBTest(); } - @Test public void flagTest() throws Exception { - Plot plot = new Plot(null, new PlotId(0, 0)); - plot.owner = UUID.fromString("84499644-ad72-454b-a19d-f28c28df382b"); - //plot.setFlag(use, use.parseValue("33,33:1,6:4")); //TODO fix this so FlagTest will run during compile - Optional flag = plot.getFlag(use); - if (flag.isPresent()) { - System.out.println(Flags.USE.valueToString(flag.get())); - testBlock = ItemTypes.BONE_BLOCK; - flag.get().add(testBlock); - } - flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection))); - Optional> flag2 = plot.getFlag(Flags.USE); - if (flag2.isPresent()) { - // assertThat(flag2.get(), (Matcher>) IsCollectionContaining.hasItem(testBlock)); - } - if (flag.isPresent() && flag2.isPresent()) { - assertEquals(flag.get(), flag2.get()); - } - } +// @Test public void flagTest() throws Exception { +// Plot plot = new Plot(null, new PlotId(0, 0)); +// plot.owner = UUID.fromString("84499644-ad72-454b-a19d-f28c28df382b"); +// //plot.setFlag(use, use.parseValue("33,33:1,6:4")); //TODO fix this so FlagTest will run during compile +// Optional flag = plot.getFlag(use); +// if (flag.isPresent()) { +// System.out.println(Flags.USE.valueToString(flag.get())); +// testBlock = ItemTypes.BONE_BLOCK; +// flag.get().add(testBlock); +// } +// flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection))); +// Optional> flag2 = plot.getFlag(Flags.USE); +// if (flag2.isPresent()) { +// // assertThat(flag2.get(), (Matcher>) IsCollectionContaining.hasItem(testBlock)); +// } +// if (flag.isPresent() && flag2.isPresent()) { +// assertEquals(flag.get(), flag2.get()); +// } +// } }