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

@ -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");

View File

@ -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,

View File

@ -9,9 +9,9 @@ import lombok.Setter;
public class Location implements Cloneable, Comparable<Location> {
@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<Location> {
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<Location> {
this.z = blockVector3.getZ();
}
@Override public Location clone() {
@Override
public Location clone() {
try {
return (Location) super.clone();
} 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.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<ItemType> 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<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: {
if (plot == null) {
return Permissions.hasPermission(player,
@ -225,10 +126,10 @@ public abstract class EventUtil {
Captions.PERMISSION_ADMIN_INTERACT_UNOWNED.getTranslated(),
notifyPerms);
}
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())) {
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
Set<BlockType> 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<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: {
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<Set<ItemType>> flagValue = plot.getFlag(Flags.USE);
Set<ItemType> value = flagValue.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value
.contains(item.get())) {
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.USE);
Set<BlockType> 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<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: {
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<Set<ItemType>> flagValue = plot.getFlag(Flags.PLACE);
Set<ItemType> value = flagValue.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value
.contains(item.get())) {
Optional<Set<BlockType>> flagValue = plot.getFlag(Flags.PLACE);
Set<BlockType> 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<Set<ItemType>> flag = plot.getFlag(Flags.PLACE);
Set<ItemType> value = flag.orElse(null);
if (value == null || !value.contains(ItemTypes.AIR) && !value
.contains(item.get())) {
Optional<Set<BlockType>> flag = plot.getFlag(Flags.PLACE);
Set<BlockType> 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<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;
Optional<Boolean> flag1 = plot.getFlag(Flags.VEHICLE_PLACE);
return flag1.orElse(false);
default:
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 permission