Updated Gradle

This commit is contained in:
Matt
2016-02-22 23:11:28 -05:00
parent 7b15d50674
commit b69e31129d
407 changed files with 15242 additions and 15248 deletions

View File

@@ -0,0 +1,85 @@
package com.plotsquared.general.commands;
import com.intellectualcrafters.plot.object.ConsolePlayer;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil;
public abstract class Argument<T> {
private final String name;
private final T example;
public Argument(final String name, final T example) {
this.name = name;
this.example = example;
}
public abstract T parse(final String in);
@Override
public final String toString() {
return this.getName();
}
public final String getName() {
return this.name;
}
public final T getExample() {
return this.example;
}
public static final Argument<Integer> Integer = new Argument<Integer>("int", 16) {
@Override
public Integer parse(final String in) {
Integer value = null;
try {
value = java.lang.Integer.parseInt(in);
} catch (final Exception ignored) {}
return value;
}
};
public static final Argument<Boolean> Boolean = new Argument<Boolean>("boolean", true) {
@Override
public Boolean parse(final String in) {
Boolean value = null;
if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in.equalsIgnoreCase("1")) {
value = true;
} else if (in.equalsIgnoreCase("false") || in.equalsIgnoreCase("No") || in.equalsIgnoreCase("0")) {
value = false;
}
return value;
}
};
public static final Argument<String> String = new Argument<String>("String", "Example") {
@Override
public String parse(final String in) {
return in;
}
};
public static Argument<String> PlayerName = new Argument<String>("PlayerName", "Dinnerbone") {
@Override
public String parse(final String in) {
return in.length() <= 16 ? in : null;
}
};
public static Argument<PlotId> PlotID = new Argument<PlotId>("PlotID", new PlotId(-6, 3)) {
@Override
public PlotId parse(final String in) {
return PlotId.fromString(in);
}
};
public static Argument<Plot> Plot = new Argument<Plot>("Plot", new Plot(PlotArea.createGeneric("world"), new PlotId(3, -6), null)) {
@Override
public Plot parse(final String in) {
return MainUtil.getPlotFromString(ConsolePlayer.getConsole(), in, false);
}
};
}

View File

@@ -0,0 +1,178 @@
package com.plotsquared.general.commands;
import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.commands.RequiredType;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public abstract class Command<E extends CommandCaller> extends CommandManager {
protected Argument<?>[] requiredArguments;
private RequiredType requiredType = RequiredType.NONE;
private String command, usage = "", description = "", permission = "";
private Set<String> aliases = new HashSet<>();
private CommandCategory category;
private int hash;
public Command() {
super(null, new ArrayList<Command>());
}
public Command(final String command) {
super(null, new ArrayList<Command>());
this.command = command;
}
public Command(final String command, final String usage) {
super(null, new ArrayList<Command>());
this.command = command;
this.usage = usage;
}
public Command(final String command, final String usage, final String description) {
super(null, new ArrayList<Command>());
this.command = command;
this.usage = usage;
this.description = description;
}
public Command(final String command, final String usage, final String description, final String permission) {
super(null, new ArrayList<Command>());
this.command = command;
this.usage = usage;
this.description = description;
this.permission = permission;
}
public Command(final String command, final String[] aliases, final String usage) {
super(null, new ArrayList<Command>());
this.command = command;
this.aliases = new HashSet<>(Arrays.asList(aliases));
this.usage = usage;
}
public Command(final String command, final String[] aliases) {
super(null, new ArrayList<Command>());
this.command = command;
this.aliases = new HashSet<>(Arrays.asList(aliases));
}
public Command(final String command, final String usage, final String description, final String permission, final String[] aliases, final RequiredType requiredType) {
super(null, new ArrayList<Command>());
this.command = command;
this.usage = usage;
this.description = description;
this.permission = permission;
this.aliases = new HashSet<>(Arrays.asList(aliases));
this.requiredType = requiredType;
}
public RequiredType getRequiredType() {
return this.requiredType;
}
public void create() {
final Annotation annotation = getClass().getAnnotation(CommandDeclaration.class);
if (annotation == null) {
throw new RuntimeException("Command does not have a CommandDeclaration");
}
final CommandDeclaration declaration = (CommandDeclaration) annotation;
this.command = declaration.command();
this.usage = declaration.usage();
this.description = declaration.description();
this.usage = declaration.usage();
this.permission = declaration.permission();
this.aliases = new HashSet<>(Arrays.asList(declaration.aliases()));
this.requiredType = declaration.requiredType();
this.category = declaration.category();
}
@Override
public String toString() {
return this.command;
}
public abstract boolean onCommand(final E plr, final String[] arguments);
public int handle(final E plr, final String[] args) {
if (args.length == 0) {
return super.handle(plr, "");
}
final StringBuilder builder = new StringBuilder();
for (final String s : args) {
builder.append(s).append(" ");
}
final String s = builder.substring(0, builder.length() - 1);
return super.handle(plr, s);
}
public String getCommand() {
return this.command;
}
public String getUsage() {
if (this.usage.isEmpty()) {
return "/{label} " + command;
}
return this.usage;
}
public String getPermission() {
if ((this.permission == null) || (this.permission.isEmpty())) {
this.permission = "plots." + command.toLowerCase();
}
return this.permission;
}
public String getDescription() {
return this.description;
}
public Set<String> getAliases() {
return this.aliases;
}
public Argument<?>[] getRequiredArguments() {
if (this.requiredArguments == null) {
return new Argument<?>[0];
}
return this.requiredArguments;
}
public CommandCategory getCategory() {
if (category == null) {
return CommandCategory.DEBUG;
}
return this.category;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Command<?> other = (Command<?>) obj;
if (this.hashCode() != other.hashCode()) {
return false;
}
return this.command.equals(other.command);
}
@Override
public int hashCode() {
if (hash == 0) {
hash = getCommand().hashCode();
}
return hash;
}
}

View File

@@ -0,0 +1,11 @@
package com.plotsquared.general.commands;
import com.intellectualcrafters.plot.commands.RequiredType;
public interface CommandCaller {
void sendMessage(final String message);
boolean hasPermission(final String perm);
RequiredType getSuperCaller();
}

View File

@@ -0,0 +1,28 @@
package com.plotsquared.general.commands;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import com.intellectualcrafters.plot.commands.CommandCategory;
import com.intellectualcrafters.plot.commands.RequiredType;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface CommandDeclaration {
String command();
String[] aliases() default {};
String permission() default "";
String usage() default "";
String description() default "";
RequiredType requiredType() default RequiredType.NONE;
CommandCategory category();
}

View File

@@ -0,0 +1,31 @@
package com.plotsquared.general.commands;
import java.lang.reflect.Field;
public class CommandHandlingOutput {
public static int CALLER_OF_WRONG_TYPE = -6;
public static int NOT_COMMAND = -5;
public static int NOT_FOUND = -4;
public static int NOT_PERMITTED = -3;
public static int ERROR = -2;
public static int WRONG_USAGE = -1;
public static int SUCCESS = 1;
public static String nameField(final int code) {
final Field[] fields = CommandHandlingOutput.class.getDeclaredFields();
for (final Field field : fields) {
if (field.getGenericType() == Integer.TYPE) {
try {
if ((Integer) field.get(CommandHandlingOutput.class) == code) {
return field.getName();
}
} catch (final IllegalAccessException e) {
e.printStackTrace();
}
}
}
return "null??";
}
}

View File

@@ -0,0 +1,149 @@
package com.plotsquared.general.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.util.Permissions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
public class CommandManager<T extends CommandCaller> {
final public ConcurrentHashMap<String, Command<T>> commands;
final private Character initialCharacter;
public CommandManager() {
this('/', new ArrayList<Command<T>>());
}
public CommandManager(final Character initialCharacter, final List<Command<T>> commands) {
this.commands = new ConcurrentHashMap<>();
for (final Command<T> command : commands) {
addCommand(command);
}
this.initialCharacter = initialCharacter;
}
final public void addCommand(final Command<T> command) {
if (command.getCommand() == null) {
command.create();
}
this.commands.put(command.getCommand().toLowerCase(), command);
for (final String alias : command.getAliases()) {
this.commands.put(alias.toLowerCase(), command);
}
}
final public Command<T> getCommand(final String command) {
return commands.get(command.toLowerCase());
}
final public boolean createCommand(final Command<T> command) {
try {
command.create();
} catch (final Exception e) {
e.printStackTrace();
return false;
}
if (command.getCommand() != null) {
addCommand(command);
return true;
}
return false;
}
final public ArrayList<Command<T>> getCommands() {
final HashSet<Command<T>> set = new HashSet<>(this.commands.values());
final ArrayList<Command<T>> result = new ArrayList<>(set);
Collections.sort(result, new Comparator<Command<T>>() {
@Override
public int compare(final Command<T> a, final Command<T> b) {
if (a == b) {
return 0;
}
if (a == null) {
return -1;
}
if (b == null) {
return 1;
}
return a.getCommand().compareTo(b.getCommand());
}
});
return result;
}
final public ArrayList<String> getCommandLabels(final ArrayList<Command<T>> cmds) {
final ArrayList<String> labels = new ArrayList<>(cmds.size());
for (final Command<T> cmd : cmds) {
labels.add(cmd.getCommand());
}
return labels;
}
public int handle(final T plr, String input) {
if ((initialCharacter != null) && !input.startsWith(initialCharacter + "")) {
return CommandHandlingOutput.NOT_COMMAND;
}
input = initialCharacter == null ? input : input.substring(1);
final String[] parts = input.split(" ");
String[] args;
final String command = parts[0].toLowerCase();
if (parts.length == 1) {
args = new String[0];
} else {
args = new String[parts.length - 1];
System.arraycopy(parts, 1, args, 0, args.length);
}
Command<T> cmd = commands.get(command);
if (cmd == null) {
return CommandHandlingOutput.NOT_FOUND;
}
if (!cmd.getRequiredType().allows(plr)) {
return CommandHandlingOutput.CALLER_OF_WRONG_TYPE;
}
if (!Permissions.hasPermission(plr, cmd.getPermission())) {
return CommandHandlingOutput.NOT_PERMITTED;
}
final Argument<?>[] requiredArguments = cmd.getRequiredArguments();
if ((requiredArguments != null) && (requiredArguments.length > 0)) {
boolean success = true;
if (args.length < requiredArguments.length) {
success = false;
} else {
for (int i = 0; i < requiredArguments.length; i++) {
if (requiredArguments[i].parse(args[i]) == null) {
success = false;
break;
}
}
}
if (!success) {
cmd.getUsage().replaceAll("\\{label\\}", parts[0]);
C.COMMAND_SYNTAX.send(plr, cmd.getUsage());
return CommandHandlingOutput.WRONG_USAGE;
}
}
try {
final boolean a = cmd.onCommand(plr, args);
if (!a) {
final String usage = cmd.getUsage();
if ((usage != null) && !usage.isEmpty()) {
plr.sendMessage(usage);
}
return CommandHandlingOutput.WRONG_USAGE;
}
} catch (final Throwable t) {
t.printStackTrace();
return CommandHandlingOutput.ERROR;
}
return CommandHandlingOutput.SUCCESS;
}
final public char getInitialCharacter() {
return this.initialCharacter;
}
}

View File

@@ -0,0 +1,12 @@
package com.plotsquared.listener;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
public class ExtentWrapper extends AbstractDelegateExtent {
protected ExtentWrapper(final Extent extent) {
super(extent);
}
}

View File

@@ -0,0 +1,29 @@
package com.plotsquared.listener;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
public class HeightLimitExtent extends AbstractDelegateExtent {
private final int max;
private final int min;
public HeightLimitExtent(final int min, final int max, final Extent child) {
super(child);
this.min = min;
this.max = max;
}
@Override
public boolean setBlock(final Vector location, final BaseBlock block) throws WorldEditException {
final int y = location.getBlockY();
if ((y < min) || (y > max)) {
return false;
}
return super.setBlock(location, block);
}
}

View File

@@ -0,0 +1,42 @@
package com.plotsquared.listener;
public enum PlayerBlockEventType {
// Non interactive
EAT,
READ,
// Right click with monster egg
SPAWN_MOB,
// Dragon egg
TELEPORT_OBJECT,
// armor stands
PLACE_MISC,
// blocks
PLACE_BLOCK,
// paintings / item frames
PLACE_HANGING,
// vehicles
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,
// Pressure plate, tripwire etc
TRIGGER_PHYSICAL,
}

View File

@@ -0,0 +1,241 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.listener;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.AbstractTitle;
import com.intellectualcrafters.plot.util.CommentManager;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.PlotGamemode;
import com.intellectualcrafters.plot.util.PlotWeather;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*/
public class PlotListener {
public static boolean plotEntry(final PlotPlayer pp, final Plot plot) {
if (plot.isDenied(pp.getUUID()) && !Permissions.hasPermission(pp, "plots.admin.entry.denied")) {
return false;
}
final Plot last = pp.getMeta("lastplot");
if ((last != null) && !last.getId().equals(plot.getId())) {
plotExit(pp, last);
}
pp.setMeta("lastplot", plot.getBasePlot(false));
EventUtil.manager.callEntry(pp, plot);
if (plot.hasOwner()) {
final HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);
final int size = flags.size();
boolean titles = Settings.TITLES;
final String greeting;
if (size != 0) {
final Flag titleFlag = flags.get("titles");
if (titleFlag != null) {
titles = (Boolean) titleFlag.getValue();
}
final Flag greetingFlag = flags.get("greeting");
if (greetingFlag != null) {
greeting = (String) greetingFlag.getValue();
MainUtil.format(C.PREFIX_GREETING.s() + greeting, plot, pp, false, new RunnableVal<String>() {
@Override
public void run(String value) {
MainUtil.sendMessage(pp, value);
}
});
} else {
greeting = "";
}
final Flag enter = flags.get("notify-enter");
if (enter != null && (Boolean) enter.getValue()) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (final UUID uuid : plot.getOwners()) {
final PlotPlayer owner = UUIDHandler.getPlayer(uuid);
if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) {
MainUtil.sendMessage(owner, C.NOTIFY_ENTER.s().replace("%player", pp.getName()).replace("%plot", plot.getId().toString()));
}
}
}
}
final Flag gamemodeFlag = flags.get("gamemode");
if (gamemodeFlag != null) {
if (pp.getGamemode() != gamemodeFlag.getValue()) {
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
pp.setGamemode((PlotGamemode) gamemodeFlag.getValue());
} else {
MainUtil.sendMessage(pp, StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.getValue()));
}
}
}
final Flag flyFlag = flags.get("fly");
if (flyFlag != null) {
pp.setFlight((boolean) flyFlag.getValue());
}
final Flag timeFlag = flags.get("time");
if (timeFlag != null) {
try {
final long time = (long) timeFlag.getValue();
pp.setTime(time);
} catch (final Exception e) {
FlagManager.removePlotFlag(plot, "time");
}
}
final Flag weatherFlag = flags.get("weather");
if (weatherFlag != null) {
pp.setWeather((PlotWeather) weatherFlag.getValue());
}
final Flag musicFlag = flags.get("music");
if (musicFlag != null) {
final Integer id = (Integer) musicFlag.getValue();
if ((id >= 2256 && id <= 2267) || (id == 0)) {
final Location loc = pp.getLocation();
final Location lastLoc = pp.getMeta("music");
if (lastLoc != null) {
pp.playMusic(lastLoc, 0);
if (id == 0) {
pp.deleteMeta("music");
}
}
if (id != 0) {
try {
pp.setMeta("music", loc);
pp.playMusic(loc, id);
} catch (final Exception e) {}
}
}
} else {
final Location lastLoc = pp.getMeta("music");
if (lastLoc != null) {
pp.deleteMeta("music");
pp.playMusic(lastLoc, 0);
}
}
CommentManager.sendTitle(pp, plot);
} else if (titles) {
greeting = "";
} else {
return true;
}
if (titles) {
if ((!C.TITLE_ENTERED_PLOT.s().isEmpty()) || (!C.TITLE_ENTERED_PLOT_SUB.s().isEmpty())) {
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
final Plot lastPlot = pp.getMeta("lastplot");
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
final Map<String, String> replacements = new HashMap<>();
replacements.put("%x%", lastPlot.getId().x + "");
replacements.put("%z%", lastPlot.getId().y + "");
replacements.put("%world%", plot.getArea().toString());
replacements.put("%greeting%", greeting);
replacements.put("%alias", plot.toString());
replacements.put("%s", MainUtil.getName(plot.owner));
final String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements);
final String sub = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements);
AbstractTitle.sendTitle(pp, main, sub);
}
}
}, 20);
}
}
return true;
}
return true;
}
public static boolean plotExit(final PlotPlayer pp, final Plot plot) {
pp.deleteMeta("lastplot");
EventUtil.manager.callLeave(pp, plot);
if (plot.hasOwner()) {
final PlotArea pw = plot.getArea();
if (pw == null) {
return true;
}
if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) {
if (pp.getGamemode() != pw.GAMEMODE) {
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
pp.setGamemode(pw.GAMEMODE);
} else {
MainUtil.sendMessage(pp, StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.toString(), "{gamemode}", pw.GAMEMODE.name().toLowerCase()));
}
}
}
final Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell");
if (farewell != null) {
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.getValueString(), plot, pp, false, new RunnableVal<String>() {
@Override
public void run(String value) {
MainUtil.sendMessage(pp, value);
}
});
}
final Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave");
if ((leave != null) && ((Boolean) leave.getValue())) {
if (!Permissions.hasPermission(pp, "plots.flag.notify-enter.bypass")) {
for (final UUID uuid : plot.getOwners()) {
final PlotPlayer owner = UUIDHandler.getPlayer(uuid);
if ((owner != null) && !owner.getUUID().equals(pp.getUUID())) {
MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", pp.getName()).replace("%plot", plot.getId().toString()));
}
}
}
}
if (FlagManager.getPlotFlagRaw(plot, "fly") != null) {
final PlotGamemode gamemode = pp.getGamemode();
if (gamemode == PlotGamemode.SURVIVAL || (gamemode == PlotGamemode.ADVENTURE)) {
pp.setFlight(false);
}
}
if (FlagManager.getPlotFlagRaw(plot, "time") != null) {
pp.setTime(Long.MAX_VALUE);
}
if (FlagManager.getPlotFlagRaw(plot, "weather") != null) {
pp.setWeather(PlotWeather.RESET);
}
final Location lastLoc = pp.getMeta("music");
if (lastLoc != null) {
pp.deleteMeta("music");
pp.playMusic(lastLoc, 0);
}
}
return true;
}
}

View File

@@ -0,0 +1,257 @@
package com.plotsquared.listener;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.SetQueue;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.*;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
import java.lang.reflect.Field;
import java.util.HashSet;
public class ProcessedWEExtent extends AbstractDelegateExtent {
private final HashSet<RegionWrapper> mask;
private final String world;
private final int max;
int BScount = 0;
int Ecount = 0;
boolean BSblocked = false;
boolean Eblocked = false;
private int count;
private Extent parent;
public ProcessedWEExtent(final String world, final HashSet<RegionWrapper> mask, int max, final Extent child, final Extent parent) {
super(child);
this.mask = mask;
this.world = world;
if (max == -1) {
max = Integer.MAX_VALUE;
}
this.max = max;
count = 0;
this.parent = parent;
}
@Override
public boolean setBlock(final Vector location, final BaseBlock block) throws WorldEditException {
final int id = block.getType();
switch (id) {
case 54:
case 130:
case 142:
case 27:
case 137:
case 52:
case 154:
case 84:
case 25:
case 144:
case 138:
case 176:
case 177:
case 63:
case 68:
case 323:
case 117:
case 116:
case 28:
case 66:
case 157:
case 61:
case 62:
case 140:
case 146:
case 149:
case 150:
case 158:
case 23:
case 123:
case 124:
case 29:
case 33:
case 151:
case 178: {
if (BSblocked) {
return false;
}
BScount++;
if (BScount > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) {
BSblocked = true;
PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ()));
}
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
if (count++ > max) {
if (parent != null) {
try {
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true);
field.set(parent, new com.sk89q.worldedit.extent.NullExtent());
} catch (final Exception e) {
e.printStackTrace();
}
parent = null;
}
return false;
}
return super.setBlock(location, block);
}
break;
}
default: {
final int x = location.getBlockX();
final int y = location.getBlockY();
final int z = location.getBlockZ();
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
if (count++ > max) {
if (parent != null) {
try {
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true);
field.set(parent, new com.sk89q.worldedit.extent.NullExtent());
} catch (final Exception e) {
e.printStackTrace();
}
parent = null;
}
return false;
}
switch (id) {
case 0:
case 2:
case 4:
case 13:
case 14:
case 15:
case 20:
case 21:
case 22:
case 24:
case 25:
case 30:
case 32:
case 37:
case 39:
case 40:
case 41:
case 42:
case 45:
case 46:
case 47:
case 48:
case 49:
case 51:
case 52:
case 54:
case 55:
case 56:
case 57:
case 58:
case 60:
case 61:
case 62:
case 7:
case 8:
case 9:
case 10:
case 11:
case 73:
case 74:
case 78:
case 79:
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 87:
case 88:
case 101:
case 102:
case 103:
case 110:
case 112:
case 113:
case 117:
case 121:
case 122:
case 123:
case 124:
case 129:
case 133:
case 138:
case 137:
case 140:
case 165:
case 166:
case 169:
case 170:
case 172:
case 173:
case 174:
case 176:
case 177:
case 181:
case 182:
case 188:
case 189:
case 190:
case 191:
case 192: {
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
SetQueue.IMP.setBlock(world, x, y, z, id);
} else {
super.setBlock(location, block);
}
break;
}
default: {
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
SetQueue.IMP.setBlock(world, x, y, z, new PlotBlock((short) id, (byte) block.getData()));
} else {
super.setBlock(location, block);
}
break;
}
}
return true;
}
}
}
return false;
}
@Override
public Entity createEntity(final Location location, final BaseEntity entity) {
if (Eblocked) {
return null;
}
Ecount++;
if (Ecount > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
Eblocked = true;
PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ()));
}
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
return super.createEntity(location, entity);
}
return null;
}
@Override
public boolean setBiome(final Vector2D position, final BaseBiome biome) {
if (WEManager.maskContains(mask, position.getBlockX(), position.getBlockZ())) {
return super.setBiome(position, biome);
}
return false;
}
}

View File

@@ -0,0 +1,48 @@
package com.plotsquared.listener;
import java.util.HashSet;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.Vector2D;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.biome.BaseBiome;
public class WEExtent extends AbstractDelegateExtent {
private final HashSet<RegionWrapper> mask;
public WEExtent(final HashSet<RegionWrapper> mask, final Extent extent) {
super(extent);
this.mask = mask;
}
@Override
public boolean setBlock(final Vector location, final BaseBlock block) throws WorldEditException {
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
return super.setBlock(location, block);
}
return false;
}
@Override
public Entity createEntity(final Location location, final BaseEntity entity) {
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
return super.createEntity(location, entity);
}
return null;
}
@Override
public boolean setBiome(final Vector2D position, final BaseBiome biome) {
if (WEManager.maskContains(mask, position.getBlockX(), position.getBlockZ())) {
return super.setBiome(position, biome);
}
return false;
}
}

View File

@@ -0,0 +1,70 @@
package com.plotsquared.listener;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
public class WEManager {
public static boolean maskContains(final HashSet<RegionWrapper> mask, final int x, final int y, final int z) {
for (final RegionWrapper region : mask) {
if (region.isIn(x, y, z)) {
return true;
}
}
return false;
}
public static boolean maskContains(final HashSet<RegionWrapper> mask, final int x, final int z) {
for (final RegionWrapper region : mask) {
if (region.isIn(x, z)) {
return true;
}
}
return false;
}
public static HashSet<RegionWrapper> getMask(final PlotPlayer player) {
final HashSet<RegionWrapper> regions = new HashSet<>();
final UUID uuid = player.getUUID();
final Location location = player.getLocation();
final String world = location.getWorld();
if (!PS.get().hasPlotArea(world)) {
regions.add(new RegionWrapper(Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE));
return regions;
}
PlotArea area = player.getApplicablePlotArea();
if (area == null) {
return regions;
}
for (final Plot plot : area.getPlots()) {
if (!plot.isBasePlot() || (Settings.DONE_RESTRICTS_BUILDING && (FlagManager.getPlotFlagRaw(plot, "done") != null))) {
continue;
}
if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (plot.isOwner(uuid) || plot.getTrusted().contains(uuid))) {
regions.addAll(plot.getRegions());
}
}
return regions;
}
public static boolean intersects(final RegionWrapper region1, final RegionWrapper region2) {
return (region1.minX <= region2.maxX) && (region1.maxX >= region2.minX) && (region1.minZ <= region2.maxZ) && (region1.maxZ >= region2.minZ);
}
public static boolean regionContains(final RegionWrapper selection, final HashSet<RegionWrapper> mask) {
for (final RegionWrapper region : mask) {
if (intersects(region, selection)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,128 @@
package com.plotsquared.listener;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.tool.BrushTool;
import com.sk89q.worldedit.command.tool.Tool;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.*;
import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
import com.sk89q.worldedit.extent.world.FastModeExtent;
import com.sk89q.worldedit.util.eventbus.EventHandler.Priority;
import com.sk89q.worldedit.util.eventbus.Subscribe;
import com.sk89q.worldedit.world.World;
import java.lang.reflect.Field;
import java.util.HashSet;
public class WESubscriber {
@Subscribe(priority = Priority.VERY_EARLY)
public void onEditSession(final EditSessionEvent event) {
final WorldEdit worldedit = PS.get().worldedit;
if (worldedit == null) {
WorldEdit.getInstance().getEventBus().unregister(this);
return;
}
final World worldObj = event.getWorld();
final String world = worldObj.getName();
final Actor actor = event.getActor();
if (actor != null && actor.isPlayer()) {
final String name = actor.getName();
final PlotPlayer pp = PlotPlayer.wrap(name);
if (pp != null && pp.getAttribute("worldedit")) {
return;
}
final HashSet<RegionWrapper> mask = WEManager.getMask(pp);
if (mask.isEmpty()) {
if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) {
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
}
if (PS.get().hasPlotArea(world)) {
event.setExtent(new com.sk89q.worldedit.extent.NullExtent());
}
return;
}
if (Settings.CHUNK_PROCESSOR) {
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
try {
final LocalSession session = worldedit.getSessionManager().findByName(name);
boolean hasMask = session.getMask() != null;
final Player objPlayer = (Player) actor;
final int item = objPlayer.getItemInHand();
if (!hasMask) {
try {
final Tool tool = session.getTool(item);
if (tool instanceof BrushTool) {
hasMask = ((BrushTool) tool).getMask() != null;
}
} catch (final Exception e) {
}
}
AbstractDelegateExtent extent = (AbstractDelegateExtent) event.getExtent();
ChangeSetExtent history = null;
MultiStageReorder reorder = null;
MaskingExtent maskextent = null;
final boolean fast = session.hasFastMode();
while (extent.getExtent() != null && extent.getExtent() instanceof AbstractDelegateExtent) {
final AbstractDelegateExtent tmp = (AbstractDelegateExtent) extent.getExtent();
if (tmp.getExtent() != null && tmp.getExtent() instanceof AbstractDelegateExtent) {
if (tmp instanceof ChangeSetExtent) {
history = (ChangeSetExtent) tmp;
}
if (tmp instanceof MultiStageReorder) {
reorder = (MultiStageReorder) tmp;
}
if (hasMask && tmp instanceof MaskingExtent) {
maskextent = (MaskingExtent) tmp;
}
extent = tmp;
} else {
break;
}
}
final int max = event.getMaxBlocks();
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
field.setAccessible(true);
if (history == null) {
final ExtentWrapper wrapper = new ExtentWrapper(event.getExtent());
event.setExtent(wrapper);
field.set(extent, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper));
} else if (fast) {
event.setExtent(new ExtentWrapper(extent));
} else {
ExtentWrapper wrapper;
if (maskextent != null) {
wrapper = new ExtentWrapper(maskextent);
field.set(maskextent, history);
event.setExtent(wrapper);
} else {
wrapper = new ExtentWrapper(history);
event.setExtent(wrapper);
}
field.set(history, reorder);
field.set(reorder, new ProcessedWEExtent(world, mask, max, new FastModeExtent(worldObj, true), wrapper));
}
return;
} catch (IllegalAccessException | SecurityException | NoSuchFieldException | IllegalArgumentException e) {
e.printStackTrace();
}
}
if (PS.get().hasPlotArea(world)) {
event.setExtent(new ProcessedWEExtent(world, mask, event.getMaxBlocks(), event.getExtent(), event.getExtent()));
}
} else if (PS.get().hasPlotArea(world)) {
event.setExtent(new WEExtent(mask, event.getExtent()));
}
}
}
}