PlotSquared/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java

300 lines
14 KiB
Java
Raw Normal View History

2015-02-23 06:29:45 +01:00
package com.intellectualcrafters.plot.util;
2015-07-27 20:12:51 +02:00
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
2015-07-05 17:44:10 +02:00
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
2015-07-26 16:51:12 +02:00
import com.plotsquared.bukkit.listeners.PlayerBlockEventType;
2015-07-27 20:12:51 +02:00
import com.intellectualcrafters.plot.object.LazyBlock;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
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);
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);
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);
public abstract void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
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) {
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
}
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()))) {
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
}
return true;
}
case BREAK_HANGING:
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
}
if (FlagManager.isPlotFlagTrue(plot, "hanging-break")) {
return true;
}
if (plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
}
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
case BREAK_MISC:
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
}
if (FlagManager.isPlotFlagTrue(plot, "misc-break")) {
return true;
}
if (plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
}
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
case BREAK_VEHICLE:
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.BREAK_ROAD.s, notifyPerms);
}
if (FlagManager.isPlotFlagTrue(plot, "vehicle-break")) {
return true;
}
if (plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.BREAK_OTHER.s, notifyPerms);
}
return Permissions.hasPermission(pp, Permissions.BREAK_UNOWNED.s, notifyPerms);
case INTERACT_BLOCK: {
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
}
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()))) {
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
}
return true;
}
case PLACE_BLOCK: {
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.BUILD_ROAD.s, notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.BUILD_UNOWNED.s, notifyPerms);
}
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.BUILD_OTHER.s, notifyPerms);
}
return true;
}
case TRIGGER_PHYSICAL: {
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, false);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, false);
}
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()))) {
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
}
return true;
}
case INTERACT_HANGING: {
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
}
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()))) {
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
}
return true;
}
case INTERACT_MISC: {
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
}
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()))) {
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
}
return true;
}
case INTERACT_VEHICLE: {
if (plot == null) {
return Permissions.hasPermission(pp, Permissions.INTERACT_ROAD.s, notifyPerms);
}
if (!plot.hasOwner()) {
return Permissions.hasPermission(pp, Permissions.INTERACT_UNOWNED.s, notifyPerms);
}
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()))) {
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
}
return true;
}
case SPAWN_MOB: {
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, "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()))) {
return Permissions.hasPermission(pp, Permissions.INTERACT_OTHER.s, notifyPerms);
}
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;
}
default:
break;
}
return true;
}
2015-02-23 06:29:45 +01:00
}