mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-08-03 21:15:27 +02:00
Major code reformatting
This commit is contained in:
@@ -7,44 +7,21 @@ 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) {
|
||||
public Integer parse(String in) {
|
||||
Integer value = null;
|
||||
try {
|
||||
value = java.lang.Integer.parseInt(in);
|
||||
} catch (final Exception ignored) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Argument<Boolean> Boolean = new Argument<Boolean>("boolean", true) {
|
||||
@Override
|
||||
public Boolean parse(final String in) {
|
||||
public Boolean parse(String in) {
|
||||
Boolean value = null;
|
||||
if (in.equalsIgnoreCase("true") || in.equalsIgnoreCase("Yes") || in.equalsIgnoreCase("1")) {
|
||||
value = true;
|
||||
@@ -54,32 +31,50 @@ public abstract class Argument<T> {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
public static final Argument<String> String = new Argument<String>("String", "Example") {
|
||||
@Override
|
||||
public String parse(final String in) {
|
||||
public String parse(String in) {
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
public static Argument<String> PlayerName = new Argument<String>("PlayerName", "Dinnerbone") {
|
||||
@Override
|
||||
public String parse(final String in) {
|
||||
public String parse(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) {
|
||||
public PlotId parse(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) {
|
||||
public Plot parse(String in) {
|
||||
return MainUtil.getPlotFromString(ConsolePlayer.getConsole(), in, false);
|
||||
}
|
||||
};
|
||||
private final String name;
|
||||
private final T example;
|
||||
|
||||
public Argument(String name, T example) {
|
||||
this.name = name;
|
||||
this.example = example;
|
||||
}
|
||||
|
||||
public abstract T parse(String in);
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final T getExample() {
|
||||
return this.example;
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,10 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
|
||||
protected Argument<?>[] requiredArguments;
|
||||
private RequiredType requiredType = RequiredType.NONE;
|
||||
private String command, usage = "", description = "", permission = "";
|
||||
private String command;
|
||||
private String usage = "";
|
||||
private String description = "";
|
||||
private String permission = "";
|
||||
private Set<String> aliases = new HashSet<>();
|
||||
private CommandCategory category;
|
||||
private int hash;
|
||||
@@ -21,47 +24,47 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
public Command() {
|
||||
super(null, new ArrayList<Command>());
|
||||
}
|
||||
|
||||
public Command(final String command) {
|
||||
|
||||
public Command(String command) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public Command(final String command, final String usage) {
|
||||
|
||||
public Command(String command, String usage) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Command(final String command, final String usage, final String description) {
|
||||
|
||||
public Command(String command, String usage, 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) {
|
||||
|
||||
public Command(String command, String usage, String description, 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) {
|
||||
|
||||
public Command(String command, String[] aliases, 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) {
|
||||
|
||||
public Command(String command, 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) {
|
||||
|
||||
public Command(String command, String usage, String description, String permission, String[] aliases, RequiredType requiredType) {
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
@@ -70,17 +73,17 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
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);
|
||||
Annotation annotation = getClass().getAnnotation(CommandDeclaration.class);
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException("Command does not have a CommandDeclaration");
|
||||
}
|
||||
final CommandDeclaration declaration = (CommandDeclaration) annotation;
|
||||
CommandDeclaration declaration = (CommandDeclaration) annotation;
|
||||
this.command = declaration.command();
|
||||
this.usage = declaration.usage();
|
||||
this.description = declaration.description();
|
||||
@@ -90,86 +93,86 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
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) {
|
||||
|
||||
public abstract boolean onCommand(E plr, String[] arguments);
|
||||
|
||||
public int handle(E plr, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return super.handle(plr, "");
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final String s : args) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : args) {
|
||||
builder.append(s).append(" ");
|
||||
}
|
||||
final String s = builder.substring(0, builder.length() - 1);
|
||||
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 "/{label} " + this.command;
|
||||
}
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
|
||||
public String getPermission() {
|
||||
if ((this.permission == null) || (this.permission.isEmpty())) {
|
||||
this.permission = "plots." + command.toLowerCase();
|
||||
if (this.permission == null || this.permission.isEmpty()) {
|
||||
this.permission = "plots." + this.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) {
|
||||
if (this.category == null) {
|
||||
return CommandCategory.DEBUG;
|
||||
}
|
||||
return this.category;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Command<?> other = (Command<?>) obj;
|
||||
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();
|
||||
if (this.hash == 0) {
|
||||
this.hash = getCommand().hashCode();
|
||||
}
|
||||
return hash;
|
||||
return this.hash;
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,10 @@ package com.plotsquared.general.commands;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
|
||||
public interface CommandCaller {
|
||||
void sendMessage(final String message);
|
||||
|
||||
boolean hasPermission(final String perm);
|
||||
|
||||
void sendMessage(String message);
|
||||
|
||||
boolean hasPermission(String perm);
|
||||
|
||||
RequiredType getSuperCaller();
|
||||
}
|
||||
|
@@ -12,16 +12,16 @@ public class CommandHandlingOutput {
|
||||
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) {
|
||||
|
||||
public static String nameField(int code) {
|
||||
Field[] fields = CommandHandlingOutput.class.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (field.getGenericType() == Integer.TYPE) {
|
||||
try {
|
||||
if ((Integer) field.get(CommandHandlingOutput.class) == code) {
|
||||
return field.getName();
|
||||
}
|
||||
} catch (final IllegalAccessException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@@ -11,40 +11,36 @@ 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) {
|
||||
|
||||
public final ConcurrentHashMap<String, Command<T>> commands;
|
||||
private final Character initialCharacter;
|
||||
|
||||
public CommandManager(Character initialCharacter, List<Command<T>> commands) {
|
||||
this.commands = new ConcurrentHashMap<>();
|
||||
for (final Command<T> command : commands) {
|
||||
for (Command<T> command : commands) {
|
||||
addCommand(command);
|
||||
}
|
||||
this.initialCharacter = initialCharacter;
|
||||
}
|
||||
|
||||
final public void addCommand(final Command<T> command) {
|
||||
|
||||
public final void addCommand(Command<T> command) {
|
||||
if (command.getCommand() == null) {
|
||||
command.create();
|
||||
}
|
||||
this.commands.put(command.getCommand().toLowerCase(), command);
|
||||
for (final String alias : command.getAliases()) {
|
||||
for (String alias : command.getAliases()) {
|
||||
this.commands.put(alias.toLowerCase(), command);
|
||||
}
|
||||
}
|
||||
|
||||
final public Command<T> getCommand(final String command) {
|
||||
return commands.get(command.toLowerCase());
|
||||
|
||||
public final Command<T> getCommand(String command) {
|
||||
return this.commands.get(command.toLowerCase());
|
||||
}
|
||||
|
||||
final public boolean createCommand(final Command<T> command) {
|
||||
|
||||
public final boolean createCommand(Command<T> command) {
|
||||
try {
|
||||
command.create();
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@@ -54,13 +50,13 @@ public class CommandManager<T extends CommandCaller> {
|
||||
}
|
||||
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);
|
||||
|
||||
public final ArrayList<Command<T>> getCommands() {
|
||||
HashSet<Command<T>> set = new HashSet<>(this.commands.values());
|
||||
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) {
|
||||
public int compare(Command<T> a, Command<T> b) {
|
||||
if (a == b) {
|
||||
return 0;
|
||||
}
|
||||
@@ -75,34 +71,34 @@ public class CommandManager<T extends CommandCaller> {
|
||||
});
|
||||
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) {
|
||||
|
||||
public final ArrayList<String> getCommandLabels(ArrayList<Command<T>> cmds) {
|
||||
ArrayList<String> labels = new ArrayList<>(cmds.size());
|
||||
for (Command<T> cmd : cmds) {
|
||||
labels.add(cmd.getCommand());
|
||||
}
|
||||
return labels;
|
||||
}
|
||||
|
||||
public int handle(final T plr, String input) {
|
||||
if (initialCharacter != null && !input.startsWith(initialCharacter + "")) {
|
||||
|
||||
public int handle(T plr, String input) {
|
||||
if (this.initialCharacter != null && !input.startsWith(this.initialCharacter + "")) {
|
||||
return CommandHandlingOutput.NOT_COMMAND;
|
||||
}
|
||||
if (initialCharacter == null) {
|
||||
if (this.initialCharacter == null) {
|
||||
input = input;
|
||||
} else {
|
||||
input = input.substring(1);
|
||||
}
|
||||
final String[] parts = input.split(" ");
|
||||
String[] parts = input.split(" ");
|
||||
String[] args;
|
||||
final String command = parts[0].toLowerCase();
|
||||
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);
|
||||
Command<T> cmd = this.commands.get(command);
|
||||
if (cmd == null) {
|
||||
return CommandHandlingOutput.NOT_FOUND;
|
||||
}
|
||||
@@ -112,7 +108,7 @@ public class CommandManager<T extends CommandCaller> {
|
||||
if (!Permissions.hasPermission(plr, cmd.getPermission())) {
|
||||
return CommandHandlingOutput.NOT_PERMITTED;
|
||||
}
|
||||
final Argument<?>[] requiredArguments = cmd.getRequiredArguments();
|
||||
Argument<?>[] requiredArguments = cmd.getRequiredArguments();
|
||||
if ((requiredArguments != null) && (requiredArguments.length > 0)) {
|
||||
boolean success = true;
|
||||
if (args.length < requiredArguments.length) {
|
||||
@@ -132,22 +128,22 @@ public class CommandManager<T extends CommandCaller> {
|
||||
}
|
||||
}
|
||||
try {
|
||||
final boolean a = cmd.onCommand(plr, args);
|
||||
boolean a = cmd.onCommand(plr, args);
|
||||
if (!a) {
|
||||
final String usage = cmd.getUsage();
|
||||
String usage = cmd.getUsage();
|
||||
if ((usage != null) && !usage.isEmpty()) {
|
||||
plr.sendMessage(usage);
|
||||
}
|
||||
return CommandHandlingOutput.WRONG_USAGE;
|
||||
}
|
||||
} catch (final Throwable t) {
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return CommandHandlingOutput.ERROR;
|
||||
}
|
||||
return CommandHandlingOutput.SUCCESS;
|
||||
}
|
||||
|
||||
final public char getInitialCharacter() {
|
||||
|
||||
public final char getInitialCharacter() {
|
||||
return this.initialCharacter;
|
||||
}
|
||||
}
|
||||
|
@@ -35,26 +35,23 @@ import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.ExpireManager;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.PlotGamemode;
|
||||
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");
|
||||
Plot last = pp.getMeta("lastplot");
|
||||
if ((last != null) && !last.getId().equals(plot.getId())) {
|
||||
plotExit(pp, last);
|
||||
}
|
||||
@@ -64,17 +61,17 @@ public class PlotListener {
|
||||
pp.setMeta("lastplot", plot);
|
||||
EventUtil.manager.callEntry(pp, plot);
|
||||
if (plot.hasOwner()) {
|
||||
final HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);
|
||||
final int size = flags.size();
|
||||
HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);
|
||||
int size = flags.size();
|
||||
boolean titles = Settings.TITLES;
|
||||
final String greeting;
|
||||
|
||||
if (size != 0) {
|
||||
final Flag titleFlag = flags.get("titles");
|
||||
Flag titleFlag = flags.get("titles");
|
||||
if (titleFlag != null) {
|
||||
titles = (Boolean) titleFlag.getValue();
|
||||
}
|
||||
final Flag greetingFlag = flags.get("greeting");
|
||||
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>() {
|
||||
@@ -86,51 +83,53 @@ public class PlotListener {
|
||||
} else {
|
||||
greeting = "";
|
||||
}
|
||||
final Flag enter = flags.get("notify-enter");
|
||||
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()));
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
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");
|
||||
Flag gamemodeFlag = flags.get("gamemode");
|
||||
if (gamemodeFlag != null) {
|
||||
if (pp.getGamemode() != gamemodeFlag.getValue()) {
|
||||
if (pp.getGameMode() != gamemodeFlag.getValue()) {
|
||||
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
|
||||
pp.setGamemode((PlotGamemode) gamemodeFlag.getValue());
|
||||
pp.setGameMode((PlotGameMode) gamemodeFlag.getValue());
|
||||
} else {
|
||||
MainUtil.sendMessage(pp, StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.getValue()));
|
||||
MainUtil.sendMessage(pp,
|
||||
StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.getId(), "{gamemode}", gamemodeFlag.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
final Flag flyFlag = flags.get("fly");
|
||||
Flag flyFlag = flags.get("fly");
|
||||
if (flyFlag != null) {
|
||||
pp.setFlight((boolean) flyFlag.getValue());
|
||||
}
|
||||
final Flag timeFlag = flags.get("time");
|
||||
Flag timeFlag = flags.get("time");
|
||||
if (timeFlag != null) {
|
||||
try {
|
||||
final long time = (long) timeFlag.getValue();
|
||||
long time = (long) timeFlag.getValue();
|
||||
pp.setTime(time);
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
FlagManager.removePlotFlag(plot, "time");
|
||||
}
|
||||
}
|
||||
final Flag weatherFlag = flags.get("weather");
|
||||
Flag weatherFlag = flags.get("weather");
|
||||
if (weatherFlag != null) {
|
||||
pp.setWeather((PlotWeather) weatherFlag.getValue());
|
||||
}
|
||||
|
||||
final Flag musicFlag = flags.get("music");
|
||||
Flag musicFlag = flags.get("music");
|
||||
if (musicFlag != null) {
|
||||
final Integer id = (Integer) musicFlag.getValue();
|
||||
Integer id = (Integer) musicFlag.getValue();
|
||||
if ((id >= 2256 && id <= 2267) || (id == 0)) {
|
||||
final Location loc = pp.getLocation();
|
||||
final Location lastLoc = pp.getMeta("music");
|
||||
Location loc = pp.getLocation();
|
||||
Location lastLoc = pp.getMeta("music");
|
||||
if (lastLoc != null) {
|
||||
pp.playMusic(lastLoc, 0);
|
||||
if (id == 0) {
|
||||
@@ -141,11 +140,12 @@ public class PlotListener {
|
||||
try {
|
||||
pp.setMeta("music", loc);
|
||||
pp.playMusic(loc, id);
|
||||
} catch (final Exception e) {}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
final Location lastLoc = pp.getMeta("music");
|
||||
Location lastLoc = pp.getMeta("music");
|
||||
if (lastLoc != null) {
|
||||
pp.deleteMeta("music");
|
||||
pp.playMusic(lastLoc, 0);
|
||||
@@ -158,21 +158,21 @@ public class PlotListener {
|
||||
return true;
|
||||
}
|
||||
if (titles) {
|
||||
if ((!C.TITLE_ENTERED_PLOT.s().isEmpty()) || (!C.TITLE_ENTERED_PLOT_SUB.s().isEmpty())) {
|
||||
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");
|
||||
Plot lastPlot = pp.getMeta("lastplot");
|
||||
if ((lastPlot != null) && plot.getId().equals(lastPlot.getId())) {
|
||||
final Map<String, String> replacements = new HashMap<>();
|
||||
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);
|
||||
String main = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT.s(), replacements);
|
||||
String sub = StringMan.replaceFromMap(C.TITLE_ENTERED_PLOT_SUB.s(), replacements);
|
||||
AbstractTitle.sendTitle(pp, main, sub);
|
||||
}
|
||||
}
|
||||
@@ -184,24 +184,25 @@ public class PlotListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean plotExit(final PlotPlayer pp, final Plot plot) {
|
||||
public static boolean plotExit(final PlotPlayer pp, Plot plot) {
|
||||
pp.deleteMeta("lastplot");
|
||||
EventUtil.manager.callLeave(pp, plot);
|
||||
if (plot.hasOwner()) {
|
||||
final PlotArea pw = plot.getArea();
|
||||
PlotArea pw = plot.getArea();
|
||||
if (pw == null) {
|
||||
return true;
|
||||
}
|
||||
if (FlagManager.getPlotFlagRaw(plot, "gamemode") != null) {
|
||||
if (pp.getGamemode() != pw.GAMEMODE) {
|
||||
if (pp.getGameMode() != pw.GAMEMODE) {
|
||||
if (!Permissions.hasPermission(pp, "plots.gamemode.bypass")) {
|
||||
pp.setGamemode(pw.GAMEMODE);
|
||||
pp.setGameMode(pw.GAMEMODE);
|
||||
} else {
|
||||
MainUtil.sendMessage(pp, StringMan.replaceAll(C.GAMEMODE_WAS_BYPASSED.s(), "{plot}", plot.toString(), "{gamemode}", pw.GAMEMODE.name().toLowerCase()));
|
||||
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");
|
||||
Flag farewell = FlagManager.getPlotFlagRaw(plot, "farewell");
|
||||
if (farewell != null) {
|
||||
MainUtil.format(C.PREFIX_FAREWELL.s() + farewell.getValueString(), plot, pp, false, new RunnableVal<String>() {
|
||||
@Override
|
||||
@@ -210,11 +211,11 @@ public class PlotListener {
|
||||
}
|
||||
});
|
||||
}
|
||||
final Flag leave = FlagManager.getPlotFlagRaw(plot, "notify-leave");
|
||||
if ((leave != null) && ((Boolean) leave.getValue())) {
|
||||
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);
|
||||
for (UUID uuid : plot.getOwners()) {
|
||||
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()));
|
||||
}
|
||||
@@ -222,8 +223,8 @@ public class PlotListener {
|
||||
}
|
||||
}
|
||||
if (FlagManager.getPlotFlagRaw(plot, "fly") != null) {
|
||||
final PlotGamemode gamemode = pp.getGamemode();
|
||||
if (gamemode == PlotGamemode.SURVIVAL || (gamemode == PlotGamemode.ADVENTURE)) {
|
||||
PlotGameMode gamemode = pp.getGameMode();
|
||||
if (gamemode == PlotGameMode.SURVIVAL || (gamemode == PlotGameMode.ADVENTURE)) {
|
||||
pp.setFlight(false);
|
||||
}
|
||||
}
|
||||
@@ -233,7 +234,7 @@ public class PlotListener {
|
||||
if (FlagManager.getPlotFlagRaw(plot, "weather") != null) {
|
||||
pp.setWeather(PlotWeather.RESET);
|
||||
}
|
||||
final Location lastLoc = pp.getMeta("music");
|
||||
Location lastLoc = pp.getMeta("music");
|
||||
if (lastLoc != null) {
|
||||
pp.deleteMeta("music");
|
||||
pp.playMusic(lastLoc, 0);
|
||||
|
@@ -11,7 +11,8 @@ 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.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
|
||||
@@ -19,6 +20,7 @@ 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;
|
||||
@@ -28,8 +30,8 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
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) {
|
||||
|
||||
public ProcessedWEExtent(String world, HashSet<RegionWrapper> mask, int max, Extent child, Extent parent) {
|
||||
super(child);
|
||||
this.mask = mask;
|
||||
this.world = world;
|
||||
@@ -37,13 +39,13 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
max = Integer.MAX_VALUE;
|
||||
}
|
||||
this.max = max;
|
||||
count = 0;
|
||||
this.count = 0;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean setBlock(final Vector location, final BaseBlock block) throws WorldEditException {
|
||||
final int id = block.getType();
|
||||
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
|
||||
int id = block.getType();
|
||||
switch (id) {
|
||||
case 54:
|
||||
case 130:
|
||||
@@ -80,25 +82,25 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
case 33:
|
||||
case 151:
|
||||
case 178: {
|
||||
if (BSblocked) {
|
||||
if (this.BSblocked) {
|
||||
return false;
|
||||
}
|
||||
BScount++;
|
||||
if (BScount > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) {
|
||||
BSblocked = true;
|
||||
PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ()));
|
||||
this.BScount++;
|
||||
if (this.BScount > Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES) {
|
||||
this.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) {
|
||||
if (WEManager.maskContains(this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
|
||||
if (this.count++ > this.max) {
|
||||
if (this.parent != null) {
|
||||
try {
|
||||
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
field.set(parent, new com.sk89q.worldedit.extent.NullExtent());
|
||||
} catch (final Exception e) {
|
||||
field.set(this.parent, new com.sk89q.worldedit.extent.NullExtent());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
parent = null;
|
||||
this.parent = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -107,20 +109,20 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
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) {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
if (WEManager.maskContains(this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
|
||||
if (this.count++ > this.max) {
|
||||
if (this.parent != null) {
|
||||
try {
|
||||
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
field.set(parent, new com.sk89q.worldedit.extent.NullExtent());
|
||||
} catch (final Exception e) {
|
||||
field.set(this.parent, new com.sk89q.worldedit.extent.NullExtent());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
parent = null;
|
||||
this.parent = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -208,7 +210,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
case 191:
|
||||
case 192: {
|
||||
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
|
||||
SetQueue.IMP.setBlock(world, x, y, z, id);
|
||||
SetQueue.IMP.setBlock(this.world, x, y, z, id);
|
||||
} else {
|
||||
super.setBlock(location, block);
|
||||
}
|
||||
@@ -216,7 +218,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
}
|
||||
default: {
|
||||
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
|
||||
SetQueue.IMP.setBlock(world, x, y, z, new PlotBlock((short) id, (byte) block.getData()));
|
||||
SetQueue.IMP.setBlock(this.world, x, y, z, new PlotBlock((short) id, (byte) block.getData()));
|
||||
} else {
|
||||
super.setBlock(location, block);
|
||||
}
|
||||
@@ -226,32 +228,29 @@ public class ProcessedWEExtent extends AbstractDelegateExtent {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Entity createEntity(final Location location, final BaseEntity entity) {
|
||||
if (Eblocked) {
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
if (this.Eblocked) {
|
||||
return null;
|
||||
}
|
||||
Ecount++;
|
||||
if (Ecount > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||
Eblocked = true;
|
||||
PS.debug("&cPlotSquared detected unsafe WorldEdit: " + (location.getBlockX()) + "," + (location.getBlockZ()));
|
||||
this.Ecount++;
|
||||
if (this.Ecount > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) {
|
||||
this.Eblocked = true;
|
||||
PS.debug("&cPlotSquared detected unsafe WorldEdit: " + location.getBlockX() + "," + location.getBlockZ());
|
||||
}
|
||||
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
|
||||
if (WEManager.maskContains(this.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;
|
||||
public boolean setBiome(Vector2D position, BaseBiome biome) {
|
||||
return WEManager.maskContains(this.mask, position.getBlockX(), position.getBlockZ()) && super.setBiome(position, biome);
|
||||
}
|
||||
}
|
||||
|
@@ -1,7 +1,5 @@
|
||||
package com.plotsquared.listener;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
import com.sk89q.worldedit.Vector;
|
||||
import com.sk89q.worldedit.Vector2D;
|
||||
@@ -14,35 +12,32 @@ import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BaseBiome;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class WEExtent extends AbstractDelegateExtent {
|
||||
|
||||
private final HashSet<RegionWrapper> mask;
|
||||
|
||||
public WEExtent(final HashSet<RegionWrapper> mask, final Extent extent) {
|
||||
|
||||
public WEExtent(HashSet<RegionWrapper> mask, 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;
|
||||
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException {
|
||||
return WEManager.maskContains(this.mask, location.getBlockX(), location.getBlockY(), location.getBlockZ()) && super.setBlock(location, block);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Entity createEntity(final Location location, final BaseEntity entity) {
|
||||
if (WEManager.maskContains(mask, location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
|
||||
public Entity createEntity(Location location, BaseEntity entity) {
|
||||
if (WEManager.maskContains(this.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;
|
||||
public boolean setBiome(Vector2D position, BaseBiome biome) {
|
||||
return WEManager.maskContains(this.mask, position.getBlockX(), position.getBlockZ()) && super.setBiome(position, biome);
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,5 @@
|
||||
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;
|
||||
@@ -12,30 +9,34 @@ import com.intellectualcrafters.plot.object.PlotArea;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.RegionWrapper;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
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) {
|
||||
|
||||
public static boolean maskContains(HashSet<RegionWrapper> mask, int x, int y, int z) {
|
||||
for (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) {
|
||||
|
||||
public static boolean maskContains(HashSet<RegionWrapper> mask, int x, int z) {
|
||||
for (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();
|
||||
|
||||
public static HashSet<RegionWrapper> getMask(PlotPlayer player) {
|
||||
HashSet<RegionWrapper> regions = new HashSet<>();
|
||||
UUID uuid = player.getUUID();
|
||||
Location location = player.getLocation();
|
||||
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;
|
||||
@@ -44,23 +45,24 @@ public class WEManager {
|
||||
if (area == null) {
|
||||
return regions;
|
||||
}
|
||||
for (final Plot plot : area.getPlots()) {
|
||||
for (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))) {
|
||||
if (Settings.WE_ALLOW_HELPER && plot.isAdded(uuid) || !Settings.WE_ALLOW_HELPER && (plot.isOwner(uuid) || plot.getTrusted()
|
||||
.contains(uuid))) {
|
||||
regions.addAll(plot.getRegions());
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
public static boolean intersects(final RegionWrapper region1, final RegionWrapper region2) {
|
||||
|
||||
public static boolean intersects(RegionWrapper region1, 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) {
|
||||
|
||||
public static boolean regionContains(RegionWrapper selection, HashSet<RegionWrapper> mask) {
|
||||
for (RegionWrapper region : mask) {
|
||||
if (intersects(region, selection)) {
|
||||
return true;
|
||||
}
|
||||
|
@@ -18,38 +18,42 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
|
||||
import com.sk89q.worldedit.extent.ChangeSetExtent;
|
||||
import com.sk89q.worldedit.extent.MaskingExtent;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.extent.reorder.MultiStageReorder;
|
||||
import com.sk89q.worldedit.extent.world.FastModeExtent;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
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;
|
||||
public void onEditSession(EditSessionEvent event) {
|
||||
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();
|
||||
World worldObj = event.getWorld();
|
||||
String world = worldObj.getName();
|
||||
Actor actor = event.getActor();
|
||||
if (actor != null && actor.isPlayer()) {
|
||||
final String name = actor.getName();
|
||||
final PlotPlayer pp = PlotPlayer.wrap(name);
|
||||
final HashSet<RegionWrapper> mask;
|
||||
String name = actor.getName();
|
||||
PlotPlayer pp = PlotPlayer.wrap(name);
|
||||
HashSet<RegionWrapper> mask;
|
||||
if (pp == null) {
|
||||
Player player = (Player) actor;
|
||||
Location loc = player.getLocation();
|
||||
com.intellectualcrafters.plot.object.Location pLoc = new com.intellectualcrafters.plot.object.Location(player.getWorld().getName(), loc.getBlockX(), loc.getBlockX(), loc.getBlockZ());
|
||||
com.intellectualcrafters.plot.object.Location pLoc =
|
||||
new com.intellectualcrafters.plot.object.Location(player.getWorld().getName(), loc.getBlockX(), loc.getBlockX(),
|
||||
loc.getBlockZ());
|
||||
Plot plot = pLoc.getPlot();
|
||||
if (plot == null) {
|
||||
event.setExtent(new com.sk89q.worldedit.extent.NullExtent());
|
||||
event.setExtent(new NullExtent());
|
||||
return;
|
||||
}
|
||||
mask = plot.getRegions();
|
||||
@@ -62,7 +66,7 @@ public class WESubscriber {
|
||||
MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS);
|
||||
}
|
||||
if (PS.get().hasPlotArea(world)) {
|
||||
event.setExtent(new com.sk89q.worldedit.extent.NullExtent());
|
||||
event.setExtent(new NullExtent());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -70,26 +74,26 @@ public class WESubscriber {
|
||||
if (Settings.CHUNK_PROCESSOR) {
|
||||
if (Settings.EXPERIMENTAL_FAST_ASYNC_WORLDEDIT) {
|
||||
try {
|
||||
final LocalSession session = worldedit.getSessionManager().findByName(name);
|
||||
LocalSession session = worldedit.getSessionManager().findByName(name);
|
||||
boolean hasMask = session.getMask() != null;
|
||||
final Player objPlayer = (Player) actor;
|
||||
final int item = objPlayer.getItemInHand();
|
||||
Player objPlayer = (Player) actor;
|
||||
int item = objPlayer.getItemInHand();
|
||||
if (!hasMask) {
|
||||
try {
|
||||
final Tool tool = session.getTool(item);
|
||||
Tool tool = session.getTool(item);
|
||||
if (tool instanceof BrushTool) {
|
||||
hasMask = ((BrushTool) tool).getMask() != null;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
AbstractDelegateExtent extent = (AbstractDelegateExtent) event.getExtent();
|
||||
ChangeSetExtent history = null;
|
||||
MultiStageReorder reorder = null;
|
||||
MaskingExtent maskextent = null;
|
||||
final boolean fast = session.hasFastMode();
|
||||
boolean fast = session.hasFastMode();
|
||||
while (extent.getExtent() != null && extent.getExtent() instanceof AbstractDelegateExtent) {
|
||||
final AbstractDelegateExtent tmp = (AbstractDelegateExtent) extent.getExtent();
|
||||
AbstractDelegateExtent tmp = (AbstractDelegateExtent) extent.getExtent();
|
||||
if (tmp.getExtent() != null && tmp.getExtent() instanceof AbstractDelegateExtent) {
|
||||
if (tmp instanceof ChangeSetExtent) {
|
||||
history = (ChangeSetExtent) tmp;
|
||||
@@ -105,11 +109,11 @@ public class WESubscriber {
|
||||
break;
|
||||
}
|
||||
}
|
||||
final int max = event.getMaxBlocks();
|
||||
final Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
int max = event.getMaxBlocks();
|
||||
Field field = AbstractDelegateExtent.class.getDeclaredField("extent");
|
||||
field.setAccessible(true);
|
||||
if (history == null) {
|
||||
final ExtentWrapper wrapper = new ExtentWrapper(event.getExtent());
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user