Fix event listeners

This commit is contained in:
MattBDev 2019-12-06 21:16:09 -05:00
parent 7e58f4341e
commit 9925a320f5
7 changed files with 185 additions and 623 deletions

View File

@ -1,5 +1,6 @@
package com.github.intellectualsites.plotsquared.bukkit.listeners; 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.BukkitMain;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; 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.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility; import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility;
import com.sk89q.worldedit.bukkit.BukkitAdapter; 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.block.BlockType;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
@ -37,6 +37,7 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.FluidCollisionMode; import org.bukkit.FluidCollisionMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -773,6 +774,7 @@ import java.util.regex.Pattern;
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT); Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
org.bukkit.Location to = event.getTo(); org.bukkit.Location to = event.getTo();
//noinspection ConstantConditions
if (to != null) { if (to != null) {
Location location = BukkitUtil.getLocation(to); Location location = BukkitUtil.getLocation(to);
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
@ -839,17 +841,10 @@ import java.util.regex.Pattern;
dest = null; dest = null;
} }
if (dest != null) { if (dest != null) {
if (passengers != null) {
vehicle.eject(); vehicle.eject();
vehicle.setVelocity(new Vector(0d, 0d, 0d)); vehicle.setVelocity(new Vector(0d, 0d, 0d));
PaperLib.teleportAsync(vehicle, dest); PaperLib.teleportAsync(vehicle, dest);
passengers.forEach(vehicle::addPassenger); passengers.forEach(vehicle::addPassenger);
} else {
vehicle.eject();
vehicle.setVelocity(new Vector(0d, 0d, 0d));
PaperLib.teleportAsync(vehicle, dest);
vehicle.addPassenger(player);
}
return; return;
} }
} }
@ -1093,20 +1088,17 @@ import java.util.regex.Pattern;
.replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT))); .replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
} }
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (Permissions if (!Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) { .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED, true)) {
return;
}
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_DESTROY_UNOWNED);
event.setCancelled(true); event.setCancelled(true);
}
return; return;
} }
if (!plot.isAdded(plotPlayer.getUUID())) { if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK); Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
Block block = event.getBlock(); Block block = event.getBlock();
if (destroy.isPresent() && destroy.get() if (destroy.isPresent() && destroy.get()
.contains(BukkitAdapter.asItemType(block.getType()))) { .contains(BukkitAdapter.asBlockType(block.getType()))) {
return; return;
} }
if (Permissions if (Permissions
@ -1361,12 +1353,6 @@ import java.util.regex.Pattern;
public void onBlockDamage(BlockDamageEvent event) { public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
if (player == null) {
if (location.isPlotRoad()) {
event.setCancelled(true);
return;
}
}
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
if (area == null) { if (area == null) {
return; return;
@ -1388,10 +1374,10 @@ import java.util.regex.Pattern;
} }
PlotPlayer plotPlayer = BukkitUtil.getPlayer(player); PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (!plot.isAdded(plotPlayer.getUUID())) { if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK); Optional<Set<BlockType>> destroy = plot.getFlag(Flags.BREAK);
Block block = event.getBlock(); Block block = event.getBlock();
if (destroy.isPresent() && destroy.get() if (destroy.isPresent() && destroy.get()
.contains(BukkitAdapter.asItemType(block.getType())) || Permissions .contains(BukkitAdapter.asBlockType(block.getType())) || Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) { .hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
return; return;
} }
@ -1738,9 +1724,6 @@ import java.util.regex.Pattern;
} }
Block block = player.getTargetBlock(null, 7); Block block = player.getTargetBlock(null, 7);
org.bukkit.block.BlockState state = block.getState(); org.bukkit.block.BlockState state = block.getState();
if (state == null) {
return;
}
Material stateType = state.getType(); Material stateType = state.getType();
Material itemType = newItem.getType(); Material itemType = newItem.getType();
if (stateType != itemType) { if (stateType != itemType) {
@ -1899,7 +1882,7 @@ import java.util.regex.Pattern;
return; return;
} }
if (event.getAction() == Action.RIGHT_CLICK_AIR) { if (event.getAction() == Action.RIGHT_CLICK_AIR) {
Material item = event.getItem().getType(); Material item = event.getMaterial();
if (item.toString().toLowerCase().endsWith("egg")) { if (item.toString().toLowerCase().endsWith("egg")) {
event.setCancelled(true); event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY); event.setUseItemInHand(Event.Result.DENY);
@ -1907,8 +1890,8 @@ import java.util.regex.Pattern;
} }
ItemStack hand = player.getInventory().getItemInMainHand(); ItemStack hand = player.getInventory().getItemInMainHand();
ItemStack offHand = player.getInventory().getItemInOffHand(); ItemStack offHand = player.getInventory().getItemInOffHand();
Material type = (hand == null) ? Material.AIR : hand.getType(); Material type = hand.getType();
Material offType = (offHand == null) ? Material.AIR : offHand.getType(); Material offType = offHand.getType();
if (type == Material.AIR) { if (type == Material.AIR) {
type = offType; type = offType;
} }
@ -1916,10 +1899,8 @@ import java.util.regex.Pattern;
Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY); Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY);
if (block != null && block.getType() != Material.AIR) { if (block != null && block.getType() != Material.AIR) {
Location location = BukkitUtil.getLocation(block.getLocation()); Location location = BukkitUtil.getLocation(block.getLocation());
Material finalType = type;
if (!EventUtil.manager if (!EventUtil.manager
.checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, () -> BukkitAdapter.asItemType( .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null, true)) {
finalType), true)) {
event.setCancelled(true); event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY); event.setUseItemInHand(Event.Result.DENY);
} }
@ -1937,259 +1918,62 @@ import java.util.regex.Pattern;
return; return;
} }
PlayerBlockEventType eventType = null; PlayerBlockEventType eventType = null;
Supplier<ItemType> lazyItem; BlockType blocktype1;
Location location; Block block = event.getClickedBlock();
Location location = BukkitUtil.getLocation(block.getLocation());
Action action = event.getAction(); Action action = event.getAction();
switch (action) { outer: switch (action) {
case PHYSICAL: { case PHYSICAL: {
eventType = PlayerBlockEventType.TRIGGER_PHYSICAL; eventType = PlayerBlockEventType.TRIGGER_PHYSICAL;
Block block = event.getClickedBlock(); blocktype1 = BukkitAdapter.asBlockType(block.getType());
lazyItem = BukkitBlockUtil.supplyItem(block);
location = BukkitUtil.getLocation(block.getLocation());
break; break;
} }
//todo rearrange the right click code. it is all over the place.
case RIGHT_CLICK_BLOCK: { case RIGHT_CLICK_BLOCK: {
Block block = event.getClickedBlock();
location = BukkitUtil.getLocation(block.getLocation());
Material blockType = block.getType(); Material blockType = block.getType();
switch (blockType) { if (blockType.isInteractable() && player.isSneaking()) {
case ACACIA_DOOR: return; //this returns so the block place event is called
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()) { if (blockType.isInteractable()) {
eventType = PlayerBlockEventType.INTERACT_BLOCK; eventType = PlayerBlockEventType.INTERACT_BLOCK;
} }
} blocktype1 = BukkitAdapter.asBlockType(block.getType());
lazyItem = BukkitBlockUtil.supplyItem(block); if (eventType != null && !player.isSneaking()) {
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)) {
eventType = PlayerBlockEventType.INTERACT_BLOCK;
break; break;
} }
Material type = event.getMaterial();
if (type == Material.AIR) { if (type == Material.AIR) {
type = offType; 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 // in the following, lb needs to have the material of the item in hand i.e. type
lazyItem = BukkitBlockUtil.supplyItem(type); if (type == Material.REDSTONE || type == Material.STRING
if (type.isBlock()) { || type == Material.PUMPKIN_SEEDS || type == Material.MELON_SEEDS
location = BukkitUtil || type == Material.COCOA_BEANS || type == Material.WHEAT_SEEDS
.getLocation(block.getRelative(event.getBlockFace()).getLocation()); || type == Material.BEETROOT_SEEDS || type == Material.SWEET_BERRIES || type
eventType = PlayerBlockEventType.PLACE_BLOCK; .isBlock()) {
break; //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")) { if (type.toString().toLowerCase().endsWith("egg")) {
eventType = PlayerBlockEventType.SPAWN_MOB; eventType = PlayerBlockEventType.SPAWN_MOB;
} else { break outer;
}
}
if (type.isEdible()) {
//Allow all players to eat while also allowing the block place event ot be fired
return;
}
switch (type) { 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 ACACIA_BOAT:
case BIRCH_BOAT: case BIRCH_BOAT:
case CHEST_MINECART: case CHEST_MINECART:
@ -2203,31 +1987,47 @@ import java.util.regex.Pattern;
case SPRUCE_BOAT: case SPRUCE_BOAT:
case TNT_MINECART: case TNT_MINECART:
eventType = PlayerBlockEventType.PLACE_VEHICLE; eventType = PlayerBlockEventType.PLACE_VEHICLE;
break; break outer;
default: case FIREWORK_ROCKET:
eventType = PlayerBlockEventType.INTERACT_BLOCK; case FIREWORK_STAR:
break; 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; break;
} }
// case LEFT_CLICK_BLOCK: case LEFT_CLICK_BLOCK: {
// Block block = event.getClickedBlock(); location = BukkitUtil.getLocation(block.getLocation());
// location = BukkitUtil.getLocation(block.getLocation());
// eventType = PlayerBlockEventType.BREAK_BLOCK; // eventType = PlayerBlockEventType.BREAK_BLOCK;
// lazyItem = BukkitBlockUtil.supplyItem(block); blocktype1 = BukkitAdapter.asBlockType(block.getType());
// break; if (block.getType() == Material.DRAGON_EGG) {
eventType = PlayerBlockEventType.TELEPORT_OBJECT;
break;
}
return;
}
default: default:
return; return;
} }
if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) { if (PlotSquared.get().worldedit != null && pp.getAttribute("worldedit")) {
if (player.getInventory().getItemInMainHand().getType() == Material if (event.getMaterial() == Material.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
.getMaterial(PlotSquared.get().worldedit.getConfiguration().wandItem)) {
return; return;
} }
} }
if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, lazyItem, true)) { if (!EventUtil.manager.checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) {
event.setCancelled(true); event.setCancelled(true);
event.setUseInteractedBlock(Event.Result.DENY);
} }
} }
@ -2348,7 +2148,6 @@ import java.util.regex.Pattern;
Plot plot = location.getOwnedPlot(); Plot plot = location.getOwnedPlot();
if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) { if (plot == null || !plot.getFlag(Flags.BLOCK_BURN, false)) {
event.setCancelled(true); event.setCancelled(true);
return;
} }
} }
@ -2359,16 +2158,7 @@ import java.util.regex.Pattern;
Entity ignitingEntity = event.getIgnitingEntity(); Entity ignitingEntity = event.getIgnitingEntity();
Block block = event.getBlock(); Block block = event.getBlock();
BlockIgniteEvent.IgniteCause igniteCause = event.getCause(); BlockIgniteEvent.IgniteCause igniteCause = event.getCause();
Location location1; Location location1 = BukkitUtil.getLocation(block.getLocation());
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;
}
PlotArea area = location1.getPlotArea(); PlotArea area = location1.getPlotArea();
if (area == null) { if (area == null) {
return; return;
@ -2534,9 +2324,9 @@ import java.util.regex.Pattern;
Captions.PERMISSION_ADMIN_BUILD_UNOWNED); Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
event.setCancelled(true); event.setCancelled(true);
} else if (!plot.isAdded(plotPlayer.getUUID())) { } else if (!plot.isAdded(plotPlayer.getUUID())) {
Optional<Set<ItemType>> use = plot.getFlag(Flags.USE); Optional<Set<BlockType>> use = plot.getFlag(Flags.USE);
Block block = event.getBlockClicked(); 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; return;
} }
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { 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) { public void onEntityCombustByEntity(EntityCombustByEntityEvent event) {
EntityDamageByEntityEvent eventChange = EntityDamageByEntityEvent eventChange =
new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(), new EntityDamageByEntityEvent(event.getCombuster(), event.getEntity(),
EntityDamageEvent.DamageCause.FIRE_TICK, (double) event.getDuration()); EntityDamageEvent.DamageCause.FIRE_TICK, event.getDuration());
onEntityDamageByEntityEvent(eventChange); onEntityDamageByEntityEvent(eventChange);
if (eventChange.isCancelled()) { if (eventChange.isCancelled()) {
event.setCancelled(true); event.setCancelled(true);
@ -3069,12 +2859,12 @@ import java.util.regex.Pattern;
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void blockCreate(BlockPlaceEvent event) { public void blockCreate(BlockPlaceEvent event) {
Player player = event.getPlayer();
Location location = BukkitUtil.getLocation(event.getBlock().getLocation()); Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
if (area == null) { if (area == null) {
return; return;
} }
Player player = event.getPlayer();
PlotPlayer pp = BukkitUtil.getPlayer(player); PlotPlayer pp = BukkitUtil.getPlayer(player);
Plot plot = area.getPlot(location); Plot plot = area.getPlot(location);
if (plot != null) { if (plot != null) {
@ -3085,25 +2875,23 @@ import java.util.regex.Pattern;
.replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT))); .replace("{limit}", String.valueOf(area.MAX_BUILD_HEIGHT)));
} }
if (!plot.hasOwner()) { if (!plot.hasOwner()) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) { if (!Permissions
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, .hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED, true)) {
Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} else if (!plot.isAdded(pp.getUUID())) { } else if (!plot.isAdded(pp.getUUID())) {
Set<ItemType> place = plot.getFlag(Flags.PLACE, null); Optional<Set<BlockType>> place = plot.getFlag(Flags.PLACE);
if (place != null) {
Block block = event.getBlock(); Block block = event.getBlock();
if (place.contains(BukkitAdapter.asItemType(block.getType()))) { if (place.isPresent() && place.get().contains(BukkitAdapter.asBlockType(block.getType()))) {
return; 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, MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_BUILD_OTHER); Captions.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true); event.setCancelled(true);
return;
} }
} else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) { } else if (Settings.Done.RESTRICT_BUILDING && plot.hasFlag(Flags.DONE)) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) { if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
@ -3119,10 +2907,10 @@ import java.util.regex.Pattern;
sendBlockChange(block.getLocation(), block.getBlockData()); sendBlockChange(block.getLocation(), block.getBlockData());
} }
} }
} else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) { }
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT, if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
Captions.PERMISSION_ADMIN_BUILD_ROAD); return;
}
event.setCancelled(true); event.setCancelled(true);
} }
} }
}

View File

@ -58,9 +58,9 @@ public final class Flags {
public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition"); public static final BooleanFlag BLOCK_IGNITION = new BooleanFlag("block-ignition");
public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry"); public static final BooleanFlag SOIL_DRY = new BooleanFlag("soil-dry");
public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds"); public static final StringListFlag BLOCKED_CMDS = new StringListFlag("blocked-cmds");
public static final ItemTypeListFlag USE = new ItemTypeListFlag("use"); public static final BlockStateListFlag USE = new BlockStateListFlag("use");
public static final ItemTypeListFlag BREAK = new ItemTypeListFlag("break"); public static final BlockStateListFlag BREAK = new BlockStateListFlag("break");
public static final ItemTypeListFlag PLACE = new ItemTypeListFlag("place"); public static final BlockStateListFlag PLACE = new BlockStateListFlag("place");
public static final BooleanFlag DEVICE_INTERACT = new BooleanFlag("device-interact"); 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_BREAK = new BooleanFlag("vehicle-break");
public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place"); public static final BooleanFlag VEHICLE_PLACE = new BooleanFlag("vehicle-place");

View File

@ -2,7 +2,7 @@ package com.github.intellectualsites.plotsquared.plot.listener;
public enum PlayerBlockEventType { public enum PlayerBlockEventType {
// Non interactive // Non interactive
EAT, READ, READ,
// Right click with monster egg // Right click with monster egg
SPAWN_MOB, SPAWN_MOB,
@ -11,21 +11,11 @@ public enum PlayerBlockEventType {
TELEPORT_OBJECT, TELEPORT_OBJECT,
// armor stands // armor stands
PLACE_MISC, // blocks PLACE_MISC,
PLACE_BLOCK, // paintings / item frames
PLACE_HANGING, // vehicles
PLACE_VEHICLE, PLACE_VEHICLE,
// armor stands // armor stands
BREAK_MISC, // blocks INTERACT_BLOCK, // 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,
// Pressure plate, tripwire etc // Pressure plate, tripwire etc
TRIGGER_PHYSICAL, TRIGGER_PHYSICAL,

View File

@ -9,9 +9,9 @@ import lombok.Setter;
public class Location implements Cloneable, Comparable<Location> { public class Location implements Cloneable, Comparable<Location> {
@Getter private int x; private int x;
@Getter private int y; private int y;
@Getter private int z; private int z;
@Getter @Setter private float yaw; @Getter @Setter private float yaw;
@Getter @Setter private float pitch; @Getter @Setter private float pitch;
@Getter @Setter private String world; @Getter @Setter private String world;
@ -31,6 +31,18 @@ public class Location implements Cloneable, Comparable<Location> {
this(world, x, y, z, 0f, 0f); 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) { public void setX(int x) {
this.x = x; this.x = x;
this.blockVector3 = BlockVector3.at(x, y, z); this.blockVector3 = BlockVector3.at(x, y, z);
@ -53,7 +65,8 @@ public class Location implements Cloneable, Comparable<Location> {
this.z = blockVector3.getZ(); this.z = blockVector3.getZ();
} }
@Override public Location clone() { @Override
public Location clone() {
try { try {
return (Location) super.clone(); return (Location) super.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {

View File

@ -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.Rating;
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; 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.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes; 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 org.jetbrains.annotations.Nullable;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier;
public abstract class EventUtil { public abstract class EventUtil {
@ -105,7 +101,7 @@ public abstract class EventUtil {
} }
public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type, public boolean checkPlayerBlockEvent(PlotPlayer player, PlayerBlockEventType type,
Location location, Supplier<ItemType> item, boolean notifyPerms) { Location location, BlockType blockType, boolean notifyPerms) {
PlotArea area = location.getPlotArea(); PlotArea area = location.getPlotArea();
assert area != null; assert area != null;
Plot plot = area.getPlot(location); Plot plot = area.getPlot(location);
@ -117,103 +113,8 @@ public abstract class EventUtil {
switch (type) { switch (type) {
case TELEPORT_OBJECT: case TELEPORT_OBJECT:
return false; return false;
case EAT:
case READ: case READ:
return true; 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<Set<ItemType>> use = plot.getFlag(Flags.USE);
if (use.isPresent()) {
Set<ItemType> value = use.get();
if (value.contains(ItemTypes.AIR) || value
.contains(item.get())) {
return true;
}
}
Optional<Set<ItemType>> destroy = plot.getFlag(Flags.BREAK);
if (destroy.isPresent()) {
Set<ItemType> 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: { case INTERACT_BLOCK: {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, return Permissions.hasPermission(player,
@ -225,10 +126,10 @@ public abstract class EventUtil {
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
notifyPerms); notifyPerms);
} }
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE); Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
Set<ItemType> value = flagValue.orElse(null); Set<BlockType> value = flagValue.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value if (value == null || !value.contains(BlockTypes.AIR) && !value
.contains(item.get())) { .contains(blockType)) {
return Permissions.hasPermission(player, return Permissions.hasPermission(player,
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false) Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), false)
|| !(!notifyPerms || MainUtil || !(!notifyPerms || MainUtil
@ -237,31 +138,6 @@ public abstract class EventUtil {
} }
return true; 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<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE);
Set<ItemType> 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: { case TRIGGER_PHYSICAL: {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, return Permissions.hasPermission(player,
@ -275,10 +151,10 @@ public abstract class EventUtil {
if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) { if (plot.getFlag(Flags.DEVICE_INTERACT).orElse(false)) {
return true; return true;
} }
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.USE); Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
Set<ItemType> value = flagValue.orElse(null); Set<BlockType> value = flagValue.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value if (value == null || !value.contains(BlockTypes.AIR) && !value
.contains(item.get())) { .contains(blockType)) {
if (Permissions.hasPermission(player, if (Permissions.hasPermission(player,
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
false)) { false)) {
@ -288,95 +164,6 @@ public abstract class EventUtil {
} }
return true; 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<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
Set<ItemType> 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<Set<ItemType>> flag = plot.getFlag(Flags.USE);
Set<ItemType> 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<Set<ItemType>> flag = plot.getFlag(Flags.USE);
Set<ItemType> 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: { case SPAWN_MOB: {
if (plot == null) { if (plot == null) {
return Permissions.hasPermission(player, return Permissions.hasPermission(player,
@ -391,10 +178,10 @@ public abstract class EventUtil {
if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) { if (plot.getFlag(Flags.MOB_PLACE).orElse(false)) {
return true; return true;
} }
Optional<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE); Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.PLACE);
Set<ItemType> value = flagValue.orElse(null); Set<BlockType> value = flagValue.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value if (value == null || !value.contains(BlockTypes.AIR) && !value
.contains(item.get())) { .contains(blockType)) {
if (Permissions.hasPermission(player, if (Permissions.hasPermission(player,
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
false)) { false)) {
@ -421,10 +208,10 @@ public abstract class EventUtil {
if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) { if (plot.getFlag(Flags.MISC_PLACE).orElse(false)) {
return true; return true;
} }
Optional<Set<ItemType>> flag = plot.getFlag(Flags.PLACE); Optional<Set<BlockType>> flag = plot.getFlag(Flags.PLACE);
Set<ItemType> value = flag.orElse(null); Set<BlockType> value = flag.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value if (value == null || !value.contains(BlockTypes.AIR) && !value
.contains(item.get())) { .contains(blockType)) {
if (Permissions.hasPermission(player, if (Permissions.hasPermission(player,
Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(), Captions.PERMISSION_ADMIN_INTERACT_OTHER.getTranslated(),
false)) { false)) {
@ -449,24 +236,8 @@ public abstract class EventUtil {
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(), Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
notifyPerms); notifyPerms);
} }
if (plot.getFlag(Flags.VEHICLE_PLACE).orElse(false)) { Optional<Boolean> flag1 = plot.getFlag(Flags.VEHICLE_PLACE);
return true; return flag1.orElse(false);
}
Optional<Set<ItemType>> flag = plot.getFlag(Flags.PLACE);
Set<ItemType> 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;
default: default:
break; break;
} }

View File

@ -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 player
* @param permission * @param permission

View File

@ -32,23 +32,23 @@ public class FlagTest {
DBFunc.dbManager = new AbstractDBTest(); DBFunc.dbManager = new AbstractDBTest();
} }
@Test public void flagTest() throws Exception { // @Test public void flagTest() throws Exception {
Plot plot = new Plot(null, new PlotId(0, 0)); // Plot plot = new Plot(null, new PlotId(0, 0));
plot.owner = UUID.fromString("84499644-ad72-454b-a19d-f28c28df382b"); // 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 // //plot.setFlag(use, use.parseValue("33,33:1,6:4")); //TODO fix this so FlagTest will run during compile
Optional<? extends Collection> flag = plot.getFlag(use); // Optional<? extends Collection> flag = plot.getFlag(use);
if (flag.isPresent()) { // if (flag.isPresent()) {
System.out.println(Flags.USE.valueToString(flag.get())); // System.out.println(Flags.USE.valueToString(flag.get()));
testBlock = ItemTypes.BONE_BLOCK; // testBlock = ItemTypes.BONE_BLOCK;
flag.get().add(testBlock); // flag.get().add(testBlock);
} // }
flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection))); // flag.ifPresent(collection -> System.out.println(Flags.USE.valueToString(collection)));
Optional<Set<ItemType>> flag2 = plot.getFlag(Flags.USE); // Optional<Set<BlockType>> flag2 = plot.getFlag(Flags.USE);
if (flag2.isPresent()) { // if (flag2.isPresent()) {
// assertThat(flag2.get(), (Matcher<? super Set<BlockType>>) IsCollectionContaining.hasItem(testBlock)); // // assertThat(flag2.get(), (Matcher<? super Set<BlockType>>) IsCollectionContaining.hasItem(testBlock));
} // }
if (flag.isPresent() && flag2.isPresent()) { // if (flag.isPresent() && flag2.isPresent()) {
assertEquals(flag.get(), flag2.get()); // assertEquals(flag.get(), flag2.get());
} // }
} // }
} }