Type weakening and Direction changes

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-03-06 12:47:38 -05:00
parent 4c8457ad14
commit 56c24a6a56
20 changed files with 171 additions and 155 deletions

View File

@ -134,7 +134,7 @@ final class MessagePart implements JsonRepresentedObject, ConfigurationSerializa
json.endObject();
} catch (IOException e) {
Bukkit.getLogger()
.log(Level.WARNING, "A problem occured during writing of JSON string", e);
.log(Level.WARNING, "A problem occurred during writing of JSON string", e);
}
}

View File

@ -174,7 +174,7 @@ import java.util.*;
*
* @param player the recipient of the message
* @param caption the message
* @see MainUtil#sendMessage(PlotPlayer, Captions, String...)
* @see MainUtil#sendMessage(com.github.intellectualsites.plotsquared.commands.CommandCaller, Captions, String...)
*/
public static void sendMessage(Player player, Captions caption) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);

View File

@ -13,7 +13,6 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.*;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
@ -56,10 +55,9 @@ public abstract class Command {
public Command(Command parent, boolean isStatic) {
this.parent = parent;
this.isStatic = isStatic;
Annotation cdAnnotation = getClass().getAnnotation(CommandDeclaration.class);
CommandDeclaration cdAnnotation = getClass().getAnnotation(CommandDeclaration.class);
if (cdAnnotation != null) {
CommandDeclaration declaration = (CommandDeclaration) cdAnnotation;
init(declaration);
init(cdAnnotation);
}
for (final Method method : getClass().getDeclaredMethods()) {
if (method.isAnnotationPresent(CommandDeclaration.class)) {
@ -101,7 +99,7 @@ public abstract class Command {
return this.id;
}
public List<Command> getCommands(PlotPlayer player) {
public List<Command> getCommands(CommandCaller player) {
List<Command> commands = new ArrayList<>();
for (Command cmd : this.allCommands) {
if (cmd.canExecute(player, false)) {
@ -111,10 +109,10 @@ public abstract class Command {
return commands;
}
public List<Command> getCommands(CommandCategory cat, PlotPlayer player) {
public List<Command> getCommands(CommandCategory category, CommandCaller player) {
List<Command> commands = getCommands(player);
if (cat != null) {
commands.removeIf(command -> command.category != cat);
if (category != null) {
commands.removeIf(command -> command.category != category);
}
return commands;
}
@ -123,7 +121,7 @@ public abstract class Command {
return this.allCommands;
}
public boolean hasConfirmation(PlotPlayer player) {
public boolean hasConfirmation(CommandCaller player) {
return this.confirmation && !player.hasPermission(getPermission() + ".confirm.bypass");
}
@ -272,7 +270,7 @@ public abstract class Command {
}
return;
}
if (this.allCommands == null || this.allCommands.isEmpty()) {
if (this.allCommands.isEmpty()) {
player.sendMessage(
"Not Implemented: https://github.com/IntellectualSites/PlotSquared/issues/new");
return;
@ -285,13 +283,13 @@ public abstract class Command {
}
// Help command
try {
if (args.length == 0 || MathMan.isInteger(args[0])
|| CommandCategory.valueOf(args[0].toUpperCase()) != null) {
if (!MathMan.isInteger(args[0])) {
CommandCategory.valueOf(args[0].toUpperCase());
}
// This will default certain syntax to the help command
// e.g. /plot, /plot 1, /plot claiming
MainCommand.getInstance().help.execute(player, args, null, null);
return;
}
} catch (IllegalArgumentException ignored) {
}
// Command recommendation
@ -328,7 +326,7 @@ public abstract class Command {
}
}
public boolean checkArgs(PlotPlayer player, String[] args) {
public boolean checkArgs(CommandCaller player, String[] args) {
Argument<?>[] reqArgs = getRequiredArguments();
if (reqArgs != null && reqArgs.length > 0) {
boolean failed = args.length < reqArgs.length;
@ -421,7 +419,7 @@ public abstract class Command {
return null;
}
public boolean canExecute(PlotPlayer player, boolean message) {
public boolean canExecute(CommandCaller player, boolean message) {
if (player == null) {
return true;
}
@ -447,7 +445,6 @@ public abstract class Command {
}
public String getCommandString() {
String base;
if (this.parent == null) {
return "/" + toString();
} else {
@ -577,7 +574,7 @@ public abstract class Command {
this.args = args;
}
public void perform(PlotPlayer player) {
public void perform(CommandCaller player) {
if (player != null && message != null) {
message.send(player, args);
}

View File

@ -26,6 +26,7 @@ import java.util.Set;
@Override public void execute(final PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
check(EconHandler.manager, Captions.ECON_DISABLED);
final Plot plot;
if (args.length != 0) {

View File

@ -4,8 +4,8 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@CommandDeclaration(command = "chat", description = "Toggle plot chat on or off",
usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT,
requiredType = RequiredType.NONE) public class Chat extends SubCommand {
usage = "/plot chat [on|off]", permission = "plots.chat", category = CommandCategory.CHAT, requiredType = RequiredType.PLAYER)
public class Chat extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
MainCommand.getInstance().toggle.chat(this, player, new String[0], null, null);

View File

@ -50,6 +50,8 @@ public enum CommandCategory {
this.name = name;
}
@Override public String toString() {
return this.name;
}

View File

@ -31,6 +31,8 @@ import java.util.*;
private Bindings scope;
public DebugExec() {
init();
/*
try {
if (PlotSquared.get() != null) {
File file = new File(PlotSquared.get().IMP.getDirectory(),
@ -49,6 +51,7 @@ import java.util.*;
} catch (IOException | ScriptException ignored) {
ignored.printStackTrace();
}
*/
}
public ScriptEngine getEngine() {

View File

@ -1,6 +1,7 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
@ -18,7 +19,7 @@ public class Help extends Command {
super(parent, true);
}
@Override public boolean canExecute(PlotPlayer player, boolean message) {
@Override public boolean canExecute(CommandCaller player, boolean message) {
return true;
}
@ -54,7 +55,7 @@ public class Help extends Command {
}
}
public void displayHelp(PlotPlayer player, String cat, int page) {
public void displayHelp(CommandCaller player, String cat, int page) {
CommandCategory catEnum = null;
if (cat != null) {
if (StringMan.isEqualIgnoreCase(cat, "all")) {

View File

@ -1,8 +1,8 @@
package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.*;
import com.github.intellectualsites.plotsquared.plot.util.CmdConfirm;
@ -126,15 +126,12 @@ public class MainCommand extends Command {
@Override
public void run(final Command cmd, final Runnable success, final Runnable failure) {
if (cmd.hasConfirmation(player)) {
CmdConfirm.addPending(player, cmd.getUsage(), new Runnable() {
@Override public void run() {
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
if (EconHandler.manager != null) {
PlotArea area = player.getApplicablePlotArea();
if (area != null) {
Expression<Double> priceEval =
area.PRICES.get(cmd.getFullId());
Double price =
priceEval != null ? priceEval.evaluate(0d) : 0d;
Expression<Double> priceEval = area.PRICES.get(cmd.getFullId());
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != null
&& EconHandler.manager.getMoney(player) < price) {
if (failure != null) {
@ -147,7 +144,6 @@ public class MainCommand extends Command {
if (success != null) {
success.run();
}
}
});
return;
}
@ -180,13 +176,6 @@ public class MainCommand extends Command {
return true;
}
@Deprecated
/**
* @Deprecated legacy
*/ public void addCommand(SubCommand command) {
PlotSquared.debug("Command registration is now done during instantiation");
}
@Override public void execute(final PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
@ -281,7 +270,7 @@ public class MainCommand extends Command {
}
}
@Override public boolean canExecute(PlotPlayer player, boolean message) {
@Override public boolean canExecute(CommandCaller player, boolean message) {
return true;
}
}

View File

@ -16,8 +16,8 @@ import java.util.Map.Entry;
import java.util.UUID;
@CommandDeclaration(command = "rate", permission = "plots.rate", description = "Rate the plot",
usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO,
requiredType = RequiredType.NONE) public class Rate extends SubCommand {
usage = "/plot rate [#|next|purge]", aliases = "rt", category = CommandCategory.INFO, requiredType = RequiredType.PLAYER)
public class Rate extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length == 1) {

View File

@ -6,11 +6,9 @@ public enum RequiredType {
CONSOLE, PLAYER, NONE;
public boolean allows(CommandCaller player) {
switch (this) {
case NONE:
if (this == RequiredType.NONE) {
return true;
default:
}
return this == player.getSuperCaller();
}
}
}

View File

@ -16,7 +16,7 @@ import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
@CommandDeclaration(command = "trust", aliases = {"t"}, requiredType = RequiredType.NONE,
@CommandDeclaration(command = "trust", aliases = {"t"}, requiredType = RequiredType.PLAYER,
usage = "/plot trust <player>",
description = "Allow a user to build in a plot while you are offline",
category = CommandCategory.SETTINGS) public class Trust extends Command {
@ -28,16 +28,19 @@ import java.util.UUID;
@Override public void execute(final PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
checkTrue(plot.hasOwner(), Captions.PLOT_UNOWNED);
checkTrue(plot.isOwner(player.getUUID()) || Permissions
final Plot currentPlot = player.getCurrentPlot();
if (currentPlot == null) {
throw new CommandException(Captions.NOT_IN_PLOT);
}
checkTrue(currentPlot.hasOwner(), Captions.PLOT_UNOWNED);
checkTrue(currentPlot.isOwner(player.getUUID()) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
Captions.NO_PLOT_PERMS);
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
final Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
Iterator<UUID> iter = uuids.iterator();
int size = plot.getTrusted().size() + plot.getMembers().size();
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
while (iter.hasNext()) {
UUID uuid = iter.next();
if (uuid == DBFunc.EVERYONE && !(
@ -47,34 +50,34 @@ import java.util.UUID;
iter.remove();
continue;
}
if (plot.isOwner(uuid)) {
if (currentPlot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_OWNER, MainUtil.getName(uuid));
iter.remove();
continue;
}
if (plot.getTrusted().contains(uuid)) {
if (currentPlot.getTrusted().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iter.remove();
continue;
}
size += plot.getMembers().contains(uuid) ? 0 : 1;
size += currentPlot.getMembers().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions
checkTrue(size <= currentPlot.getArea().MAX_PLOT_MEMBERS || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
Captions.PLOT_MAX_MEMBERS);
// Success
confirm.run(this, () -> {
for (UUID uuid : uuids) {
if (uuid != DBFunc.EVERYONE) {
if (!plot.removeMember(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
if (!currentPlot.removeMember(uuid)) {
if (currentPlot.getDenied().contains(uuid)) {
currentPlot.removeDenied(uuid);
}
}
}
plot.addTrusted(uuid);
EventUtil.manager.callTrusted(player, plot, uuid, true);
currentPlot.addTrusted(uuid);
EventUtil.manager.callTrusted(player, currentPlot, uuid, true);
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
}
}, null);

View File

@ -8,8 +8,7 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.*;
@CommandDeclaration(command = "unlink", aliases = {"u", "unmerge"},
description = "Unlink a mega-plot", usage = "/plot unlink [createroads]",
requiredType = RequiredType.NONE, category = CommandCategory.SETTINGS, confirmation = true)
description = "Unlink a mega-plot", usage = "/plot unlink [createroads]", requiredType = RequiredType.PLAYER, category = CommandCategory.SETTINGS, confirmation = true)
public class Unlink extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {

View File

@ -14,8 +14,8 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import java.util.*;
@CommandDeclaration(command = "visit", permission = "plots.visit",
description = "Visit someones plot", usage = "/plot visit [<player>|<alias>|<world>|<id>] [#]",
aliases = {"v", "tp", "teleport", "goto", "home", "h"}, requiredType = RequiredType.NONE,
description = "Visit someones plot", usage = "/plot visit [<player>|<alias>|<world>|<id>] [#]", aliases = {
"v", "tp", "teleport", "goto", "home", "h"}, requiredType = RequiredType.PLAYER,
category = CommandCategory.TELEPORT) public class Visit extends Command {
public Visit() {

View File

@ -920,15 +920,15 @@ public class Plot {
}
if (this.area.TERRAIN != 3 && createRoad) {
for (Plot current : plots) {
if (current.getMerged(1)) {
if (current.getMerged(Direction.EAST)) {
manager.createRoadEast(current.area, current);
if (current.getMerged(2)) {
if (getMerged(Direction.SOUTH)) {
manager.createRoadSouth(current.area, current);
if (current.getMerged(5)) {
if (getMerged(Direction.SOUTHEAST)) {
manager.createRoadSouthEast(current.area, current);
}
}
} else if (current.getMerged(2)) {
} else if (getMerged(Direction.SOUTH)) {
manager.createRoadSouth(current.area, current);
}
}
@ -1624,11 +1624,11 @@ public class Plot {
if (!this.isMerged()) {
return top;
}
if (this.getMerged(Direction.SOUTH.getIndex())) {
top.setZ(this.getRelative(Direction.SOUTH.getIndex()).getBottomAbs().getZ() - 1);
if (this.getMerged(Direction.SOUTH)) {
top.setZ(this.getRelative(Direction.SOUTH).getBottomAbs().getZ() - 1);
}
if (this.getMerged(Direction.EAST.getIndex())) {
top.setX(this.getRelative(Direction.SOUTH.getIndex()).getBottomAbs().getX() - 1);
if (this.getMerged(Direction.EAST)) {
top.setX(this.getRelative(Direction.SOUTH).getBottomAbs().getX() - 1);
}
return top;
}
@ -1645,11 +1645,11 @@ public class Plot {
if (!this.isMerged()) {
return bot;
}
if (this.getMerged(Direction.NORTH.getIndex())) {
bot.setZ(this.getRelative(Direction.NORTH.getIndex()).getTopAbs().getZ() + 1);
if (this.getMerged(Direction.NORTH)) {
bot.setZ(this.getRelative(Direction.NORTH).getTopAbs().getZ() + 1);
}
if (this.getMerged(Direction.WEST.getIndex())) {
bot.setX(this.getRelative(Direction.WEST.getIndex()).getTopAbs().getX() + 1);
if (this.getMerged(Direction.WEST)) {
bot.setX(this.getRelative(Direction.WEST).getTopAbs().getX() + 1);
}
return bot;
}
@ -1678,7 +1678,7 @@ public class Plot {
if (this.area.TERRAIN == 3) {
return;
}
Plot other = this.getRelative(Direction.EAST.getIndex());
Plot other = this.getRelative(Direction.EAST);
Location bot = other.getBottomAbs();
Location top = this.getTopAbs();
Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ());
@ -2147,7 +2147,7 @@ public class Plot {
if (this.area.TERRAIN == 3) {
return;
}
Plot other = this.getRelative(2);
Plot other = this.getRelative(Direction.SOUTH);
Location bot = other.getBottomAbs();
Location top = this.getTopAbs();
Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ());
@ -2192,8 +2192,8 @@ public class Plot {
}
visited.add(current);
Set<Plot> plots;
if ((dir == -1 || dir == 0) && !current.getMerged(0)) {
Plot other = current.getRelative(0);
if ((dir == -1 || dir == 0) && !getMerged(Direction.NORTH)) {
Plot other = current.getRelative(Direction.NORTH);
if (other != null && other.isOwner(uuid) && (
other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier
@ -2204,8 +2204,8 @@ public class Plot {
toReturn = true;
}
}
if (max >= 0 && (dir == -1 || dir == 1) && !current.getMerged(1)) {
Plot other = current.getRelative(1);
if (max >= 0 && (dir == -1 || dir == 1) && !current.getMerged(Direction.EAST)) {
Plot other = current.getRelative(Direction.EAST);
if (other != null && other.isOwner(uuid) && (
other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier
@ -2216,8 +2216,8 @@ public class Plot {
toReturn = true;
}
}
if (max >= 0 && (dir == -1 || dir == 2) && !current.getMerged(2)) {
Plot other = current.getRelative(2);
if (max >= 0 && (dir == -1 || dir == 2) && !getMerged(Direction.SOUTH)) {
Plot other = current.getRelative(Direction.SOUTH);
if (other != null && other.isOwner(uuid) && (
other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier
@ -2228,8 +2228,8 @@ public class Plot {
toReturn = true;
}
}
if (max >= 0 && (dir == -1 || dir == 3) && !current.getMerged(3)) {
Plot other = current.getRelative(3);
if (max >= 0 && (dir == -1 || dir == 3) && !getMerged(Direction.WEST)) {
Plot other = current.getRelative(Direction.WEST);
if (other != null && other.isOwner(uuid) && (
other.getBasePlot(false).equals(current.getBasePlot(false))
|| (plots = other.getConnectedPlots()).size() <= max && frontier
@ -2344,6 +2344,21 @@ public class Plot {
return this.area.getPlotAbs(this.id.getRelative(direction));
}
/**
* Gets the plot in a relative direction<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* Note: May be null if the partial plot area does not include the relative location
*
* @param direction
* @return
*/
public Plot getRelative(Direction direction) {
return this.area.getPlotAbs(this.id.getRelative(direction));
}
/**
* Gets a set of plots connected (and including) this plot<br>
* - This result is cached globally
@ -2370,8 +2385,8 @@ public class Plot {
tmpSet.add(this);
Plot tmp;
if (merged[0]) {
tmp = this.area.getPlotAbs(this.id.getRelative(0));
if (!tmp.getMerged(2)) {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.NORTH));
if (!tmp.getMerged(Direction.SOUTH)) {
// invalid merge
PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) {
@ -2386,8 +2401,8 @@ public class Plot {
frontier.add(tmp);
}
if (merged[1]) {
tmp = this.area.getPlotAbs(this.id.getRelative(1));
if (!tmp.getMerged(3)) {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.EAST));
if (!tmp.getMerged(Direction.WEST)) {
// invalid merge
PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) {
@ -2402,8 +2417,8 @@ public class Plot {
frontier.add(tmp);
}
if (merged[2]) {
tmp = this.area.getPlotAbs(this.id.getRelative(2));
if (!tmp.getMerged(0)) {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.SOUTH));
if (!tmp.getMerged(Direction.NORTH)) {
// invalid merge
PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) {
@ -2418,8 +2433,8 @@ public class Plot {
frontier.add(tmp);
}
if (merged[3]) {
tmp = this.area.getPlotAbs(this.id.getRelative(3));
if (!tmp.getMerged(1)) {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.WEST));
if (!tmp.getMerged(Direction.EAST)) {
// invalid merge
PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) {
@ -2446,28 +2461,28 @@ public class Plot {
queuecache.remove(current);
merged = current.getMerged();
if (merged[0]) {
tmp = current.area.getPlotAbs(current.id.getRelative(0));
tmp = current.area.getPlotAbs(current.id.getRelative(Direction.NORTH));
if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) {
queuecache.add(tmp);
frontier.add(tmp);
}
}
if (merged[1]) {
tmp = current.area.getPlotAbs(current.id.getRelative(1));
tmp = current.area.getPlotAbs(current.id.getRelative(Direction.EAST));
if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) {
queuecache.add(tmp);
frontier.add(tmp);
}
}
if (merged[2]) {
tmp = current.area.getPlotAbs(current.id.getRelative(2));
tmp = current.area.getPlotAbs(current.id.getRelative(Direction.SOUTH));
if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) {
queuecache.add(tmp);
frontier.add(tmp);
}
}
if (merged[3]) {
tmp = current.area.getPlotAbs(current.id.getRelative(3));
tmp = current.area.getPlotAbs(current.id.getRelative(Direction.WEST));
if (tmp != null && !queuecache.contains(tmp) && !tmpSet.contains(tmp)) {
queuecache.add(tmp);
frontier.add(tmp);
@ -2516,7 +2531,8 @@ public class Plot {
boolean tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.getMerged(2) || visited.contains(plot.getId())) {
if (plot == null || !plot.getMerged(Direction.SOUTH) || visited
.contains(plot.getId())) {
tmp = false;
}
}
@ -2529,7 +2545,8 @@ public class Plot {
tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.getMerged(3) || visited.contains(plot.getId())) {
if (plot == null || !plot.getMerged(Direction.WEST) || visited
.contains(plot.getId())) {
tmp = false;
}
}
@ -2542,7 +2559,8 @@ public class Plot {
tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.getMerged(0) || visited.contains(plot.getId())) {
if (plot == null || !plot.getMerged(Direction.NORTH) || visited
.contains(plot.getId())) {
tmp = false;
}
}
@ -2555,7 +2573,8 @@ public class Plot {
tmp = true;
for (PlotId id : ids) {
Plot plot = this.area.getPlotAbs(id);
if (plot == null || !plot.getMerged(1) || visited.contains(plot.getId())) {
if (plot == null || !plot.getMerged(Direction.EAST) || visited
.contains(plot.getId())) {
tmp = false;
}
}
@ -2569,14 +2588,14 @@ public class Plot {
visited.addAll(MainUtil.getPlotSelectionIds(bot, top));
for (int x = bot.x; x <= top.x; x++) {
Plot plot = this.area.getPlotAbs(new PlotId(x, top.y));
if (plot.getMerged(2)) {
if (plot.getMerged(Direction.SOUTH)) {
// south wedge
Location toploc = plot.getExtendedTopAbs();
Location botabs = plot.getBottomAbs();
Location topabs = plot.getTopAbs();
regions.add(new RegionWrapper(botabs.getX(), topabs.getX(), topabs.getZ() + 1,
toploc.getZ()));
if (plot.getMerged(5)) {
if (plot.getMerged(Direction.SOUTHEAST)) {
regions.add(
new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1,
toploc.getZ()));
@ -2587,14 +2606,14 @@ public class Plot {
for (int y = bot.y; y <= top.y; y++) {
Plot plot = this.area.getPlotAbs(new PlotId(top.x, y));
if (plot.getMerged(1)) {
if (plot.getMerged(Direction.EAST)) {
// east wedge
Location toploc = plot.getExtendedTopAbs();
Location botabs = plot.getBottomAbs();
Location topabs = plot.getTopAbs();
regions.add(new RegionWrapper(topabs.getX() + 1, toploc.getX(), botabs.getZ(),
topabs.getZ()));
if (plot.getMerged(5)) {
if (plot.getMerged(Direction.SOUTHEAST)) {
regions.add(
new RegionWrapper(topabs.getX() + 1, toploc.getX(), topabs.getZ() + 1,
toploc.getZ()));
@ -2776,7 +2795,7 @@ public class Plot {
lesserPlot = greaterPlot;
greaterPlot = tmp;
}
if (!lesserPlot.getMerged(2)) {
if (!lesserPlot.getMerged(Direction.SOUTH)) {
lesserPlot.clearRatings();
greaterPlot.clearRatings();
lesserPlot.setMerged(2, true);
@ -2784,13 +2803,13 @@ public class Plot {
lesserPlot.mergeData(greaterPlot);
if (removeRoads) {
lesserPlot.removeRoadSouth();
Plot diagonal = greaterPlot.getRelative(1);
if (diagonal.getMerged(7)) {
Plot diagonal = greaterPlot.getRelative(Direction.EAST);
if (diagonal.getMerged(Direction.NORTHWEST)) {
lesserPlot.removeRoadSouthEast();
}
Plot below = greaterPlot.getRelative(3);
if (below.getMerged(4)) {
below.getRelative(0).removeRoadSouthEast();
Plot below = greaterPlot.getRelative(Direction.WEST);
if (below.getMerged(Direction.NORTHEAST)) {
below.getRelative(Direction.NORTH).removeRoadSouthEast();
}
}
}
@ -2800,22 +2819,22 @@ public class Plot {
lesserPlot = greaterPlot;
greaterPlot = tmp;
}
if (!lesserPlot.getMerged(1)) {
if (!lesserPlot.getMerged(Direction.EAST)) {
lesserPlot.clearRatings();
greaterPlot.clearRatings();
lesserPlot.setMerged(1, true);
greaterPlot.setMerged(3, true);
lesserPlot.mergeData(greaterPlot);
if (removeRoads) {
Plot diagonal = greaterPlot.getRelative(2);
if (diagonal.getMerged(7)) {
Plot diagonal = greaterPlot.getRelative(Direction.SOUTH);
if (diagonal.getMerged(Direction.NORTHWEST)) {
lesserPlot.removeRoadSouthEast();
}
lesserPlot.removeRoadEast();
}
Plot below = greaterPlot.getRelative(0);
if (below.getMerged(6)) {
below.getRelative(3).removeRoadSouthEast();
Plot below = greaterPlot.getRelative(Direction.NORTH);
if (below.getMerged(Direction.SOUTHWEST)) {
below.getRelative(Direction.WEST).removeRoadSouthEast();
}
}
}

View File

@ -560,6 +560,7 @@ public abstract class PlotArea {
return this.plots.entrySet().stream().anyMatch(entry -> entry.getValue().isOwner(uuid));
}
//todo check if this method is needed in this class
public int getPlotCount(@Nullable final PlotPlayer player) {
return player != null ? getPlotCount(player.getUUID()) : 0;
}
@ -876,19 +877,19 @@ public abstract class PlotArea {
Plot plot2;
if (lx) {
if (ly) {
if (!plot.getMerged(1) || !plot.getMerged(2)) {
if (!plot.getMerged(Direction.EAST) || !plot.getMerged(Direction.SOUTH)) {
if (removeRoads) {
plot.removeRoadSouthEast();
}
}
}
if (!plot.getMerged(1)) {
if (!plot.getMerged(Direction.EAST)) {
plot2 = plot.getRelative(1, 0);
plot.mergePlot(plot2, removeRoads);
}
}
if (ly) {
if (!plot.getMerged(2)) {
if (!plot.getMerged(Direction.SOUTH)) {
plot2 = plot.getRelative(0, 1);
plot.mergePlot(plot2, removeRoads);
}

View File

@ -86,6 +86,9 @@ public class PlotId {
}
}
public PlotId getRelative(Direction direction) {
return getRelative(direction.getIndex());
}
/**
* Get the PlotId in a relative direction
* 0 = north<br>

View File

@ -1,5 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.util;
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
@ -576,7 +577,7 @@ public class MainUtil {
* @param prefix If the message should be prefixed with the configured prefix
* @return
*/
public static boolean sendMessage(PlotPlayer player, String msg, boolean prefix) {
public static boolean sendMessage(CommandCaller player, String msg, boolean prefix) {
if (!msg.isEmpty()) {
if (player == null) {
String message = (prefix ? Captions.PREFIX.s() : "") + msg;
@ -595,7 +596,7 @@ public class MainUtil {
* @param caption the message to send
* @return boolean success
*/
public static boolean sendMessage(PlotPlayer player, Captions caption, String... args) {
public static boolean sendMessage(CommandCaller player, Captions caption, String... args) {
return sendMessage(player, caption, (Object[]) args);
}
@ -606,20 +607,18 @@ public class MainUtil {
* @param caption the message to send
* @return boolean success
*/
public static boolean sendMessage(final PlotPlayer player, final Captions caption,
public static boolean sendMessage(final CommandCaller player, final Captions caption,
final Object... args) {
if (caption.s().isEmpty()) {
return true;
}
TaskManager.runTaskAsync(new Runnable() {
@Override public void run() {
TaskManager.runTaskAsync(() -> {
String m = Captions.format(caption, args);
if (player == null) {
PlotSquared.log(m);
} else {
player.sendMessage(m);
}
}
});
return true;
}

View File

@ -1,24 +1,24 @@
package com.github.intellectualsites.plotsquared.plot.util.helpmenu;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.commands.MainCommand;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import java.util.List;
public class HelpMenu {
public static final int PER_PAGE = 5;
private static final int PER_PAGE = 5;
private final PlotPlayer player;
private final CommandCaller commandCaller;
private HelpPage page = new HelpPage(CommandCategory.INFO, 0, 0);
private int maxPage;
private CommandCategory commandCategory;
private List<Command> commands;
public HelpMenu(PlotPlayer player) {
this.player = player;
public HelpMenu(CommandCaller commandCaller) {
this.commandCaller = commandCaller;
}
public HelpMenu setCategory(CommandCategory commandCategory) {
@ -27,7 +27,8 @@ public class HelpMenu {
}
public HelpMenu getCommands() {
this.commands = MainCommand.getInstance().getCommands(this.commandCategory, this.player);
this.commands =
MainCommand.getInstance().getCommands(this.commandCategory, this.commandCaller);
return this;
}
@ -52,7 +53,7 @@ public class HelpMenu {
}
public void render() {
this.page.render(this.player);
this.page.render(this.commandCaller);
}
}

View File

@ -1,8 +1,8 @@
package com.github.intellectualsites.plotsquared.plot.util.helpmenu;
import com.github.intellectualsites.plotsquared.commands.CommandCaller;
import com.github.intellectualsites.plotsquared.plot.commands.CommandCategory;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
@ -21,7 +21,7 @@ public class HelpPage {
.replace("%current%", (currentPage + 1) + "").replace("%max%", (maxPages + 1) + "");
}
public void render(PlotPlayer player) {
public void render(CommandCaller player) {
if (this.helpObjects.size() < 1) {
MainUtil.sendMessage(player, Captions.NOT_VALID_NUMBER, "(0)");
} else {