Merge branch 'v5' into features/v5/road-respect-flags

# Conflicts:
#	Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
This commit is contained in:
dordsor21
2020-07-01 14:12:16 +01:00
196 changed files with 7452 additions and 4927 deletions

View File

@ -35,22 +35,29 @@ import com.plotsquared.core.util.ChatManager;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
import com.sk89q.worldedit.extension.platform.Actor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.List;
import java.util.Map;
public interface IPlotMain extends ILogger {
/**
* PlotSquared main utility class
*
* @param <P> Player type
*/
public interface IPlotMain<P> extends ILogger {
/**
* Logs a message to console.
@ -79,7 +86,7 @@ public interface IPlotMain extends ILogger {
* @param player The player to convert to a PlotPlayer
* @return A PlotPlayer
*/
PlotPlayer wrapPlayer(Object player);
@Nullable PlotPlayer<P> wrapPlayer(Object player);
/**
* Completely shuts down the plugin.
@ -168,11 +175,18 @@ public interface IPlotMain extends ILogger {
boolean initWorldEdit();
/**
* Gets the economy provider.
* Gets the economy provider, if there is one
*
* @return the PlotSquared economy manager
*/
EconHandler getEconomyHandler();
@Nullable EconHandler getEconomyHandler();
/**
* Gets the permission provider, if there is one
*
* @return the PlotSquared permission manager
*/
@Nullable PermHandler getPermissionHandler();
/**
* Gets the {@link QueueProvider} class.
@ -220,12 +234,6 @@ public interface IPlotMain extends ILogger {
*/
void setGenerator(String world);
/**
* Gets the {@link UUIDHandlerImplementation} which will cache and
* provide UUIDs.
*/
UUIDHandlerImplementation initUUIDHandler();
/**
* Gets the {@link InventoryUtil} class (used for implementation specific
* inventory guis).
@ -285,6 +293,13 @@ public interface IPlotMain extends ILogger {
*
* @return World manager
*/
@NotNull PlatformWorldManager getWorldManager();
@NotNull PlatformWorldManager<?> getWorldManager();
/**
* Get the player manager implementation for the platform
*
* @return Player manager
*/
@NotNull PlayerManager<? extends PlotPlayer<P>, ? extends P> getPlayerManager();
}

View File

@ -53,6 +53,7 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotCluster;
import com.plotsquared.core.plot.PlotFilter;
@ -79,17 +80,18 @@ import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.StringWrapper;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
@ -116,6 +118,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -123,6 +126,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -137,9 +141,14 @@ public class PlotSquared {
private static final Set<Plot> EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet());
private static PlotSquared instance;
// Implementation
public final IPlotMain IMP;
public final IPlotMain<?> IMP;
// Current thread
private final Thread thread;
// UUID pipelines
@Getter private final UUIDPipeline impromptuUUIDPipeline =
new UUIDPipeline(Executors.newCachedThreadPool());
@Getter private final UUIDPipeline backgroundUUIDPipeline =
new UUIDPipeline(Executors.newSingleThreadExecutor());
// WorldEdit instance
public WorldEdit worldedit;
public File styleFile;
@ -252,15 +261,6 @@ public class PlotSquared {
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
this.IMP.registerChunkProcessor();
}
// create UUIDWrapper
UUIDHandler.implementation = this.IMP.initUUIDHandler();
if (Settings.Enabled_Components.UUID_CACHE) {
startUuidCatching();
} else {
// Start these separately
UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
startExpiryTasks();
}
// Create Event utility class
eventDispatcher = new EventDispatcher();
// create Hybrid utility class
@ -270,7 +270,8 @@ public class PlotSquared {
// create setup util class
SetupUtils.manager = this.IMP.initSetupUtils();
// Set block
GlobalBlockQueue.IMP = new GlobalBlockQueue(IMP.initBlockQueue(), 1);
GlobalBlockQueue.IMP =
new GlobalBlockQueue(IMP.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME);
GlobalBlockQueue.IMP.runTask();
// Set chunk
ChunkManager.manager = this.IMP.initChunkManager();
@ -303,8 +304,7 @@ public class PlotSquared {
}
// Economy
if (Settings.Enabled_Components.ECONOMY) {
TaskManager
.runTask(() -> EconHandler.manager = PlotSquared.this.IMP.getEconomyHandler());
TaskManager.runTask(() -> EconHandler.initializeEconHandler());
}
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
@ -385,11 +385,11 @@ public class PlotSquared {
return PlotSquared.instance;
}
public static IPlotMain imp() {
if (instance != null) {
@NotNull public static IPlotMain<?> imp() {
if (instance != null && instance.IMP != null) {
return instance.IMP;
}
return null;
throw new IllegalStateException("Plot main implementation is missing");
}
/**
@ -427,23 +427,6 @@ public class PlotSquared {
}
}
private void startUuidCatching() {
TaskManager.runTaskLater(() -> {
debug("Starting UUID caching");
UUIDHandler.startCaching(() -> {
UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
forEachPlotRaw(plot -> {
if (plot.hasOwner() && plot.temp != -1) {
if (UUIDHandler.getName(plot.getOwnerAbs()) == null) {
UUIDHandler.implementation.unknown.add(plot.getOwnerAbs());
}
}
});
startExpiryTasks();
});
}, 20);
}
private void startExpiryTasks() {
if (Settings.Enabled_Components.PLOT_EXPIRY) {
ExpireManager.IMP = new ExpireManager();
@ -640,17 +623,7 @@ public class PlotSquared {
* @return Set of base Plots
*/
public Set<Plot> getBasePlots() {
int size = getPlotCount();
final Set<Plot> result = new HashSet<>(size);
forEachPlotArea(value -> {
for (Plot plot : value.getPlots()) {
if (!plot.isBasePlot()) {
continue;
}
result.add(plot);
}
});
return Collections.unmodifiableSet(result);
return PlotQuery.newQuery().whereBasePlot().asSet();
}
public List<Plot> sortPlotsByTemp(Collection<Plot> plots) {
@ -903,27 +876,25 @@ public class PlotSquared {
*
* @param filters the filter
* @return a filtered set of plots
* @deprecated Use {@link PlotQuery}
*/
public Set<Plot> getPlots(final PlotFilter... filters) {
final HashSet<Plot> set = new HashSet<>();
forEachPlotArea(value -> {
for (PlotFilter filter : filters) {
if (!filter.allowsArea(value)) {
return;
@Deprecated public Set<Plot> getPlots(final PlotFilter... filters) {
final List<PlotArea> areas = new LinkedList<>();
for (final PlotArea plotArea : this.getPlotAreas()) {
for (final PlotFilter filter : filters) {
if (filter.allowsArea(plotArea)) {
areas.add(plotArea);
}
}
loop:
for (Entry<PlotId, Plot> entry2 : value.getPlotEntries()) {
Plot plot = entry2.getValue();
for (PlotFilter filter : filters) {
if (!filter.allowsPlot(plot)) {
continue loop;
}
}
return PlotQuery.newQuery().inAreas(areas).thatPasses(plot -> {
for (final PlotFilter filter : filters) {
if (!filter.allowsPlot(plot)) {
return false;
}
set.add(plot);
}
});
return set;
return true;
}).asSet();
}
/**
@ -966,7 +937,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set<Plot> getPlots(String world, String player) {
final UUID uuid = UUIDHandler.getUUID(player, null);
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
return getPlots(world, uuid);
}
@ -978,7 +949,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set<Plot> getPlots(PlotArea area, String player) {
UUID uuid = UUIDHandler.getUUID(player, null);
final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
return getPlots(area, uuid);
}
@ -990,7 +961,7 @@ public class PlotSquared {
* @return Set of plot
*/
public Set<Plot> getPlots(String world, PlotPlayer player) {
return getPlots(world, player.getUUID());
return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet();
}
/**
@ -1001,7 +972,7 @@ public class PlotSquared {
* @return Set of plot
*/
public Set<Plot> getPlots(PlotArea area, PlotPlayer player) {
return getPlots(area, player.getUUID());
return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet();
}
/**
@ -1012,10 +983,7 @@ public class PlotSquared {
* @return Set of plot
*/
public Set<Plot> getPlots(String world, UUID uuid) {
final Set<Plot> plots =
getPlots(world).stream().filter(plot -> plot.hasOwner() && plot.isOwnerAbs(uuid))
.collect(Collectors.toSet());
return Collections.unmodifiableSet(plots);
return PlotQuery.newQuery().inWorld(world).ownedBy(uuid).asSet();
}
/**
@ -1026,13 +994,7 @@ public class PlotSquared {
* @return Set of plots
*/
public Set<Plot> getPlots(PlotArea area, UUID uuid) {
final Set<Plot> plots = new HashSet<>();
for (Plot plot : getPlots(area)) {
if (plot.hasOwner() && plot.isOwnerAbs(uuid)) {
plots.add(plot);
}
}
return Collections.unmodifiableSet(plots);
return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet();
}
/**
@ -1047,9 +1009,7 @@ public class PlotSquared {
}
public Collection<Plot> getPlots(String world) {
final Set<Plot> set = new HashSet<>();
forEachPlotArea(world, value -> set.addAll(value.getPlots()));
return set;
return PlotQuery.newQuery().inWorld(world).asCollection();
}
/**
@ -1059,7 +1019,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set<Plot> getPlots(PlotPlayer player) {
return getPlots(player.getUUID());
return PlotQuery.newQuery().ownedBy(player).asSet();
}
public Collection<Plot> getPlots(PlotArea area) {
@ -1081,13 +1041,7 @@ public class PlotSquared {
* @return Set of Plot's owned by the player
*/
public Set<Plot> getPlots(final UUID uuid) {
final Set<Plot> plots = new HashSet<>();
forEachPlot(value -> {
if (value.isOwnerAbs(uuid)) {
plots.add(value);
}
});
return Collections.unmodifiableSet(plots);
return PlotQuery.newQuery().ownedBy(uuid).asSet();
}
public boolean hasPlot(final UUID uuid) {
@ -1096,13 +1050,7 @@ public class PlotSquared {
}
public Set<Plot> getBasePlots(final UUID uuid) {
final Set<Plot> plots = new HashSet<>();
forEachBasePlot(value -> {
if (value.isOwner(uuid)) {
plots.add(value);
}
});
return Collections.unmodifiableSet(plots);
return PlotQuery.newQuery().ownedBy(uuid).whereBasePlot().asSet();
}
/**
@ -1112,13 +1060,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set<Plot> getPlotsAbs(final UUID uuid) {
final Set<Plot> plots = new HashSet<>();
forEachPlot(value -> {
if (value.isOwnerAbs(uuid)) {
plots.add(value);
}
});
return Collections.unmodifiableSet(plots);
return PlotQuery.newQuery().ownedBy(uuid).asSet();
}
/**
@ -1620,7 +1562,6 @@ public class PlotSquared {
// Close the connection
DBFunc.close();
UUIDHandler.handleShutdown();
} catch (NullPointerException throwable) {
throwable.printStackTrace();
PlotSquared.log("&cCould not close database connection!");
@ -2014,6 +1955,23 @@ public class PlotSquared {
return Collections.unmodifiableSet(set);
}
/**
* Check if the chunk uses vanilla/non-PlotSquared generation
*
* @param world World name
* @param chunkCoordinates Chunk coordinates
* @return True if the chunk uses non-standard generation, false if not
*/
public boolean isNonStandardGeneration(@NotNull final String world,
@NotNull final BlockVector2 chunkCoordinates) {
final Location location = new Location(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
final PlotArea area = plotAreaManager.getApplicablePlotArea(location);
if (area == null) {
return true;
}
return area.getTerrain() != PlotAreaTerrainType.NONE;
}
public boolean isAugmented(@NonNull final String world) {
final PlotArea[] areas = plotAreaManager.getPlotAreas(world, null);
return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL);
@ -2103,16 +2061,7 @@ public class PlotSquared {
*/
public Set<Plot> getPlotsByAlias(@Nullable final String alias,
@NonNull final String worldname) {
final Set<Plot> result = new HashSet<>();
if (alias != null) {
for (final Plot plot : getPlots()) {
if (alias.equals(plot.getAlias()) && (worldname == null || worldname
.equals(plot.getWorldName()))) {
result.add(plot);
}
}
}
return Collections.unmodifiableSet(result);
return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet();
}
public Set<PlotArea> getPlotAreas(final String world, final CuboidRegion region) {

View File

@ -38,8 +38,6 @@ import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.util.uuid.UUIDWrapper;
import lombok.NoArgsConstructor;
import java.util.Collections;
@ -60,9 +58,7 @@ import java.util.UUID;
*
* @version 5
*/
@SuppressWarnings({"unused", "WeakerAccess"})
@NoArgsConstructor
public class PlotAPI {
@SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI {
/**
* Gets all plots.
@ -140,17 +136,6 @@ public class PlotAPI {
return GlobalBlockQueue.IMP;
}
/**
* UUIDWrapper class has basic methods for getting UUIDS. It's recommended
* to use the UUIDHandler class instead.
*
* @return UUIDWrapper
* @see UUIDWrapper
*/
public UUIDWrapper getUUIDWrapper() {
return UUIDHandler.getUUIDWrapper();
}
/**
* SchematicHandler class contains methods related to pasting, reading
* and writing schematics.

View File

@ -142,7 +142,7 @@ public class PlayerBackupProfile implements BackupProfile {
}
final List<Plot> plots = Collections.singletonList(plot);
final boolean result = SchematicHandler.manager.exportAll(plots, getBackupDirectory().toFile(),
"%world%-%id%-%owner%-" + System.currentTimeMillis(), () ->
"%world%-%id%-" + System.currentTimeMillis(), () ->
future.complete(new Backup(this, System.currentTimeMillis(), null)));
if (!result) {
future.completeExceptionally(new RuntimeException("Failed to complete the backup"));

View File

@ -32,13 +32,16 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "add",
description = "Allow a user to build in a plot while the plot owner is online.",
@ -53,7 +56,7 @@ public class Add extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> 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);
@ -62,51 +65,73 @@ public class Add extends Command {
.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> iterator = uuids.iterator();
int size = plot.getTrusted().size() + plot.getMembers().size();
while (iterator.hasNext()) {
UUID uuid = iterator.next();
if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (plot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (plot.getMembers().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
size += plot.getTrusted().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= plot.getArea().getMaxPlotMembers() || 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.removeTrusted(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
}
}
plot.addMember(uuid);
PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true);
MainUtil.sendMessage(player, Captions.MEMBER_ADDED);
}
}, null);
return CompletableFuture.completedFuture(true);
final CompletableFuture<Boolean> future = new CompletableFuture<>();
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable != null) {
if (throwable instanceof TimeoutException) {
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
} else {
Captions.INVALID_PLAYER.send(player, args[0]);
}
future.completeExceptionally(throwable);
return;
} else {
try {
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
Iterator<UUID> iterator = uuids.iterator();
int size = plot.getTrusted().size() + plot.getMembers().size();
while (iterator.hasNext()) {
UUID uuid = iterator.next();
if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (plot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (plot.getMembers().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
size += plot.getTrusted().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= plot.getArea().getMaxPlotMembers() || 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.removeTrusted(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
}
}
plot.addMember(uuid);
PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true);
MainUtil.sendMessage(player, Captions.MEMBER_ADDED);
}
}, null);
} catch (final Throwable exception) {
future.completeExceptionally(exception);
return;
}
}
future.complete(true);
});
return future;
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
}
}

View File

@ -33,19 +33,26 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringWrapper;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.util.query.PlotQuery;
@CommandDeclaration(command = "setalias",
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "alias",
permission = "plots.alias",
description = "Set the plot name",
usage = "/plot alias <set|remove> <alias>",
aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"},
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Alias extends SubCommand {
private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {};
private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {};
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
@ -63,13 +70,11 @@ public class Alias extends SubCommand {
return false;
}
if (!plot.isOwner(player.getUUID())) {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
boolean result = false;
boolean owner = plot.isOwner(player.getUUID());
boolean permission;
boolean admin;
switch (args[0].toLowerCase()) {
case "set":
if (args.length != 2) {
@ -77,17 +82,34 @@ public class Alias extends SubCommand {
return false;
}
if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET, false)
|| canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
result = setAlias(player, plot, args[1]);
permission = isPermitted(player, Captions.PERMISSION_ALIAS_SET)
|| isPermitted(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE);
admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_SET);
if (!admin && !owner) {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
if (permission) { // is either admin or owner
setAlias(player, plot, args[1]);
return true;
} else {
MainUtil.sendMessage(player, Captions.NO_PERMISSION);
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_ALIAS_SET.getTranslated());
}
break;
case "remove":
if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_REMOVE, true)) {
permission = isPermitted(player, Captions.PERMISSION_ALIAS_REMOVE);
admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_REMOVE);
if (!admin && !owner) {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
if (permission) {
result = removeAlias(player, plot);
} else {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_ALIAS_REMOVE.getTranslated());
}
break;
default:
@ -98,54 +120,58 @@ public class Alias extends SubCommand {
return result;
}
private boolean setAlias(PlotPlayer player, Plot plot, String alias) {
if (alias.isEmpty()) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return false;
}
if (alias.length() >= 50) {
MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
return false;
}
if (alias.contains(" ")) {
Captions.NOT_VALID_VALUE.send(player);
return false;
}
if (MathMan.isInteger(alias)) {
Captions.NOT_VALID_VALUE.send(player);
return false;
}
for (Plot p : PlotSquared.get().getPlots(plot.getArea())) {
if (p.getAlias().equalsIgnoreCase(alias)) {
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
return false;
@Override
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
final List<Command> commands = new ArrayList<>(2);
if (args.length == 1) {
if ("set".startsWith(args[0])) {
commands.add(SET_COMMAND);
}
if ("remove".startsWith(args[0])) {
commands.add(REMOVE_COMMAND);
}
return commands;
}
if (UUIDHandler.nameExists(new StringWrapper(alias)) || PlotSquared.get()
.hasPlotArea(alias)) {
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
return false;
}
plot.setAlias(alias);
MainUtil.sendMessage(player,
Captions.ALIAS_SET_TO.getTranslated().replaceAll("%alias%", alias));
return true;
return Collections.emptySet();
}
private boolean removeAlias(PlotPlayer player, Plot plot) {
private void setAlias(PlotPlayer player, Plot plot, String alias) {
if (alias.isEmpty()) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
} else if (alias.length() >= 50) {
MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
} else if (alias.contains(" ")) {
Captions.NOT_VALID_VALUE.send(player);
} else if (MathMan.isInteger(alias)) {
Captions.NOT_VALID_VALUE.send(player);
} else {
if (PlotQuery.newQuery().inArea(plot.getArea())
.withAlias(alias)
.anyMatch()) {
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
return;
}
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (uuid != null) {
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
} else {
plot.setAlias(alias);
MainUtil.sendMessage(player,
Captions.ALIAS_SET_TO.getTranslated().replaceAll("%alias%", alias));
}
}));
}
}
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
plot.setAlias(null);
MainUtil.sendMessage(player, Captions.ALIAS_REMOVED.getTranslated());
return true;
}
private boolean canExecuteCommand(PlotPlayer player, Captions caption, boolean sendMessage) {
if (!Permissions.hasPermission(player, caption)) {
if (sendMessage) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION);
}
return false;
}
return true;
private boolean isPermitted(PlotPlayer<?> player, Captions caption) {
return Permissions.hasPermission(player, caption);
}
}

View File

@ -33,26 +33,41 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.generator.HybridPlotWorld;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.RegionUtil;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal3;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
@ -68,12 +83,140 @@ import java.util.Set;
confirmation = true)
public class Area extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return false;
}
switch (args[0].toLowerCase()) {
case "single":
if (player instanceof ConsolePlayer) {
MainUtil.sendMessage(player, Captions.IS_CONSOLE);
return false;
}
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_CREATE)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_AREA_CREATE);
return false;
}
if (args.length < 2) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
return false;
}
final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]);
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
return false;
}
final LocalSession localSession = WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor());
if (localSession == null) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
return false;
}
Region playerSelectedRegion = null;
try {
playerSelectedRegion = localSession.getSelection(((Player) player.toActor()).getWorld());
} catch (final Exception ignored) {}
if (playerSelectedRegion == null) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
return false;
}
if (playerSelectedRegion.getWidth() != playerSelectedRegion.getLength()) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE);
return false;
}
if (PlotSquared.get().getPlotAreaManager().getPlotAreas(
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING);
}
// Alter the region
final BlockVector3 playerSelectionMin = playerSelectedRegion.getMinimumPoint();
final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
// Create a new selection that spans the entire vertical range of the world
final CuboidRegion selectedRegion = new CuboidRegion(playerSelectedRegion.getWorld(),
BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
// There's only one plot in the area...
final PlotId plotId = new PlotId(1, 1);
final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorld(), args[1],
Objects.requireNonNull(PlotSquared.imp()).getDefaultGenerator(), plotId, plotId);
// Plot size is the same as the region width
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
// We use a schematic generator
hybridPlotWorld.setTerrain(PlotAreaTerrainType.NONE);
// It is always a partial plot world
hybridPlotWorld.setType(PlotAreaType.PARTIAL);
// We save the schematic :D
hybridPlotWorld.PLOT_SCHEMATIC = true;
// Set the road width to 0
hybridPlotWorld.ROAD_WIDTH = hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0;
// Set the plot height to the selection height
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
// No sign plz
hybridPlotWorld.setAllowSigns(false);
final File parentFile = MainUtil.getFile(PlotSquared.imp().getDirectory(), "schematics" + File.separator +
"GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
hybridPlotWorld.getId());
if (!parentFile.exists() && !parentFile.mkdirs()) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_COULD_NOT_MAKE_DIRECTORIES);
return false;
}
final File file = new File(parentFile, "plot.schem");
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1);
final ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
forwardExtentCopy.setCopyingBiomes(true);
forwardExtentCopy.setCopyingEntities(true);
Operations.complete(forwardExtentCopy);
clipboardWriter.write(clipboard);
} catch (final Exception e) {
MainUtil.sendMessage(player, Captions.SINGLE_AREA_FAILED_TO_SAVE);
e.printStackTrace();
return false;
}
// Setup schematic
try {
hybridPlotWorld.setupSchematics();
} catch (final SchematicHandler.UnsupportedFormatException e) {
e.printStackTrace();
}
// Calculate the offset
final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint();
// Now the schematic is saved, which is wonderful!
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld)
.plotManager(PlotSquared.imp().getPluginName())
.generatorName(PlotSquared.imp().getPluginName())
.maximumId(plotId)
.minimumId(plotId);
Runnable singleRun = () -> {
final String path =
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-'
+ singleBuilder.minimumId() + '-' + singleBuilder.maximumId();
final int offsetX = singlePos1.getX();
final int offsetZ = singlePos1.getZ();
if (offsetX != 0) {
PlotSquared.get().worlds
.set(path + ".road.offset.x", offsetX);
}
if (offsetZ != 0) {
PlotSquared.get().worlds
.set(path + ".road.offset.z", offsetZ);
}
final String world = SetupUtils.manager.setupWorld(singleBuilder);
if (WorldUtil.IMP.isWorld(world)) {
PlotSquared.get().loadWorld(world, null);
MainUtil.sendMessage(player, Captions.SINGLE_AREA_CREATED);
} else {
MainUtil.sendMessage(player,
"An error occurred while creating the world: " + hybridPlotWorld
.getWorldName());
}
};
singleRun.run();
return true;
case "c":
case "setup":
case "create":
@ -138,19 +281,14 @@ public class Area extends SubCommand {
.send(player, areas.iterator().next().toString());
return false;
}
final SetupObject object = new SetupObject();
object.world = area.getWorldName();
object.id = area.getId();
object.terrain = area.getTerrain();
object.type = area.getType();
object.min = new PlotId(1, 1);
object.max = new PlotId(numX, numZ);
object.plotManager = PlotSquared.imp().getPluginName();
object.setupGenerator = PlotSquared.imp().getPluginName();
object.step = area.getSettingNodes();
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area)
.plotManager(PlotSquared.imp().getPluginName())
.generatorName(PlotSquared.imp().getPluginName())
.minimumId(new PlotId(1, 1))
.maximumId(new PlotId(numX, numZ));
final String path =
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-'
+ object.min + '-' + object.max;
+ builder.minimumId() + '-' + builder.maximumId();
Runnable run = () -> {
if (offsetX != 0) {
PlotSquared.get().worlds
@ -160,7 +298,7 @@ public class Area extends SubCommand {
PlotSquared.get().worlds
.set(path + ".road.offset.z", offsetZ);
}
final String world = SetupUtils.manager.setupWorld(object);
final String world = SetupUtils.manager.setupWorld(builder);
if (WorldUtil.IMP.isWorld(world)) {
PlotSquared.get().loadWorld(world, null);
Captions.SETUP_FINISHED.send(player);
@ -198,9 +336,9 @@ public class Area extends SubCommand {
} else {
id = null;
}
final SetupObject object = new SetupObject();
object.world = split[0];
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id,
PlotAreaBuilder builder = new PlotAreaBuilder();
builder.worldName(split[0]);
final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
PlotSquared.get().IMP.getDefaultGenerator(), null, null);
PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id);
if (other != null && Objects.equals(pa.getId(), other.getId())) {
@ -262,13 +400,13 @@ public class Area extends SubCommand {
pa.setTerrain(PlotAreaTerrainType.fromString(pair[1])
.orElseThrow(() -> new IllegalArgumentException(
pair[1] + " is not a valid terrain.")));
object.terrain = pa.getTerrain();
builder.terrainType(pa.getTerrain());
break;
case "type":
pa.setType(PlotAreaType.fromString(pair[1]).orElseThrow(
() -> new IllegalArgumentException(
pair[1] + " is not a valid type.")));
object.type = pa.getType();
builder.plotAreaType(pa.getType());
break;
default:
Captions.COMMAND_SYNTAX.send(player, getCommandString()
@ -290,9 +428,9 @@ public class Area extends SubCommand {
PlotSquared.get().worlds.getConfigurationSection(path);
pa.saveConfiguration(section);
pa.loadConfiguration(section);
object.plotManager = PlotSquared.imp().getPluginName();
object.setupGenerator = PlotSquared.imp().getPluginName();
String world = SetupUtils.manager.setupWorld(object);
builder.plotManager(PlotSquared.imp().getPluginName());
builder.generatorName(PlotSquared.imp().getPluginName());
String world = SetupUtils.manager.setupWorld(builder);
if (WorldUtil.IMP.isWorld(world)) {
Captions.SETUP_FINISHED.send(player);
player.teleport(WorldUtil.IMP.getSpawn(world),
@ -327,9 +465,9 @@ public class Area extends SubCommand {
TeleportCause.COMMAND);
}
} else {
object.terrain = PlotAreaTerrainType.NONE;
object.type = PlotAreaType.NORMAL;
SetupUtils.manager.setupWorld(object);
builder.terrainType(PlotAreaTerrainType.NONE);
builder.plotAreaType(PlotAreaType.NORMAL);
SetupUtils.manager.setupWorld(builder);
player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()),
TeleportCause.COMMAND);
}

View File

@ -154,12 +154,12 @@ public class Auto extends SubCommand {
() -> autoClaimFromDatabase(player, area, plot.getId(), whenDone));
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
PlotArea plotarea = player.getApplicablePlotArea();
if (plotarea == null) {
if (EconHandler.manager != null) {
if (EconHandler.getEconHandler() != null) {
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
if (EconHandler.manager
if (EconHandler.getEconHandler()
.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
if (plotarea != null) {
plotarea = null;
@ -253,18 +253,18 @@ public class Auto extends SubCommand {
return true;
}
}
if (EconHandler.manager != null && plotarea.useEconomy()) {
if (EconHandler.getEconHandler() != null && plotarea.useEconomy()) {
Expression<Double> costExp = plotarea.getPrices().get("claim");
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
player.getPlotCount() :
player.getPlotCount(plotarea.getWorldName())));
cost = (size_x * size_z) * cost;
if (cost > 0d) {
if (!force && EconHandler.manager.getMoney(player) < cost) {
if (!force && EconHandler.getEconHandler().getMoney(player) < cost) {
sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
EconHandler.manager.withdrawMoney(player, cost);
EconHandler.getEconHandler().withdrawMoney(player, cost);
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
}

View File

@ -70,7 +70,7 @@ public final class Backup extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length == 0 || !Arrays.asList("save", "list", "load")

View File

@ -37,7 +37,6 @@ import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@ -55,11 +54,11 @@ public class Buy extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) {
check(EconHandler.manager, Captions.ECON_DISABLED);
check(EconHandler.getEconHandler(), Captions.ECON_DISABLED);
final Plot plot;
if (args.length != 0) {
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
@ -82,10 +81,10 @@ public class Buy extends Command {
// Success
confirm.run(this, () -> {
Captions.REMOVED_BALANCE.send(player, price);
EconHandler.manager
.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.getOwnerAbs()),
price);
PlotPlayer owner = UUIDHandler.getPlayer(plot.getOwnerAbs());
EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
if (owner != null) {
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
}

View File

@ -50,7 +50,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
usage = "/plot caps")
public class Caps extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, final String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
return Captions.NOT_IN_PLOT.send(player);

View File

@ -37,7 +37,7 @@ import com.plotsquared.core.util.MainUtil;
requiredType = RequiredType.PLAYER)
public class Chat extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (player.getPlotAreaAbs().isForcingPlotChat()) {
MainUtil.sendMessage(player, Captions.PLOT_CHAT_FORCED);
return true;

View File

@ -54,7 +54,7 @@ import com.plotsquared.core.util.task.TaskManager;
usage = "/plot claim")
public class Claim extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String schematic = null;
if (args.length >= 1) {
schematic = args[0];
@ -105,14 +105,14 @@ public class Claim extends SubCommand {
}
}
}
if ((EconHandler.manager != null) && area.useEconomy() && !force) {
if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) {
Expression<Double> costExr = area.getPrices().get("claim");
double cost = costExr.evaluate((double) currentPlots);
if (cost > 0d) {
if (EconHandler.manager.getMoney(player) < cost) {
if (EconHandler.getEconHandler().getMoney(player) < cost) {
return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
}
EconHandler.manager.withdrawMoney(player, cost);
EconHandler.getEconHandler().withdrawMoney(player, cost);
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
}

View File

@ -64,7 +64,7 @@ public class Clear extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
checkTrue(args.length == 0, Captions.COMMAND_SYNTAX, getUsage());

View File

@ -39,12 +39,12 @@ import com.plotsquared.core.plot.PlotCluster;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "cluster",
aliases = "clusters",
@ -54,7 +54,7 @@ import java.util.UUID;
description = "Manage a plot cluster")
public class Cluster extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
if (args.length == 0) {
@ -371,22 +371,29 @@ public class Cluster extends SubCommand {
return false;
}
}
// check uuid
UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
return false;
}
if (!cluster.isAdded(uuid)) {
// add the user if not added
cluster.invited.add(uuid);
DBFunc.setInvited(cluster, uuid);
PlotPlayer player2 = UUIDHandler.getPlayer(uuid);
if (player2 != null) {
MainUtil.sendMessage(player2, Captions.CLUSTER_INVITED, cluster.getName());
}
}
MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_USER);
PlotSquared.get().getImpromptuUUIDPipeline()
.getSingle(args[1], (uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
} else {
if (!cluster.isAdded(uuid)) {
// add the user if not added
cluster.invited.add(uuid);
DBFunc.setInvited(cluster, uuid);
final PlotPlayer otherPlayer =
PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (otherPlayer != null) {
MainUtil.sendMessage(otherPlayer, Captions.CLUSTER_INVITED,
cluster.getName());
}
}
MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_USER);
}
});
return true;
}
case "k":
@ -420,35 +427,43 @@ public class Cluster extends SubCommand {
}
}
// check uuid
UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
return false;
}
// Can't kick if the player is yourself, the owner, or not added to the cluster
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner) || !cluster
.isAdded(uuid)) {
MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER, cluster.getName());
return false;
}
if (cluster.helpers.contains(uuid)) {
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
PlotPlayer player2 = UUIDHandler.getPlayer(uuid);
if (player2 != null) {
MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED, cluster.getName());
}
for (Plot plot : new ArrayList<>(
PlotSquared.get().getPlots(player2.getLocation().getWorld(), uuid))) {
PlotCluster current = plot.getCluster();
if (current != null && current.equals(cluster)) {
plot.unclaim();
}
}
MainUtil.sendMessage(player2, Captions.CLUSTER_KICKED_USER);
PlotSquared.get().getImpromptuUUIDPipeline()
.getSingle(args[1], (uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
} else {
// Can't kick if the player is yourself, the owner, or not added to the cluster
if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner)
|| !cluster.isAdded(uuid)) {
MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER,
cluster.getName());
} else {
if (cluster.helpers.contains(uuid)) {
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
}
cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid);
final PlotPlayer player2 =
PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (player2 != null) {
MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED,
cluster.getName());
}
for (Plot plot : new ArrayList<>(PlotSquared.get()
.getPlots(player2.getLocation().getWorld(), uuid))) {
PlotCluster current = plot.getCluster();
if (current != null && current.equals(cluster)) {
plot.unclaim();
}
}
MainUtil.sendMessage(player2, Captions.CLUSTER_KICKED_USER);
}
}
});
return true;
}
case "quit":
@ -529,24 +544,29 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER);
return false;
}
UUID uuid = UUIDHandler.getUUID(args[2], null);
if (uuid == null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
return false;
}
if (args[1].equalsIgnoreCase("add")) {
cluster.helpers.add(uuid);
DBFunc.setHelper(cluster, uuid);
return MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER);
}
if (args[1].equalsIgnoreCase("remove")) {
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
return MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER);
}
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
"/plot cluster helpers <add|remove> <player>");
return false;
PlotSquared.get().getImpromptuUUIDPipeline()
.getSingle(args[2], (uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
} else {
if (args[1].equalsIgnoreCase("add")) {
cluster.helpers.add(uuid);
DBFunc.setHelper(cluster, uuid);
MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER);
} else if (args[1].equalsIgnoreCase("remove")) {
cluster.helpers.remove(uuid);
DBFunc.removeHelper(cluster, uuid);
MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER);
} else {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
"/plot cluster helpers <add|remove> <player>");
}
}
});
return true;
}
case "spawn":
case "home":
@ -615,21 +635,31 @@ public class Cluster extends SubCommand {
}
}
String id = cluster.toString();
String owner = UUIDHandler.getName(cluster.owner);
if (owner == null) {
owner = "unknown";
}
String name = cluster.getName();
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
cluster.getP2().y - cluster.getP1().y + 1);
String rights = cluster.isAdded(player.getUUID()) + "";
String message = Captions.CLUSTER_INFO.getTranslated();
message = message.replaceAll("%id%", id);
message = message.replaceAll("%owner%", owner);
message = message.replaceAll("%name%", name);
message = message.replaceAll("%size%", size);
message = message.replaceAll("%rights%", rights);
MainUtil.sendMessage(player, message);
PlotSquared.get().getImpromptuUUIDPipeline()
.getSingle(cluster.owner, (username, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else {
final String owner;
if (username == null) {
owner = "unknown";
} else {
owner = username;
}
String name = cluster.getName();
String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
cluster.getP2().y - cluster.getP1().y + 1);
String rights = cluster.isAdded(player.getUUID()) + "";
String message = Captions.CLUSTER_INFO.getTranslated();
message = message.replaceAll("%id%", id);
message = message.replaceAll("%owner%", owner);
message = message.replaceAll("%name%", name);
message = message.replaceAll("%size%", size);
message = message.replaceAll("%rights%", rights);
MainUtil.sendMessage(player, message);
}
});
return true;
}
case "sh":

View File

@ -32,15 +32,15 @@ import com.plotsquared.core.util.task.TaskManager;
public class CmdConfirm {
public static CmdInstance getPending(PlotPlayer player) {
public static CmdInstance getPending(PlotPlayer<?> player) {
return player.getMeta("cmdConfirm");
}
public static void removePending(PlotPlayer player) {
public static void removePending(PlotPlayer<?> player) {
player.deleteMeta("cmdConfirm");
}
public static void addPending(final PlotPlayer player, String commandStr,
public static void addPending(final PlotPlayer<?> player, String commandStr,
final Runnable runnable) {
removePending(player);
if (commandStr != null) {

View File

@ -37,6 +37,8 @@ import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@ -104,7 +106,7 @@ public abstract class Command {
&& types[4] == RunnableVal2.class) {
Command tmp = new Command(this, true) {
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
try {
@ -298,7 +300,7 @@ public abstract class Command {
* @return CompletableFuture true if the command executed fully, false in
* any other case
*/
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length == 0 || args[0] == null) {
@ -603,6 +605,10 @@ public abstract class Command {
return object;
}
@SneakyThrows protected static void sneakyThrow(@NotNull final Throwable throwable) {
throw throwable;
}
public enum CommandResult {
FAILURE, SUCCESS
}

View File

@ -25,6 +25,7 @@
*/
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@ -33,11 +34,9 @@ import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.comment.PlotComment;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map.Entry;
@CommandDeclaration(command = "comment",
aliases = {"msg"},
@ -47,7 +46,7 @@ import java.util.Map.Entry;
permission = "plots.comment")
public class Comment extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length < 2) {
sendMessage(player, Captions.COMMENT_SYNTAX,
StringMan.join(CommentManager.inboxes.keySet(), "|"));
@ -96,12 +95,13 @@ public class Comment extends SubCommand {
StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue();
for (final PlotPlayer pp : PlotSquared.imp().getPlayerManager().getPlayers()) {
if (pp.getAttribute("chatspy")) {
MainUtil.sendMessage(pp, "/plot comment " + StringMan.join(args, " "));
}
}
sendMessage(player, Captions.COMMENT_ADDED);
return true;
}

View File

@ -54,7 +54,7 @@ public class Condense extends SubCommand {
public static boolean TASK = false;
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length != 2 && args.length != 3) {
MainUtil.sendMessage(player, getUsage());
return false;

View File

@ -37,7 +37,7 @@ import com.plotsquared.core.util.task.TaskManager;
category = CommandCategory.INFO)
public class Confirm extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
CmdInstance command = CmdConfirm.getPending(player);
if (command == null) {
MainUtil.sendMessage(player, Captions.FAILED_CONFIRM);

View File

@ -44,7 +44,7 @@ import com.plotsquared.core.util.Permissions;
requiredType = RequiredType.PLAYER)
public class Continue extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Plot plot = player.getCurrentPlot();
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(player, Captions.NOT_IN_PLOT);

View File

@ -41,7 +41,7 @@ import com.plotsquared.core.util.Permissions;
requiredType = RequiredType.NONE)
public class Copy extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot1 = location.getPlotAbs();
if (plot1 == null) {

View File

@ -42,7 +42,7 @@ import com.plotsquared.core.util.MainUtil;
usage = "/plot createroadschematic")
public class CreateRoadSchematic extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {

View File

@ -74,7 +74,7 @@ public class DatabaseCommand extends SubCommand {
});
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length < 1) {
MainUtil.sendMessage(player, getUsage());
return false;

View File

@ -34,8 +34,10 @@ import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.entity.EntityCategory;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.uuid.UUIDMapping;
import com.sk89q.worldedit.world.entity.EntityType;
import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
@ -46,7 +48,7 @@ import java.util.Map;
permission = "plots.admin")
public class Debug extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length > 0) {
if ("player".equalsIgnoreCase(args[0])) {
for (Map.Entry<String, Object> meta : player.getMeta().entrySet()) {
@ -65,6 +67,18 @@ public class Debug extends SubCommand {
.currentThread().getName()));
return true;
}
if (args.length > 0 && "uuids".equalsIgnoreCase(args[0])) {
final Collection<UUIDMapping> mappings = PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
MainUtil.sendMessage(player, String.format("There are %d cached UUIDs", mappings.size()));
return true;
}
if (args.length > 0 && "debug-players".equalsIgnoreCase(args[0])) {
MainUtil.sendMessage(player, "Player in debug mode: " );
for (final PlotPlayer<?> pp : PlotPlayer.getDebugModePlayers()) {
MainUtil.sendMessage(player, "- " + pp.getName());
}
return true;
}
if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) {
EntityCategories.init();
player.sendMessage(Captions.PREFIX.getTranslated() + "§cEntity Categories: ");

View File

@ -42,7 +42,7 @@ public class DebugAllowUnsafe extends SubCommand {
public static final List<UUID> unsafeAllowed = new ArrayList<>();
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (unsafeAllowed.contains(player.getUUID())) {
unsafeAllowed.remove(player.getUUID());

View File

@ -1,134 +0,0 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* 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, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.command;
import com.google.common.collect.BiMap;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.StringWrapper;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.math.BlockVector2;
import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugclaimtest",
description =
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from plot signs. "
+ "Execution time may vary",
category = CommandCategory.DEBUG,
requiredType = RequiredType.CONSOLE,
permission = "plots.debugclaimtest")
public class DebugClaimTest extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length < 3) {
return !MainUtil.sendMessage(null,
"If you accidentally delete your database, this command will attempt to restore all plots based on the data from the "
+ "plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}");
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[0]);
if (area == null || !WorldUtil.IMP.isWorld(area.getWorldName())) {
Captions.NOT_VALID_PLOT_WORLD.send(player, args[0]);
return false;
}
PlotId min, max;
try {
args[1].split(";");
args[2].split(";");
min = PlotId.fromString(args[1]);
max = PlotId.fromString(args[2]);
} catch (Exception ignored) {
return !MainUtil.sendMessage(player,
"&cInvalid min/max values. &7The values are to Plot IDs in the format &cX;Y &7where X;Y are the plot coords\nThe conversion "
+ "will only check the plots in the selected area.");
}
MainUtil.sendMessage(player,
"&3Sign Block&8->&3Plot&8: &7Beginning sign to plot conversion. This may take a while...");
MainUtil.sendMessage(player,
"&3Sign Block&8->&3Plot&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)");
PlotManager manager = area.getPlotManager();
CompletableFuture.runAsync(() -> {
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(min, max);
MainUtil.sendMessage(player,
"&3Sign Block&8->&3Plot&8: " + ids.size() + " plot ids to check!");
for (PlotId id : ids) {
Plot plot = area.getPlotAbs(id);
if (plot.hasOwner()) {
MainUtil.sendMessage(player, " - &cDB Already contains: " + plot.getId());
continue;
}
Location location = manager.getSignLoc(plot);
BlockVector2 chunk = BlockVector2.at(location.getX() >> 4, location.getZ() >> 4);
ChunkManager.manager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
String[] lines = WorldUtil.IMP.getSignSynchronous(location);
if (lines != null) {
String line = lines[2];
if (line != null && line.length() > 2) {
line = line.substring(2);
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
UUID uuid = map.get(new StringWrapper(line));
if (uuid == null) {
for (Map.Entry<StringWrapper, UUID> stringWrapperUUIDEntry : map
.entrySet()) {
if (stringWrapperUUIDEntry.getKey().value.toLowerCase()
.startsWith(line.toLowerCase())) {
uuid = stringWrapperUUIDEntry.getValue();
break;
}
}
}
if (uuid == null) {
uuid = UUIDHandler.getUUID(line, null);
}
if (uuid != null) {
MainUtil.sendMessage(player,
" - &aFound plot: " + plot.getId() + " : " + line);
plot.setOwner(uuid);
MainUtil.sendMessage(player, " - &8Updated plot: " + plot.getId());
} else {
MainUtil.sendMessage(player,
" - &cInvalid PlayerName: " + plot.getId() + " : " + line);
}
}
}
}).join();
}
}).thenRun(() -> MainUtil.sendMessage(player, "&3Sign Block&8->&3Plot&8: Finished scan."));
return true;
}
}

View File

@ -35,7 +35,6 @@ import com.plotsquared.core.events.Result;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
@ -59,7 +58,6 @@ import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.world.block.BlockState;
import javax.script.Bindings;
@ -71,13 +69,10 @@ import javax.script.SimpleScriptContext;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugexec",
@ -171,8 +166,7 @@ public class DebugExec extends SubCommand {
this.scope.put("BlockManager", WorldUtil.IMP);
this.scope.put("SetupUtils", SetupUtils.manager);
this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher());
this.scope.put("EconHandler", EconHandler.manager);
this.scope.put("UUIDHandler", UUIDHandler.implementation);
this.scope.put("EconHandler", EconHandler.getEconHandler());
this.scope.put("DBFunc", DBFunc.dbManager);
this.scope.put("HybridUtils", HybridUtils.manager);
this.scope.put("IMP", PlotSquared.get().IMP);
@ -184,7 +178,7 @@ public class DebugExec extends SubCommand {
}
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
List<String> allowed_params = Arrays
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
@ -301,27 +295,6 @@ public class DebugExec extends SubCommand {
} else {
return MainUtil.sendMessage(player, "Plot expiry task already started");
}
case "seen":
if (args.length != 2) {
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
}
UUID uuid = UUIDHandler.getUUID(args[1], null);
if (uuid == null) {
return MainUtil.sendMessage(player, "Player not found: " + args[1]);
}
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
if (op == null || op.getLastPlayed() == 0) {
return MainUtil
.sendMessage(player, "Player hasn't connected before: " + args[1]);
}
Timestamp stamp = new Timestamp(op.getLastPlayed());
Date date = new Date(stamp.getTime());
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
MainUtil.sendMessage(player, "UUID: " + uuid);
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
return true;
case "h":
case "he":
case "?":
@ -339,7 +312,7 @@ public class DebugExec extends SubCommand {
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
RequiredType.NONE, CommandCategory.DEBUG) {
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player,
String[] args, RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
try {

View File

@ -27,6 +27,7 @@ package com.plotsquared.core.command;
import com.google.common.base.Charsets;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
@ -35,7 +36,6 @@ import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.io.File;
import java.util.UUID;
@ -52,7 +52,7 @@ public class DebugImportWorlds extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
@ -76,7 +76,8 @@ public class DebugImportWorlds extends Command {
if (name.length() > 16) {
uuid = UUID.fromString(name);
} else {
uuid = UUIDHandler.getUUID(name, null);
Captions.FETCHING_PLAYER.send(player);
uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(name, 60000L);
}
if (uuid == null) {
uuid =

View File

@ -37,7 +37,7 @@ import com.plotsquared.core.player.PlotPlayer;
requiredType = RequiredType.CONSOLE)
public class DebugLoadTest extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
PlotSquared.get().plots_tmp = DBFunc.getPlots();
return true;
}

View File

@ -35,7 +35,6 @@ import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.net.IncendoPaster;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import lombok.NonNull;
import java.io.BufferedReader;
@ -72,7 +71,7 @@ public class DebugPaste extends SubCommand {
return content.toString();
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
TaskManager.runTaskAsync(() -> {
try {
@ -90,7 +89,7 @@ public class DebugPaste extends SubCommand {
b.append("# Server Information\n");
b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation())
.append("\n");
b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';')
b.append("online_mode: ").append(!Settings.UUID.OFFLINE).append(';')
.append(!Settings.UUID.OFFLINE).append('\n');
b.append("Plugins:");
for (Map.Entry<Map.Entry<String, String>, Boolean> pluginInfo : PlotSquared
@ -122,7 +121,7 @@ public class DebugPaste extends SubCommand {
b.append("OS Arch: ").append(System.getProperty("os.arch")).append('\n');
b.append("# Okay :D Great. You are now ready to create your bug report!");
b.append(
"\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
"\n# You can do so at https://issues.intellectualsites.com/projects/ps");
b.append("\n# or via our Discord at https://discord.gg/KxkjDVg");
final IncendoPaster incendoPaster = new IncendoPaster("plotsquared");

View File

@ -46,7 +46,7 @@ import java.util.Arrays;
public class DebugRoadRegen extends SubCommand {
public static final String USAGE = "/plot debugroadregen <plot|region [height]>";
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length < 1) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE);
return false;

View File

@ -41,7 +41,7 @@ import java.util.ArrayList;
description = "This command will force the recreation of all plots in the DB")
public class DebugSaveTest extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
ArrayList<Plot> plots = new ArrayList<>(PlotSquared.get().getPlots());
MainUtil.sendMessage(player, "&6Starting `DEBUGSAVETEST`");
DBFunc.createPlotsAndData(plots,

View File

@ -53,7 +53,7 @@ public class Delete extends SubCommand {
// Note: To delete a specific plot use /plot <plot> delete
// The syntax also works with any command: /plot <plot> <command>
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
@ -86,11 +86,11 @@ public class Delete extends SubCommand {
final long start = System.currentTimeMillis();
boolean result = plot.deletePlot(() -> {
plot.removeRunning();
if ((EconHandler.manager != null) && plotArea.useEconomy()) {
if ((EconHandler.getEconHandler() != null) && plotArea.useEconomy()) {
Expression<Double> valueExr = plotArea.getPrices().get("sell");
double value = plots.size() * valueExr.evaluate((double) currentPlots);
if (value > 0d) {
EconHandler.manager.depositMoney(player, value);
EconHandler.getEconHandler().depositMoney(player, value);
sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value));
}
}

View File

@ -33,12 +33,14 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.world.gamemode.GameModes;
import java.util.Set;
import java.util.Collection;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "deny",
aliases = {"d", "ban"},
@ -52,7 +54,7 @@ public class Deny extends SubCommand {
super(Argument.PlayerName);
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
@ -68,51 +70,55 @@ public class Deny extends SubCommand {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return true;
}
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (uuids.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return false;
}
for (UUID uuid : uuids) {
if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
continue;
}
if (plot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid));
return false;
}
if (plot.getDenied().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
return false;
}
if (uuid != DBFunc.EVERYONE) {
plot.removeMember(uuid);
plot.removeTrusted(uuid);
}
plot.addDenied(uuid);
PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true);
if (!uuid.equals(DBFunc.EVERYONE)) {
handleKick(UUIDHandler.getPlayer(uuid), plot);
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null || uuids.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else {
for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
// Ignore plot-owners
if (plot.isAdded(plotPlayer.getUUID())) {
continue;
for (UUID uuid : uuids) {
if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
} else if (plot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid));
return;
} else if (plot.getDenied().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
return;
} else {
if (uuid != DBFunc.EVERYONE) {
plot.removeMember(uuid);
plot.removeTrusted(uuid);
}
plot.addDenied(uuid);
PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true);
if (!uuid.equals(DBFunc.EVERYONE)) {
handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid), plot);
} else {
for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
// Ignore plot-owners
if (plot.isAdded(plotPlayer.getUUID())) {
continue;
}
handleKick(plotPlayer, plot);
}
}
}
handleKick(plotPlayer, plot);
}
MainUtil.sendMessage(player, Captions.DENIED_ADDED);
}
}
if (!uuids.isEmpty()) {
MainUtil.sendMessage(player, Captions.DENIED_ADDED);
}
});
return true;
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
}
private void handleKick(PlotPlayer player, Plot plot) {
if (player == null) {
return;

View File

@ -35,7 +35,7 @@ import com.plotsquared.core.player.PlotPlayer;
requiredType = RequiredType.PLAYER)
public class Dislike extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
return Like.handleLike(player, args, false);
}

View File

@ -51,7 +51,7 @@ import com.plotsquared.core.util.task.RunnableVal;
requiredType = RequiredType.NONE)
public class Done extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if ((plot == null) || !plot.hasOwner()) {

View File

@ -50,7 +50,7 @@ import java.net.URL;
permission = "plots.download")
public class Download extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);

View File

@ -207,7 +207,7 @@ public final class FlagCommand extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length == 0 || !Arrays

View File

@ -26,6 +26,7 @@
package com.plotsquared.core.command;
import com.google.common.primitives.Ints;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.database.DBFunc;
@ -35,10 +36,10 @@ import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "grant",
category = CommandCategory.CLAIMING,
@ -52,7 +53,7 @@ public class Grant extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
checkTrue(args.length >= 1 && args.length <= 2, Captions.COMMAND_SYNTAX, getUsage());
@ -69,43 +70,44 @@ public class Grant extends Command {
if (args.length > 2) {
break;
}
final UUID uuid;
if (args.length == 2) {
uuid = UUIDHandler.getUUIDFromString(args[1]);
} else {
uuid = player.getUUID();
}
if (uuid == null) {
Captions.INVALID_PLAYER.send(player, args[1]);
return CompletableFuture.completedFuture(false);
}
MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal<byte[]>() {
@Override public void run(byte[] array) {
if (arg0.equals("check")) { // check
int granted;
if (array == null) {
granted = 0;
} else {
granted = Ints.fromByteArray(array);
MainUtil.getUUIDsFromString(args[1], (uuids, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null || uuids.size() != 1) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
} else {
final UUID uuid = uuids.toArray(new UUID[0])[0];
MainUtil.getPersistentMeta(uuid,
"grantedPlots", new RunnableVal<byte[]>() {
@Override public void run(byte[] array) {
if (arg0.equals("check")) { // check
int granted;
if (array == null) {
granted = 0;
} else {
granted = Ints.fromByteArray(array);
}
Captions.GRANTED_PLOTS.send(player, granted);
} else { // add
int amount;
if (array == null) {
amount = 1;
} else {
amount = 1 + Ints.fromByteArray(array);
}
boolean replace = array != null;
String key = "grantedPlots";
byte[] rawData = Ints.toByteArray(amount);
PlotPlayer online = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (online != null) {
online.setPersistentMeta(key, rawData);
} else {
DBFunc.addPersistentMeta(uuid, key, rawData, replace);
}
}
}
Captions.GRANTED_PLOTS.send(player, granted);
} else { // add
int amount;
if (array == null) {
amount = 1;
} else {
amount = 1 + Ints.fromByteArray(array);
}
boolean replace = array != null;
String key = "grantedPlots";
byte[] rawData = Ints.toByteArray(amount);
PlotPlayer online = UUIDHandler.getPlayer(uuid);
if (online != null) {
online.setPersistentMeta(key, rawData);
} else {
DBFunc.addPersistentMeta(uuid, key, rawData, replace);
}
}
});
}
});
return CompletableFuture.completedFuture(true);

View File

@ -52,7 +52,7 @@ public class Help extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
switch (args.length) {

View File

@ -86,7 +86,7 @@ public class Inbox extends SubCommand {
MainUtil.sendMessage(player, string.toString());
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
sendMessage(player, Captions.NOT_IN_PLOT);

View File

@ -41,7 +41,7 @@ import com.plotsquared.core.util.task.RunnableVal;
category = CommandCategory.INFO)
public class Info extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Plot plot;
String arg;
if (args.length > 0) {

View File

@ -33,12 +33,15 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "kick",
aliases = "k",
@ -53,7 +56,7 @@ public class Kick extends SubCommand {
super(Argument.PlayerName);
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlot();
if (plot == null) {
@ -64,57 +67,72 @@ public class Kick extends SubCommand {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (uuids.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return false;
}
Set<PlotPlayer> players = new HashSet<>();
for (UUID uuid : uuids) {
if (uuid == DBFunc.EVERYONE) {
for (PlotPlayer pp : plot.getPlayersInPlot()) {
if (pp == player || Permissions
.hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null || uuids.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else {
Set<PlotPlayer<?>> players = new HashSet<>();
for (UUID uuid : uuids) {
if (uuid == DBFunc.EVERYONE) {
for (PlotPlayer<?> pp : plot.getPlayersInPlot()) {
if (pp == player || Permissions
.hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
continue;
}
players.add(pp);
}
continue;
}
players.add(pp);
PlotPlayer<?> pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (pp != null) {
players.add(pp);
}
}
continue;
}
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if (pp != null) {
players.add(pp);
}
}
players.remove(player); // Don't ever kick the calling player
if (players.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return false;
}
for (PlotPlayer player2 : players) {
if (!plot.equals(player2.getCurrentPlot())) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return false;
}
if (Permissions.hasPermission(player2, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
Captions.CANNOT_KICK_PLAYER.send(player, player2.getName());
return false;
}
Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
Captions.YOU_GOT_KICKED.send(player2);
if (plot.equals(spawn.getPlot())) {
Location newSpawn = WorldUtil.IMP
.getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]);
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
player2.kick(Captions.YOU_GOT_KICKED.getTranslated());
} else {
player2.plotkick(newSpawn);
players.remove(player); // Don't ever kick the calling player
if (players.isEmpty()) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return;
}
for (PlotPlayer<?> player2 : players) {
if (!plot.equals(player2.getCurrentPlot())) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return;
}
if (Permissions.hasPermission(player2, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
Captions.CANNOT_KICK_PLAYER.send(player, player2.getName());
return;
}
Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
Captions.YOU_GOT_KICKED.send(player2);
if (plot.equals(spawn.getPlot())) {
Location newSpawn = WorldUtil.IMP
.getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]);
if (plot.equals(newSpawn.getPlot())) {
// Kick from server if you can't be teleported to spawn
player2.kick(Captions.YOU_GOT_KICKED.getTranslated());
} else {
player2.plotkick(newSpawn);
}
} else {
player2.plotkick(spawn);
}
}
} else {
player2.plotkick(spawn);
}
}
});
return true;
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
return Collections.emptyList();
}
return TabCompletions.completePlayersInPlot(plot, String.join(",", args).trim(),
Collections.singletonList(player.getName()));
}
}

View File

@ -48,7 +48,7 @@ public class Leave extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(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);

View File

@ -175,7 +175,7 @@ public class Like extends SubCommand {
return numLikes / (numLikes + numDislikes);
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
return handleLike(player, args, true);
}

View File

@ -26,13 +26,12 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.PlotSquared.SortType;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
@ -43,26 +42,36 @@ import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.query.SortingStrategy;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.uuid.UUIDMapping;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@CommandDeclaration(command = "list",
aliases = {"l", "find", "search"},
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO,
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|unknown|player|world|done|fuzzy <search...>> [#]")
usage = "/plot list <forsale|mine|shared|world|top|all|unowned|player|world|done|fuzzy <search...>> [#]")
public class ListCmd extends SubCommand {
private String[] getArgumentList(PlotPlayer player) {
List<String> args = new ArrayList<>();
if (EconHandler.manager != null && Permissions
if (EconHandler.getEconHandler() != null && Permissions
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
args.add("forsale");
}
@ -84,9 +93,6 @@ public class ListCmd extends SubCommand {
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
args.add("unowned");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNKNOWN)) {
args.add("unknown");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
args.add("<player>");
}
@ -110,30 +116,58 @@ public class ListCmd extends SubCommand {
.toString(getArgumentList(player)));
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length < 1) {
noArgs(player);
return false;
}
int page = 0;
final int page;
if (args.length > 1) {
int tempPage = -1;
try {
page = Integer.parseInt(args[args.length - 1]);
--page;
if (page < 0) {
page = 0;
tempPage = Integer.parseInt(args[args.length - 1]);
--tempPage;
if (tempPage < 0) {
tempPage = 0;
}
} catch (NumberFormatException ignored) {
page = -1;
}
page = tempPage;
} else {
page = 0;
}
List<Plot> plots = null;
String world = player.getLocation().getWorld();
PlotArea area = player.getApplicablePlotArea();
String arg = args[0].toLowerCase();
boolean sort = true;
final boolean[] sort = new boolean[] {true};
final Consumer<PlotQuery> plotConsumer = query -> {
if (query == null) {
sendMessage(player, Captions.DID_YOU_MEAN,
new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"})
.getBestMatch());
return;
}
if (area != null) {
query.relativeToArea(area);
}
if (sort[0]) {
query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
}
final List<Plot> plots = query.asList();
if (plots.isEmpty()) {
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
return;
}
displayPlots(player, plots, 12, page, args);
};
switch (arg) {
case "mine":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) {
@ -141,8 +175,8 @@ public class ListCmd extends SubCommand {
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_MINE);
return false;
}
sort = false;
plots = PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getBasePlots(player));
sort[0] = false;
plotConsumer.accept(PlotQuery.newQuery().ownedBy(player).whereBasePlot().withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
break;
case "shared":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_SHARED)) {
@ -150,13 +184,7 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_SHARED);
return false;
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
if (plot.getTrusted().contains(player.getUUID()) || plot.getMembers()
.contains(player.getUUID())) {
plots.add(plot);
}
}
plotConsumer.accept(PlotQuery.newQuery().withMember(player.getUUID()).thatPasses(plot -> !plot.isOwnerAbs(player.getUUID())));
break;
case "world":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
@ -171,7 +199,7 @@ public class ListCmd extends SubCommand {
world));
return false;
}
plots = new ArrayList<>(PlotSquared.get().getPlots(world));
plotConsumer.accept(PlotQuery.newQuery().inWorld(world));
break;
case "expired":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_EXPIRED)) {
@ -179,9 +207,11 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_EXPIRED);
return false;
}
plots = ExpireManager.IMP == null ?
new ArrayList<Plot>() :
new ArrayList<>(ExpireManager.IMP.getPendingExpired());
if (ExpireManager.IMP == null) {
plotConsumer.accept(PlotQuery.newQuery().noPlots());
} else {
plotConsumer.accept(PlotQuery.newQuery().expiredPlots());
}
break;
case "area":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_AREA)) {
@ -196,7 +226,11 @@ public class ListCmd extends SubCommand {
world));
return false;
}
plots = area == null ? new ArrayList<Plot>() : new ArrayList<>(area.getPlots());
if (area == null) {
plotConsumer.accept(PlotQuery.newQuery().noPlots());
} else {
plotConsumer.accept(PlotQuery.newQuery().inArea(area));
}
break;
case "all":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_ALL)) {
@ -204,7 +238,7 @@ public class ListCmd extends SubCommand {
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_ALL);
return false;
}
plots = new ArrayList<>(PlotSquared.get().getPlots());
plotConsumer.accept(PlotQuery.newQuery().allPlots());
break;
case "done":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_DONE)) {
@ -212,24 +246,8 @@ public class ListCmd extends SubCommand {
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_DONE);
return false;
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
if (DoneFlag.isDone(plot)) {
plots.add(plot);
}
}
plots.sort((a, b) -> {
String va = a.getFlag(DoneFlag.class);
String vb = b.getFlag(DoneFlag.class);
if (MathMan.isInteger(va)) {
if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va);
}
return -1;
}
return 1;
});
sort = false;
sort[0] = false;
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(DoneFlag::isDone).withSortingStrategy(SortingStrategy.SORT_BY_DONE));
break;
case "top":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_TOP)) {
@ -237,32 +255,8 @@ public class ListCmd extends SubCommand {
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_TOP);
return false;
}
plots = new ArrayList<>(PlotSquared.get().getPlots());
plots.sort((p1, p2) -> {
double v1 = 0;
int p1s = p1.getSettings().getRatings().size();
int p2s = p2.getRatings().size();
if (!p1.getSettings().getRatings().isEmpty()) {
v1 = p1.getRatings().values().stream().mapToDouble(Rating::getAverageRating)
.map(av -> av * av).sum();
v1 /= p1s;
v1 += p1s;
}
double v2 = 0;
if (!p2.getSettings().getRatings().isEmpty()) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
v2 += av * av;
}
v2 /= p2s;
v2 += p2s;
}
if (v2 == v1 && v2 != 0) {
return p2s - p1s;
}
return (int) Math.signum(v2 - v1);
});
sort = false;
sort[0] = false;
plotConsumer.accept(PlotQuery.newQuery().allPlots().withSortingStrategy(SortingStrategy.SORT_BY_RATING));
break;
case "forsale":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
@ -270,15 +264,10 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_FOR_SALE);
return false;
}
if (EconHandler.manager == null) {
if (EconHandler.getEconHandler() == null) {
break;
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
if (plot.getFlag(PriceFlag.class) > 0) {
plots.add(plot);
}
}
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getFlag(PriceFlag.class) > 0));
break;
case "unowned":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
@ -286,28 +275,7 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_UNOWNED);
return false;
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
if (plot.getOwner() == null) {
plots.add(plot);
}
}
break;
case "unknown":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNKNOWN)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_LIST_UNKNOWN);
return false;
}
plots = new ArrayList<>();
for (Plot plot : PlotSquared.get().getPlots()) {
if (plot.getOwner() == null) {
continue;
}
if (UUIDHandler.getName(plot.getOwner()) == null) {
plots.add(plot);
}
}
plotConsumer.accept(PlotQuery.newQuery().allPlots().thatPasses(plot -> plot.getOwner() == null));
break;
case "fuzzy":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_FUZZY)) {
@ -325,8 +293,8 @@ public class ListCmd extends SubCommand {
} else {
term = StringMan.join(Arrays.copyOfRange(args, 1, args.length), " ");
}
plots = MainUtil.getPlotsBySearch(term);
sort = false;
sort[0] = false;
plotConsumer.accept(PlotQuery.newQuery().plotsBySearch(term));
break;
default:
if (PlotSquared.get().hasPlotArea(args[0])) {
@ -343,50 +311,43 @@ public class ListCmd extends SubCommand {
args[0]));
return false;
}
plots = new ArrayList<>(PlotSquared.get().getPlots(args[0]));
break;
}
UUID uuid = UUIDHandler.getUUID(args[0], null);
if (uuid == null) {
try {
uuid = UUID.fromString(args[0]);
} catch (Exception ignored) {
}
}
if (uuid != null) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_LIST_PLAYER);
return false;
}
sort = false;
plots = PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getPlots(uuid));
plotConsumer.accept(PlotQuery.newQuery().inWorld(args[0]));
break;
}
PlotSquared.get().getImpromptuUUIDPipeline()
.getSingle(args[0], (uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null) {
if (uuid == null) {
try {
uuid = UUID.fromString(args[0]);
} catch (Exception ignored) {
}
}
}
if (uuid == null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else {
if (!Permissions
.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
Captions.PERMISSION_LIST_PLAYER);
} else {
sort[0] = false;
plotConsumer.accept(PlotQuery.newQuery().ownedBy(uuid).withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
}
}
});
}
if (plots == null) {
sendMessage(player, Captions.DID_YOU_MEAN,
new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"})
.getBestMatch());
return false;
}
if (plots.isEmpty()) {
MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
return false;
}
displayPlots(player, plots, 12, page, area, args, sort);
return true;
}
public void displayPlots(final PlotPlayer player, List<Plot> plots, int pageSize, int page,
PlotArea area, String[] args, boolean sort) {
public void displayPlots(final PlotPlayer player, List<Plot> plots, int pageSize, int page, String[] args) {
// Header
plots.removeIf(plot -> !plot.isBasePlot());
if (sort) {
plots = PlotSquared.get().sortPlots(plots, SortType.CREATION_DATE, area);
}
this.paginate(player, plots, pageSize, page,
new RunnableVal3<Integer, Plot, PlotMessage>() {
@Override public void run(Integer i, Plot plot, PlotMessage message) {
@ -417,25 +378,72 @@ public class ListCmd extends SubCommand {
.command("/plot info " + plot.getArea() + ";" + plot.getId()).color(color)
.text(" - ").color("$2");
String prefix = "";
for (UUID uuid : plot.getOwners()) {
String name = UUIDHandler.getName(uuid);
if (name == null) {
message = message.text(prefix).color("$4").text("unknown").color("$2")
.tooltip(uuid.toString()).suggest(uuid.toString());
} else {
PlotPlayer pp = UUIDHandler.getPlayer(uuid);
try {
final List<UUIDMapping> names = PlotSquared.get().getImpromptuUUIDPipeline()
.getNames(plot.getOwners()).get(Settings.UUID.BLOCKING_TIMEOUT, TimeUnit.MILLISECONDS);
for (final UUIDMapping uuidMapping : names) {
PlotPlayer pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuidMapping.getUuid());
if (pp != null) {
message = message.text(prefix).color("$4").text(name).color("$1")
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
.tooltip(new PlotMessage("Online").color("$4"));
} else {
message = message.text(prefix).color("$4").text(name).color("$1")
message = message.text(prefix).color("$4").text(uuidMapping.getUsername()).color("$1")
.tooltip(new PlotMessage("Offline").color("$3"));
}
prefix = ", ";
}
prefix = ", ";
} catch (InterruptedException | ExecutionException e) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
} catch (TimeoutException e) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
}
}
}, "/plot list " + args[0], Captions.PLOT_LIST_HEADER_PAGED.getTranslated());
}
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
final List<String> completions = new LinkedList<>();
if (EconHandler.getEconHandler() != null && Permissions
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
completions.add("forsale");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) {
completions.add("mine");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_SHARED)) {
completions.add("shared");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
completions.addAll(PlotSquared.imp().getWorldManager().getWorlds());
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_TOP)) {
completions.add("top");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_ALL)) {
completions.add("all");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
completions.add("unowned");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_DONE)) {
completions.add("done");
}
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_EXPIRED)) {
completions.add("expired");
}
final List<Command> commands = new LinkedList<>();
commands.addAll(completions.stream()
.filter(completion -> completion.toLowerCase().startsWith(args[0].toLowerCase()))
.map(completion -> new Command(null, true, completion, "", RequiredType.NONE, CommandCategory.TELEPORT) {})
.collect(Collectors.toList()));
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER) && args[0].length() > 0) {
commands.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
}
return commands;
}
}

View File

@ -52,7 +52,7 @@ import java.util.List;
usage = "/plot load")
public class Load extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
@ -152,7 +152,7 @@ public class Load extends SubCommand {
return true;
}
public void displaySaves(PlotPlayer player) {
public void displaySaves(PlotPlayer<?> player) {
List<String> schematics = player.getMeta("plot_schematics");
for (int i = 0; i < Math.min(schematics.size(), 32); i++) {
try {

View File

@ -99,7 +99,6 @@ public class MainCommand extends Command {
new DebugPaste();
new Unlink();
new Kick();
new DebugClaimTest();
new Inbox();
new Comment();
new DatabaseCommand();
@ -165,14 +164,14 @@ public class MainCommand extends Command {
public void run(final Command cmd, final Runnable success, final Runnable failure) {
if (cmd.hasConfirmation(player)) {
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
if (EconHandler.manager != null) {
if (EconHandler.getEconHandler() != null) {
PlotArea area = player.getApplicablePlotArea();
if (area != null) {
Expression<Double> priceEval =
area.getPrices().get(cmd.getFullId());
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != null
&& EconHandler.manager.getMoney(player) < price) {
&& EconHandler.getEconHandler().getMoney(player) < price) {
if (failure != null) {
failure.run();
}
@ -186,12 +185,12 @@ public class MainCommand extends Command {
});
return;
}
if (EconHandler.manager != null) {
if (EconHandler.getEconHandler() != null) {
PlotArea area = player.getApplicablePlotArea();
if (area != null) {
Expression<Double> priceEval = area.getPrices().get(cmd.getFullId());
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != 0d && EconHandler.manager.getMoney(player) < price) {
if (price != 0d && EconHandler.getEconHandler().getMoney(player) < price) {
if (failure != null) {
failure.run();
}
@ -218,7 +217,7 @@ public class MainCommand extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
// Clear perm caching //
@ -253,14 +252,14 @@ public class MainCommand extends Command {
if ("f".equals(args[0].substring(1))) {
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
@Override public void run(Command cmd, Runnable success, Runnable failure) {
if (EconHandler.manager != null) {
if (EconHandler.getEconHandler() != null) {
PlotArea area = player.getApplicablePlotArea();
if (area != null) {
Expression<Double> priceEval =
area.getPrices().get(cmd.getFullId());
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
if (price != 0d
&& EconHandler.manager.getMoney(player) < price) {
&& EconHandler.getEconHandler().getMoney(player) < price) {
if (failure != null) {
failure.run();
}

View File

@ -40,7 +40,6 @@ import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.UUID;
@ -79,7 +78,7 @@ public class Merge extends SubCommand {
}
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocationFull();
final Plot plot = location.getPlotAbs();
if (plot == null) {
@ -157,8 +156,8 @@ public class Merge extends SubCommand {
return true;
}
if (plot.autoMerge(Direction.ALL, maxSize, uuid, terrain)) {
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
EconHandler.manager.withdrawMoney(player, price);
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
EconHandler.getEconHandler().withdrawMoney(player, price);
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
}
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
@ -172,11 +171,11 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
} else {
uuid = plot.guessOwner();
uuid = plot.getOwnerAbs();
}
}
if (!force && EconHandler.manager != null && plotArea.useEconomy() && price > 0d
&& EconHandler.manager.getMoney(player) < price) {
if (!force && EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d
&& EconHandler.getEconHandler().getMoney(player) < price) {
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
return false;
}
@ -193,8 +192,8 @@ public class Merge extends SubCommand {
return true;
}
if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) {
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
EconHandler.manager.withdrawMoney(player, price);
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
EconHandler.getEconHandler().withdrawMoney(player, price);
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
}
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);
@ -213,7 +212,7 @@ public class Merge extends SubCommand {
java.util.Set<UUID> uuids = adjacent.getOwners();
boolean isOnline = false;
for (final UUID owner : uuids) {
final PlotPlayer accepter = UUIDHandler.getPlayer(owner);
final PlotPlayer accepter = PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner);
if (!force && accepter == null) {
continue;
}
@ -222,17 +221,17 @@ public class Merge extends SubCommand {
Runnable run = () -> {
MainUtil.sendMessage(accepter, Captions.MERGE_ACCEPTED);
plot.autoMerge(dir, maxSize - size, owner, terrain);
PlotPlayer plotPlayer = UUIDHandler.getPlayer(player.getUUID());
PlotPlayer plotPlayer = PlotSquared.imp().getPlayerManager().getPlayerIfExists(player.getUUID());
if (plotPlayer == null) {
sendMessage(accepter, Captions.MERGE_NOT_VALID);
return;
}
if (EconHandler.manager != null && plotArea.useEconomy() && price > 0d) {
if (!force && EconHandler.manager.getMoney(player) < price) {
if (EconHandler.getEconHandler() != null && plotArea.useEconomy() && price > 0d) {
if (!force && EconHandler.getEconHandler().getMoney(player) < price) {
sendMessage(player, Captions.CANNOT_AFFORD_MERGE, String.valueOf(price));
return;
}
EconHandler.manager.withdrawMoney(player, price);
EconHandler.getEconHandler().withdrawMoney(player, price);
sendMessage(player, Captions.REMOVED_BALANCE, String.valueOf(price));
}
MainUtil.sendMessage(player, Captions.SUCCESS_MERGE);

View File

@ -42,7 +42,7 @@ import com.plotsquared.core.plot.Plot;
requiredType = RequiredType.PLAYER)
public class Middle extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] arguments) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
Location location = player.getLocation();
Plot plot = location.getPlot();
if (plot == null) {

View File

@ -47,7 +47,7 @@ import java.util.concurrent.CompletableFuture;
public class Move extends SubCommand {
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
Location location = player.getLocation();
@ -107,7 +107,7 @@ public class Move extends SubCommand {
});
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
return true;
}

View File

@ -55,7 +55,7 @@ public class Music extends SubCommand {
"music_disc_far", "music_disc_mall", "music_disc_mellohi", "music_disc_stal",
"music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait");
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {

View File

@ -46,7 +46,7 @@ public class Near extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(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);

View File

@ -36,10 +36,11 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
@CommandDeclaration(command = "setowner",
permission = "plots.set.owner",
@ -57,91 +58,103 @@ public class Owner extends SetCommand {
return false;
}
Set<Plot> plots = plot.getConnectedPlots();
UUID uuid = null;
final Consumer<UUID> uuidConsumer = uuid -> {
if (uuid == null && !value.equalsIgnoreCase("none") && !value.equalsIgnoreCase("null")
&& !value.equalsIgnoreCase("-")) {
Captions.INVALID_PLAYER.send(player, value);
return;
}
PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher()
.callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid,
plot.hasOwner());
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Owner change");
return;
}
uuid = event.getNewOwner();
boolean force = event.getEventResult() == Result.FORCE;
if (uuid == null) {
if (!force && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SET_OWNER.getTranslated(),
true)) {
return;
}
PlotUnlinkEvent unlinkEvent = PlotSquared.get().getEventDispatcher()
.callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER);
if (unlinkEvent.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Unlink on owner change");
return;
}
plot.unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad());
Set<Plot> connected = plot.getConnectedPlots();
for (Plot current : connected) {
current.unclaim();
current.removeSign();
}
MainUtil.sendMessage(player, Captions.SET_OWNER);
return;
}
final PlotPlayer other = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (plot.isOwner(uuid)) {
Captions.ALREADY_OWNER.send(player, MainUtil.getName(uuid));
return;
}
if (!force && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SET_OWNER)) {
if (other == null) {
Captions.INVALID_PLAYER_OFFLINE.send(player, value);
return;
}
int size = plots.size();
int currentPlots = (Settings.Limit.GLOBAL ?
other.getPlotCount() :
other.getPlotCount(plot.getWorldName())) + size;
if (currentPlots > other.getAllowedPlots()) {
sendMessage(player, Captions.CANT_TRANSFER_MORE_PLOTS);
return;
}
}
final UUID finalUUID = uuid;
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(uuid, (finalName, throwable) -> {
final boolean removeDenied = plot.isDenied(finalUUID);
Runnable run = () -> {
if (plot.setOwner(finalUUID, player)) {
if (removeDenied)
plot.removeDenied(finalUUID);
plot.setSign(finalName);
MainUtil.sendMessage(player, Captions.SET_OWNER);
if (other != null) {
MainUtil.sendMessage(other, Captions.NOW_OWNER,
plot.getArea() + ";" + plot.getId());
}
} else {
MainUtil.sendMessage(player, Captions.SET_OWNER_CANCELLED);
}
};
if (hasConfirmation(player)) {
CmdConfirm.addPending(player, "/plot set owner " + value, run);
} else {
TaskManager.runTask(run);
}
});
};
if (value.length() == 36) {
try {
uuid = UUID.fromString(value);
uuidConsumer.accept(UUID.fromString(value));
} catch (Exception ignored) {
}
} else {
uuid = UUIDHandler.getUUID(value, null);
}
if (uuid == null && !value.equalsIgnoreCase("none") && !value.equalsIgnoreCase("null")
&& !value.equalsIgnoreCase("-")) {
Captions.INVALID_PLAYER.send(player, value);
return false;
}
PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher()
.callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid,
plot.hasOwner());
if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Owner change");
return false;
}
uuid = event.getNewOwner();
boolean force = event.getEventResult() == Result.FORCE;
if (uuid == null) {
if (!force && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SET_OWNER.getTranslated(),
true)) {
return false;
}
PlotUnlinkEvent unlinkEvent = PlotSquared.get().getEventDispatcher()
.callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER);
if (unlinkEvent.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Unlink on owner change");
return true;
}
plot.unlinkPlot(unlinkEvent.isCreateRoad(), unlinkEvent.isCreateRoad());
Set<Plot> connected = plot.getConnectedPlots();
for (Plot current : connected) {
current.unclaim();
current.removeSign();
}
MainUtil.sendMessage(player, Captions.SET_OWNER);
return true;
}
final PlotPlayer other = UUIDHandler.getPlayer(uuid);
if (plot.isOwner(uuid)) {
Captions.ALREADY_OWNER.send(player, MainUtil.getName(uuid));
return false;
}
if (!force && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_SET_OWNER)) {
if (other == null) {
Captions.INVALID_PLAYER_OFFLINE.send(player, value);
return false;
}
int size = plots.size();
int currentPlots = (Settings.Limit.GLOBAL ?
other.getPlotCount() :
other.getPlotCount(plot.getWorldName())) + size;
if (currentPlots > other.getAllowedPlots()) {
sendMessage(player, Captions.CANT_TRANSFER_MORE_PLOTS);
return false;
}
}
final String finalName = UUIDHandler.getName(uuid);
final UUID finalUUID = uuid;
final boolean removeDenied = plot.isDenied(finalUUID);
Runnable run = () -> {
if (plot.setOwner(finalUUID, player)) {
if (removeDenied)
plot.removeDenied(finalUUID);
plot.setSign(finalName);
MainUtil.sendMessage(player, Captions.SET_OWNER);
if (other != null) {
MainUtil.sendMessage(other, Captions.NOW_OWNER,
plot.getArea() + ";" + plot.getId());
}
} else {
MainUtil.sendMessage(player, Captions.SET_OWNER_CANCELLED);
}
};
if (hasConfirmation(player)) {
CmdConfirm.addPending(player, "/plot set owner " + value, run);
} else {
TaskManager.runTask(run);
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(value, (uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (throwable != null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, value);
} else {
uuidConsumer.accept(uuid);
}
});
}
return true;
}

View File

@ -39,7 +39,7 @@ import com.plotsquared.core.util.task.TaskManager;
category = CommandCategory.INFO)
public class PluginCmd extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
TaskManager.IMP.taskAsync(() -> {
MainUtil.sendMessage(player, String.format(
"$2>> $1&l" + PlotSquared.imp().getPluginName() + " $2($1Version$2: $1%s$2)",

View File

@ -36,7 +36,6 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.HashMap;
import java.util.HashSet;
@ -54,7 +53,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
confirmation = true)
public class Purge extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return false;
@ -65,7 +64,6 @@ public class Purge extends SubCommand {
PlotId id = null;
UUID owner = null;
UUID added = null;
boolean unknown = false;
boolean clear = false;
for (String arg : args) {
String[] split = arg.split(":");
@ -97,7 +95,7 @@ public class Purge extends SubCommand {
break;
case "owner":
case "o":
owner = UUIDHandler.getUUID(split[1], null);
owner = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(split[1], Settings.UUID.BLOCKING_TIMEOUT);
if (owner == null) {
Captions.INVALID_PLAYER.send(player, split[1]);
return false;
@ -105,17 +103,12 @@ public class Purge extends SubCommand {
break;
case "shared":
case "s":
added = UUIDHandler.getUUID(split[1], null);
added = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(split[1], Settings.UUID.BLOCKING_TIMEOUT);
if (added == null) {
Captions.INVALID_PLAYER.send(player, split[1]);
return false;
}
break;
case "unknown":
case "?":
case "u":
unknown = Boolean.parseBoolean(split[1]);
break;
case "clear":
case "c":
case "delete":
@ -145,9 +138,6 @@ public class Purge extends SubCommand {
if (added != null && !plot.isAdded(added)) {
continue;
}
if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) {
continue;
}
toDelete.addAll(plot.getConnectedPlots());
}
if (PlotSquared.get().plots_tmp != null) {
@ -168,9 +158,6 @@ public class Purge extends SubCommand {
if (added != null && !plot.isAdded(added)) {
continue;
}
if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) {
continue;
}
toDelete.add(plot);
}
}

View File

@ -56,7 +56,7 @@ import java.util.UUID;
requiredType = RequiredType.PLAYER)
public class Rate extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 1) {
switch (args[0].toLowerCase()) {
case "next": {

View File

@ -43,7 +43,7 @@ import com.plotsquared.core.util.MainUtil;
permission = "plots.regenallroads")
public class RegenAllRoads extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
int height = 0;
if (args.length == 2) {
try {

View File

@ -47,7 +47,7 @@ public class Relight extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
final Plot plot = player.getCurrentPlot();

View File

@ -45,7 +45,7 @@ import java.util.Objects;
category = CommandCategory.ADMINISTRATION)
public class Reload extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
try {
// The following won't affect world generation, as that has to be
// loaded during startup unfortunately.

View File

@ -33,12 +33,12 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.util.TabCompletions;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.Collection;
import java.util.Collections;
import java.util.UUID;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "remove",
aliases = {"r", "untrust", "ut", "undeny", "unban", "ud"},
@ -53,7 +53,7 @@ public class Remove extends SubCommand {
super(Argument.PlayerName);
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
@ -68,74 +68,69 @@ public class Remove extends SubCommand {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return true;
}
int count = 0;
switch (args[0]) {
case "unknown": {
HashSet<UUID> all = new HashSet<>();
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : all) {
if (UUIDHandler.getName(uuid) == null) {
toRemove.add(uuid);
count++;
}
}
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
plot.removeTrusted(uuid);
plot.removeMember(uuid);
}
break;
}
default:
Set<UUID> uuids = MainUtil.getUUIDsFromString(args[0]);
if (!uuids.isEmpty()) {
for (UUID uuid : uuids) {
if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
PlotSquared.get().getEventDispatcher()
.callTrusted(player, plot, uuid, false);
count++;
}
} else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
PlotSquared.get().getEventDispatcher()
.callMember(player, plot, uuid, false);
count++;
}
} else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
PlotSquared.get().getEventDispatcher()
.callDenied(player, plot, uuid, false);
count++;
}
} else if (uuid == DBFunc.EVERYONE) {
if (plot.removeTrusted(uuid)) {
PlotSquared.get().getEventDispatcher()
.callTrusted(player, plot, uuid, false);
count++;
} else if (plot.removeMember(uuid)) {
PlotSquared.get().getEventDispatcher()
.callMember(player, plot, uuid, false);
count++;
} else if (plot.removeDenied(uuid)) {
PlotSquared.get().getEventDispatcher()
.callDenied(player, plot, uuid, false);
count++;
}
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
int count = 0;
if (throwable instanceof TimeoutException) {
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
return;
} else if (throwable != null) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return;
} else if (!uuids.isEmpty()) {
for (UUID uuid : uuids) {
if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
PlotSquared.get().getEventDispatcher()
.callTrusted(player, plot, uuid, false);
count++;
}
} else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
PlotSquared.get().getEventDispatcher()
.callMember(player, plot, uuid, false);
count++;
}
} else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
PlotSquared.get().getEventDispatcher()
.callDenied(player, plot, uuid, false);
count++;
}
} else if (uuid == DBFunc.EVERYONE) {
if (plot.removeTrusted(uuid)) {
PlotSquared.get().getEventDispatcher()
.callTrusted(player, plot, uuid, false);
count++;
} else if (plot.removeMember(uuid)) {
PlotSquared.get().getEventDispatcher()
.callMember(player, plot, uuid, false);
count++;
} else if (plot.removeDenied(uuid)) {
PlotSquared.get().getEventDispatcher()
.callDenied(player, plot, uuid, false);
count++;
}
}
}
break;
}
if (count == 0) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
return false;
} else {
MainUtil.sendMessage(player, Captions.REMOVED_PLAYERS, count + "");
}
}
if (count == 0) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else {
MainUtil.sendMessage(player, Captions.REMOVED_PLAYERS, count + "");
}
});
return true;
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
return Collections.emptyList();
}
return TabCompletions.completeAddedPlayers(plot, String.join(",", args).trim(),
Collections.singletonList(player.getName()));
}
}

View File

@ -49,7 +49,7 @@ import java.util.UUID;
permission = "plots.save")
public class Save extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);

View File

@ -57,7 +57,7 @@ public class SchematicCmd extends SubCommand {
private boolean running = false;
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length < 1) {
sendMessage(player, Captions.SCHEMATIC_MISSING_ARG);
return true;

View File

@ -37,6 +37,7 @@ import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.PatternUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.world.block.BlockCategory;
@ -76,7 +77,6 @@ public class Set extends SubCommand {
@Override public boolean set(PlotPlayer player, final Plot plot, String value) {
PlotManager manager = player.getLocation().getPlotManager();
String[] components = manager.getPlotComponents(plot.getId());
boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(player.getUUID());
String[] args = value.split(" ");
String material =
@ -159,11 +159,7 @@ public class Set extends SubCommand {
@Override
public Collection<Command> tab(final PlotPlayer player, final String[] args,
final boolean space) {
return PatternUtil.getSuggestions(player, StringMan.join(args, ",").trim()).stream()
.map(value -> value.toLowerCase(Locale.ENGLISH).replace("minecraft:", ""))
.filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH)))
.map(value -> new Command(null, false, value, "", RequiredType.NONE, null) {
}).collect(Collectors.toList());
return TabCompletions.completePatterns(StringMan.join(args, ","));
}
};
}
@ -180,7 +176,7 @@ public class Set extends SubCommand {
return false;
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
return noArgs(player);
}

View File

@ -36,7 +36,7 @@ import com.plotsquared.core.util.StringMan;
public abstract class SetCommand extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
@ -52,7 +52,7 @@ public abstract class SetCommand extends SubCommand {
return false;
}
}
if (!plot.isOwner(player.getUUID()) && !plot.getTrusted().contains(player.getUUID())) {
if (!plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(player, CaptionUtility
.format(player, Captions.PERMISSION_ADMIN_COMMAND.getTranslated(), getFullId()))) {
MainUtil.sendMessage(player, Captions.NO_PERMISSION, CaptionUtility

View File

@ -27,39 +27,18 @@ package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.configuration.ConfigurationUtil;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.plot.message.PlotMessage;
import com.plotsquared.core.setup.SetupProcess;
import com.plotsquared.core.setup.SetupStep;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.UUID;
@CommandDeclaration(command = "setup",
permission = "plots.admin.command.setup",
@ -69,13 +48,7 @@ import java.util.UUID;
category = CommandCategory.ADMINISTRATION)
public class Setup extends SubCommand {
private static boolean d(String s) {
return s.chars().allMatch((i) -> {
return i == 95 || i == 45 || i >= 97 && i <= 122 || i >= 48 && i <= 57 || i == 46;
});
}
public void displayGenerators(PlotPlayer player) {
public void displayGenerators(PlotPlayer<?> player) {
StringBuilder message = new StringBuilder();
message.append("&6What generator do you want?");
for (Entry<String, GeneratorWrapper<?>> entry : SetupUtils.generators.entrySet()) {
@ -90,397 +63,60 @@ public class Setup extends SubCommand {
MainUtil.sendMessage(player, message.toString());
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
// going through setup
SetupObject object = player.getMeta("setup");
if (object == null) {
object = new SetupObject();
player.setMeta("setup", object);
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
SetupProcess process = player.getMeta("setup");
if (process == null) {
if (args.length > 0) {
MainUtil.sendMessage(player, Captions.SETUP_NOT_STARTED);
return true;
}
process = new SetupProcess();
player.setMeta("setup", process);
SetupUtils.manager.updateGenerators();
sendMessage(player, Captions.SETUP_INIT);
SetupStep step = process.getCurrentStep();
step.announce(player);
displayGenerators(player);
return false;
return true;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("cancel")) {
if ("back".equalsIgnoreCase(args[0])) {
process.back();
process.getCurrentStep().announce(player);
} else if ("cancel".equalsIgnoreCase(args[0])) {
player.deleteMeta("setup");
MainUtil.sendMessage(player, Captions.SETUP_CANCELLED);
return false;
}
if (args[0].equalsIgnoreCase("back")) {
if (object.setup_index > 0) {
object.setup_index--;
ConfigurationNode node = object.step[object.setup_index];
sendMessage(player, Captions.SETUP_STEP, object.setup_index + 1,
node.getDescription(), node.getType().getType(),
String.valueOf(node.getDefaultValue()));
return false;
} else if (object.current > 0) {
object.current--;
} else {
process.handleInput(player, args[0]);
if (process.getCurrentStep() != null) {
process.getCurrentStep().announce(player);
}
}
} else {
process.getCurrentStep().announce(player);
}
int index = object.current;
switch (index) {
case 0: // choose generator
if (args.length != 1 || !SetupUtils.generators.containsKey(args[0])) {
String prefix = "\n&8 - &7";
MainUtil.sendMessage(player,
Captions.SETUP_WORLD_GENERATOR_ERROR + prefix + StringMan
.join(SetupUtils.generators.keySet(), prefix)
.replaceAll(PlotSquared.imp().getPluginName(),
"&2" + PlotSquared.imp().getPluginName()));
sendMessage(player, Captions.SETUP_INIT);
return false;
}
object.setupGenerator = args[0];
object.current++;
MainUtil.sendMessage(player, Captions.SETUP_WORLD_TYPE);
break;
case 1: // choose world type
List<String> allTypes = Arrays.asList("normal", "augmented", "partial");
List<String> allDesc = Arrays
.asList("Standard plot generation", "Plot generation with vanilla terrain",
"Vanilla with clusters of plots");
ArrayList<String> types = new ArrayList<>();
if (SetupUtils.generators.get(object.setupGenerator).isFull()) {
types.add("normal");
}
types.add("augmented");
types.add("partial");
Optional<PlotAreaType> plotAreaType;
if (args.length != 1 || !(plotAreaType = PlotAreaType.fromString(args[0]))
.isPresent()) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_TYPE_ERROR);
for (String type : types) {
int i = allTypes.indexOf(type);
if (type.equals("normal")) {
MainUtil
.sendMessage(player, "&8 - &2" + type + " &8-&7 " + allDesc.get(i));
} else {
MainUtil
.sendMessage(player, "&8 - &7" + type + " &8-&7 " + allDesc.get(i));
}
}
return false;
}
object.type = plotAreaType.orElse(PlotAreaType.NORMAL);
GeneratorWrapper<?> gen = SetupUtils.generators.get(object.setupGenerator);
if (object.type == PlotAreaType.NORMAL) {
object.current = 6;
if (object.step == null) {
object.plotManager = object.setupGenerator;
object.step =
SetupUtils.generators.get(object.plotManager).getPlotGenerator()
.getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null)
.getSettingNodes();
SetupUtils.generators.get(object.plotManager).getPlotGenerator()
.processSetup(object);
}
if (object.step.length == 0) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_NAME);
object.setup_index = 0;
return true;
}
ConfigurationNode step = object.step[object.setup_index];
sendMessage(player, Captions.SETUP_STEP, object.setup_index + 1,
step.getDescription(), step.getType().getType(),
String.valueOf(step.getDefaultValue()));
} else {
if (gen.isFull()) {
object.plotManager = object.setupGenerator;
object.setupGenerator = null;
object.step =
SetupUtils.generators.get(object.plotManager).getPlotGenerator()
.getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null)
.getSettingNodes();
SetupUtils.generators.get(object.plotManager).getPlotGenerator()
.processSetup(object);
} else {
object.plotManager = PlotSquared.imp().getPluginName();
MainUtil.sendMessage(player, Captions.SETUP_WRONG_GENERATOR);
object.step =
SetupUtils.generators.get(object.plotManager).getPlotGenerator()
.getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null)
.getSettingNodes();
}
if (object.type == PlotAreaType.PARTIAL) {
MainUtil.sendMessage(player, Captions.SETUP_AREA_NAME);
object.current++;
} else {
MainUtil.sendMessage(player, Captions.SETUP_PARTIAL_AREA);
object.current = 5;
}
}
break;
case 2: // area id
if (!StringMan.isAlphanumericUnd(args[0])) {
MainUtil.sendMessage(player, Captions.SETUP_AREA_NON_ALPHANUMERICAL);
return false;
}
for (PlotArea area : PlotSquared.get().getPlotAreas()) {
if (area.getId() != null && area.getId().equalsIgnoreCase(args[0])) {
MainUtil.sendMessage(player, Captions.SETUP_AREA_INVALID_ID);
return false;
}
}
object.id = args[0];
object.current++;
MainUtil.sendMessage(player, Captions.SETUP_AREA_MIN_PLOT_ID);
break;
case 3: // min
try {
object.min = PlotId.fromString(args[0]);
} catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, Captions.SETUP_AREA_MIN_PLOT_ID_ERROR);
return false;
}
object.current++;
MainUtil.sendMessage(player, Captions.SETUP_AREA_MAX_PLOT_ID);
break;
case 4:
// max
PlotId id;
try {
id = PlotId.fromString(args[0]);
} catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, Captions.SETUP_AREA_MAX_PLOT_ID_ERROR);
return false;
}
if (id.x <= object.min.x || id.y <= object.min.y) {
MainUtil.sendMessage(player, Captions.SETUP_AREA_PLOT_ID_GREATER_THAN_MINIMUM);
return false;
}
object.max = id;
object.current++;
MainUtil.sendMessage(player, Captions.SETUP_PARTIAL_AREA);
break;
case 5: { // Choose terrain
Optional<PlotAreaTerrainType> optTerrain;
if (args.length != 1 || !(optTerrain = PlotAreaTerrainType.fromString(args[0]))
.isPresent()) {
MainUtil.sendMessage(player, Captions.SETUP_PARTIAL_AREA_ERROR,
Captions.SETUP_PARTIAL_AREA);
return false;
}
object.terrain = optTerrain.get();
object.current++;
if (object.step == null) {
object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator()
.getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null)
.getSettingNodes();
}
ConfigurationNode step = object.step[object.setup_index];
sendMessage(player, Captions.SETUP_STEP, object.setup_index + 1,
step.getDescription(), step.getType().getType(),
String.valueOf(step.getDefaultValue()));
break;
}
case 6: // world setup
if (object.setup_index == object.step.length) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_NAME);
object.setup_index = 0;
object.current++;
return true;
}
ConfigurationNode step = object.step[object.setup_index];
if (args.length < 1) {
sendMessage(player, Captions.SETUP_STEP, object.setup_index + 1,
step.getDescription(), step.getType().getType(),
String.valueOf(step.getDefaultValue()));
return false;
}
boolean valid = false;
try {
valid = step.isValid(args[0]);
} catch (final ConfigurationUtil.UnsafeBlockException e) {
Captions.NOT_ALLOWED_BLOCK.send(player, e.getUnsafeBlock().toString());
}
if (valid) {
step.setValue(args[0]);
Object value = step.getValue();
sendMessage(player, Captions.SETUP_VALID_ARG, step.getConstant(), value);
object.setup_index++;
if (object.setup_index == object.step.length) {
onCommand(player, args);
return false;
}
step = object.step[object.setup_index];
sendMessage(player, Captions.SETUP_STEP, object.setup_index + 1,
step.getDescription(), step.getType().getType(),
String.valueOf(step.getDefaultValue()));
return false;
} else {
sendMessage(player, Captions.SETUP_INVALID_ARG, args[0], step.getConstant());
sendMessage(player, Captions.SETUP_STEP, object.setup_index + 1,
step.getDescription(), step.getType().getType(),
String.valueOf(step.getDefaultValue()));
return false;
}
case 7:
if (args.length != 1) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_NAME_ERROR);
return false;
}
if (!d(args[0])) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_NAME_FORMAT + args[0]);
return false;
}
if (WorldUtil.IMP.isWorld(args[0])) {
if (PlotSquared.get().hasPlotArea(args[0])) {
MainUtil.sendMessage(player, Captions.SETUP_WORLD_NAME_TAKEN);
return false;
}
MainUtil.sendMessage(player, Captions.SETUP_WORLD_APPLY_PLOTSQUARED);
}
object.world = args[0];
player.deleteMeta("setup");
String world;
if (object.setupManager == null) {
world = SetupUtils.manager.setupWorld(object);
} else {
world = object.setupManager.setupWorld(object);
}
try {
player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND);
} catch (Exception e) {
player.sendMessage("&cAn error occurred. See console for more information");
e.printStackTrace();
}
sendMessage(player, Captions.SETUP_FINISHED, object.world);
}
return false;
}
private static final class StepPickGenerator extends SetupStep {
@Getter private String generator;
public StepPickGenerator() {
super("generator");
}
@Override public Collection<PlotMessage> showDescriptionMessage() {
SetupUtils.manager.updateGenerators();
final List<PlotMessage> messages = new ArrayList<>();
messages.add(new PlotMessage("What generator do you want?").color("$6"));
for (Entry<String, GeneratorWrapper<?>> entry : SetupUtils.generators.entrySet()) {
final PlotMessage plotMessage = new PlotMessage(" - ").color("$8");
if (entry.getKey().equals(PlotSquared.imp().getPluginName())) {
plotMessage.text(entry.getKey()).color("$8").tooltip("Select this generator")
.color("$2").command("/plot setup generator " + entry.getKey())
.text(" (Default Generator)").color("$7");
} else if (entry.getValue().isFull()) {
plotMessage.text(entry.getKey()).color("$8").tooltip("Select this generator")
.color("$7").command("/plot setup generator " + entry.getKey())
.text(" (Plot Generator)").color("$7");
} else {
plotMessage.text(entry.getKey()).color("$8").tooltip("Select this generator")
.color("$7").command("/plot setup generator " + entry.getKey())
.text(" (Unknown Structure)").color("$7");
}
messages.add(plotMessage);
}
return messages;
}
@Override public boolean parseInput(String input) {
this.generator = input.toLowerCase();
return true;
}
@Nullable @Override public String getDefault() {
return null;
}
}
private static final class StepWorldType extends SetupStep {
private static final Map<String, String> WORLD_TYPES = new HashMap<>();
static {
WORLD_TYPES.put("default", "Standard plot generation");
WORLD_TYPES.put("augmented", "Plot generation with vanilla terrain");
WORLD_TYPES.put("partial", "Vanilla clusters of plots");
}
@Getter private String worldType;
public StepWorldType() {
super("type");
}
@Override public Collection<PlotMessage> showDescriptionMessage() {
final List<PlotMessage> messages = new ArrayList<>();
messages.add(new PlotMessage("What world type do you want?").color("$6"));
for (final Map.Entry<String, String> worldType : WORLD_TYPES.entrySet()) {
messages.add(new PlotMessage(" - ").color("$8").text(worldType.getKey())
.color(worldType.getKey().equals(getDefault()) ? "$2" : "$7")
.tooltip("Select this world type")
.command("/plot setup type " + worldType.getKey())
.text(" (" + worldType.getValue() + ")").color("$7"));
}
return messages;
}
@Override public boolean parseInput(String input) {
if (!WORLD_TYPES.containsKey(input.toLowerCase())) {
return false;
}
this.worldType = input.toLowerCase();
return true;
}
@Override public String getDefault() {
return "default";
}
}
@ToString
@EqualsAndHashCode(of = "uuid")
@AllArgsConstructor
private static class SetupContext {
private final UUID uuid;
@Getter private String step;
return true;
}
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
private abstract static class SetupStep {
private final String stepName;
public abstract Collection<PlotMessage> showDescriptionMessage();
public abstract boolean parseInput(String input);
public final PlotMessage getUsage() {
return new PlotMessage("Usage: ").color("$1")
.text("/plot setup " + this.stepName + " <value>").color("$2").suggest(
"/plot setup " + this.stepName + (this.getDefault() != null ?
this.getDefault() :
""));
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
SetupProcess process = (SetupProcess) player.getMeta("setup"); // TODO use generics -> auto cast
if (process == null) {
return Collections.emptyList();
}
@Nullable public abstract String getDefault();
public void sendToPlayer(@NonNull final PlotPlayer plotPlayer) {
new PlotMessage("Setup Step: ").color("$6").text(this.stepName).color("$7")
.send(plotPlayer);
this.getUsage().send(plotPlayer);
this.showDescriptionMessage().forEach(plotMessage -> plotMessage.send(plotPlayer));
if (this.getDefault() != null) {
new PlotMessage("Default: ").color("$6").text(this.getDefault()).color("$7");
}
// player already provided too many arguments
if (args.length > 1 || (args.length == 1 && space)) {
return Collections.emptyList();
}
SetupStep setupStep = process.getCurrentStep();
List<Command> commands = new ArrayList<>(setupStep.createSuggestions(player, space ? "" : args[0]));
tryAddSubCommand("back", args[0], commands);
tryAddSubCommand("cancel", args[0], commands);
return commands;
}
private void tryAddSubCommand(String subCommand, String argument, List<Command> suggestions) {
if (!argument.isEmpty() && subCommand.startsWith(argument)) {
suggestions.add(new Command(null, false, subCommand, "", RequiredType.NONE, null) {});
}
}
}

View File

@ -54,11 +54,11 @@ public abstract class SubCommand extends Command {
}
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
return CompletableFuture.completedFuture(onCommand(player, args));
}
public abstract boolean onCommand(PlotPlayer player, String[] args);
public abstract boolean onCommand(PlotPlayer<?> player, String[] args);
}

View File

@ -45,7 +45,7 @@ import java.util.concurrent.CompletableFuture;
public class Swap extends SubCommand {
@Override
public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
Location location = player.getLocation();
@ -93,7 +93,7 @@ public class Swap extends SubCommand {
});
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
return true;
}
}

View File

@ -45,7 +45,7 @@ public class Target extends SubCommand {
super(Argument.PlotID);
}
@Override public boolean onCommand(PlotPlayer player, String[] args) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
if (!location.isPlotArea()) {
MainUtil.sendMessage(player, Captions.NOT_IN_PLOT_WORLD);

View File

@ -36,8 +36,9 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotManager;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.setup.SettingsNodesWrapper;
import com.plotsquared.core.util.FileBytes;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.SetupUtils;
@ -134,7 +135,7 @@ public class Template extends SubCommand {
}
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length != 2 && args.length != 3) {
if (args.length == 1) {
if (args[0].equalsIgnoreCase("export")) {
@ -181,15 +182,15 @@ public class Template extends SubCommand {
String manager =
worldConfig.getString("generator.plugin", PlotSquared.imp().getPluginName());
String generator = worldConfig.getString("generator.init", manager);
SetupObject setup = new SetupObject();
setup.type = MainUtil.getType(worldConfig);
setup.terrain = MainUtil.getTerrain(worldConfig);
PlotAreaBuilder builder = new PlotAreaBuilder()
.plotAreaType(MainUtil.getType(worldConfig))
.terrainType(MainUtil.getTerrain(worldConfig))
.plotManager(manager)
.generatorName(generator)
.settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
.worldName(world);
setup.plotManager = manager;
setup.setupGenerator = generator;
setup.step = new ConfigurationNode[0];
setup.world = world;
SetupUtils.manager.setupWorld(setup);
SetupUtils.manager.setupWorld(builder);
GlobalBlockQueue.IMP.addEmptyTask(() -> {
MainUtil.sendMessage(player, "Done!");
player.teleport(WorldUtil.IMP.getSpawn(world), TeleportCause.COMMAND);

View File

@ -47,7 +47,7 @@ public class Toggle extends Command {
aliases = {"spy"},
permission = "plots.admin.command.chat",
description = "Toggle plot chat spy")
public void chatspy(Command command, PlotPlayer player, String[] args,
public void chatspy(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "chatspy")) {
@ -61,7 +61,7 @@ public class Toggle extends Command {
aliases = {"we", "wea"},
permission = "plots.worldedit.bypass",
description = "Toggle worldedit area restrictions")
public void worldedit(Command command, PlotPlayer player, String[] args,
public void worldedit(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "worldedit")) {
@ -74,7 +74,7 @@ public class Toggle extends Command {
@CommandDeclaration(command = "chat",
permission = "plots.toggle.chat",
description = "Toggle plot chat")
public void chat(Command command, PlotPlayer player, String[] args,
public void chat(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "chat")) {
@ -87,7 +87,7 @@ public class Toggle extends Command {
@CommandDeclaration(command = "clear-confirmation",
permission = "plots.admin.command.autoclear",
description = "Toggle autoclear confirmation")
public void clearConfirmation(Command command, PlotPlayer player, String[] args,
public void clearConfirmation(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "ignoreExpireTask")) {
@ -100,7 +100,7 @@ public class Toggle extends Command {
@CommandDeclaration(command = "titles",
permission = "plots.toggle.titles",
description = "Toggle plot title messages")
public void titles(Command command, PlotPlayer player, String[] args,
public void titles(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "disabletitles")) {
@ -113,7 +113,7 @@ public class Toggle extends Command {
@CommandDeclaration(command = "time",
permission = "plots.toggle.time",
description = "Toggle plot time settings")
public void time(Command command, PlotPlayer player, String[] args,
public void time(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (toggle(player, "disabletime")) {
@ -123,7 +123,21 @@ public class Toggle extends Command {
}
}
public boolean toggle(PlotPlayer player, String key) {
@CommandDeclaration(command = "debug",
permission = "plots.toggle.debug",
description = "Toggle plot debugging")
public void debug(Command command, PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
if (!toggle(player, "debug")) {
MainUtil.sendMessage(player, Captions.TOGGLE_ENABLED, command.toString());
} else {
MainUtil.sendMessage(player, Captions.TOGGLE_DISABLED, command.toString());
}
player.refreshDebug();
}
public boolean toggle(PlotPlayer<?> player, String key) {
if (player.getAttribute(key)) {
player.removeAttribute(key);
return true;

View File

@ -159,7 +159,7 @@ public class Trim extends SubCommand {
return true;
}
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return false;

View File

@ -32,13 +32,16 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "trust",
aliases = {"t"},
@ -53,7 +56,7 @@ public class Trust extends Command {
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
final Plot currentPlot = player.getCurrentPlot();
@ -65,51 +68,69 @@ public class Trust extends Command {
.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> iterator = uuids.iterator();
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
while (iterator.hasNext()) {
UUID uuid = iterator.next();
if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (currentPlot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (currentPlot.getTrusted().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
size += currentPlot.getMembers().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= currentPlot.getArea().getMaxPlotMembers() || 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 (!currentPlot.removeMember(uuid)) {
if (currentPlot.getDenied().contains(uuid)) {
currentPlot.removeDenied(uuid);
}
}
}
currentPlot.addTrusted(uuid);
PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuid, true);
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
}
}, null);
final CompletableFuture<Boolean> future = new CompletableFuture<>();
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable != null) {
if (throwable instanceof TimeoutException) {
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
} else {
Captions.INVALID_PLAYER.send(player, args[0]);
}
future.completeExceptionally(throwable);
return;
} else {
checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
Iterator<UUID> iterator = uuids.iterator();
int size = currentPlot.getTrusted().size() + currentPlot.getMembers().size();
while (iterator.hasNext()) {
UUID uuid = iterator.next();
if (uuid == DBFunc.EVERYONE && !(
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (currentPlot.isOwner(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
if (currentPlot.getTrusted().contains(uuid)) {
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
iterator.remove();
continue;
}
size += currentPlot.getMembers().contains(uuid) ? 0 : 1;
}
checkTrue(!uuids.isEmpty(), null);
checkTrue(size <= currentPlot.getArea().getMaxPlotMembers() || 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 (!currentPlot.removeMember(uuid)) {
if (currentPlot.getDenied().contains(uuid)) {
currentPlot.removeDenied(uuid);
}
}
}
currentPlot.addTrusted(uuid);
PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuid, true);
MainUtil.sendMessage(player, Captions.TRUSTED_ADDED);
}
}, null);
}
future.complete(true);
});
return CompletableFuture.completedFuture(true);
}
@Override public Collection<Command> tab(final PlotPlayer player, final String[] args, final boolean space) {
return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
}
}

View File

@ -46,7 +46,7 @@ import com.plotsquared.core.util.task.TaskManager;
confirmation = true)
public class Unlink extends SubCommand {
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {

View File

@ -27,7 +27,6 @@ package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@ -36,16 +35,21 @@ import com.plotsquared.core.plot.flag.implementations.UntrustedVisitFlag;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.query.SortingStrategy;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.plotsquared.core.uuid.UUIDMapping;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "visit",
permission = "plots.visit",
@ -60,22 +64,96 @@ public class Visit extends Command {
super(MainCommand.getInstance(), true);
}
@Override public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
return tabOf(player, args, space, getUsage());
private void visit(@NotNull final PlotPlayer player, @NotNull final PlotQuery query, final PlotArea sortByArea,
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone) {
this.visit(player, query, sortByArea, confirm, whenDone, 1);
}
private void visit(@NotNull final PlotPlayer player, @NotNull final PlotQuery query, final PlotArea sortByArea,
final RunnableVal3<Command, Runnable, Runnable> confirm, final RunnableVal2<Command, CommandResult> whenDone, int page) {
// We get the query once,
// then we get it another time further on
final List<Plot> unsorted = query.asList();
if (unsorted.isEmpty()) {
Captions.FOUND_NO_PLOTS.send(player);
return;
}
if (unsorted.size() > 1) {
query.whereBasePlot();
}
if (page == Integer.MIN_VALUE) {
page = 1;
}
if (page < 1 || page > unsorted.size()) {
MainUtil.sendMessage(player, String.format("(1, %d)", unsorted.size()));
return;
}
if (sortByArea != null) {
query.relativeToArea(sortByArea).withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
} else {
query.withSortingStrategy(SortingStrategy.SORT_BY_TEMP);
}
final List<Plot> plots = query.asList();
final Plot plot = plots.get(page - 1);
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_UNOWNED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_UNOWNED);
return;
}
} else if (plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions
.hasPermission(player, Captions.PERMISSION_HOME)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED);
return;
}
} else if (plot.isAdded(player.getUUID())) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_SHARED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_SHARED);
return;
}
} else {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER);
return;
}
if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED);
return;
}
}
confirm.run(this, () -> plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
if (result) {
whenDone.run(Visit.this, CommandResult.SUCCESS);
} else {
whenDone.run(Visit.this, CommandResult.FAILURE);
}
}), () -> whenDone.run(Visit.this, CommandResult.FAILURE));
}
@Override
public CompletableFuture<Boolean> execute(final PlotPlayer player, String[] args,
RunnableVal3<Command, Runnable, Runnable> confirm,
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player,
String[] args,
final RunnableVal3<Command, Runnable, Runnable> confirm,
final RunnableVal2<Command, CommandResult> whenDone) throws CommandException {
if (args.length == 1 && args[0].contains(":")) {
args = args[0].split(":");
}
PlotArea sortByArea;
int page = Integer.MIN_VALUE;
Collection<Plot> unsorted = null;
PlotArea sortByArea = player.getApplicablePlotArea();
boolean shouldSortByArea = Settings.Teleport.PER_WORLD_VISIT;
switch (args.length) {
// /p v [...] [...] <page>
case 3:
if (!MathMan.isInteger(args[1])) {
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
@ -83,6 +161,8 @@ public class Visit extends Command {
return CompletableFuture.completedFuture(false);
}
page = Integer.parseInt(args[2]);
// /p v <name> <area> [page]
// /p v <name> [page]
case 2:
if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
sortByArea = PlotSquared.get().getPlotAreaByString(args[1]);
@ -91,101 +171,148 @@ public class Visit extends Command {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return CompletableFuture.completedFuture(false);
}
UUID user = UUIDHandler.getUUIDFromString(args[0]);
if (user == null) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return CompletableFuture.completedFuture(false);
}
unsorted = PlotSquared.get().getBasePlots(user);
shouldSortByArea = true;
final PlotArea finalSortByArea = sortByArea;
int finalPage1 = page;
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
if (throwable instanceof TimeoutException) {
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
} else if (throwable != null || uuids.size() != 1) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
} else {
final UUID uuid = uuids.toArray(new UUID[0])[0];
this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), finalSortByArea, confirm, whenDone, finalPage1);
}
});
break;
}
page = Integer.parseInt(args[1]);
// /p v <name> [page]
// /p v <page> [page]
// /p v <uuid> [page]
// /p v <plot> [page]
case 1:
UUID user = args[0].length() >= 2 ? UUIDHandler.getUUIDFromString(args[0]) : null;
if (user != null && !PlotSquared.get().hasPlot(user)) {
user = null;
final String[] finalArgs = args;
int finalPage = page;
// Try to determine whether the given argument is a username
// or an ordinal
boolean isNumber = false;
if (args[0].length() < 2) {
isNumber = true;
} else if (args[0].length() <= 4 && MathMan.isInteger(args[0])) {
// Check if it's an all-digit username that is stored in cache
final UUIDMapping mapping = PlotSquared.get().getImpromptuUUIDPipeline().getImmediately(args[0]);
// If no UUID could be found, then we assume it's a number and not a username
isNumber = mapping == null;
}
if (page == Integer.MIN_VALUE && user == null && MathMan.isInteger(args[0])) {
page = Integer.parseInt(args[0]);
unsorted = PlotSquared.get().getBasePlots(player);
break;
}
if (user != null) {
unsorted = PlotSquared.get().getBasePlots(user);
if (!isNumber && args[0].length() >= 2 && !args[0].contains(";") && !args[0].contains(",")) {
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> {
if (throwable instanceof TimeoutException) {
// The request timed out
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
} else if (uuid != null && !PlotSquared.get().hasPlot(uuid)) {
// It was a valid UUID but the player has no plots
MainUtil.sendMessage(player, Captions.PLAYER_NO_PLOTS);
} else if (uuid == null) {
if (finalPage == Integer.MIN_VALUE && MathMan.isInteger(finalArgs[0])) {
// The argument was a number, so we assume it's the page number
int parsedPage;
try {
parsedPage = Integer.parseInt(finalArgs[0]);
} catch (final Throwable t) {
MainUtil.sendMessage(player, Captions.NOT_A_NUMBER, finalArgs[0]);
return;
}
this.visit(player, PlotQuery.newQuery().ownedBy(player).whereBasePlot(), null,
confirm, whenDone, parsedPage);
} else {
// Try to parse a plot
final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
if (plot == null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_ID);
return;
}
this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1);
}
} else {
this.visit(player, PlotQuery.newQuery().ownedBy(uuid).whereBasePlot(), null, confirm, whenDone, finalPage);
}
});
} else {
Plot plot = MainUtil.getPlotFromString(player, args[0], true);
if (plot != null) {
unsorted = Collections.singletonList(plot.getBasePlot(false));
if (finalPage == Integer.MIN_VALUE && MathMan.isInteger(finalArgs[0])) {
// The argument was a number, so we assume it's the page number
int parsedPage;
try {
parsedPage = Integer.parseInt(finalArgs[0]);
this.visit(player, PlotQuery.newQuery().ownedBy(player).whereBasePlot(), null, confirm,
whenDone, parsedPage);
} catch (final Throwable throwable) {
MainUtil.sendMessage(player, Captions.NOT_A_NUMBER, finalArgs[0]);
}
} else {
// Try to parse a plot
final Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
if (plot != null) {
this.visit(player, PlotQuery.newQuery().withPlot(plot), null, confirm, whenDone, 1);
}
}
}
break;
case 0:
page = 1;
unsorted = PlotSquared.get().getPlots(player);
// /p v
this.visit(player, PlotQuery.newQuery().ownedBy(player), null, confirm, whenDone);
break;
default:
}
if (page == Integer.MIN_VALUE) {
page = 1;
}
if (unsorted == null || unsorted.isEmpty()) {
Captions.FOUND_NO_PLOTS.send(player);
return CompletableFuture.completedFuture(false);
}
unsorted = new ArrayList<>(unsorted);
if (unsorted.size() > 1) {
unsorted.removeIf(plot -> !plot.isBasePlot());
}
if (page < 1 || page > unsorted.size()) {
Captions.NOT_VALID_NUMBER.send(player, "(1, " + unsorted.size() + ")");
return CompletableFuture.completedFuture(false);
}
List<Plot> plots;
if (shouldSortByArea) {
plots = PlotSquared.get()
.sortPlots(unsorted, PlotSquared.SortType.CREATION_DATE, sortByArea);
} else {
plots = PlotSquared.get().sortPlotsByTemp(unsorted);
}
final Plot plot = plots.get(page - 1);
if (!plot.hasOwner()) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_UNOWNED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_UNOWNED);
return CompletableFuture.completedFuture(false);
}
} else if (plot.isOwner(player.getUUID())) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OWNED) && !Permissions
.hasPermission(player, Captions.PERMISSION_HOME)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OWNED);
return CompletableFuture.completedFuture(false);
}
} else if (plot.isAdded(player.getUUID())) {
if (!Permissions.hasPermission(player, Captions.PERMISSION_SHARED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_SHARED);
return CompletableFuture.completedFuture(false);
}
} else {
if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER);
return CompletableFuture.completedFuture(false);
}
if (!plot.getFlag(UntrustedVisitFlag.class) && !Permissions
.hasPermission(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED)) {
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_ADMIN_VISIT_UNTRUSTED);
return CompletableFuture.completedFuture(false);
}
}
confirm.run(this, () -> plot.teleportPlayer(player, TeleportCause.COMMAND, result -> {
if (result) {
whenDone.run(Visit.this, CommandResult.SUCCESS);
} else {
whenDone.run(Visit.this, CommandResult.FAILURE);
}
}), () -> whenDone.run(Visit.this, CommandResult.FAILURE));
return CompletableFuture.completedFuture(true);
}
public Collection<Command> tab(PlotPlayer player, String[] args, boolean space) {
final List<Command> completions = new LinkedList<>();
switch (args.length - 1) {
case 0:
this.completeNumbers(completions, args[0], 0);
completions.addAll(TabCompletions.completePlayers(args[0], Collections.emptyList()));
break;
case 1:
if (MathMan.isInteger(args[0])) {
break;
}
this.completeNumbers(completions, args[1], 0);
this.completeAreas(completions, args[1]);
break;
case 2:
if (MathMan.isInteger(args[1])) {
break;
}
this.completeNumbers(completions, args[2], 0);
break;
}
return completions;
}
private void completeNumbers(final List<Command> commands, final String arg, final int start) {
for (int i = 0; i < 100; i++) {
final String command = Integer.toString(start + 1);
if (!command.toLowerCase().startsWith(arg.toLowerCase())) {
continue;
}
commands.add(new Command(this, false, command, "",
RequiredType.NONE, CommandCategory.TELEPORT) {});
}
}
private void completeAreas(final List<Command> commands, final String arg) {
for (final PlotArea area : PlotSquared.get().getPlotAreas()) {
final String areaName = area.getWorldName() + ";" + area.getId();
if (!areaName.toLowerCase().startsWith(arg.toLowerCase())) {
continue;
}
commands.add(new Command(this, false, area.getWorldName() + ";" + area.getId(), "",
RequiredType.NONE, CommandCategory.TELEPORT) {});
}
}
}

View File

@ -37,7 +37,7 @@ import com.plotsquared.core.player.PlotPlayer;
@Deprecated
public class WE_Anywhere extends SubCommand {
@Override public boolean onCommand(PlotPlayer player, String[] arguments) {
@Override public boolean onCommand(PlotPlayer<?> player, String[] arguments) {
MainCommand.getInstance().toggle.worldedit(this, player, new String[0], null, null);
return true;
}

View File

@ -46,7 +46,7 @@ public class ComponentCommand extends SubCommand {
this.componentPresetManager = componentPresetManager;
}
@Override public boolean onCommand(final PlotPlayer player, final String[] args) {
@Override public boolean onCommand(final PlotPlayer<?> player, final String[] args) {
final PlotInventory inventory = componentPresetManager.buildInventory(player);
if (inventory != null) {
inventory.openInventory();

View File

@ -170,12 +170,12 @@ public class ComponentPresetManager {
return false;
}
if (componentPreset.getCost() > 0.0D && EconHandler.manager != null && plot.getArea().useEconomy()) {
if (EconHandler.manager.getMoney(player) < componentPreset.getCost()) {
if (componentPreset.getCost() > 0.0D && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()) {
if (EconHandler.getEconHandler().getMoney(player) < componentPreset.getCost()) {
Captions.PRESET_CANNOT_AFFORD.send(player);
return false;
} else {
EconHandler.manager.withdrawMoney(player, componentPreset.getCost());
EconHandler.getEconHandler().withdrawMoney(player, componentPreset.getCost());
Captions.REMOVED_BALANCE.send(player, componentPreset.getCost() + "");
}
}
@ -196,7 +196,7 @@ public class ComponentPresetManager {
for (int i = 0; i < allowedPresets.size(); i++) {
final ComponentPreset preset = allowedPresets.get(i);
final List<String> lore = new ArrayList<>();
if (preset.getCost() > 0 && EconHandler.manager != null && plot.getArea().useEconomy()){
if (preset.getCost() > 0 && EconHandler.getEconHandler() != null && plot.getArea().useEconomy()){
lore.add(Captions.PRESET_LORE_COST.getTranslated().replace("%cost%",
String.format("%.2f", preset.getCost())));
}

View File

@ -182,7 +182,9 @@ public enum Captions implements Caption {
PERMISSION_HOME("plots.home", "static.permissions"),
PERMISSION_ALIAS_SET_OBSOLETE("plots.set.alias", "static.permissions"), // Note this is for backwards compatibility
PERMISSION_ALIAS_SET("plots.alias.set", "static.permissions"),
PERMISSION_ADMIN_ALIAS_SET("plots.admin.alias.set", "static.permissions"),
PERMISSION_ALIAS_REMOVE("plots.alias.remove", "static.permissions"),
PERMISSION_ADMIN_ALIAS_REMOVE("plots.admin.alias.remove", "static.permissions"),
PERMISSION_ADMIN_CHAT_BYPASS("plots.admin.chat.bypass", "static.permissions"),
PERMISSION_BACKUP("plots.backup", "static.permissions"),
PERMISSION_BACKUP_SAVE("plots.backup.save", "static.permissions"),
@ -190,6 +192,7 @@ public enum Captions implements Caption {
PERMISSION_BACKUP_LOAD("plots.backup.load", "static.permissions"),
PERMISSION_ADMIN_BACKUP_OTHER("plots.admin.backup.other", "static.permissions"),
PERMISSION_ADMIN_ALLOW_UNSAFE("plots.admin.unsafe", "static.permissions"),
PERMISSION_ADMIN_DEBUG_OTHER("plots.admin.debug.other", "static.permissions"),
//</editor-fold>
//<editor-fold desc="Confirm">
EXPIRED_CONFIRM("$2Confirmation has expired, please run the command again!", "Confirm"),
@ -319,6 +322,7 @@ public enum Captions implements Caption {
REMOVED_GRANTED_PLOT("$2You used %s0 plot grant(s), you've got $1%s1 $2left", "Economy"),
//</editor-fold>
//<editor-fold desc="Setup">
SETUP_NOT_STARTED("$1No setup started. Use $2/plot setup $1to start a setup process.", "Setup"),
SETUP_INIT("$1Usage: $2/plot setup <value>", "Setup"),
SETUP_STEP("$3[$1Step %s0$3] $1%s1 $2- $1Expecting: $2%s2 $1Default: $2%s3", "Setup"),
SETUP_INVALID_ARG("$2%s0 is not a valid argument for step %s1. To cancel setup use: $1/plot setup cancel", "Setup"),
@ -357,6 +361,11 @@ public enum Captions implements Caption {
SETUP_AREA_MAX_PLOT_ID_ERROR("$7You must choose a valid maximum Plot Id!", "Setup"),
SETUP_AREA_PLOT_ID_GREATER_THAN_MINIMUM("$7The max PlotId must be greater than the minimum!", "Setup"),
//</editor-fold>
//<editor-fold desc=PlotAreaType>
PLOT_AREA_TYPE_NORMAL("Standard plot generation", "PlotAreaType"),
PLOT_AREA_TYPE_AUGMENTED("Plot generation with vanilla terrain", "PlotAreaType"),
PLOT_AREA_TYPE_PARTIAL("Vanilla with clusters of plots", "PlotAreaType"),
//</editor-fold>
//<editor-fold desc="Schematic">
SCHEMATIC_TOO_LARGE("$2The plot is too large for this action!", "Schematics"),
SCHEMATIC_MISSING_ARG("$2You need to specify an argument. Possible values: $1save$2, $1paste $2, $1exportall$2, $1list", "Schematics"),
@ -445,11 +454,14 @@ public enum Captions implements Caption {
NOT_VALID_WORLD("$2That is not a valid world (case sensitive)", "Errors"),
NOT_VALID_PLOT_WORLD("$2That is not a valid plot area (case sensitive)", "Errors"),
NO_PLOTS("$2You don't have any plots", "Errors"),
PLAYER_NO_PLOTS("$2That player does not own any plots", "Errors"),
WAIT_FOR_TIMER("$2A set block timer is bound to either the current plot or you. Please wait for it to finish", "Errors"),
TILE_ENTITY_CAP_REACHED("$2The total number of tile entities in this chunk may not exceed $1%s", "Errors"),
//</editor-fold>
DEBUG_REPORT_CREATED("$1Uploaded a full debug to: $1%url%", "Paste"),
PURGE_SUCCESS("$4Successfully purged %s plots", "Purge"),
FETCHING_PLAYER("$1PlotSquared is attempting to find the specified player from your argument(s). This may take a while.", "Players"),
FETCHING_PLAYERS_TIMEOUT("$2The specified users did not exist in the cache and will be fetched in the background. Please wait a couple of minutes.", "Players"),
//<editor-fold desc="Trim">
TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"),
//</editor-fold>
@ -783,6 +795,21 @@ public enum Captions implements Caption {
GENERIC_INVALID_CHOICE("invalid choice", "Generic"),
//</editor-fold>
//<editor-fold des="Single area">
SINGLE_AREA_MISSING_SELECTION("$2Error! You need to select a square region", "Single"),
SINGLE_AREA_NOT_SQUARE("$2Error! Your selection needs to be a square", "Single"),
SINGLE_AREA_OVERLAPPING("$2Error! Your selection overlaps with an existing plot area", "Single"),
SINGLE_AREA_NEEDS_NAME("$2Error! Please specify a plot name: /plot area single <name>", "Single"),
SINGLE_AREA_NAME_TAKEN("$2Error! The plot name is already taken", "Single"),
SINGLE_AREA_FAILED_TO_SAVE("$2Error! Failed to save the area schematic", "Single"),
SINGLE_AREA_COULD_NOT_MAKE_DIRECTORIES("$2Error! Failed to create the schematic directory", "Single"),
SINGLE_AREA_CREATED("$1The area was created successfully!", "Single"),
//</editor-fold>
//<editor-fold desc="Debug">
PLOT_DEBUG("$2Plot Debug ($1%plot%$2): %message%", "Plot-Debug"),
//</editor-fold>
/**
* Legacy Configuration Conversion
*/

View File

@ -28,9 +28,11 @@ package com.plotsquared.core.configuration;
import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.util.StringMan;
import com.sk89q.worldedit.world.block.BlockState;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
@ -38,19 +40,26 @@ import java.util.List;
*/
public class ConfigurationNode {
private final String constant;
@Getter private final String constant;
private final Object defaultValue;
private final String description;
@Getter private final String description;
private final ConfigurationUtil.SettingValue type;
@Getter private final Collection<String> suggestions;
private Object value;
public ConfigurationNode(String constant, Object defaultValue, String description,
ConfigurationUtil.SettingValue type) {
this(constant, defaultValue, description, type, new ArrayList<>());
}
public ConfigurationNode(String constant, Object defaultValue, String description,
ConfigurationUtil.SettingValue type, Collection<String> suggestions) {
this.constant = constant;
this.defaultValue = defaultValue;
this.description = description;
this.value = defaultValue;
this.type = type;
this.suggestions = suggestions;
}
public ConfigurationUtil.SettingValue getType() {
@ -97,18 +106,10 @@ public class ConfigurationNode {
return this.value;
}
public String getConstant() {
return this.constant;
}
public Object getDefaultValue() {
if (this.defaultValue instanceof Object[]) {
return StringMan.join((Object[]) this.defaultValue, ",");
}
return this.defaultValue;
}
public String getDescription() {
return this.description;
}
}

View File

@ -40,13 +40,14 @@ public class Settings extends Config {
NOTE: Fields are saved in declaration order, classes in reverse order
*/
@Comment("The first value is not configurable") // This is a comment
@Comment("This value is not configurable. It shows the platform you are using.") // This is a comment
@Final public static String PLATFORM; // These values are set from P2 before loading
@Comment("Show additional information in console") public static boolean DEBUG = false;
@Comment({"The big annoying text that appears when you enter a plot",
"For a single plot: `/plot flag set titles false`", "For just you: `/plot toggle titles`",
"For all plots: Add `titles: false` in the worlds.yml flags block"}) public static boolean
@Comment({"Show additional information in console. It helps us at IntellectualSites to find out more about an issue.",
"Leave it off if you don't need it, it can spam your console."}) public static boolean DEBUG = false;
@Comment({"The big text that appears when you enter a plot.",
"For a single plot set `/plot flag set titles false` to disable it.", "For just you run `/plot toggle titles` to disable it.",
"For all plots: Add `titles: false` in the worlds.yml flags block to disable it."}) public static boolean
TITLES = true;
@Create // This value will be generated automatically
@ -207,7 +208,7 @@ public class Settings extends Config {
public List<String> WORLDS = new ArrayList<>(Collections.singletonList("*"));
@Comment("See: https://wiki.intellectualsites.com/en/plotsquared/optimization/plot-analysis")
@Comment("See: https://wiki.intellectualsites.com/en/plotsquared/optimization/plot-analysis for a description of each value.")
public static final class CALIBRATION {
public int VARIETY = 0;
public int VARIETY_SD = 0;
@ -223,6 +224,8 @@ public class Settings extends Config {
}
@Comment({"Chunk processor related settings",
"See https://wiki.intellectualsites.com/en/plotsquared/optimization/chunk-processor for more information."})
public static class Chunk_Processor {
@Comment("Auto trim will not save chunks which aren't claimed") public static boolean
AUTO_TRIM = false;
@ -232,13 +235,28 @@ public class Settings extends Config {
}
@Comment({"UUID settings",
"DO NOT EDIT them unless you know what you are doing."})
public static class UUID {
@Comment("Force using offline UUIDs (it usually detects the right mode)")
public static boolean OFFLINE = false;
@Comment("Force using lowercase UUIDs") public static boolean FORCE_LOWERCASE = false;
@Comment("Use a database to store UUID/name info") public static boolean
USE_SQLUUIDHANDLER = false;
@Ignore public static boolean NATIVE_UUID_PROVIDER = false;
@Comment("How many UUIDs that may be stored in the cache")
public static int UUID_CACHE_SIZE = 100000;
@Comment("Rate limit (per 10 minutes) for background UUID fetching from the Mojang API")
public static int BACKGROUND_LIMIT = 200;
@Comment("Rate limit (per 10 minutes) for random UUID fetching from the Mojang API")
public static int IMPROMPTU_LIMIT = 300;
@Comment("Timeout (in milliseconds) for non-blocking UUID requests (mostly commands)")
public static long NON_BLOCKING_TIMEOUT = 3000L;
@Comment("Timeout (in milliseconds) for blocking UUID requests (events)")
public static long BLOCKING_TIMEOUT = 10L;
@Comment("Whether or not PlotSquared should read from the legacy database")
public static boolean LEGACY_DATABASE_SUPPORT = true;
@Comment("Whether or not PlotSquared should return Unknown if it fails to fulfill a request")
public static boolean UNKNOWN_AS_DEFAULT = true;
}
@ -246,7 +264,8 @@ public class Settings extends Config {
public static final class General {
@Comment("Display scientific numbers (4.2E8)") public static boolean SCIENTIFIC = false;
@Comment("Replace wall when merging") public static boolean MERGE_REPLACE_WALL = true;
@Comment("Blocks that may not be used in plot components") public static List<String>
@Comment({"Blocks that may not be used in plot components",
"Checkout the wiki article regarding plot components before modifying: https://wiki.intellectualsites.com/en/plotsquared/installation/plot-components"}) public static List<String>
INVALID_BLOCKS = Arrays.asList(
// Acacia Stuff
"acacia_button", "acacia_fence_gate", "acacia_door", "acacia_pressure_plate",
@ -360,7 +379,8 @@ public class Settings extends Config {
}
@Comment("Schematic Settings")
@Comment({"Schematic Settings",
"See https://wiki.intellectualsites.com/en/plotsquared/schematics/on-claim for more information."})
public static final class Schematics {
@Comment(
"Whether schematic based generation should paste schematic on top of plots, or from Y=1")
@ -377,6 +397,7 @@ public class Settings extends Config {
}
@Comment("Schematic and Asset interface related settings")
public static class Web {
@Comment({"The web interface for schematics", " - All schematics are anonymous and private",
" - Downloads can be deleted by the user",
@ -389,8 +410,9 @@ public class Settings extends Config {
}
@Comment("Misc settings")
public static final class Done {
@Comment("Require a plot marked as done to download") public static boolean
@Comment("Require a plot marked as done to download (/plot download)") public static boolean
REQUIRED_FOR_DOWNLOAD = false;
@Comment("Only plots marked as done can be rated") public static boolean
REQUIRED_FOR_RATINGS = false;
@ -401,6 +423,7 @@ public class Settings extends Config {
}
@Comment("Chat related settings")
public static final class Chat {
@Comment("Sometimes console color doesn't work, you can disable it here")
public static boolean CONSOLE_COLOR = true;
@ -408,7 +431,7 @@ public class Settings extends Config {
}
@Comment("Relating to how many plots someone can claim ")
@Comment("Relating to how many plots someone can claim")
public static final class Limit {
@Comment("Should the limit be global (over multiple worlds)") public static boolean GLOBAL =
false;
@ -419,9 +442,10 @@ public class Settings extends Config {
}
@Comment("Backup related settings")
@Comment({"Backup related settings",
"See https://wiki.intellectualsites.com/en/plotsquared/backups for more information."})
public static final class Backup {
@Comment("Automatically backup plots when destructive commands are performed")
@Comment("Automatically backup plots when destructive commands are performed, e.g. /plot clear")
public static boolean AUTOMATIC_BACKUPS = true;
@Comment("Maximum amount of backups associated with a plot") public static int
BACKUP_LIMIT = 3;
@ -430,12 +454,14 @@ public class Settings extends Config {
}
@Comment("Confirmation timeout related settings")
public static final class Confirmation {
@Comment("Timeout before a confirmation prompt expires") public static int
CONFIRMATION_TIMEOUT_SECONDS = 20;
}
@Comment("Teleportation related settings")
public static final class Teleport {
@Comment("Teleport to your plot on death") public static boolean ON_DEATH = false;
@Comment("Teleport to your plot on login") public static boolean ON_LOGIN = false;
@ -448,6 +474,7 @@ public class Settings extends Config {
}
@Comment("Redstone related settings")
public static final class Redstone {
@Comment("Disable redstone in unoccupied plots") public static boolean DISABLE_UNOCCUPIED =
false;
@ -459,12 +486,14 @@ public class Settings extends Config {
}
@Comment("Claim related settings")
public static final class Claim {
@Comment("The max plots claimed in a single `/plot auto <size>` command") public static int
MAX_AUTO_AREA = 4;
}
@Comment("Rating related settings")
public static final class Ratings {
@Comment("Replace the rating system with a like system. Will add /plot like/dislike,"
+ " and remove the rating command") public static boolean USE_LIKES = false;
@ -487,6 +516,22 @@ public class Settings extends Config {
public static boolean CREATURE_SPAWN = true;
@Comment("Check the tile entity limit on block placement")
public static boolean TILE_ENTITY_CHECK = true;
@Comment("Use Paper's async tab completion")
public static boolean ASYNC_TAB_COMPLETION;
}
@Comment("Settings relating to PlotSquared's GlobalBlockQueue")
public static final class QUEUE {
@Comment({"Average time per tick spent completing chunk tasks in ms.",
"Waits (chunk task time / target_time) ticks before completely the next task."})
public static int TARGET_TIME = 65;
}
@Comment("Settings related to tab completion")
public static final class Tab_Completions {
@Comment({"The time in seconds how long tab completions should remain in cache.",
"0 will disable caching. Lower values may be less performant."})
public static int CACHE_EXPIRATION = 15;
}
@ -497,8 +542,6 @@ public class Settings extends Config {
@Comment("Events are needed to track a lot of things") public static boolean EVENTS = true;
@Comment("Commands are used to interact with the plugin") public static boolean COMMANDS =
true;
@Comment("The UUID cacher is used to resolve player names") public static boolean
UUID_CACHE = true;
@Comment("Whether we should notify you about updates or not.") public static boolean
UPDATE_NOTIFICATIONS = true;
@Comment("Stores user metadata in a database") public static boolean PERSISTENT_META = true;
@ -508,29 +551,32 @@ public class Settings extends Config {
true;
@Comment("Allow WorldEdit to be restricted to plots") public static boolean
WORLDEDIT_RESTRICTIONS = true;
@Comment("Allow economy to be used") public static boolean ECONOMY = true;
@Comment("Allow economy to be used to sell, claim or buy plots.") public static boolean ECONOMY = true;
@Comment("Expiry will clear old or simplistic plots") public static boolean PLOT_EXPIRY =
false;
@Comment("Processes chunks (trimming, or entity/tile limits) ") public static boolean
CHUNK_PROCESSOR = false;
@Comment("Kill mobs on roads") public static boolean KILL_ROAD_MOBS = false;
@Comment("Kill items on roads") public static boolean KILL_ROAD_ITEMS = false;
@Comment("Kill vehicles on roads") public static boolean KILL_ROAD_VEHICLES = false;
@Comment("Notify a player of any missed comments upon plot entry") public static boolean
@Comment("Kill mobs on roads (Chicken, Cow, etc.)") public static boolean KILL_ROAD_MOBS = false;
@Comment("Kill items on roads (Stick, Paper, etc.)") public static boolean KILL_ROAD_ITEMS = false;
@Comment("Kill vehicles on roads (Boat, Minecart, etc.)") public static boolean KILL_ROAD_VEHICLES = false;
@Comment("Notify a player of any missed plot comments upon plot entry") public static boolean
COMMENT_NOTIFIER = false;
@Comment("Let players claim entire worlds with PlotSquared") public static boolean WORLDS =
false;
@Comment("Actively purge invalid database entries") public static boolean DATABASE_PURGER =
false;
@Comment("Delete plots when a player is banned") public static boolean BAN_DELETER = false;
@Comment("Allows PlaceholderAPI placeholders to be used in captions, flags, etc")
@Comment({"Delete plots when a player is banned.",
"Note: This only works with the /minecraft:ban command. Any punishment plugin like LiteBans is not supported."}) public static boolean BAN_DELETER = false;
@Comment("Allows PlaceholderAPI placeholders to be used in captions, flags, etc.")
public static boolean EXTERNAL_PLACEHOLDERS = true;
@Comment("Make road regeneration persistent across restarts") public static boolean
PERSISTENT_ROAD_REGEN = false;
@Comment("Try to guess plot owners from sign data. This may decrease server performance")
public static boolean GUESS_PLOT_OWNER = false;
@Comment("Plot component preset GUI")
public static boolean COMPONENT_PRESETS = true;
@Comment({"Enable the `/plot component` preset GUI",
"Read more about components here: https://wiki.intellectualsites.com/en/plotsquared/installation/plot-components"}) public static boolean COMPONENT_PRESETS = true;
@Comment("Use UUID cache to complete usernames")
public static boolean EXTENDED_USERNAME_COMPLETION = true;
@Comment("Command aliases that will be tab completed")
public static List<String> TAB_COMPLETED_ALIASES = Arrays.asList("plot", "plots", "p", "plotsquared", "plot2", "p2", "ps", "2", "plotme", "plotz", "ap");
}
}

View File

@ -36,6 +36,7 @@ import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.RegionManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.world.block.BlockTypes;
@ -92,75 +93,38 @@ public class ClassicPlotManager extends SquarePlotManager {
public boolean setFloor(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId);
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
if (plot.isBasePlot()) {
for (CuboidRegion region : plot.getRegions()) {
Location pos1 =
new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(),
classicPlotWorld.PLOT_HEIGHT, region.getMinimumPoint().getZ());
Location pos2 =
new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(),
classicPlotWorld.PLOT_HEIGHT, region.getMaximumPoint().getZ());
queue.setCuboid(pos1, pos2, blocks);
}
return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks,
classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT);
}
return queue.enqueue();
return false;
}
public boolean setAll(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId);
if (!plot.isBasePlot()) {
return false;
if (plot.isBasePlot()) {
return RegionManager.manager
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight());
}
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
int maxY = getWorldHeight();
for (CuboidRegion region : plot.getRegions()) {
Location pos1 =
new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), 1,
region.getMinimumPoint().getZ());
Location pos2 =
new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), maxY,
region.getMaximumPoint().getZ());
queue.setCuboid(pos1, pos2, blocks);
}
return queue.enqueue();
return false;
}
public boolean setAir(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId);
if (!plot.isBasePlot()) {
return false;
if (plot.isBasePlot()) {
return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks,
classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight());
}
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
int maxY = getWorldHeight();
for (CuboidRegion region : plot.getRegions()) {
Location pos1 =
new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(),
classicPlotWorld.PLOT_HEIGHT + 1, region.getMinimumPoint().getZ());
Location pos2 =
new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(), maxY,
region.getMaximumPoint().getZ());
queue.setCuboid(pos1, pos2, blocks);
}
return queue.enqueue();
return false;
}
public boolean setMain(PlotId plotId, Pattern blocks) {
Plot plot = classicPlotWorld.getPlotAbs(plotId);
if (!plot.isBasePlot()) {
return false;
if (plot.isBasePlot()) {
return RegionManager.manager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1,
classicPlotWorld.PLOT_HEIGHT - 1);
}
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
for (CuboidRegion region : plot.getRegions()) {
Location pos1 =
new Location(classicPlotWorld.getWorldName(), region.getMinimumPoint().getX(), 1,
region.getMinimumPoint().getZ());
Location pos2 =
new Location(classicPlotWorld.getWorldName(), region.getMaximumPoint().getX(),
classicPlotWorld.PLOT_HEIGHT - 1, region.getMaximumPoint().getZ());
queue.setCuboid(pos1, pos2, blocks);
}
return queue.enqueue();
return false;
}
public boolean setMiddle(PlotId plotId, Pattern blocks) {
@ -491,17 +455,17 @@ public class ClassicPlotManager extends SquarePlotManager {
int sz = location.getZ() + 1;
int ez = sz + classicPlotWorld.ROAD_WIDTH - 1;
LocalBlockQueue queue = classicPlotWorld.getQueue(false);
queue.setCuboid(
new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.ROAD_HEIGHT + 1, sz),
new Location(classicPlotWorld.getWorldName(), ex,
classicPlotWorld.getPlotManager().getWorldHeight(), ez),
BlockTypes.AIR.getDefaultState());
queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx,
Math.min(classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.ROAD_HEIGHT) + 1, sz),
new Location(classicPlotWorld.getWorldName(), ex,
classicPlotWorld.getPlotManager().getWorldHeight(), ez),
BlockTypes.AIR.getDefaultState());
queue.setCuboid(new Location(classicPlotWorld.getWorldName(), sx, 1, sz),
new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.ROAD_HEIGHT - 1, ez),
new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT - 1, ez),
classicPlotWorld.MAIN_BLOCK.toPattern());
queue.setCuboid(
new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.ROAD_HEIGHT, sz),
new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.ROAD_HEIGHT, ez),
new Location(classicPlotWorld.getWorldName(), sx, classicPlotWorld.PLOT_HEIGHT, sz),
new Location(classicPlotWorld.getWorldName(), ex, classicPlotWorld.PLOT_HEIGHT, ez),
classicPlotWorld.TOP_BLOCK.toPattern());
return queue.enqueue();
}

View File

@ -195,8 +195,16 @@ public class HybridPlotWorld extends ClassicPlotWorld {
public void setupSchematics() throws SchematicHandler.UnsupportedFormatException {
this.G_SCH = new HashMap<>();
this.G_SCH_B = new HashMap<>();
File root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
"schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName());
// Try to determine root. This means that plot areas can have separate schematic
// directories
File root;
if (!(root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" +
this.getWorldName() + "/" + this.getId())).exists()) {
root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
"schematics/GEN_ROAD_SCHEMATIC/" + this.getWorldName());
}
File schematic1File = new File(root, "sideroad.schem");
if (!schematic1File.exists())
schematic1File = new File(root, "sideroad.schematic");
@ -272,37 +280,8 @@ public class HybridPlotWorld extends ClassicPlotWorld {
(short) (z + shift + oddshift + centerShiftZ), biome);
}
}
/* HashMap<BlockLoc, CompoundTag> items = schematic3.getTiles();
if (!items.isEmpty()) {
this.G_SCH_STATE = new HashMap<>();
outer:
for (Map.Entry<BlockLoc, CompoundTag> entry : items.entrySet()) {
BlockLoc loc = entry.getKey();
short x = (short) (loc.x + shift + oddshift + centerShiftX);
short z = (short) (loc.z + shift + oddshift + centerShiftZ);
short y = (short) (loc.y + this.PLOT_HEIGHT);
int pair = MathMan.pair(x, z);
HashMap<Integer, CompoundTag> existing = this.G_SCH_STATE.get(pair);
if (existing == null) {
existing = new HashMap<>();
this.G_SCH_STATE.put(pair, existing);
}
existing.put((int) y, entry.getValue());
CompoundTag tag = entry.getValue();
Map<String, Tag> map = ReflectionUtils.getMap(tag.getValue());
for (int i = 1; i <= 4; i++) {
String ln = tag.getString("Line" + i);
if (ln == null || ln.length() > 11)
continue outer;
}
SIGN_LOCATION =
new Location(worldname, loc.x + centerShiftX, this.PLOT_HEIGHT + loc.y,
loc.z + centerShiftZ);
ALLOW_SIGNS = true;
continue outer;
}
}*/
PlotSquared.debug(Captions.PREFIX + "&3 - plot schematic: &7" + schematic3File.getPath());
}
if (schematic1 == null || schematic2 == null || this.ROAD_WIDTH == 0) {
PlotSquared.debug(Captions.PREFIX + "&3 - schematic: &7false");
@ -356,7 +335,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
(short) (z - shift), id, false, h2);
}
}
BiomeType biome = blockArrayClipboard1
BiomeType biome = blockArrayClipboard2
.getBiome(BlockVector2.at(x + min.getBlockX(), z + min.getBlockZ()));
addOverlayBiome((short) (x - shift), (short) (z - shift), biome);
}

View File

@ -30,6 +30,8 @@ import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.queue.ScopedLocalBlockQueue;
import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.setup.SetupProcess;
/**
* This class allows for implementation independent world generation.
@ -74,9 +76,18 @@ public abstract class IndependentPlotGenerator {
*
* @param setup
*/
@Deprecated
public void processSetup(SetupObject setup) {
}
/**
* If any additional setup options need to be changed before world creation.
* - e.g. If setup doesn't support some standard options
*
* @param builder the area builder to modify
*/
public void processAreaSetup(PlotAreaBuilder builder) { }
/**
* It is preferred for the PlotArea object to do most of the initialization necessary.
*

View File

@ -61,7 +61,6 @@ import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
import com.sk89q.worldedit.world.item.ItemType;
@ -124,7 +123,7 @@ public class PlotListener {
}, 20);
}
public static boolean plotEntry(final PlotPlayer player, final Plot plot) {
public static boolean plotEntry(final PlotPlayer<?> player, final Plot plot) {
if (plot.isDenied(player.getUUID()) && !Permissions
.hasPermission(player, "plots.admin.entry.denied")) {
return false;
@ -161,7 +160,7 @@ public class PlotListener {
if (plot.getFlag(NotifyEnterFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) {
PlotPlayer owner = UUIDHandler.getPlayer(uuid);
final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (owner != null && !owner.getUUID().equals(player.getUUID())) {
MainUtil.sendMessage(owner, Captions.NOTIFY_ENTER.getTranslated()
.replace("%player", player.getName())
@ -294,7 +293,7 @@ public class PlotListener {
return true;
}
public static boolean plotExit(final PlotPlayer player, Plot plot) {
public static boolean plotExit(final PlotPlayer<?> player, Plot plot) {
Object previous = player.deleteMeta(PlotPlayer.META_LAST_PLOT);
PlotSquared.get().getEventDispatcher().callLeave(player, plot);
if (plot.hasOwner()) {
@ -337,7 +336,7 @@ public class PlotListener {
if (plot.getFlag(NotifyLeaveFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) {
PlotPlayer owner = UUIDHandler.getPlayer(uuid);
final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if ((owner != null) && !owner.getUUID().equals(player.getUUID())) {
MainUtil.sendMessage(owner, Captions.NOTIFY_LEAVE.getTranslated()
.replace("%player", player.getName())

View File

@ -34,6 +34,8 @@ import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import lombok.Getter;
import lombok.Setter;
import org.khelekore.prtree.MBR;
import org.khelekore.prtree.SimpleMBR;
public class Location implements Cloneable, Comparable<Location> {
@ -221,6 +223,10 @@ public class Location implements Cloneable, Comparable<Location> {
return this;
}
public MBR toMBR() {
return new SimpleMBR(this.getX(), this.getX(), this.getY(), this.getY(), this.getZ(), this.getZ());
}
@Override public boolean equals(Object o) {
if (o == null) {
return false;

View File

@ -41,7 +41,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.UUID;
public class ConsolePlayer extends PlotPlayer {
public class ConsolePlayer extends PlotPlayer<Actor> {
private static ConsolePlayer instance;
@ -71,6 +71,10 @@ public class ConsolePlayer extends PlotPlayer {
return PlotSquared.get().IMP.getConsole();
}
@Override public Actor getPlatformPlayer() {
return this.toActor();
}
@Override public boolean canTeleport(@NotNull Location location) {
return true;
}

View File

@ -49,7 +49,6 @@ import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.item.ItemType;
@ -57,8 +56,11 @@ import lombok.NonNull;
import org.jetbrains.annotations.NotNull;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -69,18 +71,23 @@ import java.util.stream.Collectors;
/**
* The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}.
*/
public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer {
public static final String META_LAST_PLOT = "lastplot";
public static final String META_LOCATION = "location";
// Used to track debug mode
private static final Set<PlotPlayer<?>> debugModeEnabled = Collections.synchronizedSet(new HashSet<>());
private static final Map<Class, PlotPlayerConverter> converters = new HashMap<>();
private Map<String, byte[]> metaMap = new HashMap<>();
/**
* The metadata map.
*/
private ConcurrentHashMap<String, Object> meta;
private int hash;
public static <T> PlotPlayer from(@NonNull final T object) {
public static <T> PlotPlayer<T> from(@NonNull final T object) {
if (!converters.containsKey(object.getClass())) {
throw new IllegalArgumentException(String
.format("There is no registered PlotPlayer converter for type %s",
@ -94,6 +101,23 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
converters.put(clazz, converter);
}
public static Collection<PlotPlayer<?>> getDebugModePlayers() {
return Collections.unmodifiableCollection(debugModeEnabled);
}
public static Collection<PlotPlayer<?>> getDebugModePlayersInPlot(@NotNull final Plot plot) {
if (debugModeEnabled.isEmpty()) {
return Collections.emptyList();
}
final Collection<PlotPlayer<?>> players = new LinkedList<>();
for (final PlotPlayer<?> player : debugModeEnabled) {
if (player.getCurrentPlot().equals(plot)) {
players.add(player);
}
}
return players;
}
/**
* Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)<br>
* - Accepts sponge/bukkit Player (online)
@ -101,26 +125,17 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
* - Accepts UUID
* - Accepts bukkit OfflinePlayer (offline)
*
* @param player
* @return
* @param player Player object to wrap
* @return Wrapped player
*/
public static PlotPlayer wrap(Object player) {
public static PlotPlayer<?> wrap(Object player) {
return PlotSquared.get().IMP.wrapPlayer(player);
}
/**
* Get the cached PlotPlayer from a username<br>
* - This will return null if the player has not finished logging in or is not online
*
* @param name
* @return
*/
public static PlotPlayer get(String name) {
return UUIDHandler.getPlayer(name);
}
public abstract Actor toActor();
public abstract P getPlatformPlayer();
/**
* Set some session only metadata for this player.
*
@ -363,8 +378,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
/**
* Get this player's full location (including yaw/pitch)
*
* @return
*/
public abstract Location getLocationFull();
@ -531,6 +544,15 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
*/
public abstract void kick(String message);
public void refreshDebug() {
final boolean debug = this.getAttribute("debug");
if (debug && !debugModeEnabled.contains(this)) {
debugModeEnabled.add(this);
} else if (!debug) {
debugModeEnabled.remove(this);
}
}
/**
* Called when this player quits.
*/
@ -563,12 +585,13 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
plot.getId(), getName()));
}
}
String name = getName();
if (ExpireManager.IMP != null) {
ExpireManager.IMP.storeDate(getUUID(), System.currentTimeMillis());
}
UUIDHandler.getPlayers().remove(name);
PlotSquared.imp().getPlayerManager().removePlayer(this);
PlotSquared.get().IMP.unregister(this);
debugModeEnabled.remove(this);
}
/**
@ -616,6 +639,10 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
return;
}
if (PlotPlayer.this.getAttribute("debug")) {
debugModeEnabled.add(PlotPlayer.this);
}
if (!Settings.Teleport.ON_LOGIN) {
return;
}
@ -706,24 +733,41 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
public abstract void stopSpectating();
public boolean hasDebugMode() {
return this.getAttribute("debug");
}
@Override public int hashCode() {
if (this.hash == 0 || this.hash == 485) {
this.hash = 485 + this.getUUID().hashCode();
}
return this.hash;
}
@Override public boolean equals(final Object obj) {
if (!(obj instanceof PlotPlayer)) {
return false;
}
final PlotPlayer<?> other = (PlotPlayer<?>) obj;
return this.getUUID().equals(other.getUUID());
}
/**
* The amount of money this Player has.
*
* @return
*/
public double getMoney() {
return EconHandler.manager == null ? 0 : EconHandler.manager.getMoney(this);
return EconHandler.getEconHandler() == null ? 0 : EconHandler.getEconHandler().getMoney(this);
}
public void withdraw(double amount) {
if (EconHandler.manager != null) {
EconHandler.manager.withdrawMoney(this, amount);
if (EconHandler.getEconHandler() != null) {
EconHandler.getEconHandler().withdrawMoney(this, amount);
}
}
public void deposit(double amount) {
if (EconHandler.manager != null) {
EconHandler.manager.depositMoney(this, amount);
if (EconHandler.getEconHandler() != null) {
EconHandler.getEconHandler().depositMoney(this, amount);
}
}

View File

@ -25,7 +25,6 @@
*/
package com.plotsquared.core.plot;
import com.google.common.collect.BiMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.plotsquared.core.PlotSquared;
@ -56,17 +55,14 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag;
import com.plotsquared.core.plot.schematic.Schematic;
import com.plotsquared.core.queue.GlobalBlockQueue;
import com.plotsquared.core.queue.LocalBlockQueue;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.StringWrapper;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector2;
@ -83,7 +79,6 @@ import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
@ -404,12 +399,11 @@ public class Plot {
*
* @return list of PlotPlayer(s) or an empty list
*/
public List<PlotPlayer> getPlayersInPlot() {
ArrayList<PlotPlayer> players = new ArrayList<>();
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer plotPlayer = entry.getValue();
if (this.equals(plotPlayer.getCurrentPlot())) {
players.add(plotPlayer);
public List<PlotPlayer<?>> getPlayersInPlot() {
final List<PlotPlayer<?>> players = new ArrayList<>();
for (final PlotPlayer<?> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
if (this.equals(player.getCurrentPlot())) {
players.add(player);
}
}
return players;
@ -502,7 +496,7 @@ public class Plot {
}
if (isMerged()) {
Set<Plot> plots = getConnectedPlots();
Plot[] array = plots.toArray(new Plot[plots.size()]);
Plot[] array = plots.toArray(new Plot[0]);
ImmutableSet.Builder<UUID> owners = ImmutableSet.builder();
UUID last = this.getOwner();
owners.add(this.getOwner());
@ -1052,9 +1046,11 @@ public class Plot {
}
if (createSign) {
GlobalBlockQueue.IMP.addEmptyTask(() -> {
for (Plot current : plots) {
current.setSign(MainUtil.getName(current.getOwnerAbs()));
}
TaskManager.runTaskAsync(() -> {
for (Plot current : plots) {
current.setSign(MainUtil.getName(current.getOwnerAbs()));
}
});
});
}
if (createRoad) {
@ -1327,8 +1323,8 @@ public class Plot {
return false;
}
for (Plot current : getConnectedPlots()) {
List<PlotPlayer> players = current.getPlayersInPlot();
for (PlotPlayer pp : players) {
List<PlotPlayer<?>> players = current.getPlayersInPlot();
for (PlotPlayer<?> pp : players) {
PlotListener.plotExit(pp, current);
}
@ -1717,12 +1713,8 @@ public class Plot {
this.setSign("unknown");
return;
}
String name = UUIDHandler.getName(this.getOwnerAbs());
if (name == null) {
this.setSign("unknown");
} else {
this.setSign(name);
}
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(this.getOwnerAbs(), (username, sign) ->
this.setSign(username));
}
/**
@ -1759,6 +1751,7 @@ public class Plot {
}
} else {
area.addPlot(this);
updateWorldBorder();
}
setSign(player.getName());
MainUtil.sendMessage(player, Captions.CLAIMED);
@ -2372,7 +2365,6 @@ public class Plot {
* Check if a plot can be claimed by the provided player.
*
* @param player the claiming player
* @return
*/
public boolean canClaim(@NotNull PlotPlayer player) {
PlotCluster cluster = this.getCluster();
@ -2382,81 +2374,13 @@ public class Plot {
return false;
}
}
final UUID owner = this.guessOwner();
final UUID owner = this.getOwnerAbs();
if (owner != null) {
return false;
}
return !isMerged();
}
/**
* Guess the owner of a plot either by the value in memory, or the sign data<br>
* Note: Recovering from sign information is useful if e.g. PlotMe conversion wasn't successful
*
* @return UUID
*/
public UUID guessOwner() {
if (this.hasOwner()) {
return this.getOwnerAbs();
}
if (!this.area.allowSigns() || !Settings.Enabled_Components.GUESS_PLOT_OWNER) {
return null;
}
try {
final Location location = this.getManager().getSignLoc(this);
String[] lines = TaskManager.IMP.sync(new RunnableVal<String[]>() {
@Override public void run(String[] value) {
ChunkManager.manager
.loadChunk(location.getWorld(), location.getBlockVector2(), false);
this.value = WorldUtil.IMP.getSignSynchronous(location);
}
});
if (lines == null) {
return null;
}
loop:
for (int i = 4; i > 0; i--) {
String caption = Captions.valueOf("OWNER_SIGN_LINE_" + i).getTranslated();
int index = caption.indexOf("%plr%");
if (index < 0) {
continue;
}
String line = lines[i - 1];
if (line.length() <= index) {
return null;
}
String name = line.substring(index);
if (name.isEmpty()) {
return null;
}
UUID owner = UUIDHandler.getUUID(name, null);
if (owner != null) {
this.setOwnerAbs(owner);
break;
}
if (lines[i - 1].length() == 15) {
BiMap<StringWrapper, UUID> map = UUIDHandler.getUuidMap();
for (Entry<StringWrapper, UUID> entry : map.entrySet()) {
String key = entry.getKey().value;
if (key.length() > name.length() && key.startsWith(name)) {
this.setOwnerAbs(entry.getValue());
break loop;
}
}
}
this.setOwnerAbs(UUID.nameUUIDFromBytes(
("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)));
break;
}
if (this.hasOwner()) {
this.create();
}
return this.getOwnerAbs();
} catch (IllegalArgumentException ignored) {
return null;
}
}
/**
* Remove the south road section of a plot<br>
* - Used when a plot is merged<br>
@ -2994,13 +2918,29 @@ public class Plot {
*/
public void reEnter() {
TaskManager.runTaskLater(() -> {
for (PlotPlayer pp : Plot.this.getPlayersInPlot()) {
for (PlotPlayer<?> pp : Plot.this.getPlayersInPlot()) {
PlotListener.plotExit(pp, Plot.this);
PlotListener.plotEntry(pp, Plot.this);
}
}, 1);
}
public void debug(@NotNull final String message) {
try {
final Collection<PlotPlayer<?>> players = PlotPlayer.getDebugModePlayersInPlot(this);
if (players.isEmpty()) {
return;
}
final String string =
Captions.PLOT_DEBUG.getTranslated().replace("%plot%", this.toString()).replace("%message%", message);
for (final PlotPlayer<?> player : players) {
if (isOwner(player.getUUID()) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_DEBUG_OTHER)) {
player.sendMessage(string);
}
}
} catch (final Exception ignored) {}
}
/**
* Gets all the corners of the plot (supports non-rectangular shapes).
*
@ -3099,10 +3039,12 @@ public class Plot {
return false;
}
if (!isMerged()) {
return UUIDHandler.getPlayer(this.getOwnerAbs()) != null;
return PlotSquared.imp().getPlayerManager()
.getPlayerIfExists(Objects.requireNonNull(this.getOwnerAbs())) != null;
}
for (final Plot current : getConnectedPlots()) {
if (current.hasOwner() && UUIDHandler.getPlayer(current.getOwnerAbs()) != null) {
if (current.hasOwner() && PlotSquared.imp().getPlayerManager()
.getPlayerIfExists(Objects.requireNonNull(current.getOwnerAbs())) != null) {
return true;
}
}
@ -3114,9 +3056,9 @@ public class Plot {
* - E.g. floor, wall, border etc.<br>
* - The available components depend on the generator being used<br>
*
* @param component
* @param blocks
* @return
* @param component Component to set
* @param blocks Pattern to use the generation
* @return True if the component was set successfully
*/
public boolean setComponent(String component, Pattern blocks) {
PlotComponentSetEvent event =

View File

@ -1026,7 +1026,7 @@ public abstract class PlotArea {
* @return true if plot signs are allow, false otherwise.
*/
public boolean allowSigns() {
return allowSigns;
return allowSigns && (this.plots.size() > 1) /* Do not generate signs for single plots */;
}
/**

View File

@ -25,6 +25,10 @@
*/
package com.plotsquared.core.plot;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.Captions;
import lombok.Getter;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
@ -32,11 +36,23 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
public enum PlotAreaType {
NORMAL, AUGMENTED, PARTIAL;
NORMAL(Captions.PLOT_AREA_TYPE_NORMAL),
AUGMENTED(Captions.PLOT_AREA_TYPE_AUGMENTED),
PARTIAL(Captions.PLOT_AREA_TYPE_PARTIAL);
@Getter private final Caption description;
private static final Map<String, PlotAreaType> types = Stream.of(values())
.collect(Collectors.toMap(e -> e.toString().toLowerCase(), Function.identity()));
PlotAreaType(Caption description) {
this.description = description;
}
public static Map<PlotAreaType, Caption> getDescriptionMap() {
return Stream.of(values()).collect(Collectors.toMap(e -> e, PlotAreaType::getDescription));
}
public static Optional<PlotAreaType> fromString(String typeName) {
return Optional.ofNullable(types.get(typeName.toLowerCase()));
}

View File

@ -25,7 +25,10 @@
*/
package com.plotsquared.core.plot;
public abstract class PlotFilter {
/**
* Use {@link com.plotsquared.core.util.query.PlotQuery} instead
*/
@Deprecated public abstract class PlotFilter {
public boolean allowsArea(final PlotArea area) {
return true;
}
@ -33,4 +36,5 @@ public abstract class PlotFilter {
public boolean allowsPlot(final Plot plot) {
return true;
}
}

View File

@ -33,40 +33,40 @@ import lombok.NonNull;
public class PlotInventory {
private static final String META_KEY = "inventory";
public final PlotPlayer player;
public final PlotPlayer<?> player;
public final int size;
private final PlotItemStack[] items;
private String title;
private boolean open = false;
public PlotInventory(PlotPlayer player) {
public PlotInventory(PlotPlayer<?> player) {
this.size = 4;
this.title = null;
this.player = player;
this.items = InventoryUtil.manager.getItems(player);
}
public PlotInventory(PlotPlayer player, int size, String name) {
public PlotInventory(PlotPlayer<?> player, int size, String name) {
this.size = size;
this.title = name == null ? "" : name;
this.player = player;
this.items = new PlotItemStack[size * 9];
}
public static boolean hasPlotInventoryOpen(@NonNull final PlotPlayer plotPlayer) {
public static boolean hasPlotInventoryOpen(@NonNull final PlotPlayer<?> plotPlayer) {
return getOpenPlotInventory(plotPlayer) != null;
}
public static PlotInventory getOpenPlotInventory(@NonNull final PlotPlayer plotPlayer) {
public static PlotInventory getOpenPlotInventory(@NonNull final PlotPlayer<?> plotPlayer) {
return plotPlayer.getMeta(META_KEY, null);
}
public static void setPlotInventoryOpen(@NonNull final PlotPlayer plotPlayer,
public static void setPlotInventoryOpen(@NonNull final PlotPlayer<?> plotPlayer,
@NonNull final PlotInventory plotInventory) {
plotPlayer.setMeta(META_KEY, plotInventory);
}
public static void removePlotInventoryOpen(@NonNull final PlotPlayer plotPlayer) {
public static void removePlotInventoryOpen(@NonNull final PlotPlayer<?>plotPlayer) {
plotPlayer.deleteMeta(META_KEY);
}

View File

@ -0,0 +1,105 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* 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, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.plot;
import com.plotsquared.core.location.Location;
import com.sk89q.worldedit.regions.CuboidRegion;
import lombok.EqualsAndHashCode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
/**
* A world that contains plots
*/
@EqualsAndHashCode
public abstract class PlotWorld {
private final String world;
/**
* Create a new plot world with a given world name
*
* @param world World name
*/
protected PlotWorld(@NotNull final String world) {
this.world = world;
}
/**
* Get the plot area that contains the given location, or null
* if the location is not a part of a plot area.
*
* @param location Location
* @return Containing plot area, or null
*/
@Nullable public abstract PlotArea getArea(@NotNull final Location location);
/**
* Get all plot areas in the world
*
* @return All plot areas in the world
*/
@NotNull public abstract Collection<PlotArea> getAreas();
/**
* Get all plot areas in a specified region
*
* @param region Region
* @return All areas in the region
*/
@NotNull public abstract Collection<PlotArea> getAreasInRegion(
@NotNull final CuboidRegion region);
/**
* Register a new area in the world
*
* @param area Plot area
*/
public void addArea(@NotNull final PlotArea area) {
throw new UnsupportedOperationException("This world type does not allow adding new areas");
}
/**
* Remove an area from the world
*
* @param area Plot area
*/
public void removeArea(@NotNull final PlotArea area) {
throw new UnsupportedOperationException("This world type does not allow removing areas");
}
/**
* Get the world name
*
* @return World name
*/
public String getWorld() {
return this.world;
}
}

View File

@ -28,6 +28,10 @@ package com.plotsquared.core.plot;
import com.plotsquared.core.configuration.ConfigurationNode;
import com.plotsquared.core.util.SetupUtils;
/**
* @deprecated will be removed in v6
*/
@Deprecated
public class SetupObject {
/**

View File

@ -38,8 +38,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@Beta
public class CommentManager {
@Beta public class CommentManager {
public static final HashMap<String, CommentInbox> inboxes = new HashMap<>();
@ -76,7 +75,7 @@ public class CommentManager {
}, 20);
}
public static long getTimestamp(PlotPlayer player, String inbox) {
public static long getTimestamp(PlotPlayer<?> player, String inbox) {
return player.getMeta("inbox:" + inbox, player.getLastPlayed());
}

View File

@ -27,7 +27,6 @@ package com.plotsquared.core.plot.expiration;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.database.DBFunc;
import com.plotsquared.core.events.PlotFlagAddEvent;
import com.plotsquared.core.events.PlotUnlinkEvent;
@ -48,7 +47,6 @@ import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.ArrayDeque;
import java.util.ArrayList;
@ -85,7 +83,7 @@ public class ExpireManager {
this.tasks.add(task);
}
public void handleJoin(PlotPlayer pp) {
public void handleJoin(PlotPlayer<?> pp) {
storeDate(pp.getUUID(), System.currentTimeMillis());
if (plotsToDelete != null && !plotsToDelete.isEmpty()) {
for (Plot plot : pp.getPlots()) {
@ -153,11 +151,11 @@ public class ExpireManager {
//.text("\n - ").color("$3").text("Delete all (/plot delete expired)").color("$2").command("/plot delete expired")
.text("\n - ").color("$3").text("Delete this (/plot delete)")
.color("$2").command("/plot delete").tooltip("/plot delete")
.text("\n - ").color("$3").text("Remind later (/plot set keep 1d)")
.color("$2").command("/plot set keep 1d").tooltip("/plot set keep 1d")
.text("\n - ").color("$3").text("Keep this (/plot set keep true)")
.color("$2").command("/plot set keep true")
.tooltip("/plot set keep true").text("\n - ").color("$3")
.text("\n - ").color("$3").text("Remind later (/plot flag set keep 1d)")
.color("$2").command("/plot flag set keep 1d").tooltip("/plot flag set keep 1d")
.text("\n - ").color("$3").text("Keep this (/plot flag set keep true)")
.color("$2").command("/plot flag set keep true")
.tooltip("/plot flag set keep true").text("\n - ").color("$3")
.text("Don't show me this").color("$2")
.command("/plot toggle clear-confirmation")
.tooltip("/plot toggle clear-confirmation");
@ -411,13 +409,13 @@ public class ExpireManager {
}
}
for (UUID helper : plot.getTrusted()) {
PlotPlayer player = UUIDHandler.getPlayer(helper);
PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(helper);
if (player != null) {
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
}
}
for (UUID helper : plot.getMembers()) {
PlotPlayer player = UUIDHandler.getPlayer(helper);
PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(helper);
if (player != null) {
MainUtil.sendMessage(player, Captions.PLOT_REMOVED_USER, plot.toString());
}
@ -433,56 +431,34 @@ public class ExpireManager {
.getString(plots));
PlotSquared.debug("$4 - Area: " + plot.getArea());
if (plot.hasOwner()) {
PlotSquared.debug("$4 - Owner: " + UUIDHandler.getName(plot.getOwner()));
PlotSquared.debug("$4 - Owner: " + plot.getOwner());
} else {
PlotSquared.debug("$4 - Owner: Unowned");
}
}
public long getAge(UUID uuid) {
if (UUIDHandler.getPlayer(uuid) != null) {
if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid) != null) {
return 0;
}
String name = UUIDHandler.getName(uuid);
if (name != null) {
Long last = this.dates_cache.get(uuid);
if (last == null) {
OfflinePlotPlayer opp;
if (Settings.UUID.NATIVE_UUID_PROVIDER) {
opp = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
} else {
opp = UUIDHandler.getUUIDWrapper().getOfflinePlayer(name);
}
if (opp != null && (last = opp.getLastPlayed()) != 0) {
this.dates_cache.put(uuid, last);
} else {
return 0;
}
}
if (last == 0) {
Long last = this.dates_cache.get(uuid);
if (last == null) {
OfflinePlotPlayer opp = PlotSquared.imp().getPlayerManager().getOfflinePlayer(uuid);
if (opp != null && (last = opp.getLastPlayed()) != 0) {
this.dates_cache.put(uuid, last);
} else {
return 0;
}
return System.currentTimeMillis() - last;
}
return 0;
}
public long getAccountAge(Plot plot) {
if (!plot.hasOwner() || Objects.equals(DBFunc.EVERYONE, plot.getOwner())
|| UUIDHandler.getPlayer(plot.getOwner()) != null || plot.getRunning() > 0) {
return Long.MAX_VALUE;
if (last == 0) {
return 0;
}
long max = 0;
for (UUID owner : plot.getOwners()) {
long age = getAccountAge(owner);
max = Math.max(age, max);
}
return max;
return System.currentTimeMillis() - last;
}
public long getAge(Plot plot) {
if (!plot.hasOwner() || Objects.equals(DBFunc.EVERYONE, plot.getOwner())
|| UUIDHandler.getPlayer(plot.getOwner()) != null || plot.getRunning() > 0) {
|| PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwner()) != null || plot.getRunning() > 0) {
return 0;
}

View File

@ -42,8 +42,7 @@ import java.util.Map;
/**
* Container type for {@link PlotFlag plot flags}.
*/
@EqualsAndHashCode(of = "flagMap")
public class FlagContainer {
@EqualsAndHashCode(of = "flagMap") public class FlagContainer {
private final Map<String, String> unknownFlags = new HashMap<>();
private final Map<Class<?>, PlotFlag<?, ?>> flagMap = new HashMap<>();
@ -341,8 +340,7 @@ public class FlagContainer {
/**
* Handler for update events in {@link FlagContainer flag containers}.
*/
@FunctionalInterface
public interface PlotFlagUpdateHandler {
@FunctionalInterface public interface PlotFlagUpdateHandler {
/**
* Act on the flag update event

View File

@ -41,8 +41,7 @@ import java.util.Collections;
*
* @param <T> Value contained in the flag.
*/
@EqualsAndHashCode(of = "value")
public abstract class PlotFlag<T, F extends PlotFlag<T, F>> {
@EqualsAndHashCode(of = "value") public abstract class PlotFlag<T, F extends PlotFlag<T, F>> {
private final T value;
private final Caption flagCategory;

Some files were not shown because too many files have changed in this diff Show More