mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 18:24:43 +02:00
Progress.
This commit is contained in:
@ -36,13 +36,13 @@ import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.EconHandler;
|
||||
import com.plotsquared.core.util.InventoryUtil;
|
||||
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;
|
||||
|
||||
@ -220,12 +220,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 +279,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 getPlayerManager();
|
||||
|
||||
}
|
||||
|
@ -79,11 +79,9 @@ 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.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;
|
||||
@ -91,6 +89,7 @@ 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;
|
||||
@ -259,15 +258,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
|
||||
@ -392,11 +382,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");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -437,8 +427,7 @@ public class PlotSquared {
|
||||
private void startUuidCatching() {
|
||||
TaskManager.runTaskLater(() -> {
|
||||
debug("Starting UUID caching");
|
||||
UUIDHandler.startCaching(() -> {
|
||||
UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
|
||||
/*UUIDHandler.startCaching(() -> {
|
||||
forEachPlotRaw(plot -> {
|
||||
if (plot.hasOwner() && plot.temp != -1) {
|
||||
if (UUIDHandler.getName(plot.getOwnerAbs()) == null) {
|
||||
@ -447,7 +436,8 @@ public class PlotSquared {
|
||||
}
|
||||
});
|
||||
startExpiryTasks();
|
||||
});
|
||||
});*/
|
||||
// TODO: Re-implement
|
||||
}, 20);
|
||||
}
|
||||
|
||||
@ -973,7 +963,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, 10L);
|
||||
return getPlots(world, uuid);
|
||||
}
|
||||
|
||||
@ -985,7 +975,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, 10L);
|
||||
return getPlots(area, uuid);
|
||||
}
|
||||
|
||||
@ -1018,7 +1008,10 @@ public class PlotSquared {
|
||||
* @param uuid the plot owner
|
||||
* @return Set of plot
|
||||
*/
|
||||
public Set<Plot> getPlots(String world, UUID uuid) {
|
||||
public Set<Plot> getPlots(String world, @Nullable UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
final Set<Plot> plots =
|
||||
getPlots(world).stream().filter(plot -> plot.hasOwner() && plot.isOwnerAbs(uuid))
|
||||
.collect(Collectors.toSet());
|
||||
@ -1627,7 +1620,6 @@ public class PlotSquared {
|
||||
|
||||
// Close the connection
|
||||
DBFunc.close();
|
||||
UUIDHandler.handleShutdown();
|
||||
} catch (NullPointerException throwable) {
|
||||
throwable.printStackTrace();
|
||||
PlotSquared.log("&cCould not close database connection!");
|
||||
|
@ -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;
|
||||
@ -138,17 +136,6 @@ import java.util.UUID;
|
||||
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.
|
||||
|
@ -36,7 +36,6 @@ import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@ -62,51 +61,64 @@ 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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ 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;
|
||||
|
||||
@CommandDeclaration(command = "setalias",
|
||||
permission = "plots.alias",
|
||||
@ -79,7 +77,8 @@ public class Alias extends SubCommand {
|
||||
|
||||
if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET, false)
|
||||
|| canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
|
||||
result = setAlias(player, plot, args[1]);
|
||||
setAlias(player, plot, args[1]);
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION);
|
||||
}
|
||||
@ -99,38 +98,32 @@ public class Alias extends SubCommand {
|
||||
}
|
||||
|
||||
|
||||
private boolean setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||
private void setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||
if (alias.isEmpty()) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return false;
|
||||
}
|
||||
if (alias.length() >= 50) {
|
||||
} else if (alias.length() >= 50) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
|
||||
return false;
|
||||
}
|
||||
if (alias.contains(" ")) {
|
||||
} else if (alias.contains(" ")) {
|
||||
Captions.NOT_VALID_VALUE.send(player);
|
||||
return false;
|
||||
}
|
||||
if (MathMan.isInteger(alias)) {
|
||||
} else 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;
|
||||
} else {
|
||||
for (Plot p : PlotSquared.get().getPlots(plot.getArea())) {
|
||||
if (p.getAlias().equalsIgnoreCase(alias)) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
||||
return;
|
||||
}
|
||||
}
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
|
||||
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));
|
||||
}
|
||||
}));
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
private boolean removeAlias(PlotPlayer player, Plot plot) {
|
||||
|
@ -39,7 +39,6 @@ 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;
|
||||
@ -371,22 +370,27 @@ 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 != 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 +424,41 @@ 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 != 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 +539,27 @@ 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 != 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 +628,27 @@ 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) -> {
|
||||
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":
|
||||
|
@ -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;
|
||||
@ -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
|
||||
}
|
||||
|
@ -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"},
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
@ -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 =
|
||||
|
@ -34,10 +34,8 @@ import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
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.UUID;
|
||||
|
||||
@CommandDeclaration(command = "deny",
|
||||
@ -68,48 +66,46 @@ 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 != 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;
|
||||
}
|
||||
|
||||
|
@ -172,7 +172,7 @@ 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
|
||||
|
@ -38,14 +38,16 @@ import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@CommandDeclaration(command = "visit",
|
||||
permission = "plots.visit",
|
||||
@ -71,10 +73,71 @@ public class Visit extends Command {
|
||||
if (args.length == 1 && args[0].contains(":")) {
|
||||
args = args[0].split(":");
|
||||
}
|
||||
int page = Integer.MIN_VALUE;
|
||||
Collection<Plot> unsorted = null;
|
||||
PlotArea sortByArea = player.getApplicablePlotArea();
|
||||
boolean shouldSortByArea = Settings.Teleport.PER_WORLD_VISIT;
|
||||
|
||||
final Collection<Plot> unsortedPre = new HashSet<>();
|
||||
final PlotArea[] sortByArea = new PlotArea[] {player.getApplicablePlotArea()};
|
||||
final AtomicBoolean shouldSortByArea = new AtomicBoolean(Settings.Teleport.PER_WORLD_VISIT);
|
||||
|
||||
final Consumer<Integer> pageConsumer = page -> {
|
||||
if (page == Integer.MIN_VALUE) {
|
||||
page = 1;
|
||||
}
|
||||
if (unsortedPre.isEmpty()) {
|
||||
Captions.FOUND_NO_PLOTS.send(player);
|
||||
} else {
|
||||
final Collection<Plot> unsorted = new ArrayList<>(unsortedPre);
|
||||
if (unsorted.size() > 1) {
|
||||
unsorted.removeIf(plot -> !plot.isBasePlot());
|
||||
}
|
||||
if (page < 1 || page > unsorted.size()) {
|
||||
Captions.NOT_VALID_NUMBER.send(player, "(1, " + unsorted.size() + ")");
|
||||
} else {
|
||||
List<Plot> plots;
|
||||
if (shouldSortByArea.get()) {
|
||||
plots = PlotSquared.get().sortPlots(unsorted, PlotSquared.SortType.CREATION_DATE, sortByArea[0]);
|
||||
} 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;
|
||||
}
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final int[] page = new int[]{Integer.MIN_VALUE};
|
||||
|
||||
switch (args.length) {
|
||||
case 3:
|
||||
if (!MathMan.isInteger(args[1])) {
|
||||
@ -82,109 +145,66 @@ public class Visit extends Command {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
page = Integer.parseInt(args[2]);
|
||||
page[0] = Integer.parseInt(args[2]);
|
||||
case 2:
|
||||
if (page != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
|
||||
sortByArea = PlotSquared.get().getPlotAreaByString(args[1]);
|
||||
if (sortByArea == null) {
|
||||
if (page[0] != Integer.MIN_VALUE || !MathMan.isInteger(args[1])) {
|
||||
sortByArea[0] = PlotSquared.get().getPlotAreaByString(args[1]);
|
||||
if (sortByArea[0] == null) {
|
||||
Captions.NOT_VALID_NUMBER.send(player, "(1, ∞)");
|
||||
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;
|
||||
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable != null || uuids.size() != 1) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
} else {
|
||||
unsortedPre.addAll(PlotSquared.get().getBasePlots((UUID) uuids.toArray()[0]));
|
||||
shouldSortByArea.set(true);
|
||||
pageConsumer.accept(page[0]);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
page = Integer.parseInt(args[1]);
|
||||
page[0] = Integer.parseInt(args[1]);
|
||||
case 1:
|
||||
UUID user = args[0].length() >= 2 ? UUIDHandler.getUUIDFromString(args[0]) : null;
|
||||
if (user != null && !PlotSquared.get().hasPlot(user)) {
|
||||
user = 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);
|
||||
} else {
|
||||
Plot plot = MainUtil.getPlotFromString(player, args[0], true);
|
||||
if (plot != null) {
|
||||
unsorted = Collections.singletonList(plot.getBasePlot(false));
|
||||
final String[] finalArgs = args;
|
||||
final Consumer<UUID> uuidConsumer = uuid -> {
|
||||
if (page[0] == Integer.MIN_VALUE && uuid == null && MathMan.isInteger(finalArgs[0])) {
|
||||
page[0] = Integer.parseInt(finalArgs[0]);
|
||||
unsortedPre.addAll(PlotSquared.get().getBasePlots(player));
|
||||
} else {
|
||||
if (uuid != null) {
|
||||
unsortedPre.addAll(PlotSquared.get().getBasePlots(uuid));
|
||||
} else {
|
||||
Plot plot = MainUtil.getPlotFromString(player, finalArgs[0], true);
|
||||
if (plot != null) {
|
||||
unsortedPre.addAll(Collections.singletonList(plot.getBasePlot(false)));
|
||||
}
|
||||
}
|
||||
}
|
||||
pageConsumer.accept(page[0]);
|
||||
};
|
||||
|
||||
if (args[0].length() >= 2) {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(args[0], (uuid, throwable) -> {
|
||||
if (uuid != null && !PlotSquared.get().hasPlot(uuid)) {
|
||||
uuidConsumer.accept(null);
|
||||
} else {
|
||||
uuidConsumer.accept(uuid);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
uuidConsumer.accept(null);
|
||||
}
|
||||
break;
|
||||
case 0:
|
||||
page = 1;
|
||||
unsorted = PlotSquared.get().getPlots(player);
|
||||
unsortedPre.addAll(PlotSquared.get().getPlots(player));
|
||||
pageConsumer.accept(1);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -450,6 +450,7 @@ public enum Captions implements Caption {
|
||||
//</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"),
|
||||
//<editor-fold desc="Trim">
|
||||
TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"),
|
||||
//</editor-fold>
|
||||
|
@ -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;
|
||||
@ -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())
|
||||
@ -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())
|
||||
|
@ -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;
|
||||
@ -108,17 +107,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
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();
|
||||
|
||||
/**
|
||||
@ -363,8 +351,6 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
||||
|
||||
/**
|
||||
* Get this player's full location (including yaw/pitch)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public abstract Location getLocationFull();
|
||||
|
||||
@ -563,11 +549,10 @@ 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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -405,11 +400,10 @@ 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);
|
||||
final List<PlotPlayer> players = new ArrayList<>();
|
||||
for (final PlotPlayer player : PlotSquared.imp().getPlayerManager().getPlayers()) {
|
||||
if (this.equals(player.getCurrentPlot())) {
|
||||
players.add(player);
|
||||
}
|
||||
}
|
||||
return players;
|
||||
@ -1717,12 +1711,7 @@ 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(), this::setSign);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2372,7 +2361,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 +2370,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>
|
||||
@ -3099,10 +3019,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 +3036,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 =
|
||||
|
@ -49,7 +49,7 @@ import com.plotsquared.core.plot.flag.types.DoubleFlag;
|
||||
import com.plotsquared.core.util.net.AbstractDelegateOutputStream;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.uuid.UUIDHandler;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
@ -73,6 +73,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@ -81,6 +82,7 @@ import java.util.Optional;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntConsumer;
|
||||
import java.util.function.IntFunction;
|
||||
@ -99,12 +101,6 @@ public class MainUtil {
|
||||
FLAG_DECIMAL_FORMAT.setMaximumFractionDigits(340);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the NMS code for sending chunk updates is functional<br>
|
||||
* - E.g. If using an older version of Bukkit, or before the plugin is updated to 1.5<br>
|
||||
* - Slower fallback code will be used if not.<br>
|
||||
*/
|
||||
public static boolean canSendChunk = false;
|
||||
/**
|
||||
* Cache of mapping x,y,z coordinates to the chunk array<br>
|
||||
* - Used for efficient world generation<br>
|
||||
@ -152,15 +148,6 @@ public class MainUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendAdmin(final String s) {
|
||||
for (final PlotPlayer player : UUIDHandler.getPlayers().values()) {
|
||||
if (player.hasPermission(Captions.PERMISSION_ADMIN.getTranslated())) {
|
||||
player.sendMessage(Captions.color(s));
|
||||
}
|
||||
}
|
||||
PlotSquared.debug(s);
|
||||
}
|
||||
|
||||
public static void upload(UUID uuid, String file, String extension,
|
||||
final RunnableVal<OutputStream> writeTask, final RunnableVal<URL> whenDone) {
|
||||
if (writeTask == null) {
|
||||
@ -396,7 +383,7 @@ public class MainUtil {
|
||||
if (owner.equals(DBFunc.SERVER)) {
|
||||
return Captions.SERVER.getTranslated();
|
||||
}
|
||||
String name = UUIDHandler.getName(owner);
|
||||
String name = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(owner, 10L);
|
||||
if (name == null) {
|
||||
return Captions.UNKNOWN.getTranslated();
|
||||
}
|
||||
@ -467,7 +454,7 @@ public class MainUtil {
|
||||
|
||||
for (String term : split) {
|
||||
try {
|
||||
UUID uuid = UUIDHandler.getUUID(term, null);
|
||||
UUID uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(term, 10L);
|
||||
if (uuid == null) {
|
||||
uuid = UUID.fromString(term);
|
||||
}
|
||||
@ -738,33 +725,44 @@ public class MainUtil {
|
||||
return ratings;
|
||||
}
|
||||
|
||||
public static Set<UUID> getUUIDsFromString(String list) {
|
||||
public static void getUUIDsFromString(final String list, final BiConsumer<Collection<UUID>, Throwable> consumer) {
|
||||
String[] split = list.split(",");
|
||||
HashSet<UUID> result = new HashSet<>();
|
||||
for (String name : split) {
|
||||
|
||||
final Set<UUID> result = new HashSet<>();
|
||||
final List<String> request = new LinkedList<>();
|
||||
|
||||
for (final String name : split) {
|
||||
if (name.isEmpty()) {
|
||||
// Invalid
|
||||
return Collections.emptySet();
|
||||
}
|
||||
if ("*".equals(name)) {
|
||||
consumer.accept(Collections.emptySet(), null);
|
||||
return;
|
||||
} else if ("*".equals(name)) {
|
||||
result.add(DBFunc.EVERYONE);
|
||||
continue;
|
||||
}
|
||||
if (name.length() > 16) {
|
||||
} else if (name.length() > 16) {
|
||||
try {
|
||||
result.add(UUID.fromString(name));
|
||||
continue;
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
return Collections.emptySet();
|
||||
consumer.accept(Collections.emptySet(), null);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
request.add(name);
|
||||
}
|
||||
UUID uuid = UUIDHandler.getUUID(name, null);
|
||||
if (uuid == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
result.add(uuid);
|
||||
}
|
||||
return result;
|
||||
|
||||
if (request.isEmpty()) {
|
||||
consumer.accept(result, null);
|
||||
} else {
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getUUIDs(request).whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
consumer.accept(null, throwable);
|
||||
} else {
|
||||
for (final UUIDMapping uuid : uuids) {
|
||||
result.add(uuid.getUuid());
|
||||
}
|
||||
consumer.accept(result, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -931,7 +929,7 @@ public class MainUtil {
|
||||
|
||||
public static void getPersistentMeta(UUID uuid, final String key,
|
||||
final RunnableVal<byte[]> result) {
|
||||
PlotPlayer player = UUIDHandler.getPlayer(uuid);
|
||||
PlotPlayer player = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
|
||||
if (player != null) {
|
||||
result.run(player.getPersistentMeta(key));
|
||||
} else {
|
||||
|
120
Core/src/main/java/com/plotsquared/core/util/PlayerManager.java
Normal file
120
Core/src/main/java/com/plotsquared/core/util/PlayerManager.java
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.util;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Manages player instances
|
||||
*/
|
||||
public abstract class PlayerManager {
|
||||
|
||||
private final Map<UUID, PlotPlayer> playerMap = new HashMap<>();
|
||||
private final Object playerLock = new Object();
|
||||
|
||||
/**
|
||||
* Remove a player from the player map
|
||||
*
|
||||
* @param plotPlayer Player to remove
|
||||
*/
|
||||
public void removePlayer(@NotNull final PlotPlayer plotPlayer) {
|
||||
synchronized (playerLock) {
|
||||
this.playerMap.remove(plotPlayer.getUUID());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player from its UUID if it is stored in the player map.
|
||||
*
|
||||
* @param uuid Player UUID
|
||||
* @return Player, or null
|
||||
*/
|
||||
@Nullable public PlotPlayer getPlayerIfExists(@Nullable final UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
return this.playerMap.get(uuid);
|
||||
}
|
||||
|
||||
@Nullable public PlotPlayer getPlayerIfExists(@Nullable final String name) {
|
||||
for (final PlotPlayer plotPlayer : this.playerMap.values()) {
|
||||
if (plotPlayer.getName().equalsIgnoreCase(name)) {
|
||||
return plotPlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a plot player from a UUID. This method requires
|
||||
* that the caller actually knows that the player exists.
|
||||
* <p>
|
||||
* The method will throw an exception if there is no such
|
||||
* player online.
|
||||
*
|
||||
* @param uuid Player UUID
|
||||
* @return Player object
|
||||
*/
|
||||
@NotNull public PlotPlayer getPlayer(@NotNull final UUID uuid) {
|
||||
synchronized (playerLock) {
|
||||
PlotPlayer player = this.playerMap.get(uuid);
|
||||
if (player == null) {
|
||||
player = createPlayer(uuid);
|
||||
this.playerMap.put(uuid, player);
|
||||
}
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull protected abstract PlotPlayer createPlayer(@NotNull final UUID uuid);
|
||||
|
||||
/**
|
||||
* Get all online players
|
||||
*
|
||||
* @return Unmodifiable collection of players
|
||||
*/
|
||||
public Collection<PlotPlayer> getPlayers() {
|
||||
return Collections.unmodifiableCollection(this.playerMap.values());
|
||||
}
|
||||
|
||||
|
||||
public static final class NoSuchPlayerException extends IllegalArgumentException {
|
||||
|
||||
public NoSuchPlayerException(@NotNull final UUID uuid) {
|
||||
super(String.format("There is no online player with UUID '%s'", uuid.toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -104,7 +104,7 @@ public abstract class SchematicHandler {
|
||||
Iterator<Plot> i = plots.iterator();
|
||||
final Plot plot = i.next();
|
||||
i.remove();
|
||||
String owner = UUIDHandler.getName(plot.guessOwner());
|
||||
String owner = UUIDHandler.getName(plot.getOwnerAbs());
|
||||
if (owner == null) {
|
||||
owner = "unknown";
|
||||
}
|
||||
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* 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.util;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.command.Command;
|
||||
import com.plotsquared.core.command.CommandCategory;
|
||||
import com.plotsquared.core.command.RequiredType;
|
||||
import com.plotsquared.core.uuid.UUIDMapping;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Tab completion utilities
|
||||
*/
|
||||
@UtilityClass public class TabCompletions {
|
||||
|
||||
private final Cache<String, List<String>> cachedCompletionValues =
|
||||
CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.MINUTES).build();
|
||||
|
||||
/**
|
||||
* Get a list of tab completions corresponding to player names. This uses the UUID pipeline
|
||||
* cache, so it will complete will all names known to PlotSquared
|
||||
*
|
||||
* @param input Command input
|
||||
* @param existing Players that should not be included in completions
|
||||
* @return List of completions
|
||||
*/
|
||||
@NotNull public List<Command> completePlayers(@NotNull final String input,
|
||||
@NotNull final List<String> existing) {
|
||||
List<String> players = cachedCompletionValues.getIfPresent("players");
|
||||
if (players == null) {
|
||||
final Collection<UUIDMapping> mappings =
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
|
||||
players = new ArrayList<>(mappings.size());
|
||||
for (final UUIDMapping mapping : mappings) {
|
||||
players.add(mapping.getUsername());
|
||||
}
|
||||
cachedCompletionValues.put("players", players);
|
||||
}
|
||||
final String processedInput = input.toLowerCase(Locale.ENGLISH);
|
||||
return players.stream()
|
||||
.filter(player -> player.toLowerCase(Locale.ENGLISH).startsWith(processedInput))
|
||||
.filter(player -> !existing.contains(player)).map(
|
||||
player -> new Command(null, false, player, "", RequiredType.NONE,
|
||||
CommandCategory.INFO) {
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
@ -1,198 +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.util.uuid;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UUIDHandler {
|
||||
|
||||
public static UUIDHandlerImplementation implementation;
|
||||
|
||||
public static void add(StringWrapper name, UUID uuid) {
|
||||
implementation.add(name, uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map containing all names/uuids.
|
||||
*
|
||||
* @return map with names + uuids
|
||||
* @see BiMap
|
||||
*/
|
||||
public static BiMap<StringWrapper, UUID> getUuidMap() {
|
||||
return implementation.getUUIDMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a uuid is cached
|
||||
*
|
||||
* @param uuid to check
|
||||
* @return true of the uuid is cached
|
||||
* @see BiMap#containsValue(Object)
|
||||
*/
|
||||
public static boolean uuidExists(UUID uuid) {
|
||||
return implementation.uuidExists(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a name is cached
|
||||
*
|
||||
* @param name to check
|
||||
* @return true of the name is cached
|
||||
* @see BiMap#containsKey(Object)
|
||||
*/
|
||||
public static boolean nameExists(StringWrapper name) {
|
||||
return implementation.nameExists(name);
|
||||
}
|
||||
|
||||
public static HashSet<UUID> getAllUUIDS() {
|
||||
final HashSet<UUID> uuids = new HashSet<>();
|
||||
PlotSquared.get().forEachPlotRaw(plot -> {
|
||||
if (plot.hasOwner()) {
|
||||
uuids.add(plot.getOwnerAbs());
|
||||
uuids.addAll(plot.getTrusted());
|
||||
uuids.addAll(plot.getMembers());
|
||||
uuids.addAll(plot.getDenied());
|
||||
}
|
||||
});
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public static UUIDWrapper getUUIDWrapper() {
|
||||
return implementation.getUUIDWrapper();
|
||||
}
|
||||
|
||||
public static void setUUIDWrapper(UUIDWrapper wrapper) {
|
||||
implementation.setUUIDWrapper(wrapper);
|
||||
}
|
||||
|
||||
public static void startCaching(Runnable whenDone) {
|
||||
implementation.startCaching(whenDone);
|
||||
}
|
||||
|
||||
public static void cache(BiMap<StringWrapper, UUID> toAdd) {
|
||||
implementation.add(toAdd);
|
||||
}
|
||||
|
||||
@NotNull public static UUID getUUID(PlotPlayer player) {
|
||||
return implementation.getUUID(player);
|
||||
}
|
||||
|
||||
public static UUID getUUID(OfflinePlotPlayer player) {
|
||||
if (implementation == null) {
|
||||
return null;
|
||||
}
|
||||
return implementation.getUUID(player);
|
||||
}
|
||||
|
||||
@Nullable public static String getName(UUID uuid) {
|
||||
if (implementation == null) {
|
||||
return null;
|
||||
}
|
||||
if (uuid != null && uuid.equals(DBFunc.SERVER)) {
|
||||
return Captions.SERVER.getTranslated();
|
||||
}
|
||||
return implementation.getName(uuid);
|
||||
}
|
||||
|
||||
@Nullable public static PlotPlayer getPlayer(@Nullable final UUID uuid) {
|
||||
if (implementation == null || uuid == null) {
|
||||
return null;
|
||||
}
|
||||
return check(implementation.getPlayer(uuid));
|
||||
}
|
||||
|
||||
public static PlotPlayer getPlayer(String name) {
|
||||
if (implementation == null) {
|
||||
return null;
|
||||
}
|
||||
return check(implementation.getPlayer(name));
|
||||
}
|
||||
|
||||
private static PlotPlayer check(@Nullable PlotPlayer player) {
|
||||
if (player != null && !player.isOnline()) {
|
||||
UUIDHandler.getPlayers().remove(player.getName());
|
||||
PlotSquared.get().IMP.unregister(player);
|
||||
player = null;
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
public static UUID getUUIDFromString(String nameOrUUIDString) {
|
||||
if (implementation == null) {
|
||||
return null;
|
||||
}
|
||||
if (nameOrUUIDString.length() > 16) {
|
||||
try {
|
||||
return UUID.fromString(nameOrUUIDString);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return UUIDHandler.getUUID(nameOrUUIDString, null);
|
||||
}
|
||||
|
||||
public static UUID getUUID(String name, RunnableVal<UUID> ifFetch) {
|
||||
if (implementation == null) {
|
||||
return null;
|
||||
}
|
||||
return implementation.getUUID(name, ifFetch);
|
||||
}
|
||||
|
||||
public static UUID getCachedUUID(String name, RunnableVal<UUID> ifFetch) {
|
||||
if (implementation == null) {
|
||||
return null;
|
||||
}
|
||||
return implementation.getUUIDMap().get(new StringWrapper(name));
|
||||
}
|
||||
|
||||
public static Map<String, PlotPlayer> getPlayers() {
|
||||
if (implementation == null) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
return implementation.getPlayers();
|
||||
}
|
||||
|
||||
public static void handleShutdown() {
|
||||
if (implementation == null) {
|
||||
return;
|
||||
}
|
||||
implementation.handleShutdown();
|
||||
}
|
||||
}
|
@ -1,324 +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.util.uuid;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
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.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.StringWrapper;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class UUIDHandlerImplementation {
|
||||
|
||||
public final HashSet<UUID> unknown = new HashSet<>();
|
||||
private final ConcurrentHashMap<String, PlotPlayer> players;
|
||||
protected UUIDWrapper uuidWrapper;
|
||||
private boolean cached = false;
|
||||
private BiMap<StringWrapper, UUID> uuidMap = HashBiMap.create(new HashMap<>());
|
||||
|
||||
public UUIDHandlerImplementation(UUIDWrapper wrapper) {
|
||||
this.uuidWrapper = wrapper;
|
||||
this.players = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the UUID is not found, some commands can request to fetch the UUID when possible.
|
||||
*
|
||||
* @param name
|
||||
* @param ifFetch
|
||||
*/
|
||||
public abstract void fetchUUID(String name, RunnableVal<UUID> ifFetch);
|
||||
|
||||
/**
|
||||
* Start UUID caching (this should be an async task)
|
||||
* Recommended to override this is you want to cache offline players
|
||||
*/
|
||||
public boolean startCaching(Runnable whenDone) {
|
||||
if (this.cached) {
|
||||
return false;
|
||||
}
|
||||
return this.cached = true;
|
||||
}
|
||||
|
||||
public UUIDWrapper getUUIDWrapper() {
|
||||
return this.uuidWrapper;
|
||||
}
|
||||
|
||||
public void setUUIDWrapper(UUIDWrapper wrapper) {
|
||||
this.uuidWrapper = wrapper;
|
||||
}
|
||||
|
||||
public void rename(UUID uuid, StringWrapper name) {
|
||||
this.uuidMap.inverse().remove(uuid);
|
||||
this.uuidMap.put(name, uuid);
|
||||
}
|
||||
|
||||
public void add(BiMap<StringWrapper, UUID> toAdd) {
|
||||
if (this.uuidMap.isEmpty()) {
|
||||
this.uuidMap = toAdd;
|
||||
}
|
||||
for (Map.Entry<StringWrapper, UUID> entry : toAdd.entrySet()) {
|
||||
UUID uuid = entry.getValue();
|
||||
StringWrapper name = entry.getKey();
|
||||
if (uuid == null || name == null) {
|
||||
continue;
|
||||
}
|
||||
StringWrapper oldName = this.uuidMap.inverse().get(uuid);
|
||||
if (oldName != null) {
|
||||
if (this.uuidMap.containsKey(name)) {
|
||||
continue;
|
||||
}
|
||||
if (getPlayer(uuid) == null) {
|
||||
rename(uuid, name);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
this.uuidMap.put(name, uuid);
|
||||
}
|
||||
PlotSquared
|
||||
.debug(Captions.PREFIX + "&6Cached a total of: " + this.uuidMap.size() + " UUIDs");
|
||||
}
|
||||
|
||||
public boolean add(final StringWrapper name, final UUID uuid) {
|
||||
if (uuid == null) {
|
||||
PlotSquared.debug("UUID cannot be null!");
|
||||
return false;
|
||||
}
|
||||
if (name == null) {
|
||||
try {
|
||||
this.unknown.add(uuid);
|
||||
} catch (Exception e) {
|
||||
PlotSquared.log("&c(minor) Invalid UUID mapping: " + uuid);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* lazy UUID conversion:
|
||||
* - Useful if the person misconfigured the database, or settings before
|
||||
* PlotMe conversion
|
||||
*/
|
||||
if (!Settings.UUID.OFFLINE && !this.unknown.isEmpty()) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
UUID offline = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
|
||||
if (!UUIDHandlerImplementation.this.unknown.contains(offline) && !name.value
|
||||
.equals(name.value.toLowerCase())) {
|
||||
offline = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + name.value.toLowerCase()).getBytes(Charsets.UTF_8));
|
||||
if (!UUIDHandlerImplementation.this.unknown.contains(offline)) {
|
||||
offline = null;
|
||||
}
|
||||
}
|
||||
if (offline != null && !offline.equals(uuid)) {
|
||||
UUIDHandlerImplementation.this.unknown.remove(offline);
|
||||
Set<Plot> plots = PlotSquared.get().getPlotsAbs(offline);
|
||||
if (!plots.isEmpty()) {
|
||||
for (final Plot plot : plots) {
|
||||
plot.setOwnerAbs(uuid);
|
||||
}
|
||||
DBFunc.replaceUUID(offline, uuid);
|
||||
PlotSquared.debug("&cDetected invalid UUID stored for: " + name.value);
|
||||
PlotSquared.debug(
|
||||
"&7 - Did you recently switch to online-mode storage without running `uuidconvert`?");
|
||||
PlotSquared.debug("&6" + PlotSquared.imp().getPluginName()
|
||||
+ " will update incorrect entries when the user logs in, or you can reconstruct your database.");
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (Settings.UUID.FORCE_LOWERCASE && !this.unknown.isEmpty() && !name.value
|
||||
.equals(name.value.toLowerCase())) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
UUID offlineUpper = UUID.nameUUIDFromBytes(
|
||||
("OfflinePlayer:" + name.value).getBytes(Charsets.UTF_8));
|
||||
if (UUIDHandlerImplementation.this.unknown.contains(offlineUpper) && !offlineUpper
|
||||
.equals(uuid)) {
|
||||
UUIDHandlerImplementation.this.unknown.remove(offlineUpper);
|
||||
Set<Plot> plots = PlotSquared.get().getPlotsAbs(offlineUpper);
|
||||
if (!plots.isEmpty()) {
|
||||
for (final Plot plot : plots) {
|
||||
plot.setOwnerAbs(uuid);
|
||||
}
|
||||
replace(offlineUpper, uuid, name.value);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
try {
|
||||
UUID existing = this.uuidMap.put(name, uuid);
|
||||
if (existing != null) {
|
||||
if (!existing.equals(uuid)) {
|
||||
Set<Plot> plots = PlotSquared.get().getPlots(existing);
|
||||
if (!plots.isEmpty()) {
|
||||
for (final Plot plot : plots) {
|
||||
plot.setOwnerAbs(uuid);
|
||||
}
|
||||
replace(existing, uuid, name.value);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
StringWrapper oName = this.uuidMap.inverse().get(existing);
|
||||
if (!oName.equals(name)) {
|
||||
this.uuidMap.remove(name);
|
||||
this.uuidMap.put(name, uuid);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
BiMap<UUID, StringWrapper> inverse = this.uuidMap.inverse();
|
||||
StringWrapper oldName = inverse.get(uuid);
|
||||
if (oldName != null) {
|
||||
if (this.uuidMap.containsKey(name)) {
|
||||
return false;
|
||||
}
|
||||
PlotPlayer player = getPlayer(uuid);
|
||||
if (player == null || player.getName().equalsIgnoreCase(name.value)) {
|
||||
rename(uuid, name);
|
||||
return false;
|
||||
}
|
||||
StringWrapper newName = new StringWrapper(player.getName());
|
||||
UUID newUUID = player.getUUID();
|
||||
if (newUUID.equals(uuid) && !newName.equals(oldName)) {
|
||||
inverse.remove(uuid);
|
||||
this.uuidMap.put(newName, newUUID);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
this.uuidMap.put(name, uuid);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void replace(UUID from, UUID to, String name) {
|
||||
DBFunc.replaceUUID(from, to);
|
||||
PlotSquared.debug("&cDetected invalid UUID stored for: " + name);
|
||||
PlotSquared.debug(
|
||||
"&7 - Did you recently switch to online-mode storage without running `uuidconvert`?");
|
||||
PlotSquared.debug("&6" + PlotSquared.imp().getPluginName()
|
||||
+ " will update incorrect entries when the user logs in, or you can reconstruct your database.");
|
||||
}
|
||||
|
||||
public boolean uuidExists(UUID uuid) {
|
||||
return this.uuidMap.containsValue(uuid);
|
||||
}
|
||||
|
||||
public BiMap<StringWrapper, UUID> getUUIDMap() {
|
||||
return this.uuidMap;
|
||||
}
|
||||
|
||||
public boolean nameExists(StringWrapper wrapper) {
|
||||
return this.uuidMap.containsKey(wrapper);
|
||||
}
|
||||
|
||||
public void handleShutdown() {
|
||||
this.players.clear();
|
||||
this.uuidMap.clear();
|
||||
}
|
||||
|
||||
@Nullable public String getName(UUID uuid) {
|
||||
if (uuid == null) {
|
||||
return null;
|
||||
}
|
||||
StringWrapper name = this.uuidMap.inverse().get(uuid);
|
||||
if (name != null) {
|
||||
return name.value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable public UUID getUUID(String name, RunnableVal<UUID> ifFetch) {
|
||||
if (name.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// check online
|
||||
PlotPlayer player = getPlayer(name);
|
||||
if (player != null) {
|
||||
return player.getUUID();
|
||||
}
|
||||
// check cache
|
||||
StringWrapper wrap = new StringWrapper(name);
|
||||
UUID uuid = this.uuidMap.get(wrap);
|
||||
if (uuid != null) {
|
||||
return uuid;
|
||||
}
|
||||
// Read from disk OR convert directly to offline UUID
|
||||
if (Settings.UUID.OFFLINE && !StringMan.contains(name, ';')) {
|
||||
uuid = this.uuidWrapper.getUUID(name);
|
||||
add(new StringWrapper(name), uuid);
|
||||
return uuid;
|
||||
}
|
||||
if ((ifFetch != null)) {
|
||||
fetchUUID(name, ifFetch);
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull public UUID getUUID(PlotPlayer player) {
|
||||
return this.uuidWrapper.getUUID(player);
|
||||
}
|
||||
|
||||
public UUID getUUID(OfflinePlotPlayer player) {
|
||||
return this.uuidWrapper.getUUID(player);
|
||||
}
|
||||
|
||||
@Nullable public PlotPlayer getPlayer(UUID uuid) {
|
||||
String name = getName(uuid);
|
||||
if (name != null) {
|
||||
return getPlayer(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlotPlayer getPlayer(String name) {
|
||||
return this.players.get(name);
|
||||
}
|
||||
|
||||
public Map<String, PlotPlayer> getPlayers() {
|
||||
return this.players;
|
||||
}
|
||||
|
||||
}
|
@ -1,47 +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.util.uuid;
|
||||
|
||||
import com.plotsquared.core.player.OfflinePlotPlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface UUIDWrapper {
|
||||
|
||||
@NotNull UUID getUUID(PlotPlayer player);
|
||||
|
||||
UUID getUUID(OfflinePlotPlayer player);
|
||||
|
||||
UUID getUUID(String name);
|
||||
|
||||
OfflinePlotPlayer getOfflinePlayer(UUID uuid);
|
||||
|
||||
OfflinePlotPlayer getOfflinePlayer(String name);
|
||||
|
||||
OfflinePlotPlayer[] getOfflinePlayers();
|
||||
}
|
@ -30,6 +30,7 @@ import com.google.common.cache.CacheBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
@ -73,4 +74,8 @@ public class CacheUUIDService implements UUIDService, Consumer<List<UUIDMapping>
|
||||
}
|
||||
}
|
||||
|
||||
@Override @NotNull public Collection<UUIDMapping> getImmediately() {
|
||||
return this.usernameCache.asMap().values();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.uuid;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@ -32,7 +33,7 @@ import java.util.UUID;
|
||||
/**
|
||||
* A pair consisting of a UUID and a username
|
||||
*/
|
||||
public class UUIDMapping {
|
||||
@EqualsAndHashCode public class UUIDMapping {
|
||||
|
||||
private final UUID uuid;
|
||||
private final String username;
|
||||
|
@ -35,13 +35,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
@ -181,10 +184,16 @@ public class UUIDPipeline {
|
||||
* @param username Username
|
||||
* @param uuid UUID consumer
|
||||
*/
|
||||
public void getSingle(@NotNull final String username, @NotNull final Consumer<UUID> uuid) {
|
||||
this.getUUIDs(Collections.singletonList(username)).thenAccept(uuids -> {
|
||||
if (!uuids.isEmpty()) {
|
||||
uuid.accept(uuids.get(0).getUuid());
|
||||
public void getSingle(@NotNull final String username, @NotNull final BiConsumer<UUID, Throwable> uuid) {
|
||||
this.getUUIDs(Collections.singletonList(username)).whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
uuid.accept(null, throwable);
|
||||
} else {
|
||||
if (!uuids.isEmpty()) {
|
||||
uuid.accept(uuids.get(0).getUuid(), null);
|
||||
} else {
|
||||
uuid.accept(null, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -195,10 +204,16 @@ public class UUIDPipeline {
|
||||
* @param uuid UUID
|
||||
* @param username Username consumer
|
||||
*/
|
||||
public void getSingle(@NotNull final UUID uuid, @NotNull final Consumer<String> username) {
|
||||
this.getNames(Collections.singletonList(uuid)).thenAccept(uuids -> {
|
||||
if (!uuids.isEmpty()) {
|
||||
username.accept(uuids.get(0).getUsername());
|
||||
public void getSingle(@NotNull final UUID uuid, @NotNull final BiConsumer<String, Throwable> username) {
|
||||
this.getNames(Collections.singletonList(uuid)).whenComplete((uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
username.accept(null, throwable);
|
||||
} else {
|
||||
if (!uuids.isEmpty()) {
|
||||
username.accept(uuids.get(0).getUsername(), null);
|
||||
} else {
|
||||
username.accept(null, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -274,4 +289,18 @@ public class UUIDPipeline {
|
||||
}, this.executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get as many UUID mappings as possible under the condition
|
||||
* that the operation cannot be blocking (for an extended amount of time)
|
||||
*
|
||||
* @return All mappings that could be provided immediately
|
||||
*/
|
||||
@NotNull public final Collection<UUIDMapping> getAllImmediately() {
|
||||
final Set<UUIDMapping> mappings = new LinkedHashSet<>();
|
||||
for (final UUIDService service : this.getServiceListInstance()) {
|
||||
mappings.addAll(service.getImmediately());
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ package com.plotsquared.core.uuid;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -53,4 +55,14 @@ public interface UUIDService {
|
||||
*/
|
||||
@NotNull List<UUIDMapping> getUUIDs(@NotNull final List<String> usernames);
|
||||
|
||||
/**
|
||||
* Get as many UUID mappings as possible under the condition
|
||||
* that the operation cannot be blocking (for an extended amount of time)
|
||||
*
|
||||
* @return All mappings that could be provided immediately
|
||||
*/
|
||||
default @NotNull Collection<UUIDMapping> getImmediately() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user