meta = entity.getMetadata("shulkerPlot");
@@ -542,71 +762,76 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
}
continue;
- case LLAMA:
- case DONKEY:
- case MULE:
- case ZOMBIE_HORSE:
- case SKELETON_HORSE:
- case HUSK:
- case ELDER_GUARDIAN:
- case WITHER_SKELETON:
- case STRAY:
- case ZOMBIE_VILLAGER:
- case EVOKER:
- case EVOKER_FANGS:
- case VEX:
- case VINDICATOR:
- case POLAR_BEAR:
- case BAT:
- case BLAZE:
- case CAVE_SPIDER:
- case CHICKEN:
- case COW:
- case CREEPER:
- case ENDERMAN:
- case ENDERMITE:
- case ENDER_DRAGON:
- case GHAST:
- case GIANT:
- case GUARDIAN:
- case HORSE:
- case IRON_GOLEM:
- case MAGMA_CUBE:
- case MUSHROOM_COW:
- case OCELOT:
- case PIG:
- case PIG_ZOMBIE:
- case RABBIT:
- case SHEEP:
- case SILVERFISH:
- case SKELETON:
- case SLIME:
- case SNOWMAN:
- case SPIDER:
- case SQUID:
- case VILLAGER:
- case WITCH:
- case WITHER:
- case WOLF:
- case ZOMBIE:
- case PARROT:
- case SALMON:
- case DOLPHIN:
- case TROPICAL_FISH:
- case DROWNED:
- case COD:
- case TURTLE:
- case PUFFERFISH:
- case PHANTOM:
- case ILLUSIONER:
- case CAT:
- case PANDA:
- case FOX:
- case PILLAGER:
- case TRADER_LLAMA:
- case WANDERING_TRADER:
- case RAVAGER:
- //case BEE:
+ case "ZOMBIFIED_PIGLIN":
+ case "LLAMA":
+ case "DONKEY":
+ case "MULE":
+ case "ZOMBIE_HORSE":
+ case "SKELETON_HORSE":
+ case "HUSK":
+ case "ELDER_GUARDIAN":
+ case "WITHER_SKELETON":
+ case "STRAY":
+ case "ZOMBIE_VILLAGER":
+ case "EVOKER":
+ case "EVOKER_FANGS":
+ case "VEX":
+ case "VINDICATOR":
+ case "POLAR_BEAR":
+ case "BAT":
+ case "BLAZE":
+ case "CAVE_SPIDER":
+ case "CHICKEN":
+ case "COW":
+ case "CREEPER":
+ case "ENDERMAN":
+ case "ENDERMITE":
+ case "ENDER_DRAGON":
+ case "GHAST":
+ case "GIANT":
+ case "GUARDIAN":
+ case "HORSE":
+ case "IRON_GOLEM":
+ case "MAGMA_CUBE":
+ case "MUSHROOM_COW":
+ case "OCELOT":
+ case "PIG":
+ case "PIG_ZOMBIE":
+ case "RABBIT":
+ case "SHEEP":
+ case "SILVERFISH":
+ case "SKELETON":
+ case "SLIME":
+ case "SNOWMAN":
+ case "SPIDER":
+ case "SQUID":
+ case "VILLAGER":
+ case "WITCH":
+ case "WITHER":
+ case "WOLF":
+ case "ZOMBIE":
+ case "PARROT":
+ case "SALMON":
+ case "DOLPHIN":
+ case "TROPICAL_FISH":
+ case "DROWNED":
+ case "COD":
+ case "TURTLE":
+ case "PUFFERFISH":
+ case "PHANTOM":
+ case "ILLUSIONER":
+ case "CAT":
+ case "PANDA":
+ case "FOX":
+ case "PILLAGER":
+ case "TRADER_LLAMA":
+ case "WANDERING_TRADER":
+ case "RAVAGER":
+ case "BEE":
+ case "HOGLIN":
+ case "PIGLIN":
+ case "ZOGLIN":
+ break;
default: {
if (Settings.Enabled_Components.KILL_ROAD_MOBS) {
Location location = entity.getLocation();
@@ -687,8 +912,16 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
@Override public EconHandler getEconomyHandler() {
+ if (econ != null) {
+ if (econ.init() /* is inited */) {
+ return econ;
+ } else {
+ return null;
+ }
+ }
+
try {
- BukkitEconHandler econ = new BukkitEconHandler();
+ econ = new BukkitEconHandler();
if (econ.init()) {
return econ;
}
@@ -698,6 +931,26 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return null;
}
+ @Override public PermHandler getPermissionHandler() {
+ if (perm != null) {
+ if (perm.init() /* is inited */) {
+ return perm;
+ } else {
+ return null;
+ }
+ }
+
+ try {
+ perm = new BukkitPermHandler();
+ if (perm.init()) {
+ return perm;
+ }
+ } catch (Throwable ignored) {
+ PlotSquared.debug("No permissions detected!");
+ }
+ return null;
+ }
+
@Override public QueueProvider initBlockQueue() {
//TODO Figure out why this code is still here yet isn't being called anywhere.
// try {
@@ -715,8 +968,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return new BukkitUtil();
}
- @Override @Nullable
- public GeneratorWrapper> getGenerator(@NonNull final String world,
+ @Override @Nullable public GeneratorWrapper> getGenerator(@NonNull final String world,
@Nullable final String name) {
if (name == null) {
return null;
@@ -767,7 +1019,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
metrics.addCustomChart(new Metrics.SimplePie("premium",
() -> PremiumVerification.isPremium() ? "Premium" : "Non-Premium"));
metrics.addCustomChart(new Metrics.SimplePie("worldedit_implementation",
- () -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ? "FastAsyncWorldEdit" : "WorldEdit"));
+ () -> Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit") != null ?
+ "FastAsyncWorldEdit" :
+ "WorldEdit"));
}
@Override public ChunkManager initChunkManager() {
@@ -779,7 +1033,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
@Override public void unregister(@NonNull final PlotPlayer player) {
- BukkitUtil.removePlayer(player.getName());
+ BukkitUtil.removePlayer(player.getUUID());
}
@Override public void registerChunkProcessor() {
@@ -798,39 +1052,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return new BukkitInventoryUtil();
}
- @Override public UUIDHandlerImplementation initUUIDHandler() {
- final UUIDWrapper wrapper;
- if (Settings.UUID.OFFLINE) {
- if (Settings.UUID.FORCE_LOWERCASE) {
- wrapper = new LowerOfflineUUIDWrapper();
- } else {
- wrapper = new OfflineUUIDWrapper();
- }
- Settings.UUID.OFFLINE = true;
- } else {
- wrapper = new DefaultUUIDWrapper();
- Settings.UUID.OFFLINE = false;
- }
- if (!Bukkit.getVersion().contains("git-Spigot")) {
- if (wrapper instanceof DefaultUUIDWrapper
- || wrapper.getClass() == OfflineUUIDWrapper.class && !Bukkit.getOnlineMode()) {
- Settings.UUID.NATIVE_UUID_PROVIDER = true;
- }
- }
- if (Settings.UUID.OFFLINE) {
- PlotSquared.log(Captions.PREFIX + "&6" + getPluginName()
- + " is using Offline Mode UUIDs either because of user preference, or because you are using an old version of "
- + "Bukkit");
- } else {
- PlotSquared.log(Captions.PREFIX + "&6" + getPluginName() + " is using online UUIDs");
- }
- if (Settings.UUID.USE_SQLUUIDHANDLER) {
- return new SQLUUIDHandler(wrapper);
- } else {
- return new FileUUIDHandler(wrapper);
- }
- }
-
@Override public void setGenerator(@NonNull final String worldName) {
World world = BukkitUtil.getWorld(worldName);
if (world == null) {
@@ -838,14 +1059,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
ConfigurationSection worldConfig =
PlotSquared.get().worlds.getConfigurationSection("worlds." + worldName);
String manager = worldConfig.getString("generator.plugin", getPluginName());
- SetupObject setup = new SetupObject();
- setup.plotManager = manager;
- setup.setupGenerator = worldConfig.getString("generator.init", manager);
- setup.type = MainUtil.getType(worldConfig);
- setup.terrain = MainUtil.getTerrain(worldConfig);
- setup.step = new ConfigurationNode[0];
- setup.world = worldName;
- SetupUtils.manager.setupWorld(setup);
+ PlotAreaBuilder builder = new PlotAreaBuilder().plotManager(manager)
+ .generatorName(worldConfig.getString("generator.init", manager))
+ .plotAreaType(MainUtil.getType(worldConfig))
+ .terrainType(MainUtil.getTerrain(worldConfig))
+ .settingsNodesWrapper(new SettingsNodesWrapper(new ConfigurationNode[0], null))
+ .worldName(worldName);
+ SetupUtils.manager.setupWorld(builder);
world = Bukkit.getWorld(worldName);
} else {
try {
@@ -873,7 +1093,22 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return new BukkitSchematicHandler();
}
- @Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
+ /**
+ * Attempt to retrieve a {@link PlotPlayer} from a player identifier.
+ * This method accepts:
+ * - {@link Player} objects,
+ * - {@link OfflinePlayer} objects,
+ * - {@link String} usernames for online players, and
+ * - {@link UUID} UUIDs for online players
+ *
+ * In the case of offline players, a fake {@link Player} instance will be created.
+ * This is a rather expensive operation, and should be avoided if possible.
+ *
+ * @param player The player to convert to a PlotPlayer
+ * @return The plot player instance that corresponds to the identifier, or null
+ * if no such player object could be created
+ */
+ @Override @Nullable public PlotPlayer wrapPlayer(final Object player) {
if (player instanceof Player) {
return BukkitUtil.getPlayer((Player) player);
}
@@ -881,10 +1116,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return BukkitUtil.getPlayer((OfflinePlayer) player);
}
if (player instanceof String) {
- return UUIDHandler.getPlayer((String) player);
+ return (PlotPlayer) PlotSquared.imp().getPlayerManager()
+ .getPlayerIfExists((String) player);
}
if (player instanceof UUID) {
- return UUIDHandler.getPlayer((UUID) player);
+ return (PlotPlayer) PlotSquared.imp().getPlayerManager()
+ .getPlayerIfExists((UUID) player);
}
return null;
}
@@ -902,8 +1139,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
}
- @Override
- public GeneratorWrapper> wrapPlotGenerator(@Nullable final String world,
+ @Override public GeneratorWrapper> wrapPlotGenerator(@Nullable final String world,
@NonNull final IndependentPlotGenerator generator) {
return new BukkitPlotGenerator(world, generator);
}
@@ -925,4 +1161,9 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
return wePlugin.wrapCommandSender(console);
}
+ @Override @NotNull
+ public PlayerManager extends PlotPlayer, ? extends Player> getPlayerManager() {
+ return this.playerManager;
+ }
+
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/command/DebugUUID.java b/Bukkit/src/main/java/com/plotsquared/bukkit/command/DebugUUID.java
deleted file mode 100644
index 79b411791..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/command/DebugUUID.java
+++ /dev/null
@@ -1,323 +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 .
- */
-package com.plotsquared.bukkit.command;
-
-import com.google.common.collect.Sets;
-import com.plotsquared.bukkit.util.uuid.DatFileFilter;
-import com.plotsquared.bukkit.util.uuid.DefaultUUIDWrapper;
-import com.plotsquared.bukkit.util.uuid.LowerOfflineUUIDWrapper;
-import com.plotsquared.bukkit.util.uuid.OfflineUUIDWrapper;
-import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.command.Argument;
-import com.plotsquared.core.command.CommandCategory;
-import com.plotsquared.core.command.CommandDeclaration;
-import com.plotsquared.core.command.RequiredType;
-import com.plotsquared.core.command.SubCommand;
-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.plot.Plot;
-import com.plotsquared.core.util.MainUtil;
-import com.plotsquared.core.util.StringMan;
-import com.plotsquared.core.util.StringWrapper;
-import com.plotsquared.core.util.WorldUtil;
-import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandler;
-import com.plotsquared.core.util.uuid.UUIDWrapper;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map.Entry;
-import java.util.UUID;
-
-@CommandDeclaration(command = "uuidconvert",
- permission = "plots.admin",
- description = "Debug UUID conversion",
- usage = "/plot uuidconvert ",
- requiredType = RequiredType.CONSOLE,
- category = CommandCategory.DEBUG)
-public class DebugUUID extends SubCommand {
-
- public DebugUUID() {
- super(Argument.String);
- }
-
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
- final UUIDWrapper currentUUIDWrapper = UUIDHandler.getUUIDWrapper();
- final UUIDWrapper newWrapper;
-
- switch (args[0].toLowerCase()) {
- case "lower":
- newWrapper = new LowerOfflineUUIDWrapper();
- break;
- case "offline":
- newWrapper = new OfflineUUIDWrapper();
- break;
- case "online":
- newWrapper = new DefaultUUIDWrapper();
- break;
- default:
- try {
- Class> clazz = Class.forName(args[0]);
- newWrapper = (UUIDWrapper) clazz.newInstance();
- } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
- MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
- "/plot uuidconvert ");
- return false;
- }
- }
-
- if (args.length != 2 || !"-o".equals(args[1])) {
- MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
- "/plot uuidconvert " + args[0] + " -o");
- MainUtil.sendMessage(player, "&cBe aware of the following!");
- MainUtil.sendMessage(player,
- "&8 - &cUse the database command or another method to backup your plots beforehand");
- MainUtil.sendMessage(player,
- "&8 - &cIf the process is interrupted, all plots could be deleted");
- MainUtil.sendMessage(player, "&8 - &cIf an error occurs, all plots could be deleted");
- MainUtil.sendMessage(player, "&8 - &cPlot settings WILL be lost upon conversion");
- MainUtil
- .sendMessage(player, "&cTO REITERATE: BACK UP YOUR DATABASE BEFORE USING THIS!!!");
- MainUtil.sendMessage(player,
- "&7Retype the command with the override parameter when ready :)");
- return false;
- }
-
- if (currentUUIDWrapper.getClass().getCanonicalName()
- .equals(newWrapper.getClass().getCanonicalName())) {
- MainUtil.sendMessage(player, "&cUUID mode already in use!");
- return false;
- }
- MainUtil.sendMessage(player, "&6Beginning UUID mode conversion");
- MainUtil.sendMessage(player, "&7 - Disconnecting players");
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- entry.getValue()
- .kick("UUID conversion has been initiated. You may reconnect when finished.");
- }
-
- MainUtil.sendMessage(player, "&7 - Initializing map");
-
- final HashMap uCMap = new HashMap<>();
- final HashMap uCReverse = new HashMap<>();
-
- MainUtil.sendMessage(player, "&7 - Collecting playerdata");
-
- HashSet worlds = Sets.newHashSet(WorldUtil.IMP.getMainWorld(), "world");
- HashSet uuids = new HashSet<>();
- HashSet names = new HashSet<>();
- for (String worldName : worlds) {
- File playerDataFolder = new File(worldName + File.separator + "playerdata");
- String[] dat = playerDataFolder.list(new DatFileFilter());
- if (dat != null) {
- for (String current : dat) {
- String s = current.replaceAll(".dat$", "");
- try {
- UUID uuid = UUID.fromString(s);
- uuids.add(uuid);
- } catch (Exception ignored) {
- MainUtil.sendMessage(player,
- Captions.PREFIX + "Invalid playerdata: " + current);
- }
- }
- }
- File playersFolder = new File(worldName + File.separator + "players");
- dat = playersFolder.list(new DatFileFilter());
- if (dat != null) {
- for (String current : dat) {
- names.add(current.replaceAll(".dat$", ""));
- }
- }
- }
-
- MainUtil.sendMessage(player, "&7 - Populating map");
- UUID uuid2;
- UUIDWrapper wrapper = new DefaultUUIDWrapper();
- for (UUID uuid : uuids) {
- try {
- OfflinePlotPlayer op = wrapper.getOfflinePlayer(uuid);
- uuid = currentUUIDWrapper.getUUID(op);
- uuid2 = newWrapper.getUUID(op);
- if (!uuid.equals(uuid2) && !uCMap.containsKey(uuid) && !uCReverse
- .containsKey(uuid2)) {
- uCMap.put(uuid, uuid2);
- uCReverse.put(uuid2, uuid);
- }
- } catch (Throwable ignored) {
- MainUtil.sendMessage(player,
- Captions.PREFIX + "&6Invalid playerdata: " + uuid.toString() + ".dat");
- }
- }
- for (String name : names) {
- UUID uuid = currentUUIDWrapper.getUUID(name);
- uuid2 = newWrapper.getUUID(name);
- if (!uuid.equals(uuid2)) {
- uCMap.put(uuid, uuid2);
- uCReverse.put(uuid2, uuid);
- }
- }
- if (uCMap.isEmpty()) {
- MainUtil.sendMessage(player, "&c - Error! Attempting to repopulate");
- for (OfflinePlotPlayer op : currentUUIDWrapper.getOfflinePlayers()) {
- if (op.getLastPlayed() != 0) {
- // String name = op.getPluginName();
- // StringWrapper wrap = new StringWrapper(name);
- UUID uuid = currentUUIDWrapper.getUUID(op);
- uuid2 = newWrapper.getUUID(op);
- if (!uuid.equals(uuid2)) {
- uCMap.put(uuid, uuid2);
- uCReverse.put(uuid2, uuid);
- }
- }
- }
- if (uCMap.isEmpty()) {
- MainUtil.sendMessage(player, "&cError. Failed to collect UUIDs!");
- return false;
- } else {
- MainUtil.sendMessage(player, "&a - Successfully repopulated");
- }
- }
-
- MainUtil.sendMessage(player, "&7 - Replacing cache");
- TaskManager.runTaskAsync(() -> {
- for (Entry entry : uCMap.entrySet()) {
- String name = UUIDHandler.getName(entry.getKey());
- if (name != null) {
- UUIDHandler.add(new StringWrapper(name), entry.getValue());
- }
- }
-
- MainUtil.sendMessage(player, "&7 - Scanning for applicable files (uuids.txt)");
-
- File file = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
- if (file.exists()) {
- try {
- List lines = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
- for (String line : lines) {
- try {
- line = line.trim();
- if (line.isEmpty()) {
- continue;
- }
- line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
- String[] split = line.split("\\|");
- String name = split[0];
- if (name.isEmpty() || name.length() > 16 || !StringMan
- .isAlphanumericUnd(name)) {
- continue;
- }
- UUID old = currentUUIDWrapper.getUUID(name);
- if (old == null) {
- continue;
- }
- UUID now = newWrapper.getUUID(name);
- UUIDHandler.add(new StringWrapper(name), now);
- uCMap.put(old, now);
- uCReverse.put(now, old);
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- MainUtil.sendMessage(player, "&7 - Replacing wrapper");
- UUIDHandler.setUUIDWrapper(newWrapper);
-
- MainUtil.sendMessage(player, "&7 - Updating plot objects");
-
- for (Plot plot : PlotSquared.get().getPlots()) {
- UUID value = uCMap.get(plot.getOwnerAbs());
- if (value != null) {
- plot.setOwnerAbs(value);
- }
- plot.getTrusted().clear();
- plot.getMembers().clear();
- plot.getDenied().clear();
- }
-
- MainUtil.sendMessage(player, "&7 - Deleting database");
- boolean result = DBFunc.deleteTables();
-
- MainUtil.sendMessage(player, "&7 - Creating tables");
-
- try {
- DBFunc.createTables();
- if (!result) {
- MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
- for (Plot plot : PlotSquared.get().getPlots()) {
- UUID value = uCReverse.get(plot.getOwnerAbs());
- if (value != null) {
- plot.setOwnerAbs(value);
- }
- }
- DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()),
- () -> MainUtil.sendMessage(player, "&6Recovery was successful!"));
- return;
- }
- } catch (Exception e) {
- e.printStackTrace();
- return;
- }
-
- if (newWrapper instanceof OfflineUUIDWrapper) {
- PlotSquared.get().worlds.set("UUID.force-lowercase", false);
- PlotSquared.get().worlds.set("UUID.offline", true);
- } else if (newWrapper instanceof DefaultUUIDWrapper) {
- PlotSquared.get().worlds.set("UUID.force-lowercase", false);
- PlotSquared.get().worlds.set("UUID.offline", false);
- }
- try {
- PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
- } catch (IOException ignored) {
- MainUtil.sendMessage(player,
- "Could not save configuration. It will need to be manual set!");
- }
-
- MainUtil.sendMessage(player, "&7 - Populating tables");
-
- TaskManager.runTaskAsync(() -> {
- ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots());
- DBFunc.createPlotsAndData(plots,
- () -> MainUtil.sendMessage(player, "&aConversion complete!"));
- });
-
- MainUtil.sendMessage(player, "&aIt is now safe for players to join");
- MainUtil.sendMessage(player,
- "&cConversion is still in progress, you will be notified when it is complete");
- });
- return true;
- }
-}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
index f0ef20fba..83740e9db 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/entity/ReplicatingEntityWrapper.java
@@ -103,51 +103,51 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (!entity.hasGravity()) {
this.noGravity = true;
}
- switch (entity.getType()) {
- case BOAT:
+ switch (entity.getType().toString()) {
+ case "BOAT":
Boat boat = (Boat) entity;
this.dataByte = getOrdinal(TreeSpecies.values(), boat.getWoodType());
return;
- case ARROW:
- case EGG:
- case ENDER_CRYSTAL:
- case ENDER_PEARL:
- case ENDER_SIGNAL:
- case EXPERIENCE_ORB:
- case FALLING_BLOCK:
- case FIREBALL:
- case FIREWORK:
- case FISHING_HOOK:
- case LEASH_HITCH:
- case LIGHTNING:
- case MINECART:
- case MINECART_COMMAND:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT:
- case PLAYER:
- case PRIMED_TNT:
- case SLIME:
- case SMALL_FIREBALL:
- case SNOWBALL:
- case MINECART_FURNACE:
- case SPLASH_POTION:
- case THROWN_EXP_BOTTLE:
- case WITHER_SKULL:
- case UNKNOWN:
- case SPECTRAL_ARROW:
- case SHULKER_BULLET:
- case DRAGON_FIREBALL:
- case AREA_EFFECT_CLOUD:
- case TRIDENT:
- case LLAMA_SPIT:
+ case "ARROW":
+ case "EGG":
+ case "ENDER_CRYSTAL":
+ case "ENDER_PEARL":
+ case "ENDER_SIGNAL":
+ case "EXPERIENCE_ORB":
+ case "FALLING_BLOCK":
+ case "FIREBALL":
+ case "FIREWORK":
+ case "FISHING_HOOK":
+ case "LEASH_HITCH":
+ case "LIGHTNING":
+ case "MINECART":
+ case "MINECART_COMMAND":
+ case "MINECART_MOB_SPAWNER":
+ case "MINECART_TNT":
+ case "PLAYER":
+ case "PRIMED_TNT":
+ case "SLIME":
+ case "SMALL_FIREBALL":
+ case "SNOWBALL":
+ case "MINECART_FURNACE":
+ case "SPLASH_POTION":
+ case "THROWN_EXP_BOTTLE":
+ case "WITHER_SKULL":
+ case "UNKNOWN":
+ case "SPECTRAL_ARROW":
+ case "SHULKER_BULLET":
+ case "DRAGON_FIREBALL":
+ case "AREA_EFFECT_CLOUD":
+ case "TRIDENT":
+ case "LLAMA_SPIT":
// Do this stuff later
return;
// MISC //
- case DROPPED_ITEM:
+ case "DROPPED_ITEM":
Item item = (Item) entity;
this.stack = item.getItemStack();
return;
- case ITEM_FRAME:
+ case "ITEM_FRAME":
this.x = Math.floor(this.x);
this.y = Math.floor(this.y);
this.z = Math.floor(this.z);
@@ -155,7 +155,7 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.dataByte = getOrdinal(Rotation.values(), itemFrame.getRotation());
this.stack = itemFrame.getItem().clone();
return;
- case PAINTING:
+ case "PAINTING":
this.x = Math.floor(this.x);
this.y = Math.floor(this.y);
this.z = Math.floor(this.z);
@@ -170,18 +170,18 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
return;
// END MISC //
// INVENTORY HOLDER //
- case MINECART_CHEST:
- case MINECART_HOPPER:
+ case "MINECART_CHEST":
+ case "MINECART_HOPPER":
storeInventory((InventoryHolder) entity);
return;
// START LIVING ENTITY //
// START AGEABLE //
// START TAMEABLE //
- case HORSE:
- case DONKEY:
- case LLAMA:
- case MULE:
- case SKELETON_HORSE:
+ case "HORSE":
+ case "DONKEY":
+ case "LLAMA":
+ case "MULE":
+ case "SKELETON_HORSE":
AbstractHorse horse = (AbstractHorse) entity;
this.horse = new HorseStats();
this.horse.jump = horse.getJumpStrength();
@@ -199,15 +199,15 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
storeInventory(horse);
return;
// END INVENTORY HOLDER //
- case WOLF:
- case OCELOT:
+ case "WOLF":
+ case "OCELOT":
storeTameable((Tameable) entity);
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
// END TAMEABLE //
//todo fix sheep
- case SHEEP:
+ case "SHEEP":
Sheep sheep = (Sheep) entity;
if (sheep.isSheared()) {
this.dataByte = (byte) 1;
@@ -218,23 +218,23 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
storeAgeable(sheep);
storeLiving(sheep);
return;
- case VILLAGER:
- case CHICKEN:
- case COW:
- case MUSHROOM_COW:
- case PIG:
- case TURTLE:
- case POLAR_BEAR:
+ case "VILLAGER":
+ case "CHICKEN":
+ case "COW":
+ case "MUSHROOM_COW":
+ case "PIG":
+ case "TURTLE":
+ case "POLAR_BEAR":
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
- case RABBIT:
+ case "RABBIT":
this.dataByte = getOrdinal(Rabbit.Type.values(), ((Rabbit) entity).getRabbitType());
storeAgeable((Ageable) entity);
storeLiving((LivingEntity) entity);
return;
// END AGEABLE //
- case ARMOR_STAND:
+ case "ARMOR_STAND":
ArmorStand stand = (ArmorStand) entity;
this.inventory =
new ItemStack[] {stand.getItemInHand().clone(), stand.getHelmet().clone(),
@@ -286,42 +286,45 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
this.stand.small = true;
}
return;
- case ENDERMITE:
+ case "ENDERMITE":
return;
- case BAT:
+ case "BAT":
if (((Bat) entity).isAwake()) {
this.dataByte = (byte) 1;
} else {
this.dataByte = (byte) 0;
}
return;
- case ENDER_DRAGON:
+ case "ENDER_DRAGON":
EnderDragon entity1 = (EnderDragon) entity;
this.dataByte = (byte) entity1.getPhase().ordinal();
return;
- case SKELETON:
- case WITHER_SKELETON:
- case GUARDIAN:
- case ELDER_GUARDIAN:
- case GHAST:
- case MAGMA_CUBE:
- case SQUID:
- case PIG_ZOMBIE:
- case ZOMBIE:
- case WITHER:
- case WITCH:
- case SPIDER:
- case CAVE_SPIDER:
- case SILVERFISH:
- case GIANT:
- case ENDERMAN:
- case CREEPER:
- case BLAZE:
- case SHULKER:
- case SNOWMAN:
+ case "SKELETON":
+ case "WITHER_SKELETON":
+ case "GUARDIAN":
+ case "ELDER_GUARDIAN":
+ case "GHAST":
+ case "MAGMA_CUBE":
+ case "SQUID":
+ case "PIG_ZOMBIE":
+ case "HOGLIN":
+ case "ZOMBIFIED_PIGLIN":
+ case "PIGLIN":
+ case "ZOMBIE":
+ case "WITHER":
+ case "WITCH":
+ case "SPIDER":
+ case "CAVE_SPIDER":
+ case "SILVERFISH":
+ case "GIANT":
+ case "ENDERMAN":
+ case "CREEPER":
+ case "BLAZE":
+ case "SHULKER":
+ case "SNOWMAN":
storeLiving((LivingEntity) entity);
return;
- case IRON_GOLEM:
+ case "IRON_GOLEM":
if (((IronGolem) entity).isPlayerCreated()) {
this.dataByte = (byte) 1;
} else {
@@ -463,16 +466,16 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
return null;
}
Entity entity;
- switch (this.getType()) {
- case DROPPED_ITEM:
+ switch (this.getType().toString()) {
+ case "DROPPED_ITEM":
return world.dropItem(location, this.stack);
- case PLAYER:
- case LEASH_HITCH:
+ case "PLAYER":
+ case "LEASH_HITCH":
return null;
- case ITEM_FRAME:
+ case "ITEM_FRAME":
entity = world.spawn(location, ItemFrame.class);
break;
- case PAINTING:
+ case "PAINTING":
entity = world.spawn(location, Painting.class);
break;
default:
@@ -504,73 +507,73 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
if (this.noGravity) {
entity.setGravity(false);
}
- switch (entity.getType()) {
- case BOAT:
+ switch (entity.getType().toString()) {
+ case "BOAT":
Boat boat = (Boat) entity;
boat.setWoodType(TreeSpecies.values()[dataByte]);
return entity;
- case SLIME:
+ case "SLIME":
((Slime) entity).setSize(this.dataByte);
return entity;
- case ARROW:
- case EGG:
- case ENDER_CRYSTAL:
- case ENDER_PEARL:
- case ENDER_SIGNAL:
- case DROPPED_ITEM:
- case EXPERIENCE_ORB:
- case FALLING_BLOCK:
- case FIREBALL:
- case FIREWORK:
- case FISHING_HOOK:
- case LEASH_HITCH:
- case LIGHTNING:
- case MINECART:
- case MINECART_COMMAND:
- case MINECART_MOB_SPAWNER:
- case MINECART_TNT:
- case PLAYER:
- case PRIMED_TNT:
- case SMALL_FIREBALL:
- case SNOWBALL:
- case SPLASH_POTION:
- case THROWN_EXP_BOTTLE:
- case SPECTRAL_ARROW:
- case SHULKER_BULLET:
- case AREA_EFFECT_CLOUD:
- case DRAGON_FIREBALL:
- case WITHER_SKULL:
- case MINECART_FURNACE:
- case LLAMA_SPIT:
- case TRIDENT:
- case UNKNOWN:
+ case "ARROW":
+ case "EGG":
+ case "ENDER_CRYSTAL":
+ case "ENDER_PEARL":
+ case "ENDER_SIGNAL":
+ case "DROPPED_ITEM":
+ case "EXPERIENCE_ORB":
+ case "FALLING_BLOCK":
+ case "FIREBALL":
+ case "FIREWORK":
+ case "FISHING_HOOK":
+ case "LEASH_HITCH":
+ case "LIGHTNING":
+ case "MINECART":
+ case "MINECART_COMMAND":
+ case "MINECART_MOB_SPAWNER":
+ case "MINECART_TNT":
+ case "PLAYER":
+ case "PRIMED_TNT":
+ case "SMALL_FIREBALL":
+ case "SNOWBALL":
+ case "SPLASH_POTION":
+ case "THROWN_EXP_BOTTLE":
+ case "SPECTRAL_ARROW":
+ case "SHULKER_BULLET":
+ case "AREA_EFFECT_CLOUD":
+ case "DRAGON_FIREBALL":
+ case "WITHER_SKULL":
+ case "MINECART_FURNACE":
+ case "LLAMA_SPIT":
+ case "TRIDENT":
+ case "UNKNOWN":
// Do this stuff later
return entity;
// MISC //
- case ITEM_FRAME:
+ case "ITEM_FRAME":
ItemFrame itemframe = (ItemFrame) entity;
itemframe.setRotation(Rotation.values()[this.dataByte]);
itemframe.setItem(this.stack);
return entity;
- case PAINTING:
+ case "PAINTING":
Painting painting = (Painting) entity;
painting.setFacingDirection(BlockFace.values()[this.dataByte], true);
painting.setArt(Art.getByName(this.dataString), true);
return entity;
// END MISC //
// INVENTORY HOLDER //
- case MINECART_CHEST:
- case MINECART_HOPPER:
+ case "MINECART_CHEST":
+ case "MINECART_HOPPER":
restoreInventory((InventoryHolder) entity);
return entity;
// START LIVING ENTITY //
// START AGEABLE //
// START TAMEABLE //
- case HORSE:
- case LLAMA:
- case SKELETON_HORSE:
- case DONKEY:
- case MULE:
+ case "HORSE":
+ case "LLAMA":
+ case "SKELETON_HORSE":
+ case "DONKEY":
+ case "MULE":
AbstractHorse horse = (AbstractHorse) entity;
horse.setJumpStrength(this.horse.jump);
if (horse instanceof ChestedHorse) {
@@ -586,14 +589,14 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreInventory(horse);
return entity;
// END INVENTORY HOLDER //
- case WOLF:
- case OCELOT:
+ case "WOLF":
+ case "OCELOT":
restoreTameable((Tameable) entity);
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
// END AGEABLE //
- case SHEEP:
+ case "SHEEP":
Sheep sheep = (Sheep) entity;
if (this.dataByte == 1) {
sheep.setSheared(true);
@@ -604,25 +607,25 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
restoreAgeable(sheep);
restoreLiving(sheep);
return sheep;
- case VILLAGER:
- case CHICKEN:
- case COW:
- case TURTLE:
- case POLAR_BEAR:
- case MUSHROOM_COW:
- case PIG:
+ case "VILLAGER":
+ case "CHICKEN":
+ case "COW":
+ case "TURTLE":
+ case "POLAR_BEAR":
+ case "MUSHROOM_COW":
+ case "PIG":
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
// END AGEABLE //
- case RABBIT:
+ case "RABBIT":
if (this.dataByte != 0) {
((Rabbit) entity).setRabbitType(Rabbit.Type.values()[this.dataByte]);
}
restoreAgeable((Ageable) entity);
restoreLiving((LivingEntity) entity);
return entity;
- case ARMOR_STAND:
+ case "ARMOR_STAND":
// CHECK positions
ArmorStand stand = (ArmorStand) entity;
if (this.inventory[0] != null) {
@@ -688,42 +691,45 @@ public final class ReplicatingEntityWrapper extends EntityWrapper {
}
restoreLiving(stand);
return stand;
- case BAT:
+ case "BAT":
if (this.dataByte != 0) {
((Bat) entity).setAwake(true);
}
restoreLiving((LivingEntity) entity);
return entity;
- case ENDER_DRAGON:
+ case "ENDER_DRAGON":
if (this.dataByte != 0) {
((EnderDragon) entity).setPhase(EnderDragon.Phase.values()[this.dataByte]);
}
restoreLiving((LivingEntity) entity);
return entity;
- case ENDERMITE:
- case GHAST:
- case MAGMA_CUBE:
- case SQUID:
- case PIG_ZOMBIE:
- case ZOMBIE:
- case WITHER:
- case WITCH:
- case SPIDER:
- case CAVE_SPIDER:
- case SILVERFISH:
- case GIANT:
- case ENDERMAN:
- case CREEPER:
- case BLAZE:
- case SNOWMAN:
- case SHULKER:
- case GUARDIAN:
- case ELDER_GUARDIAN:
- case SKELETON:
- case WITHER_SKELETON:
+ case "ENDERMITE":
+ case "GHAST":
+ case "MAGMA_CUBE":
+ case "SQUID":
+ case "PIG_ZOMBIE":
+ case "HOGLIN":
+ case "PIGLIN":
+ case "ZOMBIFIED_PIGLIN":
+ case "ZOMBIE":
+ case "WITHER":
+ case "WITCH":
+ case "SPIDER":
+ case "CAVE_SPIDER":
+ case "SILVERFISH":
+ case "GIANT":
+ case "ENDERMAN":
+ case "CREEPER":
+ case "BLAZE":
+ case "SNOWMAN":
+ case "SHULKER":
+ case "GUARDIAN":
+ case "ELDER_GUARDIAN":
+ case "SKELETON":
+ case "WITHER_SKELETON":
restoreLiving((LivingEntity) entity);
return entity;
- case IRON_GOLEM:
+ case "IRON_GOLEM":
if (this.dataByte != 0) {
((IronGolem) entity).setPlayerCreated(true);
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java
index e094baf9c..0bf5e75e8 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/EntitySpawnListener.java
@@ -100,15 +100,15 @@ public class EntitySpawnListener implements Listener {
if (!originWorld.equals(world)) {
if (!ignoreTP) {
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
+ if (entity.getType() == EntityType.PLAYER) {
+ return;
+ }
try {
ignoreTP = true;
PaperLib.teleportAsync(entity, origin);
} finally {
ignoreTP = false;
}
- if (entity.getType() == EntityType.PLAYER) {
- return;
- }
if (entity.getLocation().getWorld().equals(world)) {
entity.remove();
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java
index 6c7e4c9eb..a512189f7 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PaperListener.java
@@ -31,8 +31,11 @@ import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent;
import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent;
import com.destroystokyo.paper.event.entity.SlimePathfindEvent;
import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent;
+import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared;
+import com.plotsquared.core.command.Command;
+import com.plotsquared.core.command.MainCommand;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.location.Location;
@@ -56,6 +59,12 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.projectiles.ProjectileSource;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Pattern;
+
/**
* Events specific to Paper. Some toit nups here
*/
@@ -270,7 +279,7 @@ public class PaperListener implements Listener {
}
final int tileEntityCount = event.getBlock().getChunk().getTileEntities(false).length;
if (tileEntityCount >= Settings.Chunk_Processor.MAX_TILES) {
- final PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
+ final PlotPlayer> plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
Captions.TILE_ENTITY_CAP_REACHED.send(plotPlayer, Settings.Chunk_Processor.MAX_TILES);
event.setCancelled(true);
event.setBuild(false);
@@ -299,11 +308,50 @@ public class PaperListener implements Listener {
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
return;
}
- PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
+ PlotPlayer> pp = BukkitUtil.getPlayer((Player) shooter);
Plot plot = location.getOwnedPlot();
if (plot != null && !plot.isAdded(pp.getUUID())) {
entity.remove();
event.setCancelled(true);
}
}
+
+ @EventHandler public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
+ if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
+ return;
+ }
+ String buffer = event.getBuffer();
+ if (!(event.getSender() instanceof Player)) {
+ return;
+ }
+ if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) {
+ return;
+ }
+ if (buffer.startsWith("/")) {
+ buffer = buffer.substring(1);
+ }
+ final String[] unprocessedArgs = buffer.split(Pattern.quote(" "));
+ if (unprocessedArgs.length == 1) {
+ return; // We don't do anything in this case
+ } else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES
+ .contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
+ return;
+ }
+ final String[] args = new String[unprocessedArgs.length - 1];
+ System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
+ try {
+ final PlotPlayer> player = BukkitUtil.getPlayer((Player) event.getSender());
+ final Collection objects = MainCommand.getInstance().tab(player, args, buffer.endsWith(" "));
+ if (objects == null) {
+ return;
+ }
+ final List result = new ArrayList<>();
+ for (final com.plotsquared.core.command.Command o : objects) {
+ result.add(o.toString());
+ }
+ event.setCompletions(result);
+ event.setHandled(true);
+ } catch (final Exception ignored) {}
+ }
+
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
index 421de869b..530b7a8ec 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
@@ -26,6 +26,7 @@
package com.plotsquared.bukkit.listener;
import com.destroystokyo.paper.MaterialTags;
+import com.google.common.base.Charsets;
import com.plotsquared.bukkit.player.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.UpdateUtility;
@@ -104,10 +105,8 @@ import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.RegExUtil;
-import com.plotsquared.core.util.StringWrapper;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
import io.papermc.lib.PaperLib;
@@ -179,6 +178,7 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
@@ -216,7 +216,6 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@@ -254,8 +253,8 @@ public class PlayerEvents extends PlotListener implements Listener {
int x = bloc.getBlockX();
int z = bloc.getBlockZ();
int distance = Bukkit.getViewDistance() * 16;
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer player = entry.getValue();
+
+ for (final PlotPlayer> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
Location location = player.getLocation();
if (location.getWorld().equals(world)) {
if (16 * Math.abs(location.getX() - x) / 16 > distance
@@ -315,7 +314,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Location location = BukkitUtil.getLocation(e.getEntity());
if (location.isPlotArea()) {
if (e.getEntity() instanceof Player) {
- PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity());
+ PlotPlayer player = BukkitUtil.getPlayer((Player) e.getEntity());
Plot plot = player.getCurrentPlot();
if (plot != null) {
if (!plot.isAdded(player.getUUID())) {
@@ -352,6 +351,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
if (!plot.getFlag(RedstoneFlag.class)) {
event.setNewCurrent(0);
+ plot.debug("Redstone event was cancelled because redstone = false");
return;
}
if (Settings.Redstone.DISABLE_OFFLINE) {
@@ -360,31 +360,35 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot.isMerged()) {
disable = true;
for (UUID owner : plot.getOwners()) {
- if (UUIDHandler.getPlayer(owner) != null) {
+ if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(owner) != null) {
disable = false;
break;
}
}
} else {
- disable = UUIDHandler.getPlayer(plot.guessOwner()) == null;
+ disable =
+ PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs())
+ == null;
}
}
if (disable) {
for (UUID trusted : plot.getTrusted()) {
- if (UUIDHandler.getPlayer(trusted) != null) {
+ if (PlotSquared.imp().getPlayerManager().getPlayerIfExists(trusted) != null) {
disable = false;
break;
}
}
if (disable) {
event.setNewCurrent(0);
+ plot.debug(
+ "Redstone event was cancelled because no trusted player was in the plot");
return;
}
}
}
if (Settings.Redstone.DISABLE_UNOCCUPIED) {
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- if (plot.equals(entry.getValue().getCurrentPlot())) {
+ for (final PlotPlayer> player : PlotSquared.imp().getPlayerManager().getPlayers()) {
+ if (plot.equals(player.getCurrentPlot())) {
return;
}
}
@@ -407,6 +411,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
if (!plot.getFlag(RedstoneFlag.class)) {
event.setCancelled(true);
+ plot.debug("Prevented comparator update because redstone = false");
}
return;
}
@@ -429,6 +434,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
if (plot.getFlag(DisablePhysicsFlag.class)) {
event.setCancelled(true);
+ plot.debug("Prevented block physics because disable-physics = true");
}
return;
}
@@ -466,6 +472,8 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot newPlot = area.getOwnedPlotAbs(location);
if (!plot.equals(newPlot)) {
event.setCancelled(true);
+ plot.debug(
+ "Prevented piston update because of invalid edge piston detection");
return;
}
}
@@ -487,7 +495,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!PlotSquared.get().hasPlotArea(location.getWorld())) {
return;
}
- PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
+ PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
Plot plot = location.getOwnedPlot();
if (plot != null && !plot.isAdded(pp.getUUID())) {
entity.remove();
@@ -508,7 +516,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = area.getPlot(location);
ProjectileSource shooter = entity.getShooter();
if (shooter instanceof Player) {
- PlotPlayer pp = BukkitUtil.getPlayer((Player) shooter);
+ PlotPlayer> pp = BukkitUtil.getPlayer((Player) shooter);
if (plot == null) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_PROJECTILE_UNOWNED)) {
entity.remove();
@@ -550,7 +558,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Player player = event.getPlayer();
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
Location location = plotPlayer.getLocation();
PlotArea area = location.getPlotArea();
if (area == null) {
@@ -638,17 +646,28 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
- @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPreLoin(final AsyncPlayerPreLoginEvent event) {
+ final UUID uuid;
+ if (Settings.UUID.OFFLINE) {
+ if (Settings.UUID.FORCE_LOWERCASE) {
+ uuid = UUID.nameUUIDFromBytes(
+ ("OfflinePlayer:" + event.getName().toLowerCase()).getBytes(Charsets.UTF_8));
+ } else {
+ uuid = UUID.nameUUIDFromBytes(
+ ("OfflinePlayer:" + event.getName()).getBytes(Charsets.UTF_8));
+ }
+ } else {
+ uuid = event.getUniqueId();
+ }
+ PlotSquared.get().getImpromptuUUIDPipeline().storeImmediately(event.getName(), uuid);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onConnect(PlayerJoinEvent event) {
final Player player = event.getPlayer();
- UUIDHandler.getPlayers().remove(player.getName());
- BukkitUtil.removePlayer(player.getName());
- final PlotPlayer pp = BukkitUtil.getPlayer(player);
- // Now
- String name = pp.getName();
- StringWrapper sw = new StringWrapper(name);
- UUID uuid = pp.getUUID();
- UUIDHandler.add(sw, uuid);
+ BukkitUtil.removePlayer(player.getUniqueId());
+ final PlotPlayer pp = BukkitUtil.getPlayer(player);
Location location = pp.getLocation();
PlotArea area = location.getPlotArea();
@@ -687,14 +706,14 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void playerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ PlotPlayer pp = BukkitUtil.getPlayer(player);
PlotSquared.get().getEventDispatcher().doRespawnTask(pp);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
Plot lastPlot = pp.getMeta(PlotPlayer.META_LAST_PLOT);
org.bukkit.Location to = event.getTo();
//noinspection ConstantConditions
@@ -804,7 +823,7 @@ public class PlayerEvents extends PlotListener implements Listener {
int x2;
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
// Cancel teleport
TaskManager.TELEPORT_QUEUE.remove(pp.getName());
// Set last location
@@ -864,7 +883,7 @@ public class PlayerEvents extends PlotListener implements Listener {
int z2;
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
// Cancel teleport
TaskManager.TELEPORT_QUEUE.remove(pp.getName());
// Set last location
@@ -928,7 +947,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(event.getPlayer());
Location location = plotPlayer.getLocation();
PlotArea area = location.getPlotArea();
if (area == null) {
@@ -954,8 +973,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Set recipients = event.getRecipients();
recipients.clear();
Set spies = new HashSet<>();
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer pp = entry.getValue();
+ for (final PlotPlayer> pp : PlotSquared.imp().getPlayerManager().getPlayers()) {
if (pp.getAttribute("chatspy")) {
spies.add(((BukkitPlayer) pp).player);
} else {
@@ -979,9 +997,6 @@ public class PlayerEvents extends PlotListener implements Listener {
.replace("%plot_id%", id.x + ";" + id.y).replace("%sender%", sender)
.replace("%msg%", message);
for (Player player : spies) {
- if (player.equals(event.getPlayer())) {
- continue;
- }
player.sendMessage(spyMessage);
}
}
@@ -997,7 +1012,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
Plot plot = area.getPlot(location);
if (plot != null) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (event.getBlock().getY() == 0) {
if (!Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_GROUNDLEVEL)) {
@@ -1046,7 +1061,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
return;
}
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
return;
}
@@ -1106,6 +1121,8 @@ public class PlayerEvents extends PlotListener implements Listener {
}
}
return;
+ } else {
+ plot.debug("Explosion was cancelled because explosion = false");
}
}
event.setCancelled(true);
@@ -1114,7 +1131,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWorldChanged(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
// Delete last location
Plot plot = (Plot) pp.deleteMeta(PlotPlayer.META_LAST_PLOT);
pp.deleteMeta(PlotPlayer.META_LOCATION);
@@ -1150,6 +1167,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area != null) {
Plot plot = area.getOwnedPlot(location);
if (plot != null && plot.getFlag(MobPlaceFlag.class)) {
+ plot.debug(e.getType() + " could not change block because mob-place = false");
return;
}
event.setCancelled(true);
@@ -1177,16 +1195,18 @@ public class PlayerEvents extends PlotListener implements Listener {
if (entity instanceof Player) {
Player player = (Player) entity;
if (!plot.hasOwner()) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (plot.getFlag(IceFormFlag.class)) {
+ plot.debug("Ice could not be formed because ice-form = false");
return;
}
event.setCancelled(true);
return;
}
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (!plot.isAdded(plotPlayer.getUUID())) {
if (plot.getFlag(IceFormFlag.class)) {
+ plot.debug("Ice could not be formed because ice-form = false");
return;
}
event.setCancelled(true);
@@ -1216,23 +1236,27 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
switch (event.getSource().getType()) {
- case GRASS:
+ case GRASS_BLOCK:
if (!plot.getFlag(GrassGrowFlag.class)) {
+ plot.debug("Grass could not grow because grass-grow = false");
event.setCancelled(true);
}
break;
case MYCELIUM:
if (!plot.getFlag(MycelGrowFlag.class)) {
+ plot.debug("Mycelium could not grow because mycel-grow = false");
event.setCancelled(true);
}
break;
case VINE:
if (!plot.getFlag(VineGrowFlag.class)) {
+ plot.debug("Vine could not grow because vine-grow = false");
event.setCancelled(true);
}
break;
case KELP:
if (!plot.getFlag(KelpGrowFlag.class)) {
+ plot.debug("Kelp could not grow because kelp-grow = false");
event.setCancelled(true);
}
break;
@@ -1259,6 +1283,7 @@ public class PlayerEvents extends PlotListener implements Listener {
case SNOW:
case SNOW_BLOCK:
if (!plot.getFlag(SnowFormFlag.class)) {
+ plot.debug("Snow could not form because snow-form = false");
event.setCancelled(true);
}
return;
@@ -1266,6 +1291,7 @@ public class PlayerEvents extends PlotListener implements Listener {
case FROSTED_ICE:
case PACKED_ICE:
if (!plot.getFlag(IceFormFlag.class)) {
+ plot.debug("Ice could not form because ice-form = false");
event.setCancelled(true);
}
}
@@ -1297,7 +1323,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
if (!plot.hasOwner()) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (Permissions
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_UNOWNED)) {
return;
@@ -1305,7 +1331,7 @@ public class PlayerEvents extends PlotListener implements Listener {
event.setCancelled(true);
return;
}
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (!plot.isAdded(plotPlayer.getUUID())) {
List destroy = plot.getFlag(BreakFlag.class);
Block block = event.getBlock();
@@ -1315,12 +1341,14 @@ public class PlayerEvents extends PlotListener implements Listener {
.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_OTHER)) {
return;
}
+ plot.debug(player.getName() + " could not break " + block.getType()
+ + " because it was not in the break flag");
event.setCancelled(true);
return;
}
return;
}
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
return;
}
@@ -1343,16 +1371,19 @@ public class PlayerEvents extends PlotListener implements Listener {
switch (block.getType()) {
case ICE:
if (!plot.getFlag(IceMeltFlag.class)) {
+ plot.debug("Ice could not melt because ice-melt = false");
event.setCancelled(true);
}
break;
case SNOW:
if (!plot.getFlag(SnowMeltFlag.class)) {
+ plot.debug("Snow could not melt because snow-melt = false");
event.setCancelled(true);
}
break;
case FARMLAND:
if (!plot.getFlag(SoilDryFlag.class)) {
+ plot.debug("Soil could not dry because soil-dry = false");
event.setCancelled(true);
}
break;
@@ -1371,7 +1402,13 @@ public class PlayerEvents extends PlotListener implements Listener {
case BUBBLE_CORAL_FAN:
case FIRE_CORAL_FAN:
case HORN_CORAL_FAN:
+ case BRAIN_CORAL_WALL_FAN:
+ case BUBBLE_CORAL_WALL_FAN:
+ case FIRE_CORAL_WALL_FAN:
+ case HORN_CORAL_WALL_FAN:
+ case TUBE_CORAL_WALL_FAN:
if (!plot.getFlag(CoralDryFlag.class)) {
+ plot.debug("Coral could not dry because coral-dry = false");
event.setCancelled(true);
}
break;
@@ -1390,6 +1427,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (plot != null
&& plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
.getBlock().isLiquid()) {
+ plot.debug("Liquid could now flow because liquid-flow = disabled");
event.setCancelled(true);
return;
}
@@ -1413,11 +1451,14 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
if (plot.getFlag(DisablePhysicsFlag.class)) {
+ plot.debug(event.getBlock().getType()
+ + " could not update because disable-physics = true");
event.setCancelled(true);
return;
}
if (plot.getFlag(LiquidFlowFlag.class) == LiquidFlowFlag.FlowStatus.DISABLED && event
.getBlock().isLiquid()) {
+ plot.debug("Liquid could not flow because liquid-flow = disabled");
event.setCancelled(true);
}
} else if (!area.contains(fLocation.getX(), fLocation.getZ()) || !Objects
@@ -1671,7 +1712,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Player player = (Player) clicker;
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp);
if (inventory != null && event.getRawSlot() == event.getSlot()) {
if (!inventory.onClick(event.getSlot())) {
@@ -1699,6 +1740,8 @@ public class PlayerEvents extends PlotListener implements Listener {
final ItemStack newStack =
new ItemStack(newItem.getType(), newItem.getAmount());
event.setCursor(newStack);
+ plot.debug(player.getName()
+ + " could not creative-copy an item because prevent-creative-copy = true");
}
} else {
PlotArea area = pp.getPlotAreaAbs();
@@ -1707,6 +1750,8 @@ public class PlayerEvents extends PlotListener implements Listener {
final ItemStack newStack =
new ItemStack(newItem.getType(), newItem.getAmount());
event.setCursor(newStack);
+ plot.debug(player.getName()
+ + " could not creative-copy an item because prevent-creative-copy = true");
}
}
return;
@@ -1822,7 +1867,7 @@ public class PlayerEvents extends PlotListener implements Listener {
}
EntitySpawnListener.testNether(entity);
Plot plot = location.getPlotAbs();
- PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
+ BukkitPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) {
if (!area.isRoadRespectingGlobalFlags() && !area.getFlag(MiscInteractFlag.class)
&& !Permissions.hasPermission(pp, "plots.admin.interact.road")) {
@@ -1857,6 +1902,8 @@ public class PlayerEvents extends PlotListener implements Listener {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
"plots.admin.interact.other");
e.setCancelled(true);
+ plot.debug(pp.getName() + " could not interact with " + entity.getType()
+ + " bcause misc-interact = false");
}
}
}
@@ -1884,6 +1931,9 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = area.getOwnedPlot(location);
if (plot == null || !plot.getFlag(ExplosionFlag.class)) {
event.setCancelled(true);
+ if (plot != null) {
+ plot.debug("Explosion was cancelled because explosion = false");
+ }
}
event.blockList().removeIf(
blox -> !plot.equals(area.getOwnedPlot(BukkitUtil.getLocation(blox.getLocation()))));
@@ -1893,7 +1943,7 @@ public class PlayerEvents extends PlotListener implements Listener {
public void onCancelledInteract(PlayerInteractEvent event) {
if (event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_AIR) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
PlotArea area = pp.getPlotAreaAbs();
if (area == null) {
return;
@@ -1930,7 +1980,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
PlotArea area = pp.getPlotAreaAbs();
if (area == null) {
return;
@@ -2149,6 +2199,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = area.getOwnedPlotAbs(location);
if (plot == null || plot.getFlag(DisablePhysicsFlag.class)) {
event.setCancelled(true);
+ plot.debug("Falling block event was cancelled because disable-physics = true");
return;
}
if (event.getTo().hasGravity()) {
@@ -2184,6 +2235,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = location.getOwnedPlot();
if (plot == null || !plot.getFlag(BlockBurnFlag.class)) {
+ plot.debug("Block burning was cancelled because block-burn = false");
event.setCancelled(true);
}
@@ -2207,7 +2259,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Plot plot = area.getOwnedPlot(location1);
if (player != null) {
- PlotPlayer pp = BukkitUtil.getPlayer(player);
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
if (plot == null) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
@@ -2237,6 +2289,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (ignitingEntity != null) {
if (!plot.getFlag(BlockIgnitionFlag.class)) {
event.setCancelled(true);
+ plot.debug("Block ignition was cancelled because block-ignition = false");
return;
}
if (igniteCause == BlockIgniteEvent.IgniteCause.FIREBALL) {
@@ -2283,7 +2336,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return;
}
- PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
+ BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
Plot plot = area.getPlot(location);
if (plot == null) {
if (Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
@@ -2334,7 +2387,7 @@ public class PlayerEvents extends PlotListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
- PlotPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
+ BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
pp.unregister();
PlotListener.logout(pp.getUUID());
}
@@ -2348,7 +2401,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Player player = event.getPlayer();
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
Plot plot = area.getPlot(location);
if (plot == null) {
if (Permissions.hasPermission(plotPlayer, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
@@ -2421,7 +2474,7 @@ public class PlayerEvents extends PlotListener implements Listener {
event.setCancelled(true);
return;
}
- PlotPlayer pp = BukkitUtil.getPlayer(p);
+ BukkitPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
@@ -2465,7 +2518,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return;
}
- PlotPlayer pp = BukkitUtil.getPlayer(p);
+ BukkitPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_DESTROY_ROAD)) {
@@ -2487,6 +2540,8 @@ public class PlayerEvents extends PlotListener implements Listener {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
+ plot.debug(p.getName()
+ + " could not break hanging entity because hanging-break = false");
}
}
} else if (remover instanceof Projectile) {
@@ -2498,7 +2553,7 @@ public class PlayerEvents extends PlotListener implements Listener {
if (area == null) {
return;
}
- PlotPlayer player = BukkitUtil.getPlayer(shooter);
+ BukkitPlayer player = BukkitUtil.getPlayer(shooter);
Plot plot = area.getPlot(BukkitUtil.getLocation(event.getEntity()));
if (plot != null) {
if (!plot.hasOwner()) {
@@ -2515,6 +2570,8 @@ public class PlayerEvents extends PlotListener implements Listener {
MainUtil.sendMessage(player, Captions.NO_PERMISSION_EVENT,
Captions.PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
+ plot.debug(player.getName()
+ + " could not break hanging entity because hanging-break = false");
}
}
}
@@ -2533,7 +2590,7 @@ public class PlayerEvents extends PlotListener implements Listener {
return;
}
Player p = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(p);
+ BukkitPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlot(location);
if (plot == null && !area.isRoadRespectingGlobalFlags()) {
if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_INTERACT_ROAD)) {
@@ -2616,7 +2673,7 @@ public class PlayerEvents extends PlotListener implements Listener {
Entity attacker = event.getAttacker();
if (attacker instanceof Player) {
Player p = (Player) attacker;
- PlotPlayer pp = BukkitUtil.getPlayer(p);
+ BukkitPlayer pp = BukkitUtil.getPlayer(p);
Plot plot = area.getPlot(location);
if (plot == null) {
if (!Permissions.hasPermission(pp, "plots.admin.vehicle.break.road")) {
@@ -2642,6 +2699,8 @@ public class PlayerEvents extends PlotListener implements Listener {
MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
"plots.admin.vehicle.break.other");
event.setCancelled(true);
+ plot.debug(pp.getName()
+ + " could not break vehicle because vehicle-break = false");
}
}
}
@@ -2805,7 +2864,7 @@ public class PlayerEvents extends PlotListener implements Listener {
player = null;
}
if (player != null) {
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
final com.sk89q.worldedit.world.entity.EntityType entityType;
@@ -2842,6 +2901,10 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!Permissions.hasPermission(plotPlayer, "plots.admin.destroy." + stub)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
"plots.admin.destroy." + stub);
+ if (plot != null) {
+ plot.debug(player.getName()
+ + " could not break armor stand because misc-break = false");
+ }
return false;
}
} else if (EntityCategories.HOSTILE.contains(entityType)) {
@@ -2857,6 +2920,10 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
"plots.admin.pve." + stub);
+ if (plot != null) {
+ plot.debug(player.getName() + " could not attack " + entityType
+ + " because pve = false OR hostile-attack = false");
+ }
return false;
}
} else if (EntityCategories.TAMEABLE.contains(entityType)) { // victim is tameable
@@ -2872,6 +2939,10 @@ public class PlayerEvents extends PlotListener implements Listener {
if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
"plots.admin.pve." + stub);
+ if (plot != null) {
+ plot.debug(player.getName() + " could not attack " + entityType
+ + " because pve = false OR tamned-attack = false");
+ }
return false;
}
} else if (EntityCategories.PLAYER.contains(entityType)) {
@@ -2880,6 +2951,8 @@ public class PlayerEvents extends PlotListener implements Listener {
.hasPermission(plotPlayer, "plots.admin.pvp." + stub)) {
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
"plots.admin.pvp." + stub);
+ plot.debug(player.getName() + " could not attack " + entityType
+ + " because pve = false");
return false;
} else {
return true;
@@ -2893,232 +2966,262 @@ public class PlayerEvents extends PlotListener implements Listener {
return false;
}
} else if (EntityCategories.ANIMAL.contains(entityType)) { // victim is animal
- if (isPlot) {
+<<<<<<>>>>>>v5 return true;
+ } if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
+ "plots.admin.pve." + stub);
+ return false;
+ }
+ } else if (EntityCategories.VEHICLE
+ .contains(entityType)) { // Vehicles are managed in vehicle destroy event
return true;
- }
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
- "plots.admin.pve." + stub);
- return false;
- }
- } else if (EntityCategories.VEHICLE
- .contains(entityType)) { // Vehicles are managed in vehicle destroy event
- return true;
- } else { // victim is something else
- if (isPlot) {
- if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
+ } else { // victim is something else
+ if (isPlot) {
+ if (plot.getFlag(PveFlag.class) || plot.isAdded(plotPlayer.getUUID())) {
+ return true;
+ }
+ } else if (roadFlags && area.getFlag(PveFlag.class)) {
return true;
}
- } else if (roadFlags && area.getFlag(PveFlag.class)) {
- return true;
- }
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
- MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
- "plots.admin.pve." + stub);
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.pve." + stub)) {
+ MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
+ "plots.admin.pve." + stub);
+ if (plot != null) {
+ plot.debug(player.getName() + " could not attack " + entityType
+ + " because pve = false");
+ }
+ return false;
+ }
+ } return true;
+ } else if (dplot != null && (!dplot.equals(vplot) || Objects
+ .equals(dplot.getOwnerAbs(), vplot.getOwnerAbs()))) {
+ return vplot != null && vplot.getFlag(PveFlag.class);
+ }
+ //disable the firework damage. too much of a headache to support at the moment.
+ if (vplot != null) {
+ if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
+ && damager.getType() == EntityType.FIREWORK) {
return false;
}
}
- return true;
- } else if (dplot != null && (!dplot.equals(vplot) || Objects
- .equals(dplot.guessOwner(), vplot.guessOwner()))) {
- return vplot != null && vplot.getFlag(PveFlag.class);
- }
- //disable the firework damage. too much of a headache to support at the moment.
- if (vplot != null) {
- if (EntityDamageEvent.DamageCause.ENTITY_EXPLOSION == cause
- && damager.getType() == EntityType.FIREWORK) {
- return false;
+ if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) {
+ return true;
}
+ return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
+ && !(victim instanceof Creature)));
}
- if (vplot == null && roadFlags && area.getFlag(PveFlag.class)) {
- return true;
- }
- return ((vplot != null && vplot.getFlag(PveFlag.class)) || !(damager instanceof Arrow
- && !(victim instanceof Creature)));
- }
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerEggThrow(PlayerEggThrowEvent event) {
- Location location = BukkitUtil.getLocation(event.getEgg().getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Player player = event.getPlayer();
- PlotPlayer plotPlayer = BukkitUtil.getPlayer(player);
- Plot plot = area.getPlot(location);
- if (plot == null) {
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) {
- MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
- "plots.admin.projectile.road");
- event.setHatching(false);
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onPlayerEggThrow (PlayerEggThrowEvent event){
+ Location location = BukkitUtil.getLocation(event.getEgg().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
}
- } else if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.unowned")) {
- MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
- "plots.admin.projectile.unowned");
- event.setHatching(false);
- }
- } else if (!plot.isAdded(plotPlayer.getUUID())) {
- if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.other")) {
- MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
- "plots.admin.projectile.other");
- event.setHatching(false);
- }
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void blockCreate(BlockPlaceEvent event) {
- Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- Plot plot = area.getPlot(location);
- if (plot != null) {
- if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
- .getMinBuildHeight()) && !Permissions
- .hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) {
- event.setCancelled(true);
- MainUtil.sendMessage(pp, Captions.HEIGHT_LIMIT.getTranslated()
- .replace("{limit}", String.valueOf(area.getMaxBuildHeight())));
- }
- if (!plot.hasOwner()) {
- if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
- event.setCancelled(true);
- return;
+ Player player = event.getPlayer();
+ BukkitPlayer plotPlayer = BukkitUtil.getPlayer(player);
+ Plot plot = area.getPlot(location);
+ if (plot == null) {
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.road")) {
+ MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
+ "plots.admin.projectile.road");
+ event.setHatching(false);
}
- } else if (!plot.isAdded(pp.getUUID())) {
- List place = plot.getFlag(PlaceFlag.class);
- if (place != null) {
- Block block = event.getBlock();
- if (place.contains(
- BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) {
+ } else if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.unowned")) {
+ MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
+ "plots.admin.projectile.unowned");
+ event.setHatching(false);
+ }
+ } else if (!plot.isAdded(plotPlayer.getUUID())) {
+ if (!Permissions.hasPermission(plotPlayer, "plots.admin.projectile.other")) {
+ MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
+ "plots.admin.projectile.other");
+ event.setHatching(false);
+ }
+ }
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void blockCreate (BlockPlaceEvent event){
+ Location location = BukkitUtil.getLocation(event.getBlock().getLocation());
+ PlotArea area = location.getPlotArea();
+ if (area == null) {
+ return;
+ }
+ Player player = event.getPlayer();
+ BukkitPlayer pp = BukkitUtil.getPlayer(player);
+ Plot plot = area.getPlot(location);
+ if (plot != null) {
+ if ((location.getY() > area.getMaxBuildHeight() || location.getY() < area
+ .getMinBuildHeight()) && !Permissions
+ .hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_HEIGHT_LIMIT)) {
+ event.setCancelled(true);
+ MainUtil.sendMessage(pp, Captions.HEIGHT_LIMIT.getTranslated()
+ .replace("{limit}", String.valueOf(area.getMaxBuildHeight())));
+ }
+ if (!plot.hasOwner()) {
+ if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_UNOWNED)) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
+ Captions.PERMISSION_ADMIN_BUILD_UNOWNED);
+ event.setCancelled(true);
+ return;
+ }
+ } else if (!plot.isAdded(pp.getUUID())) {
+ List place = plot.getFlag(PlaceFlag.class);
+ if (place != null) {
+ Block block = event.getBlock();
+ if (place.contains(
+ BlockTypeWrapper.get(BukkitAdapter.asBlockType(block.getType())))) {
+ return;
+ }
+ }
+ if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
+ Captions.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
+ plot.debug(
+ player.getName() + " could not place " + event.getBlock().getType()
+ + " because of the place flag");
+ return;
+ }
+ } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
+ if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
+ Captions.PERMISSION_ADMIN_BUILD_OTHER);
+ event.setCancelled(true);
return;
}
}
- if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- return;
+ if (plot.getFlag(DisablePhysicsFlag.class)) {
+ Block block = event.getBlockPlaced();
+ if (block.getType().hasGravity()) {
+ sendBlockChange(block.getLocation(), block.getBlockData());
+ plot.debug(event.getBlock().getType()
+ + " did not fall because of disable-physics = true");
+ }
}
- } else if (Settings.Done.RESTRICT_BUILDING && DoneFlag.isDone(plot)) {
- if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_OTHER)) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_BUILD_OTHER);
- event.setCancelled(true);
- return;
- }
- }
- if (plot.getFlag(DisablePhysicsFlag.class)) {
- Block block = event.getBlockPlaced();
- if (block.getType().hasGravity()) {
- sendBlockChange(block.getLocation(), block.getBlockData());
- }
- }
- } else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
- MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
- Captions.PERMISSION_ADMIN_BUILD_ROAD);
- event.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGH) public void onDamage(EntityDamageEvent event) {
- if (event.getEntityType() != EntityType.PLAYER) {
- return;
- }
- Location location = BukkitUtil.getLocation(event.getEntity());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = location.getOwnedPlot();
- if (plot == null) {
- if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) {
- event.setCancelled(true);
- }
- return;
- }
- if (plot.getFlag(InvincibleFlag.class)) {
- event.setCancelled(true);
- }
- }
-
- @EventHandler public void onItemDrop(PlayerDropItemEvent event) {
- Player player = event.getPlayer();
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- Location location = pp.getLocation();
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = location.getOwnedPlot();
- if (plot == null) {
- if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) {
- event.setCancelled(true);
- }
- return;
- }
- UUID uuid = pp.getUUID();
- if (!plot.isAdded(uuid)) {
- if (!plot.getFlag(ItemDropFlag.class)) {
+ } else if (!Permissions.hasPermission(pp, Captions.PERMISSION_ADMIN_BUILD_ROAD)) {
+ MainUtil.sendMessage(pp, Captions.NO_PERMISSION_EVENT,
+ Captions.PERMISSION_ADMIN_BUILD_ROAD);
event.setCancelled(true);
}
}
- }
- @EventHandler public void onItemPickup(EntityPickupItemEvent event) {
- LivingEntity ent = event.getEntity();
- if (ent instanceof Player) {
- Player player = (Player) ent;
- PlotPlayer pp = BukkitUtil.getPlayer(player);
- Location location = pp.getLocation();
+ @EventHandler(priority = EventPriority.HIGH) public void onDamage (EntityDamageEvent event){
+ if (event.getEntityType() != EntityType.PLAYER) {
+ return;
+ }
+ Location location = BukkitUtil.getLocation(event.getEntity());
PlotArea area = location.getPlotArea();
if (area == null) {
return;
}
Plot plot = location.getOwnedPlot();
if (plot == null) {
- if (area.isRoadRespectingGlobalFlags() && area.getFlag(DropProtectionFlag.class)) {
+ if (area.isRoadRespectingGlobalFlags() && area.getFlag(InvincibleFlag.class)) {
+ event.setCancelled(true);
+ }
+ return;
+ }
+ if (plot.getFlag(InvincibleFlag.class)) {
+ plot.debug(event.getEntity().getName()
+ + " could not take damage because invincible = true");
+ event.setCancelled(true);
+ }
+ }
+
+ @EventHandler public void onItemDrop (PlayerDropItemEvent event){
+ Player player = event.getPlayer();
+<<<<<<>>>>>>v5 if (plot == null) {
+ if (area.isRoadRespectingGlobalFlags() && area.getFlag(ItemDropFlag.class)) {
event.setCancelled(true);
}
return;
}
UUID uuid = pp.getUUID();
- if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) {
- event.setCancelled(true);
+ if (!plot.isAdded(uuid)) {
+ if (!plot.getFlag(ItemDropFlag.class)) {
+ plot.debug(
+ player.getName() + " could not drop item because of item-drop = false");
+ event.setCancelled(true);
+ }
}
}
- }
- @EventHandler public void onDeath(final PlayerDeathEvent event) {
- Location location = BukkitUtil.getLocation(event.getEntity());
- PlotArea area = location.getPlotArea();
- if (area == null) {
- return;
- }
- Plot plot = location.getOwnedPlot();
- if (plot == null) {
- if (area.isRoadRespectingGlobalFlags() && area.getFlag(KeepInventoryFlag.class)) {
- event.setCancelled(true);
+ @EventHandler public void onItemPickup (EntityPickupItemEvent event){
+ LivingEntity ent = event.getEntity();
+ if (ent instanceof Player) {
+ Player player = (Player) ent;
+<<<<<<>>>>>>v5 if (plot == null) {
+ if (area.isRoadRespectingGlobalFlags() && area
+ .getFlag(DropProtectionFlag.class)) {
+ event.setCancelled(true);
+ }
+ return;
+ }
+ UUID uuid = pp.getUUID();
+ if (!plot.isAdded(uuid) && plot.getFlag(DropProtectionFlag.class)) {
+ plot.debug(player.getName()
+ + " could not pick up item because of drop-protection = true");
+ event.setCancelled(true);
+ }
}
- return;
}
- if (plot.getFlag(KeepInventoryFlag.class)) {
- event.setKeepInventory(true);
- }
- }
-}
+ @EventHandler public void onDeath ( final PlayerDeathEvent event){
+<<<<<<>>>>>>v5 event.setKeepInventory(true);
+ }
+ }
+
+ }
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java
index 482d02896..4646868a1 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/managers/BukkitWorldManager.java
@@ -36,6 +36,9 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
/**
* Default Bukkit world manager. It will handle world creation by
@@ -76,4 +79,13 @@ public class BukkitWorldManager implements PlatformWorldManager {
return "bukkit";
}
+ @Override public Collection getWorlds() {
+ final List worlds = Bukkit.getWorlds();
+ final List worldNames = new ArrayList<>();
+ for (final World world : worlds) {
+ worldNames.add(world.getName());
+ }
+ return worldNames;
+ }
+
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
index bf2a7a8b9..5457dbe0f 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/placeholder/Placeholders.java
@@ -25,9 +25,12 @@
*/
package com.plotsquared.bukkit.placeholder;
+import com.plotsquared.core.PlotSquared;
+import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
-import com.plotsquared.core.util.uuid.UUIDHandler;
+import com.plotsquared.core.plot.flag.GlobalFlagContainer;
+import com.plotsquared.core.plot.flag.PlotFlag;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
@@ -58,31 +61,31 @@ public class Placeholders extends PlaceholderExpansion {
}
@Override public String getVersion() {
- return "2.4";
+ return "2.5";
}
@Override public String onPlaceholderRequest(Player p, String identifier) {
- final PlotPlayer pl = PlotPlayer.get(p.getName());
+ final PlotPlayer pl = PlotSquared.imp().getPlayerManager().getPlayerIfExists(p.getUniqueId());
if (pl == null) {
return "";
}
if (identifier.startsWith("has_plot_")) {
- if (identifier.split("has_plot_").length != 2)
+ identifier = identifier.substring("has_plot_".length());
+ if (identifier.isEmpty())
return "";
- identifier = identifier.split("has_plot_")[1];
return pl.getPlotCount(identifier) > 0 ?
PlaceholderAPIPlugin.booleanTrue() :
PlaceholderAPIPlugin.booleanFalse();
}
if (identifier.startsWith("plot_count_")) {
- if (identifier.split("plot_count_").length != 2)
+ identifier = identifier.substring("plot_count_".length());
+ if (identifier.isEmpty())
return "";
- identifier = identifier.split("plot_count_")[1];
return String.valueOf(pl.getPlotCount(identifier));
}
@@ -122,7 +125,9 @@ public class Placeholders extends PlaceholderExpansion {
if (uid == null) {
return "";
}
- String name = UUIDHandler.getName(uid);
+
+ String name = PlotSquared.get().getImpromptuUUIDPipeline()
+ .getSingle(uid, Settings.UUID.BLOCKING_TIMEOUT);
if (name != null) {
return name;
@@ -178,6 +183,39 @@ public class Placeholders extends PlaceholderExpansion {
default:
break;
}
+ if (identifier.startsWith("currentplot_localflag_")) {
+ return getFlagValue(plot, identifier.substring("currentplot_localflag_".length()),
+ false);
+ }
+ if (identifier.startsWith("currentplot_flag_")) {
+ return getFlagValue(plot, identifier.substring("currentplot_flag_".length()), true);
+ }
return "";
}
+
+ /**
+ * Return the flag value from its name on the current plot.
+ * If the flag doesn't exist it returns an empty string.
+ * If the flag exists but it is not set on current plot and the parameter inherit is set to true,
+ * it returns the default value.
+ *
+ * @param plot Current plot where the player is
+ * @param flagName Name of flag to get from current plot
+ * @param inherit Define if it returns only the flag set on currentplot or also inherited flag
+ * @return The value of flag serialized in string
+ */
+ private String getFlagValue(final Plot plot, final String flagName, final boolean inherit) {
+ if (flagName.isEmpty())
+ return "";
+ final PlotFlag, ?> flag = GlobalFlagContainer.getInstance().getFlagFromString(flagName);
+ if (flag == null)
+ return "";
+
+ if (inherit) {
+ return plot.getFlag(flag).toString();
+ } else {
+ final PlotFlag, ?> plotFlag = plot.getFlagContainer().queryLocal(flag.getClass());
+ return (plotFlag != null) ? plotFlag.getValue().toString() : "";
+ }
+ }
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
index 854cc6ec0..643039600 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java
@@ -25,9 +25,11 @@
*/
package com.plotsquared.bukkit.player;
+import com.google.common.base.Charsets;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
+import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer;
@@ -35,7 +37,6 @@ import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.StringMan;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.world.item.ItemType;
@@ -62,12 +63,11 @@ import static com.sk89q.worldedit.world.gamemode.GameModes.CREATIVE;
import static com.sk89q.worldedit.world.gamemode.GameModes.SPECTATOR;
import static com.sk89q.worldedit.world.gamemode.GameModes.SURVIVAL;
-public class BukkitPlayer extends PlotPlayer {
+public class BukkitPlayer extends PlotPlayer {
private static boolean CHECK_EFFECTIVE = true;
public final Player player;
private boolean offline;
- private UUID uuid;
private String name;
/**
@@ -77,30 +77,45 @@ public class BukkitPlayer extends PlotPlayer {
* @param player Bukkit player instance
*/
public BukkitPlayer(@NotNull final Player player) {
- this.player = player;
- super.populatePersistentMetaMap();
+ this(player, false);
}
public BukkitPlayer(@NotNull final Player player, final boolean offline) {
+ this(player, offline, true);
+ }
+
+ public BukkitPlayer(@NotNull final Player player, final boolean offline, final boolean realPlayer) {
this.player = player;
this.offline = offline;
- super.populatePersistentMetaMap();
+ if (realPlayer) {
+ super.populatePersistentMetaMap();
+ }
}
@Override public Actor toActor() {
return BukkitAdapter.adapt(player);
}
+ @Override public Player getPlatformPlayer() {
+ return this.player;
+ }
+
@NotNull @Override public Location getLocation() {
final Location location = super.getLocation();
return location == null ? BukkitUtil.getLocation(this.player) : location;
}
@NotNull @Override public UUID getUUID() {
- if (this.uuid == null) {
- this.uuid = UUIDHandler.getUUID(this);
+ if (Settings.UUID.OFFLINE) {
+ if (Settings.UUID.FORCE_LOWERCASE) {
+ return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
+ getName().toLowerCase()).getBytes(Charsets.UTF_8));
+ } else {
+ return UUID.nameUUIDFromBytes(("OfflinePlayer:" +
+ getName()).getBytes(Charsets.UTF_8));
+ }
}
- return this.uuid;
+ return player.getUniqueId();
}
@Override public long getLastPlayed() {
@@ -140,8 +155,8 @@ public class BukkitPlayer extends PlotPlayer {
}
@Override public boolean hasPermission(final String permission) {
- if (this.offline && EconHandler.manager != null) {
- return EconHandler.manager.hasPermission(getName(), permission);
+ if (this.offline && EconHandler.getEconHandler() != null) {
+ return EconHandler.getEconHandler().hasPermission(getName(), permission);
}
return this.player.hasPermission(permission);
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/DefaultUUIDWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
similarity index 55%
rename from Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/DefaultUUIDWrapper.java
rename to Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
index a2898ee91..a15718a5f 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/DefaultUUIDWrapper.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java
@@ -23,44 +23,46 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package com.plotsquared.bukkit.util.uuid;
+package com.plotsquared.bukkit.player;
-import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
-import com.plotsquared.bukkit.player.BukkitPlayer;
-import com.plotsquared.core.player.OfflinePlotPlayer;
-import com.plotsquared.core.player.PlotPlayer;
-import com.plotsquared.core.util.uuid.UUIDWrapper;
+import com.plotsquared.core.util.PlayerManager;
import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
+import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
-import java.util.Arrays;
import java.util.UUID;
-public class DefaultUUIDWrapper extends UUIDWrapper {
+/**
+ * Player manager providing {@link BukkitPlayer Bukkit players}
+ */
+public class BukkitPlayerManager extends PlayerManager {
- @NotNull @Override public UUID getUUID(PlotPlayer player) {
- return ((BukkitPlayer) player).player.getUniqueId();
+ @NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) {
+ try {
+ return getPlayer(object.getUniqueId());
+ } catch (final NoSuchPlayerException exception) {
+ return new BukkitPlayer(object, object.isOnline(), false);
+ }
}
- @Override public UUID getUUID(OfflinePlotPlayer player) {
- return player.getUUID();
+ @Override @NotNull public BukkitPlayer createPlayer(@NotNull final UUID uuid) {
+ final Player player = Bukkit.getPlayer(uuid);
+ if (player == null || !player.isOnline()) {
+ throw new NoSuchPlayerException(uuid);
+ }
+ return new BukkitPlayer(player);
}
- @Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
+ @Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) {
+ if (uuid == null) {
+ return null;
+ }
return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(uuid));
}
- @Override public UUID getUUID(String name) {
- return Bukkit.getOfflinePlayer(name).getUniqueId();
+ @NotNull @Override public BukkitOfflinePlayer getOfflinePlayer(@NotNull final String username) {
+ return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(username));
}
- @Override public OfflinePlotPlayer[] getOfflinePlayers() {
- OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
- return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
- }
-
- @Override public OfflinePlotPlayer getOfflinePlayer(String name) {
- return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
- }
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java
index 3f93ebb63..c8d6d929f 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/queue/BukkitLocalQueue.java
@@ -31,6 +31,7 @@ import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.queue.BasicLocalBlockQueue;
import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MainUtil;
+import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
@@ -50,7 +51,6 @@ import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.Container;
import org.bukkit.block.data.BlockData;
-import org.bukkit.inventory.BlockInventoryHolder;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
@@ -117,9 +117,6 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
@Override public final void setComponents(LocalChunk lc)
throws ExecutionException, InterruptedException {
setBaseBlocks(lc);
- if (setBiome() && lc.biomes != null) {
- setBiomes(lc);
- }
}
public void setBaseBlocks(LocalChunk localChunk) {
@@ -165,6 +162,22 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue {
}
}
}
+ if (setBiome() && localChunk.biomes != null) {
+ for (int x = 0; x < localChunk.biomes.length; x++) {
+ BiomeType[] biomeZ = localChunk.biomes[x];
+ if (biomeZ != null) {
+ for (int z = 0; z < biomeZ.length; z++) {
+ if (biomeZ[z] != null) {
+ BiomeType biomeType = biomeZ[z];
+
+ Biome biome = BukkitAdapter.adapt(biomeType);
+ worldObj.setBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z,
+ biome);
+ }
+ }
+ }
+ }
+ }
};
if (isForceSync()) {
chunkConsumer.accept(getChunk(worldObj, localChunk));
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
index 1efd7fea5..e71c48158 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java
@@ -27,49 +27,39 @@ package com.plotsquared.bukkit.util;
import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
import com.plotsquared.bukkit.player.BukkitPlayer;
+import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.util.EconHandler;
+import com.plotsquared.core.util.PermHandler;
import net.milkbowl.vault.economy.Economy;
-import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
public class BukkitEconHandler extends EconHandler {
private Economy econ;
- private Permission perms;
+ @Override
public boolean init() {
- if (this.econ == null || this.perms == null) {
- setupPermissions();
+ if (this.econ == null) {
setupEconomy();
}
- return this.econ != null && this.perms != null;
+ return this.econ != null;
}
- private boolean setupPermissions() {
- RegisteredServiceProvider permissionProvider =
- Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
- if (permissionProvider != null) {
- this.perms = permissionProvider.getProvider();
- }
- return this.perms != null;
- }
-
- private boolean setupEconomy() {
+ private void setupEconomy() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
- return false;
+ return;
}
RegisteredServiceProvider economyProvider =
Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
if (economyProvider != null) {
this.econ = economyProvider.getProvider();
}
- return this.econ != null;
}
- @Override public double getMoney(PlotPlayer player) {
+ @Override public double getMoney(PlotPlayer> player) {
double bal = super.getMoney(player);
if (Double.isNaN(bal)) {
return this.econ.getBalance(((BukkitPlayer) player).player);
@@ -77,11 +67,11 @@ public class BukkitEconHandler extends EconHandler {
return bal;
}
- @Override public void withdrawMoney(PlotPlayer player, double amount) {
+ @Override public void withdrawMoney(PlotPlayer> player, double amount) {
this.econ.withdrawPlayer(((BukkitPlayer) player).player, amount);
}
- @Override public void depositMoney(PlotPlayer player, double amount) {
+ @Override public void depositMoney(PlotPlayer> player, double amount) {
this.econ.depositPlayer(((BukkitPlayer) player).player, amount);
}
@@ -89,20 +79,19 @@ public class BukkitEconHandler extends EconHandler {
this.econ.depositPlayer(((BukkitOfflinePlayer) player).player, amount);
}
- @Override public boolean hasPermission(String world, String player, String perm) {
- return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
- }
-
- @Override public double getBalance(PlotPlayer player) {
- return this.econ.getBalance(player.getName());
- }
-
- public void setPermission(String world, String player, String perm, boolean value) {
- if (value) {
- this.perms.playerAdd(world, player, perm);
+ /**
+ * @deprecated Use {@link PermHandler#hasPermission(String, String, String)} instead
+ */
+ @Deprecated @Override public boolean hasPermission(String world, String player, String perm) {
+ if (PlotSquared.imp().getPermissionHandler() != null) {
+ return PlotSquared.imp().getPermissionHandler().hasPermission(world, player, perm);
} else {
- this.perms.playerRemove(world, player, perm);
+ return false;
}
}
+ @Override public double getBalance(PlotPlayer> player) {
+ return this.econ.getBalance(player.getName());
+ }
+
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java
new file mode 100644
index 000000000..fee00a66d
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitPermHandler.java
@@ -0,0 +1,59 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.util;
+
+import com.plotsquared.core.util.PermHandler;
+import net.milkbowl.vault.permission.Permission;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.RegisteredServiceProvider;
+
+public class BukkitPermHandler extends PermHandler {
+
+ private Permission perms;
+
+ @Override
+ public boolean init() {
+ if (this.perms == null) {
+ setupPermissions();
+ }
+ return this.perms != null;
+ }
+
+ private void setupPermissions() {
+ if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
+ return;
+ }
+ RegisteredServiceProvider permissionProvider =
+ Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
+ if (permissionProvider != null) {
+ this.perms = permissionProvider.getProvider();
+ }
+ }
+
+ @Override public boolean hasPermission(String world, String player, String perm) {
+ return this.perms.playerHas(world, Bukkit.getOfflinePlayer(player), perm);
+ }
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java
index 16c63d093..158f90928 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java
@@ -348,7 +348,7 @@ public class BukkitRegionManager extends RegionManager {
CuboidRegion currentPlotClear = RegionUtil
.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
map.saveEntitiesOut(chunkObj, currentPlotClear);
- AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.manager
+ AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager
.setChunkInPlotArea(null, new RunnableVal() {
@Override public void run(ScopedLocalBlockQueue value) {
Location min = value.getMin();
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java
index af529c251..53185b608 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java
@@ -33,6 +33,7 @@ import com.plotsquared.core.generator.GeneratorWrapper;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.SetupObject;
+import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.SetupUtils;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
@@ -97,7 +98,7 @@ public class BukkitSetupUtils extends SetupUtils {
Bukkit.unloadWorld(world, false);
}
- @Override public String setupWorld(SetupObject object) {
+ @Deprecated @Override public String setupWorld(SetupObject object) {
SetupUtils.manager.updateGenerators();
ConfigurationNode[] steps = object.step == null ? new ConfigurationNode[0] : object.step;
String world = object.world;
@@ -209,6 +210,119 @@ public class BukkitSetupUtils extends SetupUtils {
return object.world;
}
+ @Override public String setupWorld(PlotAreaBuilder builder) {
+ SetupUtils.manager.updateGenerators();
+ ConfigurationNode[] steps = builder.settingsNodesWrapper() == null ?
+ new ConfigurationNode[0] : builder.settingsNodesWrapper().getSettingsNodes();
+ String world = builder.worldName();
+ PlotAreaType type = builder.plotAreaType();
+ String worldPath = "worlds." + builder.worldName();
+ switch (type) {
+ case PARTIAL: {
+ if (builder.areaName() != null) {
+ if (!PlotSquared.get().worlds.contains(worldPath)) {
+ PlotSquared.get().worlds.createSection(worldPath);
+ }
+ ConfigurationSection worldSection =
+ PlotSquared.get().worlds.getConfigurationSection(worldPath);
+ String areaName = builder.areaName() + "-" + builder.minimumId() + "-" + builder.maximumId();
+ String areaPath = "areas." + areaName;
+ if (!worldSection.contains(areaPath)) {
+ worldSection.createSection(areaPath);
+ }
+ ConfigurationSection areaSection =
+ worldSection.getConfigurationSection(areaPath);
+ HashMap options = new HashMap<>();
+ for (ConfigurationNode step : steps) {
+ options.put(step.getConstant(), step.getValue());
+ }
+ options.put("generator.type", builder.plotAreaType().toString());
+ options.put("generator.terrain", builder.terrainType().toString());
+ options.put("generator.plugin", builder.plotManager());
+ if (builder.generatorName() != null && !builder.generatorName()
+ .equals(builder.plotManager())) {
+ options.put("generator.init", builder.generatorName());
+ }
+ for (Entry entry : options.entrySet()) {
+ String key = entry.getKey();
+ Object value = entry.getValue();
+ if (worldSection.contains(key)) {
+ Object current = worldSection.get(key);
+ if (!Objects.equals(value, current)) {
+ areaSection.set(key, value);
+ }
+ } else {
+ worldSection.set(key, value);
+ }
+ }
+ }
+ GeneratorWrapper> gen = SetupUtils.generators.get(builder.generatorName());
+ if (gen != null && gen.isFull()) {
+ builder.generatorName(null);
+ }
+ break;
+ }
+ case AUGMENTED: {
+ if (!builder.plotManager().endsWith(":single")) {
+ if (!PlotSquared.get().worlds.contains(worldPath)) {
+ PlotSquared.get().worlds.createSection(worldPath);
+ }
+ if (steps.length != 0) {
+ ConfigurationSection worldSection =
+ PlotSquared.get().worlds.getConfigurationSection(worldPath);
+ for (ConfigurationNode step : steps) {
+ worldSection.set(step.getConstant(), step.getValue());
+ }
+ }
+ PlotSquared.get().worlds
+ .set("worlds." + world + ".generator.type", builder.plotAreaType().toString());
+ PlotSquared.get().worlds
+ .set("worlds." + world + ".generator.terrain", builder.terrainType().toString());
+ PlotSquared.get().worlds
+ .set("worlds." + world + ".generator.plugin", builder.plotManager());
+ if (builder.generatorName() != null && !builder.generatorName()
+ .equals(builder.plotManager())) {
+ PlotSquared.get().worlds
+ .set("worlds." + world + ".generator.init", builder.generatorName());
+ }
+ }
+ GeneratorWrapper> gen = SetupUtils.generators.get(builder.generatorName());
+ if (gen != null && gen.isFull()) {
+ builder.generatorName(null);
+ }
+ break;
+ }
+ case NORMAL: {
+ if (steps.length != 0) {
+ if (!PlotSquared.get().worlds.contains(worldPath)) {
+ PlotSquared.get().worlds.createSection(worldPath);
+ }
+ ConfigurationSection worldSection =
+ PlotSquared.get().worlds.getConfigurationSection(worldPath);
+ for (ConfigurationNode step : steps) {
+ worldSection.set(step.getConstant(), step.getValue());
+ }
+ }
+ break;
+ }
+ }
+
+ try {
+ PlotSquared.get().worlds.save(PlotSquared.get().worldsFile);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ Objects.requireNonNull(PlotSquared.imp()).getWorldManager()
+ .handleWorldCreation(builder.worldName(), builder.generatorName());
+
+ if (Bukkit.getWorld(world) != null) {
+ return world;
+ }
+
+ return builder.worldName();
+ }
+
@Override public String getGenerator(PlotArea plotArea) {
if (SetupUtils.generators.isEmpty()) {
updateGenerators();
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
index 23fd8937b..5acdde298 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
@@ -27,6 +27,7 @@ package com.plotsquared.bukkit.util;
import com.plotsquared.bukkit.BukkitMain;
import com.plotsquared.bukkit.player.BukkitPlayer;
+import com.plotsquared.bukkit.player.BukkitPlayerManager;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.location.Location;
@@ -35,11 +36,11 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.BlockUtil;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
+import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.StringComparison;
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.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector2;
@@ -113,14 +114,16 @@ public class BukkitUtil extends WorldUtil {
private static World lastWorld = null;
private static Player lastPlayer = null;
- private static PlotPlayer lastPlotPlayer = null;
+ private static BukkitPlayer lastPlotPlayer = null;
- public static void removePlayer(String player) {
+ public static void removePlayer(UUID uuid) {
lastPlayer = null;
lastPlotPlayer = null;
+ // Make sure that it's removed internally
+ PlotSquared.imp().getPlayerManager().removePlayer(uuid);
}
- public static PlotPlayer getPlayer(@NonNull final OfflinePlayer op) {
+ public static PlotPlayer getPlayer(@NonNull final OfflinePlayer op) {
if (op.isOnline()) {
return getPlayer(op.getPlayer());
}
@@ -165,7 +168,7 @@ public class BukkitUtil extends WorldUtil {
* @return a {@code PlotPlayer}
* @see PlotPlayer#wrap(Object)
*/
- public static PlotPlayer wrapPlayer(OfflinePlayer player) {
+ public static PlotPlayer> wrapPlayer(OfflinePlayer player) {
return PlotPlayer.wrap(player);
}
@@ -177,7 +180,7 @@ public class BukkitUtil extends WorldUtil {
* @return a {@code PlotPlayer}
* @see PlotPlayer#wrap(Object)
*/
- public static PlotPlayer wrapPlayer(Player player) {
+ public static PlotPlayer> wrapPlayer(Player player) {
return PlotPlayer.wrap(player);
}
@@ -189,7 +192,7 @@ public class BukkitUtil extends WorldUtil {
* @return a {@code PlotPlayer}
* @see PlotPlayer#wrap(Object)
*/
- @Override public PlotPlayer wrapPlayer(UUID uuid) {
+ @Override public PlotPlayer> wrapPlayer(UUID uuid) {
return PlotPlayer.wrap(Bukkit.getOfflinePlayer(uuid));
}
@@ -200,7 +203,7 @@ public class BukkitUtil extends WorldUtil {
* @return the number of allowed plots
*/
public static int getAllowedPlots(Player player) {
- PlotPlayer plotPlayer = PlotPlayer.wrap(player);
+ PlotPlayer> plotPlayer = PlotPlayer.wrap(player);
return plotPlayer.getAllowedPlots();
}
@@ -226,7 +229,7 @@ public class BukkitUtil extends WorldUtil {
if (world == null) {
return new HashSet<>();
}
- return PlotPlayer.wrap(player).getPlots(world);
+ return BukkitPlayer.wrap(player).getPlots(world);
}
/**
@@ -264,19 +267,12 @@ public class BukkitUtil extends WorldUtil {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), caption);
}
- public static PlotPlayer getPlayer(@NonNull final Player player) {
+ public static BukkitPlayer getPlayer(@NonNull final Player player) {
if (player == lastPlayer) {
return lastPlotPlayer;
}
- final String name = player.getName();
- final PlotPlayer plotPlayer = UUIDHandler.getPlayer(name);
- if (plotPlayer != null) {
- return plotPlayer;
- }
- lastPlotPlayer = new BukkitPlayer(player);
- UUIDHandler.getPlayers().put(name, lastPlotPlayer);
- lastPlayer = player;
- return lastPlotPlayer;
+ final PlayerManager, ?> playerManager = PlotSquared.imp().getPlayerManager();
+ return ((BukkitPlayerManager) playerManager).getPlayer(player);
}
public static Location getLocation(@NonNull final org.bukkit.Location location) {
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java
deleted file mode 100644
index 7a920fc8b..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java
+++ /dev/null
@@ -1,167 +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 .
- */
-package com.plotsquared.bukkit.util;
-
-import com.plotsquared.bukkit.player.BukkitPlayer;
-import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.location.Location;
-import com.plotsquared.core.player.PlotPlayer;
-import com.plotsquared.core.plot.Plot;
-import com.plotsquared.core.util.ReflectionUtils.RefClass;
-import com.plotsquared.core.util.ReflectionUtils.RefConstructor;
-import com.plotsquared.core.util.ReflectionUtils.RefField;
-import com.plotsquared.core.util.ReflectionUtils.RefMethod;
-import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandler;
-import com.sk89q.worldedit.math.BlockVector2;
-import io.papermc.lib.PaperLib;
-import org.bukkit.Bukkit;
-import org.bukkit.Chunk;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map.Entry;
-
-import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
-
-/**
- * An utility that can be used to send chunks, rather than using bukkit code
- * to do so (uses heavy NMS).
- */
-public class SendChunk {
-
- private final RefMethod methodGetHandlePlayer;
- private final RefMethod methodGetHandleChunk;
- private final RefConstructor mapChunk;
- private final RefField connection;
- private final RefMethod send;
- private final RefMethod methodInitLighting;
-
- /**
- * Constructor.
- */
- public SendChunk() throws ClassNotFoundException, NoSuchMethodException, NoSuchFieldException {
- RefClass classCraftPlayer = getRefClass("{cb}.entity.CraftPlayer");
- this.methodGetHandlePlayer = classCraftPlayer.getMethod("getHandle");
- RefClass classCraftChunk = getRefClass("{cb}.CraftChunk");
- this.methodGetHandleChunk = classCraftChunk.getMethod("getHandle");
- RefClass classChunk = getRefClass("{nms}.Chunk");
- this.methodInitLighting = classChunk.getMethod("initLighting");
- RefClass classMapChunk = getRefClass("{nms}.PacketPlayOutMapChunk");
- this.mapChunk = classMapChunk.getConstructor(classChunk.getRealClass(), int.class);
- RefClass classEntityPlayer = getRefClass("{nms}.EntityPlayer");
- this.connection = classEntityPlayer.getField("playerConnection");
- RefClass classPacket = getRefClass("{nms}.Packet");
- RefClass classConnection = getRefClass("{nms}.PlayerConnection");
- this.send = classConnection.getMethod("sendPacket", classPacket.getRealClass());
- }
-
- public void sendChunk(Collection input) {
- HashSet chunks = new HashSet<>(input);
- HashMap> map = new HashMap<>();
- int view = Bukkit.getServer().getViewDistance();
- for (Chunk chunk : chunks) {
- String world = chunk.getWorld().getName();
- ArrayList list = map.computeIfAbsent(world, k -> new ArrayList<>());
- list.add(chunk);
- Object c = this.methodGetHandleChunk.of(chunk).call();
- this.methodInitLighting.of(c).call();
- }
- for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer pp = entry.getValue();
- Plot plot = pp.getCurrentPlot();
- Location location = null;
- String world;
- if (plot != null) {
- world = plot.getWorldName();
- } else {
- location = pp.getLocation();
- world = location.getWorld();
- }
- ArrayList list = map.get(world);
- if (list == null) {
- continue;
- }
- if (location == null) {
- location = pp.getLocation();
- }
- int chunkX = location.getX() >> 4;
- int chunkZ = location.getZ() >> 4;
- Player player = ((BukkitPlayer) pp).player;
- Object entity = this.methodGetHandlePlayer.of(player).call();
-
- for (Chunk chunk : list) {
- int dx = Math.abs(chunkX - chunk.getX());
- int dz = Math.abs(chunkZ - chunk.getZ());
- if ((dx > view) || (dz > view)) {
- continue;
- }
- Object c = this.methodGetHandleChunk.of(chunk).call();
- chunks.remove(chunk);
- Object con = this.connection.of(entity).get();
- Object packet = null;
- try {
- packet = this.mapChunk.create(c, 65535);
- } catch (Exception ignored) {
- }
- if (packet == null) {
- PlotSquared.debug("Error with PacketPlayOutMapChunk reflection.");
- }
- this.send.of(con).call(packet);
- }
- }
- for (final Chunk chunk : chunks) {
- TaskManager.runTask(() -> {
- try {
- chunk.unload(true);
- } catch (Throwable ignored) {
- String worldName = chunk.getWorld().getName();
- PlotSquared.debug(
- "$4Could not save chunk: " + worldName + ';' + chunk.getX() + ";" + chunk
- .getZ());
- PlotSquared.debug("$3 - $4File may be open in another process (e.g. MCEdit)");
- PlotSquared.debug("$3 - $4" + worldName + "/level.dat or " + worldName
- + "/level_old.dat may be corrupt (try repairing or removing these)");
- }
- });
- }
- }
-
- public void sendChunk(String worldName, Collection chunkLocations) {
- World myWorld = Bukkit.getWorld(worldName);
- ArrayList chunks = new ArrayList<>();
- for (BlockVector2 loc : chunkLocations) {
- if (myWorld.isChunkLoaded(loc.getX(), loc.getZ())) {
- PaperLib.getChunkAtAsync(myWorld, loc.getX(), loc.getZ()).thenAccept(chunks::add);
- }
- }
- sendChunk(chunks);
- }
-}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/FileUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/FileUUIDHandler.java
deleted file mode 100644
index c5620ffa1..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/FileUUIDHandler.java
+++ /dev/null
@@ -1,289 +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 .
- */
-package com.plotsquared.bukkit.util.uuid;
-
-import com.google.common.collect.HashBiMap;
-import com.google.common.collect.Sets;
-import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.configuration.Captions;
-import com.plotsquared.core.configuration.Settings;
-import com.plotsquared.core.player.OfflinePlotPlayer;
-import com.plotsquared.core.plot.expiration.ExpireManager;
-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 com.plotsquared.core.util.uuid.UUIDHandler;
-import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
-import com.plotsquared.core.util.uuid.UUIDWrapper;
-import com.sk89q.jnbt.CompoundTag;
-import com.sk89q.jnbt.NBTInputStream;
-import com.sk89q.jnbt.Tag;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.zip.GZIPInputStream;
-
-public class FileUUIDHandler extends UUIDHandlerImplementation {
-
- public FileUUIDHandler(UUIDWrapper wrapper) {
- super(wrapper);
- }
-
- @Override public boolean startCaching(Runnable whenDone) {
- return super.startCaching(whenDone) && cache(whenDone);
- }
-
- private Tag readTag(File file) throws IOException {
- // Don't chain the creation of the GZIP stream and the NBT stream, because their
- // constructors may throw an IOException.
- try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
- GZIPInputStream gzipInputStream = new GZIPInputStream(inputStream);
- NBTInputStream nbtInputStream = new NBTInputStream(gzipInputStream)) {
- return nbtInputStream.readNamedTag().getTag();
- }
- }
-
- public boolean cache(final Runnable whenDone) {
- final File container = Bukkit.getWorldContainer();
- List worlds = Bukkit.getWorlds();
- final String world;
- if (worlds.isEmpty()) {
- world = "world";
- } else {
- world = worlds.get(0).getName();
- }
- TaskManager.runTaskAsync(() -> {
- PlotSquared.debug(Captions.PREFIX + "Starting player data caching for: " + world);
- File uuidFile = new File(PlotSquared.get().IMP.getDirectory(), "uuids.txt");
- if (uuidFile.exists()) {
- try {
- List lines =
- Files.readAllLines(uuidFile.toPath(), StandardCharsets.UTF_8);
- for (String line : lines) {
- try {
- line = line.trim();
- if (line.isEmpty()) {
- continue;
- }
- line = line.replaceAll("[\\|][0-9]+[\\|][0-9]+[\\|]", "");
- String[] split = line.split("\\|");
- String name = split[0];
- if (name.isEmpty() || (name.length() > 16) || !StringMan
- .isAlphanumericUnd(name)) {
- continue;
- }
- UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
- if (uuid == null) {
- continue;
- }
- UUIDHandler.add(new StringWrapper(name), uuid);
- } catch (Exception e2) {
- e2.printStackTrace();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- HashBiMap toAdd = HashBiMap.create(new HashMap<>());
- if (Settings.UUID.NATIVE_UUID_PROVIDER) {
- HashSet all = UUIDHandler.getAllUUIDS();
- PlotSquared.debug("Fast mode UUID caching enabled!");
- File playerDataFolder = new File(container, world + File.separator + "playerdata");
- String[] dat = playerDataFolder.list(new DatFileFilter());
- boolean check = all.isEmpty();
- if (dat != null) {
- for (String current : dat) {
- String s = current.replaceAll(".dat$", "");
- try {
- UUID uuid = UUID.fromString(s);
- if (check || all.remove(uuid)) {
- File file = new File(playerDataFolder, current);
- CompoundTag compound = (CompoundTag) readTag(file);
- if (!compound.containsKey("bukkit")) {
- PlotSquared.debug("ERROR: Player data (" + uuid.toString()
- + ".dat) does not contain the the key \"bukkit\"");
- } else {
- Map compoundMap = compound.getValue();
- CompoundTag bukkit = (CompoundTag) compoundMap.get("bukkit");
- Map bukkitMap = bukkit.getValue();
- String name =
- (String) bukkitMap.get("lastKnownName").getValue();
- long last = (long) bukkitMap.get("lastPlayed").getValue();
- long first = (long) bukkitMap.get("firstPlayed").getValue();
- if (ExpireManager.IMP != null) {
- ExpireManager.IMP.storeDate(uuid, last);
- ExpireManager.IMP.storeAccountAge(uuid, last - first);
- }
- toAdd.put(new StringWrapper(name), uuid);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- PlotSquared.debug(Captions.PREFIX + "Invalid playerdata: " + current);
- }
- }
- }
- add(toAdd);
- if (all.isEmpty()) {
- if (whenDone != null) {
- whenDone.run();
- }
- return;
- } else {
- PlotSquared.debug(
- "Failed to cache: " + all.size() + " uuids - slowly processing all files");
- }
- }
- HashSet worlds1 = Sets.newHashSet(world, "world");
- HashSet uuids = new HashSet<>();
- HashSet names = new HashSet<>();
- File playerDataFolder = null;
- for (String worldName : worlds1) {
- // Getting UUIDs
- playerDataFolder = new File(container, worldName + File.separator + "playerdata");
- String[] dat = playerDataFolder.list(new DatFileFilter());
- if ((dat != null) && (dat.length != 0)) {
- for (String current : dat) {
- String s = current.replaceAll(".dat$", "");
- try {
- UUID uuid = UUID.fromString(s);
- uuids.add(uuid);
- } catch (Exception ignored) {
- PlotSquared.debug(Captions.PREFIX + "Invalid PlayerData: " + current);
- }
- }
- break;
- }
- // Getting names
- File playersFolder = new File(worldName + File.separator + "players");
- dat = playersFolder.list(new DatFileFilter());
- if ((dat != null) && (dat.length != 0)) {
- for (String current : dat) {
- names.add(current.replaceAll(".dat$", ""));
- }
- break;
- }
- }
- for (UUID uuid : uuids) {
- try {
- File file =
- new File(playerDataFolder + File.separator + uuid.toString() + ".dat");
- if (!file.exists()) {
- continue;
- }
- CompoundTag compound = (CompoundTag) readTag(file);
- if (!compound.containsKey("bukkit")) {
- PlotSquared.debug("ERROR: Player data (" + uuid.toString()
- + ".dat) does not contain the the key \"bukkit\"");
- } else {
- Map compoundMap = compound.getValue();
- CompoundTag bukkit = (CompoundTag) compoundMap.get("bukkit");
- Map bukkitMap = bukkit.getValue();
- String name = (String) bukkitMap.get("lastKnownName").getValue();
- StringWrapper wrap = new StringWrapper(name);
- if (!toAdd.containsKey(wrap)) {
- long last = (long) bukkitMap.get("lastPlayed").getValue();
- long first = (long) bukkitMap.get("firstPlayed").getValue();
- if (Settings.UUID.OFFLINE) {
- if (Settings.UUID.FORCE_LOWERCASE && !name.toLowerCase()
- .equals(name)) {
- uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
- } else {
- long most = (long) compoundMap.get("UUIDMost").getValue();
- long least = (long) compoundMap.get("UUIDLeast").getValue();
- uuid = new UUID(most, least);
- }
- }
- if (ExpireManager.IMP != null) {
- ExpireManager.IMP.storeDate(uuid, last);
- ExpireManager.IMP.storeAccountAge(uuid, last - first);
- }
- toAdd.put(wrap, uuid);
- }
- }
- } catch (Exception ignored) {
- PlotSquared.debug(
- Captions.PREFIX + "&6Invalid PlayerData: " + uuid.toString() + ".dat");
- }
- }
- for (String name : names) {
- UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(name);
- StringWrapper nameWrap = new StringWrapper(name);
- toAdd.put(nameWrap, uuid);
- }
-
- if (getUUIDMap().isEmpty()) {
- for (OfflinePlotPlayer offlinePlotPlayer : FileUUIDHandler.this.uuidWrapper
- .getOfflinePlayers()) {
- long last = offlinePlotPlayer.getLastPlayed();
- if (last != 0) {
- String name = offlinePlotPlayer.getName();
- StringWrapper wrap = new StringWrapper(name);
- if (!toAdd.containsKey(wrap)) {
- UUID uuid = FileUUIDHandler.this.uuidWrapper.getUUID(offlinePlotPlayer);
- if (toAdd.containsValue(uuid)) {
- StringWrapper duplicate = toAdd.inverse().get(uuid);
- PlotSquared.debug(
- "The UUID: " + uuid.toString() + " is already mapped to "
- + duplicate
- + "\n It cannot be added to the Map with a key of " + wrap);
- }
- toAdd.putIfAbsent(wrap, uuid);
- if (ExpireManager.IMP != null) {
- ExpireManager.IMP.storeDate(uuid, last);
- }
- }
- }
- }
- }
- add(toAdd);
- if (whenDone != null) {
- whenDone.run();
- }
- });
- return true;
- }
-
- @Override public void fetchUUID(final String name, final RunnableVal ifFetch) {
- TaskManager.runTaskAsync(() -> {
- ifFetch.value = FileUUIDHandler.this.uuidWrapper.getUUID(name);
- TaskManager.runTask(ifFetch);
- });
- }
-}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/OfflineUUIDWrapper.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/OfflineUUIDWrapper.java
deleted file mode 100644
index 66ca52814..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/OfflineUUIDWrapper.java
+++ /dev/null
@@ -1,131 +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 .
- */
-package com.plotsquared.bukkit.util.uuid;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.BiMap;
-import com.plotsquared.bukkit.player.BukkitOfflinePlayer;
-import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.player.OfflinePlotPlayer;
-import com.plotsquared.core.player.PlotPlayer;
-import com.plotsquared.core.util.StringWrapper;
-import com.plotsquared.core.util.uuid.UUIDHandler;
-import com.plotsquared.core.util.uuid.UUIDWrapper;
-import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.Server;
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.NotNull;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.UUID;
-
-public class OfflineUUIDWrapper extends UUIDWrapper {
-
- private final Object[] arg = new Object[0];
- private Method getOnline = null;
-
- public OfflineUUIDWrapper() {
- try {
- this.getOnline = Server.class.getMethod("getOnlinePlayers");
- } catch (NoSuchMethodException | SecurityException e) {
- e.printStackTrace();
- }
- }
-
- @NotNull @Override public UUID getUUID(PlotPlayer player) {
- return UUID
- .nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
- }
-
- @Override public UUID getUUID(OfflinePlotPlayer player) {
- return UUID
- .nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
- }
-
- public UUID getUUID(OfflinePlayer player) {
- return UUID
- .nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8));
- }
-
- @Override public OfflinePlotPlayer getOfflinePlayer(UUID uuid) {
- BiMap map = UUIDHandler.getUuidMap().inverse();
- String name = null;
- if (map.containsKey(uuid)) {
- name = map.get(uuid).value;
- }
- if (name != null) {
- OfflinePlayer op = Bukkit.getOfflinePlayer(name);
- if (op.hasPlayedBefore()) {
- return new BukkitOfflinePlayer(op);
- }
- }
- for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
- if (getUUID(player).equals(uuid)) {
- return new BukkitOfflinePlayer(player);
- }
- }
- return null;
- }
-
- public Player[] getOnlinePlayers() {
- if (this.getOnline == null) {
- Collection extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
- return onlinePlayers.toArray(new Player[0]);
- }
- try {
- Object players = this.getOnline.invoke(Bukkit.getServer(), this.arg);
- if (players instanceof Player[]) {
- return (Player[]) players;
- } else {
- @SuppressWarnings("unchecked") Collection extends Player> p =
- (Collection extends Player>) players;
- return p.toArray(new Player[0]);
- }
- } catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException ignored) {
- PlotSquared.debug("Failed to resolve online players");
- this.getOnline = null;
- Collection extends Player> onlinePlayers = Bukkit.getOnlinePlayers();
- return onlinePlayers.toArray(new Player[0]);
- }
- }
-
- @Override public UUID getUUID(String name) {
- return UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
- }
-
- @Override public OfflinePlotPlayer[] getOfflinePlayers() {
- OfflinePlayer[] ops = Bukkit.getOfflinePlayers();
- return Arrays.stream(ops).map(BukkitOfflinePlayer::new).toArray(BukkitOfflinePlayer[]::new);
- }
-
- @Override public OfflinePlotPlayer getOfflinePlayer(String name) {
- return new BukkitOfflinePlayer(Bukkit.getOfflinePlayer(name));
- }
-}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/SQLUUIDHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/SQLUUIDHandler.java
deleted file mode 100644
index a08956369..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/uuid/SQLUUIDHandler.java
+++ /dev/null
@@ -1,270 +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 .
- */
-package com.plotsquared.bukkit.util.uuid;
-
-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.SQLite;
-import com.plotsquared.core.util.MainUtil;
-import com.plotsquared.core.util.StringWrapper;
-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.util.uuid.UUIDHandlerImplementation;
-import com.plotsquared.core.util.uuid.UUIDWrapper;
-import org.json.simple.JSONArray;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayDeque;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-
-public class SQLUUIDHandler extends UUIDHandlerImplementation {
-
- final int MAX_REQUESTS = 500;
- private final String PROFILE_URL =
- "https://sessionserver.mojang.com/session/minecraft/profile/";
- private final JSONParser jsonParser = new JSONParser();
- private final SQLite sqlite;
-
- public SQLUUIDHandler(UUIDWrapper wrapper) {
- super(wrapper);
- this.sqlite =
- new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "usercache.db"));
- try {
- this.sqlite.openConnection();
- } catch (ClassNotFoundException | SQLException e) {
- e.printStackTrace();
- }
-
- try (PreparedStatement stmt = getConnection().prepareStatement(
- "CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid, username))")) {
- stmt.execute();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- startCaching(null);
- }
-
- private Connection getConnection() {
- synchronized (this.sqlite) {
- return this.sqlite.getConnection();
- }
- }
-
- @Override public boolean startCaching(final Runnable whenDone) {
- if (!super.startCaching(whenDone)) {
- return false;
- }
- TaskManager.runTaskAsync(() -> {
- try {
- HashBiMap toAdd = HashBiMap.create(new HashMap<>());
- try (PreparedStatement statement = getConnection()
- .prepareStatement("SELECT `uuid`, `username` FROM `usercache`");
- ResultSet resultSet = statement.executeQuery()) {
- while (resultSet.next()) {
- StringWrapper username = new StringWrapper(resultSet.getString("username"));
- UUID uuid = UUID.fromString(resultSet.getString("uuid"));
- toAdd.put(new StringWrapper(username.value), uuid);
- }
- }
- add(toAdd);
- // This should be called as long as there are some unknown plots
- final ArrayDeque toFetch = new ArrayDeque<>();
- for (UUID u : UUIDHandler.getAllUUIDS()) {
- if (!uuidExists(u)) {
- toFetch.add(u);
- }
- }
- if (toFetch.isEmpty()) {
- if (whenDone != null) {
- whenDone.run();
- }
- return;
- }
- FileUUIDHandler fileHandler = new FileUUIDHandler(SQLUUIDHandler.this.uuidWrapper);
- fileHandler.startCaching(() -> {
- // If the file based UUID handler didn't cache it, then we can't cache offline mode
- // Also, trying to cache based on files again, is useless as that's what the file based uuid cacher does
- if (Settings.UUID.OFFLINE) {
- if (whenDone != null) {
- whenDone.run();
- }
- return;
- }
-
- TaskManager.runTaskAsync(() -> {
- while (!toFetch.isEmpty()) {
- try {
- for (int i = 0; i < Math.min(MAX_REQUESTS, toFetch.size()); i++) {
- UUID uuid = toFetch.pop();
- HttpURLConnection connection = (HttpURLConnection) new URL(
- SQLUUIDHandler.this.PROFILE_URL + uuid.toString()
- .replace("-", "")).openConnection();
- try (InputStream con = connection.getInputStream()) {
- InputStreamReader reader = new InputStreamReader(con);
- JSONObject response =
- (JSONObject) SQLUUIDHandler.this.jsonParser
- .parse(reader);
- String name = (String) response.get("name");
- if (name != null) {
- add(new StringWrapper(name), uuid);
- }
- }
- connection.disconnect();
- }
- } catch (IOException | ParseException e) {
- PlotSquared.debug(
- "Invalid response from Mojang: Some UUIDs will be cached later. (`unknown` until then or player joins)");
- }
- try {
- //Mojang allows requests every 10 minutes according to https://wiki.vg/Mojang_API
- //15 Minutes is chosen here since system timers are not always precise
- //and it should provide enough time where Mojang won't block requests.
- TimeUnit.MINUTES.sleep(15);
- } catch (InterruptedException e) {
- e.printStackTrace();
- break;
- }
- }
- if (whenDone != null) {
- whenDone.run();
- }
- });
- });
- } catch (SQLException e) {
- throw new SQLUUIDHandlerException("Couldn't select :s", e);
- }
- });
- return true;
- }
-
- @Override public void fetchUUID(final String name, final RunnableVal ifFetch) {
- PlotSquared.debug(Captions.PREFIX + "UUID for '" + name
- + "' was null. We'll cache this from the Mojang servers!");
- if (ifFetch == null) {
- return;
- }
- TaskManager.runTaskAsync(() -> {
- try {
- URL url = new URL(SQLUUIDHandler.this.PROFILE_URL);
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", "application/json");
- connection.setUseCaches(false);
- connection.setDoInput(true);
- connection.setDoOutput(true);
- String body = JSONArray.toJSONString(Collections.singletonList(name));
- OutputStream stream = connection.getOutputStream();
- stream.write(body.getBytes());
- stream.flush();
- stream.close();
- JSONArray array = (JSONArray) SQLUUIDHandler.this.jsonParser
- .parse(new InputStreamReader(connection.getInputStream()));
- JSONObject jsonProfile = (JSONObject) array.get(0);
- String id = (String) jsonProfile.get("id");
- String name1 = (String) jsonProfile.get("name");
- ifFetch.value = UUID.fromString(
- id.substring(0, 8) + '-' + id.substring(8, 12) + '-' + id.substring(12, 16)
- + '-' + id.substring(16, 20) + '-' + id.substring(20, 32));
- } catch (IOException | ParseException e) {
- e.printStackTrace();
- }
- TaskManager.runTask(ifFetch);
- });
- }
-
- @Override public void handleShutdown() {
- super.handleShutdown();
- try {
- getConnection().close();
- } catch (SQLException e) {
- throw new SQLUUIDHandlerException("Couldn't close database connection", e);
- }
- }
-
- /**
- * This is useful for name changes
- */
- @Override public void rename(final UUID uuid, final StringWrapper name) {
- super.rename(uuid, name);
- TaskManager.runTaskAsync(() -> {
- try (PreparedStatement statement = getConnection()
- .prepareStatement("UPDATE usercache SET `username`=? WHERE `uuid`=?")) {
- statement.setString(1, name.value);
- statement.setString(2, uuid.toString());
- statement.execute();
- PlotSquared.debug(
- Captions.PREFIX + "Name change for '" + uuid + "' to '" + name.value + '\'');
- } catch (SQLException e) {
- e.printStackTrace();
- }
- });
- }
-
- @Override public boolean add(final StringWrapper name, final UUID uuid) {
- // Ignoring duplicates
- if (super.add(name, uuid)) {
- TaskManager.runTaskAsync(() -> {
- try (PreparedStatement statement = getConnection()
- .prepareStatement("REPLACE INTO usercache (`uuid`, `username`) VALUES(?, ?)")) {
- statement.setString(1, uuid.toString());
- statement.setString(2, name.toString());
- statement.execute();
- PlotSquared
- .debug(Captions.PREFIX + "&cAdded '&6" + uuid + "&c' - '&6" + name + "&c'");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- });
- return true;
- }
- return false;
- }
-
- private static class SQLUUIDHandlerException extends RuntimeException {
-
- SQLUUIDHandlerException(String s, Throwable c) {
- super("SQLUUIDHandler caused an exception: " + s, c);
- }
- }
-}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/BungeePermsUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/BungeePermsUUIDService.java
new file mode 100644
index 000000000..4de1bdb92
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/BungeePermsUUIDService.java
@@ -0,0 +1,85 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import net.luckperms.api.model.user.UserManager;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import net.alpenblock.bungeeperms.BungeePerms;
+import net.alpenblock.bungeeperms.io.UUIDPlayerDB;
+
+/**
+ * UUID service that uses the BungeePerms API
+ */
+public class BungeePermsUUIDService implements UUIDService {
+
+ private final BungeePerms bp;
+
+ public BungeePermsUUIDService() {
+ final RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(BungeePerms.class);
+ if (provider != null) {
+ this.bp = provider.getProvider();
+ } else {
+ throw new IllegalStateException("BungeePerms is not available");
+ }
+ }
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ final List mappings = new ArrayList<>(uuids.size());
+ final UUIDPlayerDB uuiddb = BungeePerms.getInstance().getPermissionsManager().getUUIDPlayerDB();
+ for (final UUID uuid : uuids) {
+ try {
+ final String username = uuiddb.getPlayerName(uuid);
+ if (username != null) {
+ mappings.add(new UUIDMapping(uuid, username));
+ }
+ } catch (final Exception ignored) {}
+ }
+ return mappings;
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull final List usernames) {
+ final List mappings = new ArrayList<>(usernames.size());
+ final UUIDPlayerDB uuiddb = BungeePerms.getInstance().getPermissionsManager().getUUIDPlayerDB();
+ for (final String username : usernames) {
+ try {
+ final UUID uuid = uuiddb.getUUID(username);
+ if (username != null) {
+ mappings.add(new UUIDMapping(uuid, username));
+ }
+ } catch (final Exception ignored) {}
+ }
+ return mappings;
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/EssentialsUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/EssentialsUUIDService.java
new file mode 100644
index 000000000..eb473d67e
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/EssentialsUUIDService.java
@@ -0,0 +1,70 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.earth2me.essentials.Essentials;
+import com.earth2me.essentials.User;
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * UUID service using the EssentialsX API
+ */
+public class EssentialsUUIDService implements UUIDService {
+
+ private final Essentials essentials;
+
+ public EssentialsUUIDService() {
+ this.essentials = Essentials.getPlugin(Essentials.class);
+ }
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ return Collections.emptyList();
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull final List usernames) {
+ final List mappings = new ArrayList<>(usernames.size());
+ for (final String username : usernames) {
+ try {
+ final User user = essentials.getUser(username);
+ if (user != null) {
+ final UUID uuid = user.getConfigUUID();
+ if (uuid != null) {
+ mappings.add(new UUIDMapping(uuid, username));
+ }
+ }
+ } catch (final Exception ignored){}
+ }
+ return mappings;
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/LuckPermsUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/LuckPermsUUIDService.java
new file mode 100644
index 000000000..47bcc9bb3
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/LuckPermsUUIDService.java
@@ -0,0 +1,84 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import net.luckperms.api.LuckPerms;
+import net.luckperms.api.model.user.UserManager;
+import org.bukkit.Bukkit;
+import org.bukkit.plugin.RegisteredServiceProvider;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * UUID service that uses the LuckPerms API
+ */
+public class LuckPermsUUIDService implements UUIDService {
+
+ private final LuckPerms luckPerms;
+
+ public LuckPermsUUIDService() {
+ final RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
+ if (provider != null) {
+ this.luckPerms = provider.getProvider();
+ } else {
+ throw new IllegalStateException("LuckPerms not available");
+ }
+ }
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ final List mappings = new ArrayList<>(uuids.size());
+ final UserManager userManager = this.luckPerms.getUserManager();
+ for (final UUID uuid : uuids) {
+ try {
+ final String username = userManager.lookupUsername(uuid).get();
+ if (username != null) {
+ mappings.add(new UUIDMapping(uuid, username));
+ }
+ } catch (final Exception ignored) {}
+ }
+ return mappings;
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull final List usernames) {
+ final List mappings = new ArrayList<>(usernames.size());
+ final UserManager userManager = this.luckPerms.getUserManager();
+ for (final String username : usernames) {
+ try {
+ final UUID uuid = userManager.lookupUniqueId(username).get();
+ if (username != null) {
+ mappings.add(new UUIDMapping(uuid, username));
+ }
+ } catch (final Exception ignored) {}
+ }
+ return mappings;
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java
new file mode 100644
index 000000000..7b904e627
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/OfflinePlayerUUIDService.java
@@ -0,0 +1,85 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.google.common.base.Charsets;
+import com.plotsquared.core.configuration.Settings;
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * UUID service that use {@link org.bukkit.OfflinePlayer offline players}
+ */
+public class OfflinePlayerUUIDService implements UUIDService {
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ if (Settings.UUID.FORCE_LOWERCASE || Bukkit.getWorlds().isEmpty()) {
+ return Collections.emptyList(); // This is useless now
+ }
+ final List wrappers = new ArrayList<>(uuids.size());
+ for (final UUID uuid : uuids) {
+ final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
+ try {
+ if (offlinePlayer.hasPlayedBefore()) {
+ wrappers.add(new UUIDMapping(uuid, offlinePlayer.getName()));
+ }
+ } catch (final Exception ignored) {} /* This can be safely ignored. If this happens, it is
+ probably because it's called before the worlds have
+ been loaded. This is bad, but does not break anything */
+ }
+ return wrappers;
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull final List usernames) {
+ final List wrappers = new ArrayList<>(usernames.size());
+ for (final String username : usernames) {
+ if (Settings.UUID.OFFLINE) {
+ if (Settings.UUID.FORCE_LOWERCASE) {
+ wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
+ username.toLowerCase()).getBytes(Charsets.UTF_8)), username));
+ } else {
+ wrappers.add(new UUIDMapping(UUID.nameUUIDFromBytes(("OfflinePlayer:" +
+ username).getBytes(Charsets.UTF_8)), username));
+ }
+ } else {
+ final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username);
+ if (offlinePlayer.hasPlayedBefore()) {
+ wrappers.add(new UUIDMapping(offlinePlayer.getUniqueId(), offlinePlayer.getName()));
+ }
+ }
+ }
+ return wrappers;
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/PaperUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/PaperUUIDService.java
new file mode 100644
index 000000000..4f370c8b3
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/PaperUUIDService.java
@@ -0,0 +1,65 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.destroystokyo.paper.profile.PlayerProfile;
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import org.bukkit.Bukkit;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * UUID service that uses the Paper profile API
+ */
+public class PaperUUIDService implements UUIDService {
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ final List mappings = new ArrayList<>(uuids.size());
+ for (final UUID uuid : uuids) {
+ final PlayerProfile playerProfile = Bukkit.createProfile(uuid);
+ if ((playerProfile.isComplete() || playerProfile.completeFromCache()) && playerProfile.getId() != null) {
+ mappings.add(new UUIDMapping(playerProfile.getId(), playerProfile.getName()));
+ }
+ }
+ return mappings;
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull final List usernames) {
+ final List mappings = new ArrayList<>(usernames.size());
+ for (final String username : usernames) {
+ final PlayerProfile playerProfile = Bukkit.createProfile(username);
+ if ((playerProfile.isComplete() || playerProfile.completeFromCache()) && playerProfile.getId() != null) {
+ mappings.add(new UUIDMapping(playerProfile.getId(), playerProfile.getName()));
+ }
+ }
+ return mappings;
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java
new file mode 100644
index 000000000..16b3abff5
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SQLiteUUIDService.java
@@ -0,0 +1,145 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.plotsquared.core.PlotSquared;
+import com.plotsquared.core.database.SQLite;
+import com.plotsquared.core.util.MainUtil;
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import org.jetbrains.annotations.NotNull;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.UUID;
+import java.util.function.Consumer;
+
+/**
+ * UUID service that uses the (legacy) SQL UUID cache
+ */
+public class SQLiteUUIDService implements UUIDService, Consumer> {
+
+ private final SQLite sqlite;
+
+ public SQLiteUUIDService(final String fileName) {
+ this.sqlite =
+ new SQLite(MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), fileName));
+ try {
+ this.sqlite.openConnection();
+ } catch (ClassNotFoundException | SQLException e) {
+ e.printStackTrace();
+ }
+
+ try (PreparedStatement stmt = getConnection().prepareStatement(
+ "CREATE TABLE IF NOT EXISTS `usercache` (uuid VARCHAR(32) NOT NULL, username VARCHAR(32) NOT NULL, PRIMARY KEY (uuid))")) {
+ stmt.execute();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Connection getConnection() {
+ synchronized (this.sqlite) {
+ return this.sqlite.getConnection();
+ }
+ }
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ final List mappings = new ArrayList<>(uuids.size());
+ try (final PreparedStatement statement = getConnection()
+ .prepareStatement("SELECT `username` FROM `usercache` WHERE `uuid` = ?")) {
+ for (final UUID uuid : uuids) {
+ statement.setString(1, uuid.toString());
+ try (final ResultSet resultSet = statement.executeQuery()) {
+ if (resultSet.next()) {
+ mappings.add(new UUIDMapping(uuid, resultSet.getString("username")));
+ }
+ }
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return mappings;
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull List usernames) {
+ final List mappings = new ArrayList<>(usernames.size());
+ try (final PreparedStatement statement = getConnection()
+ .prepareStatement("SELECT `uuid` FROM `usercache` WHERE `username` = ?")) {
+ for (final String username : usernames) {
+ statement.setString(1, username);
+ try (final ResultSet resultSet = statement.executeQuery()) {
+ if (resultSet.next()) {
+ mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")),
+ username));
+ }
+ }
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return mappings;
+ }
+
+ @Override public void accept(final List uuidWrappers) {
+ try (final PreparedStatement statement = getConnection()
+ .prepareStatement("INSERT OR REPLACE INTO `usercache` (`uuid`, `username`) VALUES(?, ?)")) {
+ for (final UUIDMapping mapping : uuidWrappers) {
+ statement.setString(1, mapping.getUuid().toString());
+ statement.setString(2, mapping.getUsername());
+ statement.executeUpdate();
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Read the entire cache at once
+ *
+ * @return All read mappings
+ */
+ @NotNull public List getAll() {
+ final List mappings = new LinkedList<>();
+ try (final PreparedStatement statement = getConnection().prepareStatement("SELECT * FROM `usercache`")) {
+ try (final ResultSet resultSet = statement.executeQuery()) {
+ while (resultSet.next()) {
+ mappings.add(new UUIDMapping(UUID.fromString(resultSet.getString("uuid")), resultSet.getString("username")));
+ }
+ }
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return mappings;
+ }
+
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java
new file mode 100644
index 000000000..4580519aa
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/uuid/SquirrelIdUUIDService.java
@@ -0,0 +1,90 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * 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 .
+ */
+package com.plotsquared.bukkit.uuid;
+
+import com.google.common.util.concurrent.RateLimiter;
+import com.plotsquared.core.uuid.UUIDMapping;
+import com.plotsquared.core.uuid.UUIDService;
+import com.sk89q.squirrelid.Profile;
+import com.sk89q.squirrelid.resolver.HttpRepositoryService;
+import com.sk89q.squirrelid.resolver.ProfileService;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * UUID service using SquirrelID
+ */
+@SuppressWarnings("UnstableApiUsage")
+public class SquirrelIdUUIDService implements UUIDService {
+
+ private final ProfileService profileService;
+ private final RateLimiter rateLimiter;
+
+ /**
+ * Create a new SquirrelID UUID service
+ *
+ * @param rateLimit Mojangs rate limit is 600 requests per 10 minutes.
+ * This parameter specifies how many of those requests
+ * we can use before our internal rate limit kicks in.
+ */
+ public SquirrelIdUUIDService(final int rateLimit) {
+ this.profileService = HttpRepositoryService.forMinecraft();
+ // RateLimiter uses request per seconds. The constructor
+ // parameter rateLimit is requests per 600 seconds
+ this.rateLimiter = RateLimiter.create(rateLimit / 600.0D);
+ }
+
+ @Override @NotNull public List getNames(@NotNull final List uuids) {
+ final List results = new ArrayList<>(uuids.size());
+ this.rateLimiter.acquire(uuids.size());
+ try {
+ for (final Profile profile : this.profileService.findAllById(uuids)) {
+ results.add(new UUIDMapping(profile.getUniqueId(), profile.getName()));
+ }
+ } catch (IOException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ return results;
+ }
+
+ @Override @NotNull public List getUUIDs(@NotNull final List usernames) {
+ final List results = new ArrayList<>(usernames.size());
+ this.rateLimiter.acquire(usernames.size());
+ try {
+ for (final Profile profile : this.profileService.findAllByName(usernames)) {
+ results.add(new UUIDMapping(profile.getUniqueId(), profile.getName()));
+ }
+ } catch (IOException | InterruptedException e) {
+ e.printStackTrace();
+ }
+ return results;
+ }
+
+}
diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml
index 05d2aa6e2..41967220c 100644
--- a/Bukkit/src/main/resources/plugin.yml
+++ b/Bukkit/src/main/resources/plugin.yml
@@ -5,8 +5,8 @@ version: "${version}"
load: STARTUP
description: "Easy, yet powerful Plot World generation and management."
authors: [Citymonstret, Empire92, MattBDev, dordsor21, NotMyFault, SirYwell]
-website: https://github.com/IntellectualSites/
-softdepend: [Vault, PlaceholderAPI]
+website: https://www.spigotmc.org/resources/77506/
+softdepend: [Vault, PlaceholderAPI, Essentials, LuckPerms, BungeePerms]
loadbefore: [MultiWorld, Multiverse-Core]
depend: [WorldEdit]
database: false
diff --git a/Core/build.gradle b/Core/build.gradle
index ee6edfda2..51f56e187 100644
--- a/Core/build.gradle
+++ b/Core/build.gradle
@@ -1,5 +1,6 @@
repositories {
maven { url = "https://jitpack.io" }
+ maven { url = "https://mvn.intellectualsites.com/content/repositories/snapshots" }
}
def textVersion = "3.0.2"
@@ -16,6 +17,7 @@ dependencies {
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
implementation("org.jetbrains:annotations:19.0.0")
+ implementation("org.khelekore:prtree:1.7.0-SNAPSHOT")
}
sourceCompatibility = 1.8
@@ -73,6 +75,7 @@ shadowJar {
include(dependency("net.kyori:text-serializer-gson:3.0.2"))
include(dependency("net.kyori:text-serializer-legacy:3.0.2"))
include(dependency("net.kyori:text-serializer-plain:3.0.2"))
+ include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
}
relocate('net.kyori.text', 'com.plotsquared.formatting.text')
relocate("org.json", "com.plotsquared.json") {
diff --git a/Core/pom.xml b/Core/pom.xml
index 280cd8b1a..d69f10a99 100644
--- a/Core/pom.xml
+++ b/Core/pom.xml
@@ -9,7 +9,7 @@
org.json
json
- 20190722
+ 20200518
compile
@@ -92,6 +92,12 @@
1.3.72
runtime
+
+ org.khelekore
+ prtree
+ 1.7.0-SNAPSHOT
+ runtime
+
junit
junit
diff --git a/Core/src/main/java/com/plotsquared/core/IPlotMain.java b/Core/src/main/java/com/plotsquared/core/IPlotMain.java
index ed6694e01..a38045acb 100644
--- a/Core/src/main/java/com/plotsquared/core/IPlotMain.java
+++ b/Core/src/main/java/com/plotsquared/core/IPlotMain.java
@@ -35,22 +35,29 @@ import com.plotsquared.core.util.ChatManager;
import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.InventoryUtil;
+import com.plotsquared.core.util.PermHandler;
import com.plotsquared.core.util.PlatformWorldManager;
+import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandlerImplementation;
import com.sk89q.worldedit.extension.platform.Actor;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.List;
import java.util.Map;
-public interface IPlotMain extends ILogger {
+/**
+ * PlotSquared main utility class
+ *
+ * @param Player type
+ */
+public interface IPlotMain
extends ILogger {
/**
* Logs a message to console.
@@ -79,7 +86,7 @@ public interface IPlotMain extends ILogger {
* @param player The player to convert to a PlotPlayer
* @return A PlotPlayer
*/
- PlotPlayer wrapPlayer(Object player);
+ @Nullable PlotPlayer
wrapPlayer(Object player);
/**
* Completely shuts down the plugin.
@@ -168,11 +175,18 @@ public interface IPlotMain extends ILogger {
boolean initWorldEdit();
/**
- * Gets the economy provider.
+ * Gets the economy provider, if there is one
*
* @return the PlotSquared economy manager
*/
- EconHandler getEconomyHandler();
+ @Nullable EconHandler getEconomyHandler();
+
+ /**
+ * Gets the permission provider, if there is one
+ *
+ * @return the PlotSquared permission manager
+ */
+ @Nullable PermHandler getPermissionHandler();
/**
* Gets the {@link QueueProvider} class.
@@ -220,12 +234,6 @@ public interface IPlotMain extends ILogger {
*/
void setGenerator(String world);
- /**
- * Gets the {@link UUIDHandlerImplementation} which will cache and
- * provide UUIDs.
- */
- UUIDHandlerImplementation initUUIDHandler();
-
/**
* Gets the {@link InventoryUtil} class (used for implementation specific
* inventory guis).
@@ -285,6 +293,13 @@ public interface IPlotMain extends ILogger {
*
* @return World manager
*/
- @NotNull PlatformWorldManager getWorldManager();
+ @NotNull PlatformWorldManager> getWorldManager();
+
+ /**
+ * Get the player manager implementation for the platform
+ *
+ * @return Player manager
+ */
+ @NotNull PlayerManager extends PlotPlayer
, ? extends P> getPlayerManager();
}
diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
index 452493181..30d738afc 100644
--- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java
+++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java
@@ -53,6 +53,7 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.BlockBucket;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
+import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotCluster;
import com.plotsquared.core.plot.PlotFilter;
@@ -79,17 +80,18 @@ import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
-import com.plotsquared.core.util.StringWrapper;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.logger.ILogger;
+import com.plotsquared.core.util.query.PlotQuery;
import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandler;
+import com.plotsquared.core.uuid.UUIDPipeline;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.regions.CuboidRegion;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
@@ -116,6 +118,7 @@ import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -123,6 +126,7 @@ import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.Executors;
import java.util.function.Consumer;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -137,9 +141,14 @@ public class PlotSquared {
private static final Set EMPTY_SET = Collections.unmodifiableSet(Collections.emptySet());
private static PlotSquared instance;
// Implementation
- public final IPlotMain IMP;
+ public final IPlotMain> IMP;
// Current thread
private final Thread thread;
+ // UUID pipelines
+ @Getter private final UUIDPipeline impromptuUUIDPipeline =
+ new UUIDPipeline(Executors.newCachedThreadPool());
+ @Getter private final UUIDPipeline backgroundUUIDPipeline =
+ new UUIDPipeline(Executors.newSingleThreadExecutor());
// WorldEdit instance
public WorldEdit worldedit;
public File styleFile;
@@ -252,15 +261,6 @@ public class PlotSquared {
if (Settings.Enabled_Components.CHUNK_PROCESSOR) {
this.IMP.registerChunkProcessor();
}
- // create UUIDWrapper
- UUIDHandler.implementation = this.IMP.initUUIDHandler();
- if (Settings.Enabled_Components.UUID_CACHE) {
- startUuidCatching();
- } else {
- // Start these separately
- UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
- startExpiryTasks();
- }
// Create Event utility class
eventDispatcher = new EventDispatcher();
// create Hybrid utility class
@@ -270,7 +270,8 @@ public class PlotSquared {
// create setup util class
SetupUtils.manager = this.IMP.initSetupUtils();
// Set block
- GlobalBlockQueue.IMP = new GlobalBlockQueue(IMP.initBlockQueue(), 1);
+ GlobalBlockQueue.IMP =
+ new GlobalBlockQueue(IMP.initBlockQueue(), 1, Settings.QUEUE.TARGET_TIME);
GlobalBlockQueue.IMP.runTask();
// Set chunk
ChunkManager.manager = this.IMP.initChunkManager();
@@ -303,8 +304,7 @@ public class PlotSquared {
}
// Economy
if (Settings.Enabled_Components.ECONOMY) {
- TaskManager
- .runTask(() -> EconHandler.manager = PlotSquared.this.IMP.getEconomyHandler());
+ TaskManager.runTask(() -> EconHandler.initializeEconHandler());
}
if (Settings.Enabled_Components.COMPONENT_PRESETS) {
@@ -385,11 +385,11 @@ public class PlotSquared {
return PlotSquared.instance;
}
- public static IPlotMain imp() {
- if (instance != null) {
+ @NotNull public static IPlotMain> imp() {
+ if (instance != null && instance.IMP != null) {
return instance.IMP;
}
- return null;
+ throw new IllegalStateException("Plot main implementation is missing");
}
/**
@@ -427,23 +427,6 @@ public class PlotSquared {
}
}
- private void startUuidCatching() {
- TaskManager.runTaskLater(() -> {
- debug("Starting UUID caching");
- UUIDHandler.startCaching(() -> {
- UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
- forEachPlotRaw(plot -> {
- if (plot.hasOwner() && plot.temp != -1) {
- if (UUIDHandler.getName(plot.getOwnerAbs()) == null) {
- UUIDHandler.implementation.unknown.add(plot.getOwnerAbs());
- }
- }
- });
- startExpiryTasks();
- });
- }, 20);
- }
-
private void startExpiryTasks() {
if (Settings.Enabled_Components.PLOT_EXPIRY) {
ExpireManager.IMP = new ExpireManager();
@@ -640,17 +623,7 @@ public class PlotSquared {
* @return Set of base Plots
*/
public Set getBasePlots() {
- int size = getPlotCount();
- final Set result = new HashSet<>(size);
- forEachPlotArea(value -> {
- for (Plot plot : value.getPlots()) {
- if (!plot.isBasePlot()) {
- continue;
- }
- result.add(plot);
- }
- });
- return Collections.unmodifiableSet(result);
+ return PlotQuery.newQuery().whereBasePlot().asSet();
}
public List sortPlotsByTemp(Collection plots) {
@@ -903,27 +876,25 @@ public class PlotSquared {
*
* @param filters the filter
* @return a filtered set of plots
+ * @deprecated Use {@link PlotQuery}
*/
- public Set getPlots(final PlotFilter... filters) {
- final HashSet set = new HashSet<>();
- forEachPlotArea(value -> {
- for (PlotFilter filter : filters) {
- if (!filter.allowsArea(value)) {
- return;
+ @Deprecated public Set getPlots(final PlotFilter... filters) {
+ final List areas = new LinkedList<>();
+ for (final PlotArea plotArea : this.getPlotAreas()) {
+ for (final PlotFilter filter : filters) {
+ if (filter.allowsArea(plotArea)) {
+ areas.add(plotArea);
}
}
- loop:
- for (Entry entry2 : value.getPlotEntries()) {
- Plot plot = entry2.getValue();
- for (PlotFilter filter : filters) {
- if (!filter.allowsPlot(plot)) {
- continue loop;
- }
+ }
+ return PlotQuery.newQuery().inAreas(areas).thatPasses(plot -> {
+ for (final PlotFilter filter : filters) {
+ if (!filter.allowsPlot(plot)) {
+ return false;
}
- set.add(plot);
}
- });
- return set;
+ return true;
+ }).asSet();
}
/**
@@ -966,7 +937,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set getPlots(String world, String player) {
- final UUID uuid = UUIDHandler.getUUID(player, null);
+ final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
return getPlots(world, uuid);
}
@@ -978,7 +949,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set getPlots(PlotArea area, String player) {
- UUID uuid = UUIDHandler.getUUID(player, null);
+ final UUID uuid = this.impromptuUUIDPipeline.getSingle(player, Settings.UUID.BLOCKING_TIMEOUT);
return getPlots(area, uuid);
}
@@ -990,7 +961,7 @@ public class PlotSquared {
* @return Set of plot
*/
public Set getPlots(String world, PlotPlayer player) {
- return getPlots(world, player.getUUID());
+ return PlotQuery.newQuery().inWorld(world).ownedBy(player).asSet();
}
/**
@@ -1001,7 +972,7 @@ public class PlotSquared {
* @return Set of plot
*/
public Set getPlots(PlotArea area, PlotPlayer player) {
- return getPlots(area, player.getUUID());
+ return PlotQuery.newQuery().inArea(area).ownedBy(player).asSet();
}
/**
@@ -1012,10 +983,7 @@ public class PlotSquared {
* @return Set of plot
*/
public Set getPlots(String world, UUID uuid) {
- final Set plots =
- getPlots(world).stream().filter(plot -> plot.hasOwner() && plot.isOwnerAbs(uuid))
- .collect(Collectors.toSet());
- return Collections.unmodifiableSet(plots);
+ return PlotQuery.newQuery().inWorld(world).ownedBy(uuid).asSet();
}
/**
@@ -1026,13 +994,7 @@ public class PlotSquared {
* @return Set of plots
*/
public Set getPlots(PlotArea area, UUID uuid) {
- final Set plots = new HashSet<>();
- for (Plot plot : getPlots(area)) {
- if (plot.hasOwner() && plot.isOwnerAbs(uuid)) {
- plots.add(plot);
- }
- }
- return Collections.unmodifiableSet(plots);
+ return PlotQuery.newQuery().inArea(area).ownedBy(uuid).asSet();
}
/**
@@ -1047,9 +1009,7 @@ public class PlotSquared {
}
public Collection getPlots(String world) {
- final Set set = new HashSet<>();
- forEachPlotArea(world, value -> set.addAll(value.getPlots()));
- return set;
+ return PlotQuery.newQuery().inWorld(world).asCollection();
}
/**
@@ -1059,7 +1019,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set getPlots(PlotPlayer player) {
- return getPlots(player.getUUID());
+ return PlotQuery.newQuery().ownedBy(player).asSet();
}
public Collection getPlots(PlotArea area) {
@@ -1081,13 +1041,7 @@ public class PlotSquared {
* @return Set of Plot's owned by the player
*/
public Set getPlots(final UUID uuid) {
- final Set plots = new HashSet<>();
- forEachPlot(value -> {
- if (value.isOwnerAbs(uuid)) {
- plots.add(value);
- }
- });
- return Collections.unmodifiableSet(plots);
+ return PlotQuery.newQuery().ownedBy(uuid).asSet();
}
public boolean hasPlot(final UUID uuid) {
@@ -1096,13 +1050,7 @@ public class PlotSquared {
}
public Set getBasePlots(final UUID uuid) {
- final Set plots = new HashSet<>();
- forEachBasePlot(value -> {
- if (value.isOwner(uuid)) {
- plots.add(value);
- }
- });
- return Collections.unmodifiableSet(plots);
+ return PlotQuery.newQuery().ownedBy(uuid).whereBasePlot().asSet();
}
/**
@@ -1112,13 +1060,7 @@ public class PlotSquared {
* @return Set of Plot
*/
public Set getPlotsAbs(final UUID uuid) {
- final Set plots = new HashSet<>();
- forEachPlot(value -> {
- if (value.isOwnerAbs(uuid)) {
- plots.add(value);
- }
- });
- return Collections.unmodifiableSet(plots);
+ return PlotQuery.newQuery().ownedBy(uuid).asSet();
}
/**
@@ -1620,7 +1562,6 @@ public class PlotSquared {
// Close the connection
DBFunc.close();
- UUIDHandler.handleShutdown();
} catch (NullPointerException throwable) {
throwable.printStackTrace();
PlotSquared.log("&cCould not close database connection!");
@@ -2014,6 +1955,23 @@ public class PlotSquared {
return Collections.unmodifiableSet(set);
}
+ /**
+ * Check if the chunk uses vanilla/non-PlotSquared generation
+ *
+ * @param world World name
+ * @param chunkCoordinates Chunk coordinates
+ * @return True if the chunk uses non-standard generation, false if not
+ */
+ public boolean isNonStandardGeneration(@NotNull final String world,
+ @NotNull final BlockVector2 chunkCoordinates) {
+ final Location location = new Location(world, chunkCoordinates.getBlockX() << 4, 64, chunkCoordinates.getBlockZ() << 4);
+ final PlotArea area = plotAreaManager.getApplicablePlotArea(location);
+ if (area == null) {
+ return true;
+ }
+ return area.getTerrain() != PlotAreaTerrainType.NONE;
+ }
+
public boolean isAugmented(@NonNull final String world) {
final PlotArea[] areas = plotAreaManager.getPlotAreas(world, null);
return areas != null && (areas.length > 1 || areas[0].getType() != PlotAreaType.NORMAL);
@@ -2103,16 +2061,7 @@ public class PlotSquared {
*/
public Set getPlotsByAlias(@Nullable final String alias,
@NonNull final String worldname) {
- final Set result = new HashSet<>();
- if (alias != null) {
- for (final Plot plot : getPlots()) {
- if (alias.equals(plot.getAlias()) && (worldname == null || worldname
- .equals(plot.getWorldName()))) {
- result.add(plot);
- }
- }
- }
- return Collections.unmodifiableSet(result);
+ return PlotQuery.newQuery().inWorld(worldname).withAlias(alias).asSet();
}
public Set getPlotAreas(final String world, final CuboidRegion region) {
diff --git a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java
index 70bd11673..3991643a3 100644
--- a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java
+++ b/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java
@@ -38,8 +38,6 @@ import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.SchematicHandler;
-import com.plotsquared.core.util.uuid.UUIDHandler;
-import com.plotsquared.core.util.uuid.UUIDWrapper;
import lombok.NoArgsConstructor;
import java.util.Collections;
@@ -60,9 +58,7 @@ import java.util.UUID;
*
* @version 5
*/
-@SuppressWarnings({"unused", "WeakerAccess"})
-@NoArgsConstructor
-public class PlotAPI {
+@SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI {
/**
* Gets all plots.
@@ -140,17 +136,6 @@ public class PlotAPI {
return GlobalBlockQueue.IMP;
}
- /**
- * UUIDWrapper class has basic methods for getting UUIDS. It's recommended
- * to use the UUIDHandler class instead.
- *
- * @return UUIDWrapper
- * @see UUIDWrapper
- */
- public UUIDWrapper getUUIDWrapper() {
- return UUIDHandler.getUUIDWrapper();
- }
-
/**
* SchematicHandler class contains methods related to pasting, reading
* and writing schematics.
diff --git a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java
index 8853f3dff..c71057ab5 100644
--- a/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java
+++ b/Core/src/main/java/com/plotsquared/core/backup/PlayerBackupProfile.java
@@ -142,7 +142,7 @@ public class PlayerBackupProfile implements BackupProfile {
}
final List plots = Collections.singletonList(plot);
final boolean result = SchematicHandler.manager.exportAll(plots, getBackupDirectory().toFile(),
- "%world%-%id%-%owner%-" + System.currentTimeMillis(), () ->
+ "%world%-%id%-" + System.currentTimeMillis(), () ->
future.complete(new Backup(this, System.currentTimeMillis(), null)));
if (!result) {
future.completeExceptionally(new RuntimeException("Failed to complete the backup"));
diff --git a/Core/src/main/java/com/plotsquared/core/command/Add.java b/Core/src/main/java/com/plotsquared/core/command/Add.java
index bc4905c68..6d86f7532 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Add.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Add.java
@@ -32,13 +32,16 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
+import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Iterator;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "add",
description = "Allow a user to build in a plot while the plot owner is online.",
@@ -53,7 +56,7 @@ public class Add extends Command {
}
@Override
- public CompletableFuture execute(final PlotPlayer player, String[] args,
+ public CompletableFuture execute(final PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
@@ -62,51 +65,73 @@ public class Add extends Command {
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
Captions.NO_PLOT_PERMS);
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
- final Set uuids = MainUtil.getUUIDsFromString(args[0]);
- checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
- Iterator 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 future = new CompletableFuture<>();
+ MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
+ if (throwable != null) {
+ if (throwable instanceof TimeoutException) {
+ Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
+ } else {
+ Captions.INVALID_PLAYER.send(player, args[0]);
+ }
+ future.completeExceptionally(throwable);
+ return;
+ } else {
+ try {
+ checkTrue(!uuids.isEmpty(), Captions.INVALID_PLAYER, args[0]);
+ Iterator iterator = uuids.iterator();
+ int size = plot.getTrusted().size() + plot.getMembers().size();
+ while (iterator.hasNext()) {
+ UUID uuid = iterator.next();
+ if (uuid == DBFunc.EVERYONE && !(
+ Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
+ .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
+ iterator.remove();
+ continue;
+ }
+ if (plot.isOwner(uuid)) {
+ MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
+ iterator.remove();
+ continue;
+ }
+ if (plot.getMembers().contains(uuid)) {
+ MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
+ iterator.remove();
+ continue;
+ }
+ size += plot.getTrusted().contains(uuid) ? 0 : 1;
+ }
+ checkTrue(!uuids.isEmpty(), null);
+ checkTrue(size <= plot.getArea().getMaxPlotMembers() || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST),
+ Captions.PLOT_MAX_MEMBERS);
+ // Success
+ confirm.run(this, () -> {
+ for (UUID uuid : uuids) {
+ if (uuid != DBFunc.EVERYONE) {
+ if (!plot.removeTrusted(uuid)) {
+ if (plot.getDenied().contains(uuid)) {
+ plot.removeDenied(uuid);
+ }
+ }
+ }
+ plot.addMember(uuid);
+ PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true);
+ MainUtil.sendMessage(player, Captions.MEMBER_ADDED);
+ }
+ }, null);
+ } catch (final Throwable exception) {
+ future.completeExceptionally(exception);
+ return;
+ }
+ }
+ future.complete(true);
+ });
+ return future;
}
+
+ @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) {
+ return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
+ }
+
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Alias.java b/Core/src/main/java/com/plotsquared/core/command/Alias.java
index b1d8d8161..59c0da49c 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Alias.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Alias.java
@@ -33,19 +33,26 @@ import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
-import com.plotsquared.core.util.StringWrapper;
-import com.plotsquared.core.util.uuid.UUIDHandler;
+import com.plotsquared.core.util.query.PlotQuery;
-@CommandDeclaration(command = "setalias",
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeoutException;
+
+@CommandDeclaration(command = "alias",
permission = "plots.alias",
description = "Set the plot name",
usage = "/plot alias ",
- aliases = {"alias", "sa", "name", "rename", "setname", "seta", "nameplot"},
+ aliases = {"setalias", "sa", "name", "rename", "setname", "seta", "nameplot"},
category = CommandCategory.SETTINGS,
requiredType = RequiredType.PLAYER)
public class Alias extends SubCommand {
+ private static final Command SET_COMMAND = new Command(null, false, "set", null, RequiredType.NONE, null) {};
+ private static final Command REMOVE_COMMAND = new Command(null, false, "remove", null, RequiredType.NONE, null) {};
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
@@ -63,13 +70,11 @@ public class Alias extends SubCommand {
return false;
}
- if (!plot.isOwner(player.getUUID())) {
- MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
- return false;
- }
-
boolean result = false;
+ boolean owner = plot.isOwner(player.getUUID());
+ boolean permission;
+ boolean admin;
switch (args[0].toLowerCase()) {
case "set":
if (args.length != 2) {
@@ -77,17 +82,34 @@ public class Alias extends SubCommand {
return false;
}
- if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET, false)
- || canExecuteCommand(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE, false)) {
- result = setAlias(player, plot, args[1]);
+ permission = isPermitted(player, Captions.PERMISSION_ALIAS_SET)
+ || isPermitted(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE);
+ admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_SET);
+ if (!admin && !owner) {
+ MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
+ return false;
+ }
+ if (permission) { // is either admin or owner
+ setAlias(player, plot, args[1]);
+ return true;
} else {
- MainUtil.sendMessage(player, Captions.NO_PERMISSION);
+ MainUtil.sendMessage(player, Captions.NO_PERMISSION,
+ Captions.PERMISSION_ALIAS_SET.getTranslated());
}
break;
case "remove":
- if (canExecuteCommand(player, Captions.PERMISSION_ALIAS_REMOVE, true)) {
+ permission = isPermitted(player, Captions.PERMISSION_ALIAS_REMOVE);
+ admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_REMOVE);
+ if (!admin && !owner) {
+ MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
+ return false;
+ }
+ if (permission) {
result = removeAlias(player, plot);
+ } else {
+ MainUtil.sendMessage(player, Captions.NO_PERMISSION,
+ Captions.PERMISSION_ALIAS_REMOVE.getTranslated());
}
break;
default:
@@ -98,54 +120,58 @@ public class Alias extends SubCommand {
return result;
}
-
- private boolean setAlias(PlotPlayer player, Plot plot, String alias) {
- if (alias.isEmpty()) {
- Captions.COMMAND_SYNTAX.send(player, getUsage());
- return false;
- }
- if (alias.length() >= 50) {
- MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
- return false;
- }
- if (alias.contains(" ")) {
- Captions.NOT_VALID_VALUE.send(player);
- return false;
- }
- if (MathMan.isInteger(alias)) {
- Captions.NOT_VALID_VALUE.send(player);
- return false;
- }
- for (Plot p : PlotSquared.get().getPlots(plot.getArea())) {
- if (p.getAlias().equalsIgnoreCase(alias)) {
- MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
- return false;
+ @Override
+ public Collection tab(PlotPlayer player, String[] args, boolean space) {
+ final List commands = new ArrayList<>(2);
+ if (args.length == 1) {
+ if ("set".startsWith(args[0])) {
+ commands.add(SET_COMMAND);
}
+ if ("remove".startsWith(args[0])) {
+ commands.add(REMOVE_COMMAND);
+ }
+ return commands;
}
- if (UUIDHandler.nameExists(new StringWrapper(alias)) || PlotSquared.get()
- .hasPlotArea(alias)) {
- MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
- return false;
- }
- plot.setAlias(alias);
- MainUtil.sendMessage(player,
- Captions.ALIAS_SET_TO.getTranslated().replaceAll("%alias%", alias));
- return true;
+ return Collections.emptySet();
}
- private boolean removeAlias(PlotPlayer player, Plot plot) {
+ private void setAlias(PlotPlayer player, Plot plot, String alias) {
+ if (alias.isEmpty()) {
+ Captions.COMMAND_SYNTAX.send(player, getUsage());
+ } else if (alias.length() >= 50) {
+ MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
+ } else if (alias.contains(" ")) {
+ Captions.NOT_VALID_VALUE.send(player);
+ } else if (MathMan.isInteger(alias)) {
+ Captions.NOT_VALID_VALUE.send(player);
+ } else {
+ if (PlotQuery.newQuery().inArea(plot.getArea())
+ .withAlias(alias)
+ .anyMatch()) {
+ MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
+ return;
+ }
+ PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (uuid != null) {
+ MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
+ } else {
+ plot.setAlias(alias);
+ MainUtil.sendMessage(player,
+ Captions.ALIAS_SET_TO.getTranslated().replaceAll("%alias%", alias));
+ }
+ }));
+ }
+ }
+
+ private boolean removeAlias(PlotPlayer> player, Plot plot) {
plot.setAlias(null);
MainUtil.sendMessage(player, Captions.ALIAS_REMOVED.getTranslated());
return true;
}
- private boolean canExecuteCommand(PlotPlayer player, Captions caption, boolean sendMessage) {
- if (!Permissions.hasPermission(player, caption)) {
- if (sendMessage) {
- MainUtil.sendMessage(player, Captions.NO_PERMISSION);
- }
- return false;
- }
- return true;
+ private boolean isPermitted(PlotPlayer> player, Captions caption) {
+ return Permissions.hasPermission(player, caption);
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java
index f5d494868..383076f0d 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Area.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Area.java
@@ -33,26 +33,41 @@ import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.generator.HybridPlotWorld;
import com.plotsquared.core.location.Location;
+import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotArea;
import com.plotsquared.core.plot.PlotAreaTerrainType;
import com.plotsquared.core.plot.PlotAreaType;
import com.plotsquared.core.plot.PlotId;
-import com.plotsquared.core.plot.SetupObject;
import com.plotsquared.core.plot.message.PlotMessage;
+import com.plotsquared.core.setup.PlotAreaBuilder;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.RegionUtil;
+import com.plotsquared.core.util.SchematicHandler;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal3;
+import com.sk89q.worldedit.EditSession;
+import com.sk89q.worldedit.LocalSession;
+import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.entity.Player;
+import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
+import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
+import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
+import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
+import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector2;
+import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
+import com.sk89q.worldedit.regions.Region;
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
@@ -68,12 +83,140 @@ import java.util.Set;
confirmation = true)
public class Area extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
if (args.length == 0) {
Captions.COMMAND_SYNTAX.send(player, getUsage());
return false;
}
switch (args[0].toLowerCase()) {
+ case "single":
+ if (player instanceof ConsolePlayer) {
+ MainUtil.sendMessage(player, Captions.IS_CONSOLE);
+ return false;
+ }
+ if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_CREATE)) {
+ MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_AREA_CREATE);
+ return false;
+ }
+ if (args.length < 2) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
+ return false;
+ }
+ final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]);
+ if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
+ return false;
+ }
+ final LocalSession localSession = WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor());
+ if (localSession == null) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
+ return false;
+ }
+ Region playerSelectedRegion = null;
+ try {
+ playerSelectedRegion = localSession.getSelection(((Player) player.toActor()).getWorld());
+ } catch (final Exception ignored) {}
+ if (playerSelectedRegion == null) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
+ return false;
+ }
+ if (playerSelectedRegion.getWidth() != playerSelectedRegion.getLength()) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE);
+ return false;
+ }
+ if (PlotSquared.get().getPlotAreaManager().getPlotAreas(
+ Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING);
+ }
+ // Alter the region
+ final BlockVector3 playerSelectionMin = playerSelectedRegion.getMinimumPoint();
+ final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
+ // Create a new selection that spans the entire vertical range of the world
+ final CuboidRegion selectedRegion = new CuboidRegion(playerSelectedRegion.getWorld(),
+ BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
+ BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
+ // There's only one plot in the area...
+ final PlotId plotId = new PlotId(1, 1);
+ final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorld(), args[1],
+ Objects.requireNonNull(PlotSquared.imp()).getDefaultGenerator(), plotId, plotId);
+ // Plot size is the same as the region width
+ hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
+ // We use a schematic generator
+ hybridPlotWorld.setTerrain(PlotAreaTerrainType.NONE);
+ // It is always a partial plot world
+ hybridPlotWorld.setType(PlotAreaType.PARTIAL);
+ // We save the schematic :D
+ hybridPlotWorld.PLOT_SCHEMATIC = true;
+ // Set the road width to 0
+ hybridPlotWorld.ROAD_WIDTH = hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0;
+ // Set the plot height to the selection height
+ hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
+ // No sign plz
+ hybridPlotWorld.setAllowSigns(false);
+ final File parentFile = MainUtil.getFile(PlotSquared.imp().getDirectory(), "schematics" + File.separator +
+ "GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
+ hybridPlotWorld.getId());
+ if (!parentFile.exists() && !parentFile.mkdirs()) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_COULD_NOT_MAKE_DIRECTORIES);
+ return false;
+ }
+ final File file = new File(parentFile, "plot.schem");
+ try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
+ final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
+ final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1);
+ final ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
+ forwardExtentCopy.setCopyingBiomes(true);
+ forwardExtentCopy.setCopyingEntities(true);
+ Operations.complete(forwardExtentCopy);
+ clipboardWriter.write(clipboard);
+ } catch (final Exception e) {
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_FAILED_TO_SAVE);
+ e.printStackTrace();
+ return false;
+ }
+
+ // Setup schematic
+ try {
+ hybridPlotWorld.setupSchematics();
+ } catch (final SchematicHandler.UnsupportedFormatException e) {
+ e.printStackTrace();
+ }
+
+ // Calculate the offset
+ final BlockVector3 singlePos1 = selectedRegion.getMinimumPoint();
+
+ // Now the schematic is saved, which is wonderful!
+ PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld)
+ .plotManager(PlotSquared.imp().getPluginName())
+ .generatorName(PlotSquared.imp().getPluginName())
+ .maximumId(plotId)
+ .minimumId(plotId);
+ Runnable singleRun = () -> {
+ final String path =
+ "worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-'
+ + singleBuilder.minimumId() + '-' + singleBuilder.maximumId();
+ final int offsetX = singlePos1.getX();
+ final int offsetZ = singlePos1.getZ();
+ if (offsetX != 0) {
+ PlotSquared.get().worlds
+ .set(path + ".road.offset.x", offsetX);
+ }
+ if (offsetZ != 0) {
+ PlotSquared.get().worlds
+ .set(path + ".road.offset.z", offsetZ);
+ }
+ final String world = SetupUtils.manager.setupWorld(singleBuilder);
+ if (WorldUtil.IMP.isWorld(world)) {
+ PlotSquared.get().loadWorld(world, null);
+ MainUtil.sendMessage(player, Captions.SINGLE_AREA_CREATED);
+ } else {
+ MainUtil.sendMessage(player,
+ "An error occurred while creating the world: " + hybridPlotWorld
+ .getWorldName());
+ }
+ };
+ singleRun.run();
+ return true;
case "c":
case "setup":
case "create":
@@ -138,19 +281,14 @@ public class Area extends SubCommand {
.send(player, areas.iterator().next().toString());
return false;
}
- final SetupObject object = new SetupObject();
- object.world = area.getWorldName();
- object.id = area.getId();
- object.terrain = area.getTerrain();
- object.type = area.getType();
- object.min = new PlotId(1, 1);
- object.max = new PlotId(numX, numZ);
- object.plotManager = PlotSquared.imp().getPluginName();
- object.setupGenerator = PlotSquared.imp().getPluginName();
- object.step = area.getSettingNodes();
+ PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area)
+ .plotManager(PlotSquared.imp().getPluginName())
+ .generatorName(PlotSquared.imp().getPluginName())
+ .minimumId(new PlotId(1, 1))
+ .maximumId(new PlotId(numX, numZ));
final String path =
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-'
- + object.min + '-' + object.max;
+ + builder.minimumId() + '-' + builder.maximumId();
Runnable run = () -> {
if (offsetX != 0) {
PlotSquared.get().worlds
@@ -160,7 +298,7 @@ public class Area extends SubCommand {
PlotSquared.get().worlds
.set(path + ".road.offset.z", offsetZ);
}
- final String world = SetupUtils.manager.setupWorld(object);
+ final String world = SetupUtils.manager.setupWorld(builder);
if (WorldUtil.IMP.isWorld(world)) {
PlotSquared.get().loadWorld(world, null);
Captions.SETUP_FINISHED.send(player);
@@ -198,9 +336,9 @@ public class Area extends SubCommand {
} else {
id = null;
}
- final SetupObject object = new SetupObject();
- object.world = split[0];
- final HybridPlotWorld pa = new HybridPlotWorld(object.world, id,
+ PlotAreaBuilder builder = new PlotAreaBuilder();
+ builder.worldName(split[0]);
+ final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id,
PlotSquared.get().IMP.getDefaultGenerator(), null, null);
PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id);
if (other != null && Objects.equals(pa.getId(), other.getId())) {
@@ -262,13 +400,13 @@ public class Area extends SubCommand {
pa.setTerrain(PlotAreaTerrainType.fromString(pair[1])
.orElseThrow(() -> new IllegalArgumentException(
pair[1] + " is not a valid terrain.")));
- object.terrain = pa.getTerrain();
+ builder.terrainType(pa.getTerrain());
break;
case "type":
pa.setType(PlotAreaType.fromString(pair[1]).orElseThrow(
() -> new IllegalArgumentException(
pair[1] + " is not a valid type.")));
- object.type = pa.getType();
+ builder.plotAreaType(pa.getType());
break;
default:
Captions.COMMAND_SYNTAX.send(player, getCommandString()
@@ -290,9 +428,9 @@ public class Area extends SubCommand {
PlotSquared.get().worlds.getConfigurationSection(path);
pa.saveConfiguration(section);
pa.loadConfiguration(section);
- object.plotManager = PlotSquared.imp().getPluginName();
- object.setupGenerator = PlotSquared.imp().getPluginName();
- String world = SetupUtils.manager.setupWorld(object);
+ builder.plotManager(PlotSquared.imp().getPluginName());
+ builder.generatorName(PlotSquared.imp().getPluginName());
+ String world = SetupUtils.manager.setupWorld(builder);
if (WorldUtil.IMP.isWorld(world)) {
Captions.SETUP_FINISHED.send(player);
player.teleport(WorldUtil.IMP.getSpawn(world),
@@ -327,9 +465,9 @@ public class Area extends SubCommand {
TeleportCause.COMMAND);
}
} else {
- object.terrain = PlotAreaTerrainType.NONE;
- object.type = PlotAreaType.NORMAL;
- SetupUtils.manager.setupWorld(object);
+ builder.terrainType(PlotAreaTerrainType.NONE);
+ builder.plotAreaType(PlotAreaType.NORMAL);
+ SetupUtils.manager.setupWorld(builder);
player.teleport(WorldUtil.IMP.getSpawn(pa.getWorldName()),
TeleportCause.COMMAND);
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java
index 518a017d6..4c75de3f8 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Auto.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java
@@ -154,12 +154,12 @@ public class Auto extends SubCommand {
() -> autoClaimFromDatabase(player, area, plot.getId(), whenDone));
}
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
PlotArea plotarea = player.getApplicablePlotArea();
if (plotarea == null) {
- if (EconHandler.manager != null) {
+ if (EconHandler.getEconHandler() != null) {
for (PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
- if (EconHandler.manager
+ if (EconHandler.getEconHandler()
.hasPermission(area.getWorldName(), player.getName(), "plots.auto")) {
if (plotarea != null) {
plotarea = null;
@@ -253,18 +253,18 @@ public class Auto extends SubCommand {
return true;
}
}
- if (EconHandler.manager != null && plotarea.useEconomy()) {
+ if (EconHandler.getEconHandler() != null && plotarea.useEconomy()) {
Expression costExp = plotarea.getPrices().get("claim");
double cost = costExp.evaluate((double) (Settings.Limit.GLOBAL ?
player.getPlotCount() :
player.getPlotCount(plotarea.getWorldName())));
cost = (size_x * size_z) * cost;
if (cost > 0d) {
- if (!force && EconHandler.manager.getMoney(player) < cost) {
+ if (!force && EconHandler.getEconHandler().getMoney(player) < cost) {
sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
return true;
}
- EconHandler.manager.withdrawMoney(player, cost);
+ EconHandler.getEconHandler().withdrawMoney(player, cost);
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Backup.java b/Core/src/main/java/com/plotsquared/core/command/Backup.java
index e06d8208a..944eaaf6b 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Backup.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Backup.java
@@ -70,7 +70,7 @@ public final class Backup extends Command {
}
@Override
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
if (args.length == 0 || !Arrays.asList("save", "list", "load")
diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java
index a660a39a1..337801385 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Buy.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java
@@ -37,7 +37,6 @@ import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -55,11 +54,11 @@ public class Buy extends Command {
}
@Override
- public CompletableFuture execute(final PlotPlayer player, String[] args,
+ public CompletableFuture execute(final PlotPlayer> player, String[] args,
RunnableVal3 confirm,
final RunnableVal2 whenDone) {
- check(EconHandler.manager, Captions.ECON_DISABLED);
+ check(EconHandler.getEconHandler(), Captions.ECON_DISABLED);
final Plot plot;
if (args.length != 0) {
checkTrue(args.length == 1, Captions.COMMAND_SYNTAX, getUsage());
@@ -82,10 +81,10 @@ public class Buy extends Command {
// Success
confirm.run(this, () -> {
Captions.REMOVED_BALANCE.send(player, price);
- EconHandler.manager
- .depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.getOwnerAbs()),
- price);
- PlotPlayer owner = UUIDHandler.getPlayer(plot.getOwnerAbs());
+
+ EconHandler.getEconHandler().depositMoney(PlotSquared.imp().getPlayerManager().getOfflinePlayer(plot.getOwnerAbs()), price);
+
+ PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(plot.getOwnerAbs());
if (owner != null) {
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Caps.java b/Core/src/main/java/com/plotsquared/core/command/Caps.java
index 372e415b8..b56d33dc0 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Caps.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Caps.java
@@ -50,7 +50,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
usage = "/plot caps")
public class Caps extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, final String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, final String[] args) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
return Captions.NOT_IN_PLOT.send(player);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Chat.java b/Core/src/main/java/com/plotsquared/core/command/Chat.java
index e8c9e395c..3bf04f223 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Chat.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Chat.java
@@ -37,7 +37,7 @@ import com.plotsquared.core.util.MainUtil;
requiredType = RequiredType.PLAYER)
public class Chat extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (player.getPlotAreaAbs().isForcingPlotChat()) {
MainUtil.sendMessage(player, Captions.PLOT_CHAT_FORCED);
return true;
diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java
index 2f4ee7781..481a25bf5 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Claim.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java
@@ -54,7 +54,7 @@ import com.plotsquared.core.util.task.TaskManager;
usage = "/plot claim")
public class Claim extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
String schematic = null;
if (args.length >= 1) {
schematic = args[0];
@@ -105,14 +105,14 @@ public class Claim extends SubCommand {
}
}
}
- if ((EconHandler.manager != null) && area.useEconomy() && !force) {
+ if ((EconHandler.getEconHandler() != null) && area.useEconomy() && !force) {
Expression costExr = area.getPrices().get("claim");
double cost = costExr.evaluate((double) currentPlots);
if (cost > 0d) {
- if (EconHandler.manager.getMoney(player) < cost) {
+ if (EconHandler.getEconHandler().getMoney(player) < cost) {
return sendMessage(player, Captions.CANNOT_AFFORD_PLOT, "" + cost);
}
- EconHandler.manager.withdrawMoney(player, cost);
+ EconHandler.getEconHandler().withdrawMoney(player, cost);
sendMessage(player, Captions.REMOVED_BALANCE, cost + "");
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Clear.java b/Core/src/main/java/com/plotsquared/core/command/Clear.java
index 5e8c2757a..9d8279eda 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Clear.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Clear.java
@@ -64,7 +64,7 @@ public class Clear extends Command {
}
@Override
- public CompletableFuture execute(final PlotPlayer player, String[] args,
+ public CompletableFuture execute(final PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
checkTrue(args.length == 0, Captions.COMMAND_SYNTAX, getUsage());
diff --git a/Core/src/main/java/com/plotsquared/core/command/Cluster.java b/Core/src/main/java/com/plotsquared/core/command/Cluster.java
index ae220831e..557ba084b 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Cluster.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Cluster.java
@@ -39,12 +39,12 @@ import com.plotsquared.core.plot.PlotCluster;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "cluster",
aliases = "clusters",
@@ -54,7 +54,7 @@ import java.util.UUID;
description = "Manage a plot cluster")
public class Cluster extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
// list, create, delete, resize, invite, kick, leave, helpers, tp, sethome
if (args.length == 0) {
@@ -371,22 +371,29 @@ public class Cluster extends SubCommand {
return false;
}
}
- // check uuid
- UUID uuid = UUIDHandler.getUUID(args[1], null);
- if (uuid == null) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
- return false;
- }
- if (!cluster.isAdded(uuid)) {
- // add the user if not added
- cluster.invited.add(uuid);
- DBFunc.setInvited(cluster, uuid);
- PlotPlayer player2 = UUIDHandler.getPlayer(uuid);
- if (player2 != null) {
- MainUtil.sendMessage(player2, Captions.CLUSTER_INVITED, cluster.getName());
- }
- }
- MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_USER);
+
+ PlotSquared.get().getImpromptuUUIDPipeline()
+ .getSingle(args[1], (uuid, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (throwable != null) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
+ } else {
+ if (!cluster.isAdded(uuid)) {
+ // add the user if not added
+ cluster.invited.add(uuid);
+ DBFunc.setInvited(cluster, uuid);
+
+ final PlotPlayer otherPlayer =
+ PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
+ if (otherPlayer != null) {
+ MainUtil.sendMessage(otherPlayer, Captions.CLUSTER_INVITED,
+ cluster.getName());
+ }
+ }
+ MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_USER);
+ }
+ });
return true;
}
case "k":
@@ -420,35 +427,43 @@ public class Cluster extends SubCommand {
}
}
// check uuid
- UUID uuid = UUIDHandler.getUUID(args[1], null);
- if (uuid == null) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
- return false;
- }
- // Can't kick if the player is yourself, the owner, or not added to the cluster
- if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner) || !cluster
- .isAdded(uuid)) {
- MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER, cluster.getName());
- return false;
- }
- if (cluster.helpers.contains(uuid)) {
- cluster.helpers.remove(uuid);
- DBFunc.removeHelper(cluster, uuid);
- }
- cluster.invited.remove(uuid);
- DBFunc.removeInvited(cluster, uuid);
- PlotPlayer player2 = UUIDHandler.getPlayer(uuid);
- if (player2 != null) {
- MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED, cluster.getName());
- }
- for (Plot plot : new ArrayList<>(
- PlotSquared.get().getPlots(player2.getLocation().getWorld(), uuid))) {
- PlotCluster current = plot.getCluster();
- if (current != null && current.equals(cluster)) {
- plot.unclaim();
- }
- }
- MainUtil.sendMessage(player2, Captions.CLUSTER_KICKED_USER);
+ PlotSquared.get().getImpromptuUUIDPipeline()
+ .getSingle(args[1], (uuid, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (throwable != null) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[1]);
+ } else {
+ // Can't kick if the player is yourself, the owner, or not added to the cluster
+ if (uuid.equals(player.getUUID()) || uuid.equals(cluster.owner)
+ || !cluster.isAdded(uuid)) {
+ MainUtil.sendMessage(player, Captions.CANNOT_KICK_PLAYER,
+ cluster.getName());
+ } else {
+ if (cluster.helpers.contains(uuid)) {
+ cluster.helpers.remove(uuid);
+ DBFunc.removeHelper(cluster, uuid);
+ }
+ cluster.invited.remove(uuid);
+ DBFunc.removeInvited(cluster, uuid);
+
+ final PlotPlayer player2 =
+ PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
+ if (player2 != null) {
+ MainUtil.sendMessage(player2, Captions.CLUSTER_REMOVED,
+ cluster.getName());
+ }
+ for (Plot plot : new ArrayList<>(PlotSquared.get()
+ .getPlots(player2.getLocation().getWorld(), uuid))) {
+ PlotCluster current = plot.getCluster();
+ if (current != null && current.equals(cluster)) {
+ plot.unclaim();
+ }
+ }
+ MainUtil.sendMessage(player2, Captions.CLUSTER_KICKED_USER);
+ }
+ }
+ });
return true;
}
case "quit":
@@ -529,24 +544,29 @@ public class Cluster extends SubCommand {
MainUtil.sendMessage(player, Captions.NOT_IN_CLUSTER);
return false;
}
- UUID uuid = UUIDHandler.getUUID(args[2], null);
- if (uuid == null) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
- return false;
- }
- if (args[1].equalsIgnoreCase("add")) {
- cluster.helpers.add(uuid);
- DBFunc.setHelper(cluster, uuid);
- return MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER);
- }
- if (args[1].equalsIgnoreCase("remove")) {
- cluster.helpers.remove(uuid);
- DBFunc.removeHelper(cluster, uuid);
- return MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER);
- }
- MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
- "/plot cluster helpers ");
- return false;
+
+ PlotSquared.get().getImpromptuUUIDPipeline()
+ .getSingle(args[2], (uuid, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (throwable != null) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[2]);
+ } else {
+ if (args[1].equalsIgnoreCase("add")) {
+ cluster.helpers.add(uuid);
+ DBFunc.setHelper(cluster, uuid);
+ MainUtil.sendMessage(player, Captions.CLUSTER_ADDED_HELPER);
+ } else if (args[1].equalsIgnoreCase("remove")) {
+ cluster.helpers.remove(uuid);
+ DBFunc.removeHelper(cluster, uuid);
+ MainUtil.sendMessage(player, Captions.CLUSTER_REMOVED_HELPER);
+ } else {
+ MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
+ "/plot cluster helpers ");
+ }
+ }
+ });
+ return true;
}
case "spawn":
case "home":
@@ -615,21 +635,31 @@ public class Cluster extends SubCommand {
}
}
String id = cluster.toString();
- String owner = UUIDHandler.getName(cluster.owner);
- if (owner == null) {
- owner = "unknown";
- }
- String name = cluster.getName();
- String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
- cluster.getP2().y - cluster.getP1().y + 1);
- String rights = cluster.isAdded(player.getUUID()) + "";
- String message = Captions.CLUSTER_INFO.getTranslated();
- message = message.replaceAll("%id%", id);
- message = message.replaceAll("%owner%", owner);
- message = message.replaceAll("%name%", name);
- message = message.replaceAll("%size%", size);
- message = message.replaceAll("%rights%", rights);
- MainUtil.sendMessage(player, message);
+
+ PlotSquared.get().getImpromptuUUIDPipeline()
+ .getSingle(cluster.owner, (username, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else {
+ final String owner;
+ if (username == null) {
+ owner = "unknown";
+ } else {
+ owner = username;
+ }
+ String name = cluster.getName();
+ String size = (cluster.getP2().x - cluster.getP1().x + 1) + "x" + (
+ cluster.getP2().y - cluster.getP1().y + 1);
+ String rights = cluster.isAdded(player.getUUID()) + "";
+ String message = Captions.CLUSTER_INFO.getTranslated();
+ message = message.replaceAll("%id%", id);
+ message = message.replaceAll("%owner%", owner);
+ message = message.replaceAll("%name%", name);
+ message = message.replaceAll("%size%", size);
+ message = message.replaceAll("%rights%", rights);
+ MainUtil.sendMessage(player, message);
+ }
+ });
return true;
}
case "sh":
diff --git a/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java b/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java
index 8b657992d..f7096834b 100644
--- a/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java
+++ b/Core/src/main/java/com/plotsquared/core/command/CmdConfirm.java
@@ -32,15 +32,15 @@ import com.plotsquared.core.util.task.TaskManager;
public class CmdConfirm {
- public static CmdInstance getPending(PlotPlayer player) {
+ public static CmdInstance getPending(PlotPlayer> player) {
return player.getMeta("cmdConfirm");
}
- public static void removePending(PlotPlayer player) {
+ public static void removePending(PlotPlayer> player) {
player.deleteMeta("cmdConfirm");
}
- public static void addPending(final PlotPlayer player, String commandStr,
+ public static void addPending(final PlotPlayer> player, String commandStr,
final Runnable runnable) {
removePending(player);
if (commandStr != null) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/Command.java b/Core/src/main/java/com/plotsquared/core/command/Command.java
index 6535e3b2c..7238d4566 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Command.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Command.java
@@ -37,6 +37,8 @@ import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
+import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -104,7 +106,7 @@ public abstract class Command {
&& types[4] == RunnableVal2.class) {
Command tmp = new Command(this, true) {
@Override
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) {
try {
@@ -298,7 +300,7 @@ public abstract class Command {
* @return CompletableFuture true if the command executed fully, false in
* any other case
*/
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
if (args.length == 0 || args[0] == null) {
@@ -603,6 +605,10 @@ public abstract class Command {
return object;
}
+ @SneakyThrows protected static void sneakyThrow(@NotNull final Throwable throwable) {
+ throw throwable;
+ }
+
public enum CommandResult {
FAILURE, SUCCESS
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Comment.java b/Core/src/main/java/com/plotsquared/core/command/Comment.java
index 284587106..a5615533f 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Comment.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Comment.java
@@ -25,6 +25,7 @@
*/
package com.plotsquared.core.command;
+import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
@@ -33,11 +34,9 @@ import com.plotsquared.core.plot.comment.CommentManager;
import com.plotsquared.core.plot.comment.PlotComment;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.StringMan;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.Arrays;
import java.util.Locale;
-import java.util.Map.Entry;
@CommandDeclaration(command = "comment",
aliases = {"msg"},
@@ -47,7 +46,7 @@ import java.util.Map.Entry;
permission = "plots.comment")
public class Comment extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (args.length < 2) {
sendMessage(player, Captions.COMMENT_SYNTAX,
StringMan.join(CommentManager.inboxes.keySet(), "|"));
@@ -96,12 +95,13 @@ public class Comment extends SubCommand {
StringMan.join(CommentManager.inboxes.keySet(), "|"));
return false;
}
- for (Entry 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;
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Condense.java b/Core/src/main/java/com/plotsquared/core/command/Condense.java
index f8a65407d..8f792ee7e 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Condense.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Condense.java
@@ -54,7 +54,7 @@ public class Condense extends SubCommand {
public static boolean TASK = false;
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
if (args.length != 2 && args.length != 3) {
MainUtil.sendMessage(player, getUsage());
return false;
diff --git a/Core/src/main/java/com/plotsquared/core/command/Confirm.java b/Core/src/main/java/com/plotsquared/core/command/Confirm.java
index 04723ac48..311c1c437 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Confirm.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Confirm.java
@@ -37,7 +37,7 @@ import com.plotsquared.core.util.task.TaskManager;
category = CommandCategory.INFO)
public class Confirm extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
CmdInstance command = CmdConfirm.getPending(player);
if (command == null) {
MainUtil.sendMessage(player, Captions.FAILED_CONFIRM);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Continue.java b/Core/src/main/java/com/plotsquared/core/command/Continue.java
index d366b2ff6..23f5e93a0 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Continue.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Continue.java
@@ -44,7 +44,7 @@ import com.plotsquared.core.util.Permissions;
requiredType = RequiredType.PLAYER)
public class Continue extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
Plot plot = player.getCurrentPlot();
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(player, Captions.NOT_IN_PLOT);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Copy.java b/Core/src/main/java/com/plotsquared/core/command/Copy.java
index 702255064..6743074ff 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Copy.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Copy.java
@@ -41,7 +41,7 @@ import com.plotsquared.core.util.Permissions;
requiredType = RequiredType.NONE)
public class Copy extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
Location location = player.getLocation();
Plot plot1 = location.getPlotAbs();
if (plot1 == null) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java
index 258467500..d5800896a 100644
--- a/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java
+++ b/Core/src/main/java/com/plotsquared/core/command/CreateRoadSchematic.java
@@ -42,7 +42,7 @@ import com.plotsquared.core.util.MainUtil;
usage = "/plot createroadschematic")
public class CreateRoadSchematic extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
if (plot == null) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java
index c652957e4..41690b5af 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java
@@ -74,7 +74,7 @@ public class DatabaseCommand extends SubCommand {
});
}
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
if (args.length < 1) {
MainUtil.sendMessage(player, getUsage());
return false;
diff --git a/Core/src/main/java/com/plotsquared/core/command/Debug.java b/Core/src/main/java/com/plotsquared/core/command/Debug.java
index 7d0ced991..91997a4ec 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Debug.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Debug.java
@@ -34,8 +34,10 @@ import com.plotsquared.core.util.StringMan;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.entity.EntityCategory;
import com.plotsquared.core.util.task.TaskManager;
+import com.plotsquared.core.uuid.UUIDMapping;
import com.sk89q.worldedit.world.entity.EntityType;
+import java.util.Collection;
import java.util.Comparator;
import java.util.Map;
@@ -46,7 +48,7 @@ import java.util.Map;
permission = "plots.admin")
public class Debug extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (args.length > 0) {
if ("player".equalsIgnoreCase(args[0])) {
for (Map.Entry meta : player.getMeta().entrySet()) {
@@ -65,6 +67,18 @@ public class Debug extends SubCommand {
.currentThread().getName()));
return true;
}
+ if (args.length > 0 && "uuids".equalsIgnoreCase(args[0])) {
+ final Collection mappings = PlotSquared.get().getImpromptuUUIDPipeline().getAllImmediately();
+ MainUtil.sendMessage(player, String.format("There are %d cached UUIDs", mappings.size()));
+ return true;
+ }
+ if (args.length > 0 && "debug-players".equalsIgnoreCase(args[0])) {
+ MainUtil.sendMessage(player, "Player in debug mode: " );
+ for (final PlotPlayer> pp : PlotPlayer.getDebugModePlayers()) {
+ MainUtil.sendMessage(player, "- " + pp.getName());
+ }
+ return true;
+ }
if (args.length > 0 && "entitytypes".equalsIgnoreCase(args[0])) {
EntityCategories.init();
player.sendMessage(Captions.PREFIX.getTranslated() + "§cEntity Categories: ");
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java b/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java
index e4de7e351..d424b809f 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugAllowUnsafe.java
@@ -42,7 +42,7 @@ public class DebugAllowUnsafe extends SubCommand {
public static final List unsafeAllowed = new ArrayList<>();
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (unsafeAllowed.contains(player.getUUID())) {
unsafeAllowed.remove(player.getUUID());
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugClaimTest.java b/Core/src/main/java/com/plotsquared/core/command/DebugClaimTest.java
deleted file mode 100644
index 5412ed6a2..000000000
--- a/Core/src/main/java/com/plotsquared/core/command/DebugClaimTest.java
+++ /dev/null
@@ -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 .
- */
-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 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 map = UUIDHandler.getUuidMap();
- UUID uuid = map.get(new StringWrapper(line));
- if (uuid == null) {
- for (Map.Entry 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;
- }
-}
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
index 8976c3348..3d6af68f1 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java
@@ -35,7 +35,6 @@ import com.plotsquared.core.events.Result;
import com.plotsquared.core.generator.HybridUtils;
import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
-import com.plotsquared.core.player.OfflinePlotPlayer;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
@@ -59,7 +58,6 @@ import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.world.block.BlockState;
import javax.script.Bindings;
@@ -71,13 +69,10 @@ import javax.script.SimpleScriptContext;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.sql.Timestamp;
import java.util.Arrays;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugexec",
@@ -171,8 +166,7 @@ public class DebugExec extends SubCommand {
this.scope.put("BlockManager", WorldUtil.IMP);
this.scope.put("SetupUtils", SetupUtils.manager);
this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher());
- this.scope.put("EconHandler", EconHandler.manager);
- this.scope.put("UUIDHandler", UUIDHandler.implementation);
+ this.scope.put("EconHandler", EconHandler.getEconHandler());
this.scope.put("DBFunc", DBFunc.dbManager);
this.scope.put("HybridUtils", HybridUtils.manager);
this.scope.put("IMP", PlotSquared.get().IMP);
@@ -184,7 +178,7 @@ public class DebugExec extends SubCommand {
}
}
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
List allowed_params = Arrays
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
@@ -301,27 +295,6 @@ public class DebugExec extends SubCommand {
} else {
return MainUtil.sendMessage(player, "Plot expiry task already started");
}
- case "seen":
- if (args.length != 2) {
- return MainUtil.sendMessage(player, "Use /plot debugexec seen ");
- }
- UUID uuid = UUIDHandler.getUUID(args[1], null);
- if (uuid == null) {
- return MainUtil.sendMessage(player, "Player not found: " + args[1]);
- }
- OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
- if (op == null || op.getLastPlayed() == 0) {
- return MainUtil
- .sendMessage(player, "Player hasn't connected before: " + args[1]);
- }
- Timestamp stamp = new Timestamp(op.getLastPlayed());
- Date date = new Date(stamp.getTime());
- MainUtil.sendMessage(player, "PLAYER: " + args[1]);
- MainUtil.sendMessage(player, "UUID: " + uuid);
- MainUtil.sendMessage(player, "Object: " + date.toGMTString());
- MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
- MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
- return true;
case "h":
case "he":
case "?":
@@ -339,7 +312,7 @@ public class DebugExec extends SubCommand {
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
RequiredType.NONE, CommandCategory.DEBUG) {
@Override
- public CompletableFuture execute(PlotPlayer player,
+ public CompletableFuture execute(PlotPlayer> player,
String[] args, RunnableVal3 confirm,
RunnableVal2 whenDone) {
try {
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java b/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java
index 9cca145a5..bdb5a13b2 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugImportWorlds.java
@@ -27,6 +27,7 @@ package com.plotsquared.core.command;
import com.google.common.base.Charsets;
import com.plotsquared.core.PlotSquared;
+import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotId;
import com.plotsquared.core.plot.world.PlotAreaManager;
@@ -35,7 +36,6 @@ import com.plotsquared.core.plot.world.SinglePlotAreaManager;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import java.io.File;
import java.util.UUID;
@@ -52,7 +52,7 @@ public class DebugImportWorlds extends Command {
}
@Override
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
// UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8))
@@ -76,7 +76,8 @@ public class DebugImportWorlds extends Command {
if (name.length() > 16) {
uuid = UUID.fromString(name);
} else {
- uuid = UUIDHandler.getUUID(name, null);
+ Captions.FETCHING_PLAYER.send(player);
+ uuid = PlotSquared.get().getImpromptuUUIDPipeline().getSingle(name, 60000L);
}
if (uuid == null) {
uuid =
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugLoadTest.java b/Core/src/main/java/com/plotsquared/core/command/DebugLoadTest.java
index 47bf4d6c5..387c5204e 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugLoadTest.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugLoadTest.java
@@ -37,7 +37,7 @@ import com.plotsquared.core.player.PlotPlayer;
requiredType = RequiredType.CONSOLE)
public class DebugLoadTest extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
PlotSquared.get().plots_tmp = DBFunc.getPlots();
return true;
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java
index c5c42a4c2..441fbdd84 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugPaste.java
@@ -35,7 +35,6 @@ import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.PremiumVerification;
import com.plotsquared.core.util.net.IncendoPaster;
import com.plotsquared.core.util.task.TaskManager;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import lombok.NonNull;
import java.io.BufferedReader;
@@ -72,7 +71,7 @@ public class DebugPaste extends SubCommand {
return content.toString();
}
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
TaskManager.runTaskAsync(() -> {
try {
@@ -90,7 +89,7 @@ public class DebugPaste extends SubCommand {
b.append("# Server Information\n");
b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation())
.append("\n");
- b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';')
+ b.append("online_mode: ").append(!Settings.UUID.OFFLINE).append(';')
.append(!Settings.UUID.OFFLINE).append('\n');
b.append("Plugins:");
for (Map.Entry, Boolean> pluginInfo : PlotSquared
@@ -122,7 +121,7 @@ public class DebugPaste extends SubCommand {
b.append("OS Arch: ").append(System.getProperty("os.arch")).append('\n');
b.append("# Okay :D Great. You are now ready to create your bug report!");
b.append(
- "\n# You can do so at https://github.com/IntellectualSites/PlotSquared/issues");
+ "\n# You can do so at https://issues.intellectualsites.com/projects/ps");
b.append("\n# or via our Discord at https://discord.gg/KxkjDVg");
final IncendoPaster incendoPaster = new IncendoPaster("plotsquared");
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java
index 07ce9a516..b20924586 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java
@@ -46,7 +46,7 @@ import java.util.Arrays;
public class DebugRoadRegen extends SubCommand {
public static final String USAGE = "/plot debugroadregen ";
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (args.length < 1) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, DebugRoadRegen.USAGE);
return false;
diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java b/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java
index dc2fc612d..7307ca185 100644
--- a/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java
+++ b/Core/src/main/java/com/plotsquared/core/command/DebugSaveTest.java
@@ -41,7 +41,7 @@ import java.util.ArrayList;
description = "This command will force the recreation of all plots in the DB")
public class DebugSaveTest extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
ArrayList plots = new ArrayList<>(PlotSquared.get().getPlots());
MainUtil.sendMessage(player, "&6Starting `DEBUGSAVETEST`");
DBFunc.createPlotsAndData(plots,
diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java
index 1a95046df..5f8178e06 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Delete.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java
@@ -53,7 +53,7 @@ public class Delete extends SubCommand {
// Note: To delete a specific plot use /plot delete
// The syntax also works with any command: /plot
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if (plot == null) {
@@ -86,11 +86,11 @@ public class Delete extends SubCommand {
final long start = System.currentTimeMillis();
boolean result = plot.deletePlot(() -> {
plot.removeRunning();
- if ((EconHandler.manager != null) && plotArea.useEconomy()) {
+ if ((EconHandler.getEconHandler() != null) && plotArea.useEconomy()) {
Expression valueExr = plotArea.getPrices().get("sell");
double value = plots.size() * valueExr.evaluate((double) currentPlots);
if (value > 0d) {
- EconHandler.manager.depositMoney(player, value);
+ EconHandler.getEconHandler().depositMoney(player, value);
sendMessage(player, Captions.ADDED_BALANCE, String.valueOf(value));
}
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java
index d591bfa1a..1cb862304 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Deny.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java
@@ -33,12 +33,14 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
+import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import com.sk89q.worldedit.world.gamemode.GameModes;
-import java.util.Set;
+import java.util.Collection;
+import java.util.Collections;
import java.util.UUID;
+import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "deny",
aliases = {"d", "ban"},
@@ -52,7 +54,7 @@ public class Deny extends SubCommand {
super(Argument.PlayerName);
}
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlotAbs();
@@ -68,51 +70,55 @@ public class Deny extends SubCommand {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return true;
}
- Set uuids = MainUtil.getUUIDsFromString(args[0]);
- if (uuids.isEmpty()) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
- return false;
- }
- for (UUID uuid : uuids) {
- if (uuid == DBFunc.EVERYONE && !(
- Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
- .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
- continue;
- }
- if (plot.isOwner(uuid)) {
- MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid));
- return false;
- }
- if (plot.getDenied().contains(uuid)) {
- MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
- return false;
- }
- if (uuid != DBFunc.EVERYONE) {
- plot.removeMember(uuid);
- plot.removeTrusted(uuid);
- }
- plot.addDenied(uuid);
- PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true);
- if (!uuid.equals(DBFunc.EVERYONE)) {
- handleKick(UUIDHandler.getPlayer(uuid), plot);
+ MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (throwable != null || uuids.isEmpty()) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
} else {
- for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
- // Ignore plot-owners
- if (plot.isAdded(plotPlayer.getUUID())) {
- continue;
+ for (UUID uuid : uuids) {
+ if (uuid == DBFunc.EVERYONE && !(
+ Permissions.hasPermission(player, Captions.PERMISSION_DENY_EVERYONE) || Permissions
+ .hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_DENY))) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
+ } else if (plot.isOwner(uuid)) {
+ MainUtil.sendMessage(player, Captions.CANT_REMOVE_OWNER, MainUtil.getName(uuid));
+ return;
+ } else if (plot.getDenied().contains(uuid)) {
+ MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
+ return;
+ } else {
+ if (uuid != DBFunc.EVERYONE) {
+ plot.removeMember(uuid);
+ plot.removeTrusted(uuid);
+ }
+ plot.addDenied(uuid);
+ PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true);
+ if (!uuid.equals(DBFunc.EVERYONE)) {
+ handleKick(PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid), plot);
+ } else {
+ for (PlotPlayer plotPlayer : plot.getPlayersInPlot()) {
+ // Ignore plot-owners
+ if (plot.isAdded(plotPlayer.getUUID())) {
+ continue;
+ }
+ handleKick(plotPlayer, plot);
+ }
+ }
}
- handleKick(plotPlayer, plot);
}
+ MainUtil.sendMessage(player, Captions.DENIED_ADDED);
}
- }
- if (!uuids.isEmpty()) {
- MainUtil.sendMessage(player, Captions.DENIED_ADDED);
- }
+ });
+
return true;
}
+ @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) {
+ return TabCompletions.completePlayers(String.join(",", args).trim(), Collections.emptyList());
+ }
+
private void handleKick(PlotPlayer player, Plot plot) {
if (player == null) {
return;
diff --git a/Core/src/main/java/com/plotsquared/core/command/Dislike.java b/Core/src/main/java/com/plotsquared/core/command/Dislike.java
index ee6664f81..410e13b57 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Dislike.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Dislike.java
@@ -35,7 +35,7 @@ import com.plotsquared.core.player.PlotPlayer;
requiredType = RequiredType.PLAYER)
public class Dislike extends SubCommand {
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
return Like.handleLike(player, args, false);
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Done.java b/Core/src/main/java/com/plotsquared/core/command/Done.java
index 4e9015e04..258454f8a 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Done.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Done.java
@@ -51,7 +51,7 @@ import com.plotsquared.core.util.task.RunnableVal;
requiredType = RequiredType.NONE)
public class Done extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
Location location = player.getLocation();
final Plot plot = location.getPlotAbs();
if ((plot == null) || !plot.hasOwner()) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java
index 25e3c13d7..efd4079d5 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Download.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Download.java
@@ -50,7 +50,7 @@ import java.net.URL;
permission = "plots.download")
public class Download extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
String world = player.getLocation().getWorld();
if (!PlotSquared.get().hasPlotArea(world)) {
return !sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
diff --git a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java
index 80ee2512a..d6b5a58e8 100644
--- a/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java
+++ b/Core/src/main/java/com/plotsquared/core/command/FlagCommand.java
@@ -207,7 +207,7 @@ public final class FlagCommand extends Command {
}
@Override
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
if (args.length == 0 || !Arrays
diff --git a/Core/src/main/java/com/plotsquared/core/command/Grant.java b/Core/src/main/java/com/plotsquared/core/command/Grant.java
index acec1b084..2d41da2e3 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Grant.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Grant.java
@@ -26,6 +26,7 @@
package com.plotsquared.core.command;
import com.google.common.primitives.Ints;
+import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.database.DBFunc;
@@ -35,10 +36,10 @@ import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.RunnableVal3;
-import com.plotsquared.core.util.uuid.UUIDHandler;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "grant",
category = CommandCategory.CLAIMING,
@@ -52,7 +53,7 @@ public class Grant extends Command {
}
@Override
- public CompletableFuture execute(final PlotPlayer player, String[] args,
+ public CompletableFuture execute(final PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
checkTrue(args.length >= 1 && args.length <= 2, Captions.COMMAND_SYNTAX, getUsage());
@@ -69,43 +70,44 @@ public class Grant extends Command {
if (args.length > 2) {
break;
}
- final UUID uuid;
- if (args.length == 2) {
- uuid = UUIDHandler.getUUIDFromString(args[1]);
- } else {
- uuid = player.getUUID();
- }
- if (uuid == null) {
- Captions.INVALID_PLAYER.send(player, args[1]);
- return CompletableFuture.completedFuture(false);
- }
- MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal() {
- @Override public void run(byte[] array) {
- if (arg0.equals("check")) { // check
- int granted;
- if (array == null) {
- granted = 0;
- } else {
- granted = Ints.fromByteArray(array);
+ MainUtil.getUUIDsFromString(args[1], (uuids, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (throwable != null || uuids.size() != 1) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER);
+ } else {
+ final UUID uuid = uuids.toArray(new UUID[0])[0];
+ MainUtil.getPersistentMeta(uuid,
+ "grantedPlots", new RunnableVal() {
+ @Override public void run(byte[] array) {
+ if (arg0.equals("check")) { // check
+ int granted;
+ if (array == null) {
+ granted = 0;
+ } else {
+ granted = Ints.fromByteArray(array);
+ }
+ Captions.GRANTED_PLOTS.send(player, granted);
+ } else { // add
+ int amount;
+ if (array == null) {
+ amount = 1;
+ } else {
+ amount = 1 + Ints.fromByteArray(array);
+ }
+ boolean replace = array != null;
+ String key = "grantedPlots";
+ byte[] rawData = Ints.toByteArray(amount);
+
+ PlotPlayer online = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
+ if (online != null) {
+ online.setPersistentMeta(key, rawData);
+ } else {
+ DBFunc.addPersistentMeta(uuid, key, rawData, replace);
+ }
+ }
}
- Captions.GRANTED_PLOTS.send(player, granted);
- } else { // add
- int amount;
- if (array == null) {
- amount = 1;
- } else {
- amount = 1 + Ints.fromByteArray(array);
- }
- boolean replace = array != null;
- String key = "grantedPlots";
- byte[] rawData = Ints.toByteArray(amount);
- PlotPlayer online = UUIDHandler.getPlayer(uuid);
- if (online != null) {
- online.setPersistentMeta(key, rawData);
- } else {
- DBFunc.addPersistentMeta(uuid, key, rawData, replace);
- }
- }
+ });
}
});
return CompletableFuture.completedFuture(true);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Help.java b/Core/src/main/java/com/plotsquared/core/command/Help.java
index a1bbdc244..ef4b5a753 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Help.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Help.java
@@ -52,7 +52,7 @@ public class Help extends Command {
}
@Override
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) {
switch (args.length) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/Inbox.java b/Core/src/main/java/com/plotsquared/core/command/Inbox.java
index 938033758..a042e72cb 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Inbox.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Inbox.java
@@ -86,7 +86,7 @@ public class Inbox extends SubCommand {
MainUtil.sendMessage(player, string.toString());
}
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
final Plot plot = player.getCurrentPlot();
if (plot == null) {
sendMessage(player, Captions.NOT_IN_PLOT);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Info.java b/Core/src/main/java/com/plotsquared/core/command/Info.java
index 23c63450b..125d0008d 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Info.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Info.java
@@ -41,7 +41,7 @@ import com.plotsquared.core.util.task.RunnableVal;
category = CommandCategory.INFO)
public class Info extends SubCommand {
- @Override public boolean onCommand(final PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(final PlotPlayer> player, String[] args) {
Plot plot;
String arg;
if (args.length > 0) {
diff --git a/Core/src/main/java/com/plotsquared/core/command/Kick.java b/Core/src/main/java/com/plotsquared/core/command/Kick.java
index 1d113a874..911ea9810 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Kick.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Kick.java
@@ -33,12 +33,15 @@ import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.Permissions;
+import com.plotsquared.core.util.TabCompletions;
import com.plotsquared.core.util.WorldUtil;
-import com.plotsquared.core.util.uuid.UUIDHandler;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
+import java.util.concurrent.TimeoutException;
@CommandDeclaration(command = "kick",
aliases = "k",
@@ -53,7 +56,7 @@ public class Kick extends SubCommand {
super(Argument.PlayerName);
}
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
Location location = player.getLocation();
Plot plot = location.getPlot();
if (plot == null) {
@@ -64,57 +67,72 @@ public class Kick extends SubCommand {
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
return false;
}
- Set uuids = MainUtil.getUUIDsFromString(args[0]);
- if (uuids.isEmpty()) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
- return false;
- }
- Set players = new HashSet<>();
- for (UUID uuid : uuids) {
- if (uuid == DBFunc.EVERYONE) {
- for (PlotPlayer pp : plot.getPlayersInPlot()) {
- if (pp == player || Permissions
- .hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
+
+ MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
+ if (throwable instanceof TimeoutException) {
+ MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
+ } else if (throwable != null || uuids.isEmpty()) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
+ } else {
+ Set> players = new HashSet<>();
+ for (UUID uuid : uuids) {
+ if (uuid == DBFunc.EVERYONE) {
+ for (PlotPlayer> pp : plot.getPlayersInPlot()) {
+ if (pp == player || Permissions
+ .hasPermission(pp, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
+ continue;
+ }
+ players.add(pp);
+ }
continue;
}
- players.add(pp);
+ PlotPlayer> pp = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
+ if (pp != null) {
+ players.add(pp);
+ }
}
- continue;
- }
- PlotPlayer pp = UUIDHandler.getPlayer(uuid);
- if (pp != null) {
- players.add(pp);
- }
- }
- players.remove(player); // Don't ever kick the calling player
- if (players.isEmpty()) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
- return false;
- }
- for (PlotPlayer player2 : players) {
- if (!plot.equals(player2.getCurrentPlot())) {
- MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
- return false;
- }
- if (Permissions.hasPermission(player2, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
- Captions.CANNOT_KICK_PLAYER.send(player, player2.getName());
- return false;
- }
- Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
- Captions.YOU_GOT_KICKED.send(player2);
- if (plot.equals(spawn.getPlot())) {
- Location newSpawn = WorldUtil.IMP
- .getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]);
- if (plot.equals(newSpawn.getPlot())) {
- // Kick from server if you can't be teleported to spawn
- player2.kick(Captions.YOU_GOT_KICKED.getTranslated());
- } else {
- player2.plotkick(newSpawn);
+ players.remove(player); // Don't ever kick the calling player
+ if (players.isEmpty()) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
+ return;
+ }
+ for (PlotPlayer> player2 : players) {
+ if (!plot.equals(player2.getCurrentPlot())) {
+ MainUtil.sendMessage(player, Captions.INVALID_PLAYER, args[0]);
+ return;
+ }
+ if (Permissions.hasPermission(player2, Captions.PERMISSION_ADMIN_ENTRY_DENIED)) {
+ Captions.CANNOT_KICK_PLAYER.send(player, player2.getName());
+ return;
+ }
+ Location spawn = WorldUtil.IMP.getSpawn(location.getWorld());
+ Captions.YOU_GOT_KICKED.send(player2);
+ if (plot.equals(spawn.getPlot())) {
+ Location newSpawn = WorldUtil.IMP
+ .getSpawn(PlotSquared.get().getPlotAreaManager().getAllWorlds()[0]);
+ if (plot.equals(newSpawn.getPlot())) {
+ // Kick from server if you can't be teleported to spawn
+ player2.kick(Captions.YOU_GOT_KICKED.getTranslated());
+ } else {
+ player2.plotkick(newSpawn);
+ }
+ } else {
+ player2.plotkick(spawn);
+ }
}
- } else {
- player2.plotkick(spawn);
}
- }
+ });
+
return true;
}
+
+ @Override public Collection tab(final PlotPlayer player, final String[] args, final boolean space) {
+ Location location = player.getLocation();
+ Plot plot = location.getPlotAbs();
+ if (plot == null) {
+ return Collections.emptyList();
+ }
+ return TabCompletions.completePlayersInPlot(plot, String.join(",", args).trim(),
+ Collections.singletonList(player.getName()));
+ }
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Leave.java b/Core/src/main/java/com/plotsquared/core/command/Leave.java
index fdd2d70b4..3a0d7f09d 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Leave.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Leave.java
@@ -48,7 +48,7 @@ public class Leave extends Command {
}
@Override
- public CompletableFuture execute(PlotPlayer player, String[] args,
+ public CompletableFuture execute(PlotPlayer> player, String[] args,
RunnableVal3 confirm,
RunnableVal2 whenDone) throws CommandException {
final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT);
diff --git a/Core/src/main/java/com/plotsquared/core/command/Like.java b/Core/src/main/java/com/plotsquared/core/command/Like.java
index 9414985c3..216c6524c 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Like.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Like.java
@@ -175,7 +175,7 @@ public class Like extends SubCommand {
return numLikes / (numLikes + numDislikes);
}
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
return handleLike(player, args, true);
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java
index 8d151fb10..a08de0cd0 100644
--- a/Core/src/main/java/com/plotsquared/core/command/ListCmd.java
+++ b/Core/src/main/java/com/plotsquared/core/command/ListCmd.java
@@ -26,13 +26,12 @@
package com.plotsquared.core.command;
import com.plotsquared.core.PlotSquared;
-import com.plotsquared.core.PlotSquared.SortType;
import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions;
+import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.Plot;
import com.plotsquared.core.plot.PlotArea;
-import com.plotsquared.core.plot.Rating;
import com.plotsquared.core.plot.expiration.ExpireManager;
import com.plotsquared.core.plot.flag.implementations.DoneFlag;
import com.plotsquared.core.plot.flag.implementations.PriceFlag;
@@ -43,26 +42,36 @@ import com.plotsquared.core.util.MathMan;
import com.plotsquared.core.util.Permissions;
import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.StringMan;
+import com.plotsquared.core.util.TabCompletions;
+import com.plotsquared.core.util.query.PlotQuery;
+import com.plotsquared.core.util.query.SortingStrategy;
import com.plotsquared.core.util.task.RunnableVal3;
-import com.plotsquared.core.util.uuid.UUIDHandler;
+import com.plotsquared.core.uuid.UUIDMapping;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
-import java.util.Map.Entry;
import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
+import java.util.stream.Collectors;
@CommandDeclaration(command = "list",
aliases = {"l", "find", "search"},
description = "List plots",
permission = "plots.list",
category = CommandCategory.INFO,
- usage = "/plot list > [#]")
+ usage = "/plot list > [#]")
public class ListCmd extends SubCommand {
private String[] getArgumentList(PlotPlayer player) {
List args = new ArrayList<>();
- if (EconHandler.manager != null && Permissions
+ if (EconHandler.getEconHandler() != null && Permissions
.hasPermission(player, Captions.PERMISSION_LIST_FOR_SALE)) {
args.add("forsale");
}
@@ -84,9 +93,6 @@ public class ListCmd extends SubCommand {
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNOWNED)) {
args.add("unowned");
}
- if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_UNKNOWN)) {
- args.add("unknown");
- }
if (Permissions.hasPermission(player, Captions.PERMISSION_LIST_PLAYER)) {
args.add("");
}
@@ -110,30 +116,58 @@ public class ListCmd extends SubCommand {
.toString(getArgumentList(player)));
}
- @Override public boolean onCommand(PlotPlayer player, String[] args) {
+ @Override public boolean onCommand(PlotPlayer> player, String[] args) {
if (args.length < 1) {
noArgs(player);
return false;
}
- int page = 0;
+
+ final int page;
if (args.length > 1) {
+ int tempPage = -1;
try {
- page = Integer.parseInt(args[args.length - 1]);
- --page;
- if (page < 0) {
- page = 0;
+ tempPage = Integer.parseInt(args[args.length - 1]);
+ --tempPage;
+ if (tempPage < 0) {
+ tempPage = 0;
}
} catch (NumberFormatException ignored) {
- page = -1;
}
+ page = tempPage;
+ } else {
+ page = 0;
}
- List plots = null;
-
String world = player.getLocation().getWorld();
PlotArea area = player.getApplicablePlotArea();
String arg = args[0].toLowerCase();
- boolean sort = true;
+ final boolean[] sort = new boolean[] {true};
+
+ final Consumer plotConsumer = query -> {
+ if (query == null) {
+ sendMessage(player, Captions.DID_YOU_MEAN,
+ new StringComparison<>(args[0], new String[] {"mine", "shared", "world", "all"})
+ .getBestMatch());
+ return;
+ }
+
+ if (area != null) {
+ query.relativeToArea(area);
+ }
+
+ if (sort[0]) {
+ query.withSortingStrategy(SortingStrategy.SORT_BY_CREATION);
+ }
+
+ final List plots = query.asList();
+
+ if (plots.isEmpty()) {
+ MainUtil.sendMessage(player, Captions.FOUND_NO_PLOTS);
+ return;
+ }
+ displayPlots(player, plots, 12, page, args);
+ };
+
switch (arg) {
case "mine":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_MINE)) {
@@ -141,8 +175,8 @@ public class ListCmd extends SubCommand {
.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_LIST_MINE);
return false;
}
- sort = false;
- plots = PlotSquared.get().sortPlotsByTemp(PlotSquared.get().getBasePlots(player));
+ sort[0] = false;
+ plotConsumer.accept(PlotQuery.newQuery().ownedBy(player).whereBasePlot().withSortingStrategy(SortingStrategy.SORT_BY_TEMP));
break;
case "shared":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_SHARED)) {
@@ -150,13 +184,7 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_SHARED);
return false;
}
- plots = new ArrayList<>();
- for (Plot plot : PlotSquared.get().getPlots()) {
- if (plot.getTrusted().contains(player.getUUID()) || plot.getMembers()
- .contains(player.getUUID())) {
- plots.add(plot);
- }
- }
+ plotConsumer.accept(PlotQuery.newQuery().withMember(player.getUUID()).thatPasses(plot -> !plot.isOwnerAbs(player.getUUID())));
break;
case "world":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_WORLD)) {
@@ -171,7 +199,7 @@ public class ListCmd extends SubCommand {
world));
return false;
}
- plots = new ArrayList<>(PlotSquared.get().getPlots(world));
+ plotConsumer.accept(PlotQuery.newQuery().inWorld(world));
break;
case "expired":
if (!Permissions.hasPermission(player, Captions.PERMISSION_LIST_EXPIRED)) {
@@ -179,9 +207,11 @@ public class ListCmd extends SubCommand {
Captions.PERMISSION_LIST_EXPIRED);
return false;
}
- plots = ExpireManager.IMP == null ?
- new ArrayList