2015-02-23 06:29:45 +01:00
|
|
|
package com.intellectualcrafters.plot.util;
|
|
|
|
|
2015-07-03 13:21:21 +02:00
|
|
|
import java.util.ArrayList;
|
2015-07-09 16:20:19 +02:00
|
|
|
import java.util.HashSet;
|
2015-07-03 13:21:21 +02:00
|
|
|
import java.util.UUID;
|
2015-02-23 06:29:45 +01:00
|
|
|
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.flag.Flag;
|
2015-07-09 16:20:19 +02:00
|
|
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
2015-07-26 16:51:12 +02:00
|
|
|
import com.plotsquared.bukkit.listeners.PlayerBlockEventType;
|
2015-07-09 16:20:19 +02:00
|
|
|
import com.intellectualcrafters.plot.object.LazyBlock;
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
2015-07-09 16:20:19 +02:00
|
|
|
import com.intellectualcrafters.plot.object.PlotBlock;
|
2015-07-05 17:44:10 +02:00
|
|
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-07-26 16:51:12 +02:00
|
|
|
import com.plotsquared.bukkit.util.SetupUtils;
|
2015-07-05 17:44:10 +02:00
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
public abstract class EventUtil {
|
|
|
|
|
|
|
|
public static EventUtil manager = null;
|
|
|
|
|
2015-04-09 07:41:14 +02:00
|
|
|
public static void unregisterPlayer(PlotPlayer player) {
|
|
|
|
String name = player.getName();
|
|
|
|
if (SetupUtils.setupMap.containsKey(name)) {
|
|
|
|
SetupUtils.setupMap.remove(name);
|
|
|
|
}
|
|
|
|
CmdConfirm.removePending(name);
|
2015-07-03 14:15:20 +02:00
|
|
|
PS.get().IMP.unregister(player);
|
2015-04-09 07:41:14 +02:00
|
|
|
}
|
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto);
|
|
|
|
|
|
|
|
public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot);
|
|
|
|
|
|
|
|
public abstract boolean callClear(final String world, final PlotId id);
|
|
|
|
|
|
|
|
public abstract void callDelete(final String world, final PlotId id);
|
|
|
|
|
|
|
|
public abstract boolean callFlagAdd(final Flag flag, final Plot plot);
|
|
|
|
|
|
|
|
public abstract boolean callFlagRemove(final Flag flag, final Plot plot);
|
|
|
|
|
2015-06-23 23:44:44 +02:00
|
|
|
public abstract boolean callFlagRemove(final Flag flag, final PlotCluster cluster);
|
|
|
|
|
2015-02-23 06:29:45 +01:00
|
|
|
public abstract boolean callMerge(final String world, final Plot plot, final ArrayList<PlotId> plots);
|
|
|
|
|
|
|
|
public abstract boolean callUnlink(final String world, final ArrayList<PlotId> plots);
|
|
|
|
|
|
|
|
public abstract void callEntry(final PlotPlayer player, final Plot plot);
|
|
|
|
|
|
|
|
public abstract void callLeave(final PlotPlayer player, final Plot plot);
|
|
|
|
|
|
|
|
public abstract void callDenied(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
|
|
|
|
|
|
|
|
public abstract void callTrusted(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
|
2015-05-14 14:55:57 +02:00
|
|
|
|
|
|
|
public abstract void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
|
2015-07-09 16:20:19 +02:00
|
|
|
|
|
|
|
public boolean checkPlayerBlockEvent(PlotPlayer pp, PlayerBlockEventType type, Location loc, LazyBlock block, boolean notifyPerms) {
|
|
|
|
Plot plot = MainUtil.getPlot(loc);
|
|
|
|
UUID uuid = pp.getUUID();
|
|
|
|
if (plot == null) {
|
|
|
|
if (!MainUtil.isPlotAreaAbs(loc)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (plot.isAdded(uuid)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
switch (type) {
|
|
|
|
case TELEPORT_OBJECT: {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
case EAT:
|
|
|
|
case READ: {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case BREAK_BLOCK: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "break");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case BREAK_HANGING:
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "hanging-break")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
case BREAK_MISC:
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "misc-break")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
case BREAK_VEHICLE:
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
case INTERACT_BLOCK: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "use");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case PLACE_BLOCK: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BUILD_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BUILD_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "place");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.BUILD_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case TRIGGER_PHYSICAL: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, false);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, false);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "device-interact")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "use");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case INTERACT_HANGING: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "hanging-interact")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "use");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case INTERACT_MISC: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "misc-interact")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "use");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case INTERACT_VEHICLE: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "vehicle-use")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "use");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
case SPAWN_MOB: {
|
|
|
|
if (plot == null) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "mob-place")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "place");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
2015-07-10 16:08:07 +02:00
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
2015-07-12 21:08:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case PLACE_HANGING: {
|
|
|
|
// if (plot == null) {
|
|
|
|
// return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
|
|
|
// }
|
|
|
|
// if (!plot.hasOwner()) {
|
|
|
|
// return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// if (FlagManager.isPlotFlagTrue(plot, "hanging-place")) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// Flag flag = FlagManager.getPlotFlag(plot, "place");
|
|
|
|
// HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
// if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
|
|
|
// return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
|
|
|
// }
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case PLACE_MISC: {
|
|
|
|
if (plot == null) {
|
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "misc-place")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "place");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case PLACE_VEHICLE: {
|
|
|
|
if (plot == null) {
|
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
|
|
|
}
|
|
|
|
if (!plot.hasOwner()) {
|
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FlagManager.isPlotFlagTrue(plot, "vehicle-place")) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Flag flag = FlagManager.getPlotFlag(plot, "place");
|
|
|
|
HashSet<PlotBlock> value = flag == null ? null : (HashSet<PlotBlock>) flag.getValue();
|
|
|
|
if (value == null || (!value.contains(PlotBlock.EVERYTHING) && !value.contains(block.getPlotBlock()))) {
|
|
|
|
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
|
|
|
|
}
|
|
|
|
return true;
|
2015-07-09 16:20:19 +02:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 06:29:45 +01:00
|
|
|
}
|