mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-23 16:48:16 +01:00
Add teleport flag
This commit is contained in:
parent
185352d3cf
commit
b9ad75ad84
@ -1668,6 +1668,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
} else if (lastPlot != null && now.equals(lastPlot)) {
|
||||
if (!Flags.DENY_TELEPORT.allowsTeleport(pp, lastPlot)) {
|
||||
event.setTo(BukkitUtil.getLocation(lastPlot.getSide()));
|
||||
}
|
||||
return;
|
||||
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
|
||||
@ -1738,6 +1741,9 @@ public class PlayerEvents extends PlotListener implements Listener {
|
||||
return;
|
||||
}
|
||||
} else if (lastPlot != null && now.equals(lastPlot)) {
|
||||
if (!Flags.DENY_TELEPORT.allowsTeleport(pp, lastPlot)) {
|
||||
event.setTo(BukkitUtil.getLocation(lastPlot.getSide()));
|
||||
}
|
||||
return;
|
||||
} else if (!plotEntry(pp, now) && this.tmpTeleport) {
|
||||
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
|
||||
|
@ -225,9 +225,16 @@ public class MainCommand extends Command {
|
||||
}
|
||||
try {
|
||||
super.execute(player, args, confirm, whenDone);
|
||||
} catch (CommandException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
C.ERROR.send(player, e.getLocalizedMessage());
|
||||
String message = e.getLocalizedMessage();
|
||||
if (message != null) {
|
||||
C.ERROR.send(player, message);
|
||||
} else {
|
||||
C.ERROR.send(player);
|
||||
}
|
||||
}
|
||||
// Reset command scope //
|
||||
if (tp && !(player instanceof ConsolePlayer)) {
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class EnumFlag extends Flag<String> {
|
||||
private final HashSet<String> values;
|
||||
|
||||
public EnumFlag(String name, String... values) {
|
||||
super(name);
|
||||
this.values = new HashSet<>(Arrays.asList(values));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(Object value) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
@Override public String parseValue(String value) {
|
||||
value = value.toLowerCase();
|
||||
if (values.contains(value)) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public String getValueDescription() {
|
||||
return "Must be one of: " + StringMan.getString(values);
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.MathMan;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -114,6 +113,8 @@ public final class Flags {
|
||||
}
|
||||
};
|
||||
public static final BooleanFlag SLEEP = new BooleanFlag("sleep");
|
||||
public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("teleport-deny");
|
||||
|
||||
|
||||
private static final HashMap<String, Flag<?>> flags;
|
||||
static {
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class TeleportDenyFlag extends EnumFlag {
|
||||
public TeleportDenyFlag(String name) {
|
||||
super(name, "trusted", "members", "nonmembers", "nontrusted", "nonowners");
|
||||
}
|
||||
|
||||
public boolean allowsTeleport(PlotPlayer player, Plot plot) {
|
||||
String value = plot.getFlag(this, null);
|
||||
if (value == null || !plot.hasOwner()) {
|
||||
return true;
|
||||
}
|
||||
boolean result;
|
||||
switch (plot.getFlag(this, null)) {
|
||||
case "trusted":
|
||||
result = !plot.getTrusted().contains(player.getUUID());
|
||||
break;
|
||||
case "members":
|
||||
result =!plot.getMembers().contains(player.getUUID());
|
||||
break;
|
||||
case "nonmembers":
|
||||
result =!plot.isAdded(player.getUUID());
|
||||
break;
|
||||
case "nontrusted":
|
||||
result =!plot.getTrusted().contains(player.getUUID()) && !plot.isOwner(player.getUUID());
|
||||
break;
|
||||
case "nonowners":
|
||||
result =!plot.isOwner(player.getUUID());
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
return result || player.hasPermission("plots.admin.entry.denied");
|
||||
}
|
||||
}
|
@ -1109,6 +1109,15 @@ public class Plot {
|
||||
return loc;
|
||||
}
|
||||
|
||||
public Location getSide() {
|
||||
RegionWrapper largest = getLargestRegion();
|
||||
int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX;
|
||||
int z = largest.minZ - 1;
|
||||
PlotManager manager = getManager();
|
||||
int y = Math.max(WorldUtil.IMP.getHighestBlock(area.worldname, x, z), manager.getSignLoc(area, this).getY());
|
||||
return new Location(area.worldname, x, y + 1, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the home location for the plot
|
||||
* @return Home location
|
||||
@ -1169,12 +1178,7 @@ public class Plot {
|
||||
return new Location(plot.area.worldname, x, y + 1, z);
|
||||
}
|
||||
// Side
|
||||
RegionWrapper largest = plot.getLargestRegion();
|
||||
int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX;
|
||||
int z = largest.minZ - 1;
|
||||
PlotManager manager = plot.getManager();
|
||||
int y = Math.max(WorldUtil.IMP.getHighestBlock(plot.area.worldname, x, z), manager.getSignLoc(plot.area, plot).getY());
|
||||
return new Location(plot.area.worldname, x, y + 1, z);
|
||||
return plot.getSide();
|
||||
}
|
||||
|
||||
public double getVolume() {
|
||||
|
@ -19,7 +19,7 @@ ext {
|
||||
git = Grgit.open()
|
||||
revision = "-${git.head().abbreviatedId}"
|
||||
}
|
||||
version = "3.4.4-SNAPSHOT-${revision}"
|
||||
version = "3.4.4-SNAPSHOT${revision}"
|
||||
description = """PlotSquared"""
|
||||
|
||||
subprojects {
|
||||
|
Loading…
Reference in New Issue
Block a user