From 1fbfc767c4542d22b253da99e9bfd407430197b3 Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Mon, 21 Jan 2019 09:20:33 +0100 Subject: [PATCH 1/9] Use PaperLib and make command task return completable futures --- Bukkit/build.gradle | 7 ++ .../plotsquared/bukkit/BukkitMain.java | 98 +++---------------- .../bukkit/events/PlayerPlotTrustedEvent.java | 4 - .../bukkit/object/BukkitPlayer.java | 78 ++++++++------- .../plotsquared/commands/Command.java | 51 +++++----- .../plotsquared/plot/commands/Add.java | 27 ++--- .../plotsquared/plot/commands/Buy.java | 40 ++++---- .../plotsquared/plot/commands/Clear.java | 49 +++++----- .../plotsquared/plot/commands/DebugExec.java | 4 +- .../plot/commands/DebugImportWorlds.java | 6 +- .../plotsquared/plot/commands/Grant.java | 9 +- .../plotsquared/plot/commands/Help.java | 85 ++++++++-------- .../plotsquared/plot/commands/Leave.java | 4 +- .../plot/commands/MainCommand.java | 89 ++++++++--------- .../plotsquared/plot/commands/Near.java | 5 +- .../plotsquared/plot/commands/Relight.java | 17 ++-- .../plotsquared/plot/commands/SubCommand.java | 7 +- .../plotsquared/plot/commands/Trust.java | 27 ++--- .../plotsquared/plot/commands/Visit.java | 23 +++-- .../plot/object/ConsolePlayer.java | 11 ++- .../plotsquared/plot/object/PlotPlayer.java | 15 +-- 21 files changed, 311 insertions(+), 345 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 3bc057a45..e6a9117bb 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -3,6 +3,10 @@ repositories { maven { url = "https://oss.sonatype.org/content/repositories/snapshots/" } maven { url "http://nexus.hc.to/content/repositories/pub_releases" } maven { url = "https://repo.codemc.org/repository/maven-public" } + maven { + name 'papermc' + url 'https://papermc.io/repo/repository/maven-public/' + } mavenLocal() } @@ -12,6 +16,7 @@ dependencies { compile 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT' compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0-SNAPSHOT') compile(group: 'org.bstats', name: 'bstats-bukkit', version: '1.4') + compile "io.papermc:paperlib:1.0.1" compile("net.milkbowl.vault:VaultAPI:1.7") { exclude module: 'bukkit' } @@ -37,7 +42,9 @@ shadowJar { dependencies { include(dependency(':Core')) include(dependency('org.bstats:bstats-bukkit:1.4')) + include(dependency("io.papermc:paperlib:1.0.1")) } + relocate 'io.papermc.lib', 'com.github.intellectualsites.plotsquared.bukkit.paperlib' // relocate('org.mcstats', 'com.plotsquared.stats') archiveName = "${parent.name}-${project.name}-${parent.version}.jar" destinationDir = file '../target' diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index ae95bd371..bc8fb225e 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -1,36 +1,11 @@ package com.github.intellectualsites.plotsquared.bukkit; -import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; - import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator; -import com.github.intellectualsites.plotsquared.bukkit.listeners.ChunkListener; -import com.github.intellectualsites.plotsquared.bukkit.listeners.EntitySpawnListener; -import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents; -import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener; -import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener; -import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents; +import com.github.intellectualsites.plotsquared.bukkit.listeners.*; import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitBlockRegistry; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitCommand; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEconHandler; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitHybridUtils; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitInventoryUtil; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitLegacyMappings; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSchematicHandler; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSetupUtils; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitTaskManager; -import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; -import com.github.intellectualsites.plotsquared.bukkit.util.SendChunk; -import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB; +import com.github.intellectualsites.plotsquared.bukkit.util.*; import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue; -import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper; -import com.github.intellectualsites.plotsquared.bukkit.uuid.FileUUIDHandler; -import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; -import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper; -import com.github.intellectualsites.plotsquared.bukkit.uuid.SQLUUIDHandler; +import com.github.intellectualsites.plotsquared.bukkit.uuid.*; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.plot.IPlotMain; import com.github.intellectualsites.plotsquared.plot.PlotSquared; @@ -41,57 +16,23 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; import com.github.intellectualsites.plotsquared.plot.generator.HybridGen; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry; -import com.github.intellectualsites.plotsquared.plot.object.Plot; -import com.github.intellectualsites.plotsquared.plot.object.PlotArea; -import com.github.intellectualsites.plotsquared.plot.object.PlotId; -import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; -import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; -import com.github.intellectualsites.plotsquared.plot.object.SetupObject; +import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator; -import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle; -import com.github.intellectualsites.plotsquared.plot.util.ChatManager; -import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; -import com.github.intellectualsites.plotsquared.plot.util.ConsoleColors; -import com.github.intellectualsites.plotsquared.plot.util.EconHandler; -import com.github.intellectualsites.plotsquared.plot.util.EventUtil; -import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil; -import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings; -import com.github.intellectualsites.plotsquared.plot.util.MainUtil; -import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils; -import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; -import com.github.intellectualsites.plotsquared.plot.util.SetupUtils; -import com.github.intellectualsites.plotsquared.plot.util.StringMan; -import com.github.intellectualsites.plotsquared.plot.util.TaskManager; -import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; -import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation; -import com.github.intellectualsites.plotsquared.plot.util.WorldUtil; +import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.extension.platform.Capability; -import java.io.File; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.UUID; -import javax.annotation.Nullable; +import io.papermc.lib.PaperLib; import lombok.Getter; import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Chunk; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -104,6 +45,13 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import javax.annotation.Nullable; +import java.io.File; +import java.lang.reflect.Method; +import java.util.*; + +import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; + public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Getter private static WorldEdit worldEdit; @@ -170,23 +118,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain getServer().getName(); PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer); - - if (Bukkit.getVersion().contains("git-Spigot")) { - // Uses System.out.println because the logger isn't initialized yet - System.out - .println("[P2] ========================== USE PAPER =========================="); - System.out.println("[P2] Paper offers a more complete API for us to work with"); - System.out.println("[P2] and we may come to rely on it in the future."); - System.out.println("[P2] It is also recommended out of a performance standpoint as"); - System.out - .println("[P2] it contains many improvements missing from Spigot and Bukkit."); - System.out.println("[P2] DOWNLOAD: https://papermc.io/downloads"); - System.out.println("[P2] GUIDE: https://www.spigotmc.org/threads/21726/"); - System.out.println("[P2] NOTE: This is only a recommendation"); - System.out.println("[P2] both Spigot and CraftBukkit are still supported."); - System.out - .println("[P2] ==============================================================="); - } + PaperLib.suggestPaper(this); new PlotSquared(this, "Bukkit"); if (Settings.Enabled_Components.METRICS) { diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java index 95440056f..f2f9efe71 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlayerPlotTrustedEvent.java @@ -6,10 +6,6 @@ import org.bukkit.event.HandlerList; import java.util.UUID; -/** - - - */ public class PlayerPlotTrustedEvent extends PlotEvent { private static final HandlerList handlers = new HandlerList(); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java index 7aecb854c..1255c0fc4 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/object/BukkitPlayer.java @@ -7,15 +7,20 @@ import com.github.intellectualsites.plotsquared.plot.object.Location; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.util.*; -import org.bukkit.*; +import com.google.common.base.Preconditions; +import io.papermc.lib.PaperLib; +import org.bukkit.GameMode; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.WeatherType; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventException; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.plugin.RegisteredListener; +import javax.annotation.Nonnull; import java.util.Arrays; import java.util.Set; import java.util.UUID; @@ -24,7 +29,7 @@ import java.util.stream.Collectors; public class BukkitPlayer extends PlotPlayer { public final Player player; - public boolean offline; + private boolean offline; private UUID uuid; private String name; @@ -32,21 +37,23 @@ public class BukkitPlayer extends PlotPlayer { *

Please do not use this method. Instead use * BukkitUtil.getPlayer(Player), as it caches player objects.

* - * @param player + * @param player Bukkit player instance */ - public BukkitPlayer(Player player) { + public BukkitPlayer(@Nonnull final Player player) { + Preconditions.checkNotNull(player, "Bukkit player instance cannot be null"); this.player = player; super.populatePersistentMetaMap(); } - public BukkitPlayer(Player player, boolean offline) { + public BukkitPlayer(@Nonnull final Player player, final boolean offline) { + Preconditions.checkNotNull(player, "Bukkit player instance cannot be null"); this.player = player; this.offline = offline; super.populatePersistentMetaMap(); } @Override public Location getLocation() { - Location location = super.getLocation(); + final Location location = super.getLocation(); return location == null ? BukkitUtil.getLocation(this.player) : location; } @@ -61,9 +68,10 @@ public class BukkitPlayer extends PlotPlayer { return this.player.getLastPlayed(); } - @Override public boolean canTeleport(Location loc) { - org.bukkit.Location to = BukkitUtil.getLocation(loc); - org.bukkit.Location from = player.getLocation(); + @Override public boolean canTeleport(@Nonnull final Location loc) { + Preconditions.checkNotNull(loc, "Bukkit location cannot be null"); + final org.bukkit.Location to = BukkitUtil.getLocation(loc); + final org.bukkit.Location from = player.getLocation(); PlayerTeleportEvent event = new PlayerTeleportEvent(player, from, to); callEvent(event); if (event.isCancelled() || !event.getTo().equals(to)) { @@ -75,32 +83,34 @@ public class BukkitPlayer extends PlotPlayer { } private void callEvent(final Event event) { - RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners(); - for (RegisteredListener listener : listeners) { + Preconditions.checkNotNull(event, "Event cannot be null"); + + final RegisteredListener[] listeners = event.getHandlers().getRegisteredListeners(); + for (final RegisteredListener listener : listeners) { if (listener.getPlugin().getName().equals(PlotSquared.imp().getPluginName())) { continue; } try { listener.callEvent(event); - } catch (EventException e) { + } catch (final EventException e) { e.printStackTrace(); } } } - @Override public boolean hasPermission(String permission) { + @Override public boolean hasPermission(final String permission) { if (this.offline && EconHandler.manager != null) { return EconHandler.manager.hasPermission(getName(), permission); } return this.player.hasPermission(permission); } - @Override public int hasPermissionRange(String stub, int range) { + @Override public int hasPermissionRange(final String stub, final int range) { if (hasPermission(C.PERMISSION_ADMIN.s())) { return Integer.MAX_VALUE; } - String[] nodes = stub.split("\\."); - StringBuilder n = new StringBuilder(); + final String[] nodes = stub.split("\\."); + final StringBuilder n = new StringBuilder(); for (int i = 0; i < (nodes.length - 1); i++) { n.append(nodes[i]).append("."); if (!stub.equals(n + C.PERMISSION_STAR.s())) { @@ -114,7 +124,7 @@ public class BukkitPlayer extends PlotPlayer { } int max = 0; String stubPlus = stub + "."; - Set effective = player.getEffectivePermissions(); + final Set effective = player.getEffectivePermissions(); if (!effective.isEmpty()) { for (PermissionAttachmentInfo attach : effective) { String perm = attach.getPermission(); @@ -139,12 +149,12 @@ public class BukkitPlayer extends PlotPlayer { return max; } - @Override public boolean isPermissionSet(String permission) { + @Override public boolean isPermissionSet(final String permission) { return this.player.isPermissionSet(permission); } - @Override public void sendMessage(String message) { - if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || ( + @Override public void sendMessage(final String message) { + if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || ( System.currentTimeMillis() - this.getMeta("lastMessageTime") > 5000)) { setMeta("lastMessage", message); setMeta("lastMessageTime", System.currentTimeMillis()); @@ -152,14 +162,13 @@ public class BukkitPlayer extends PlotPlayer { } } - @Override public void teleport(Location location) { + @Override public void teleport(@Nonnull final Location location) { if (Math.abs(location.getX()) >= 30000000 || Math.abs(location.getZ()) >= 30000000) { return; } - this.player.teleport( - new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, - location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()), - TeleportCause.COMMAND); + final org.bukkit.Location bukkitLocation = new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX() + 0.5, + location.getY(), location.getZ() + 0.5, location.getYaw(), location.getPitch()); + PaperLib.teleportAsync(player, bukkitLocation); } @Override public String getName() { @@ -177,14 +186,14 @@ public class BukkitPlayer extends PlotPlayer { this.player.setCompassTarget( new org.bukkit.Location(BukkitUtil.getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ())); - } @Override public Location getLocationFull() { return BukkitUtil.getLocationFull(this.player); } - @Override public void setWeather(PlotWeather weather) { + @Override public void setWeather(@Nonnull final PlotWeather weather) { + Preconditions.checkNotNull(weather, "Specified weather cannot be null"); switch (weather) { case CLEAR: this.player.setPlayerWeather(WeatherType.CLEAR); @@ -201,7 +210,7 @@ public class BukkitPlayer extends PlotPlayer { } } - @Override public PlotGameMode getGameMode() { + @Nonnull @Override public PlotGameMode getGameMode() { switch (this.player.getGameMode()) { case ADVENTURE: return PlotGameMode.ADVENTURE; @@ -216,7 +225,8 @@ public class BukkitPlayer extends PlotPlayer { } } - @Override public void setGameMode(PlotGameMode gameMode) { + @Override public void setGameMode(@Nonnull final PlotGameMode gameMode) { + Preconditions.checkNotNull(gameMode, "Specified gamemode cannot be null"); switch (gameMode) { case ADVENTURE: this.player.setGameMode(GameMode.ADVENTURE); @@ -236,7 +246,7 @@ public class BukkitPlayer extends PlotPlayer { } } - @Override public void setTime(long time) { + @Override public void setTime(final long time) { if (time != Long.MAX_VALUE) { this.player.setPlayerTime(time, false); } else { @@ -252,7 +262,9 @@ public class BukkitPlayer extends PlotPlayer { this.player.setAllowFlight(fly); } - @Override public void playMusic(Location location, PlotBlock id) { + @Override public void playMusic(@Nonnull final Location location, @Nonnull final PlotBlock id) { + Preconditions.checkNotNull(location, "Specified location cannot be null"); + Preconditions.checkNotNull(id, "Specified block cannot be null"); if (PlotBlock.isEverything(id) || id.isAir()) { // Let's just stop all the discs because why not? for (final Sound sound : Arrays.stream(Sound.values()).filter(sound -> sound.name().contains("DISC")).collect( @@ -266,7 +278,7 @@ public class BukkitPlayer extends PlotPlayer { } } - @Override public void kick(String message) { + @Override public void kick(final String message) { this.player.kickPlayer(message); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java index 6bac09a26..a581b8585 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/commands/Command.java @@ -13,10 +13,10 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.*; import java.io.IOException; -import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.*; +import java.util.concurrent.CompletableFuture; public abstract class Command { @@ -56,10 +56,9 @@ public abstract class Command { public Command(Command parent, boolean isStatic) { this.parent = parent; this.isStatic = isStatic; - Annotation cdAnnotation = getClass().getAnnotation(CommandDeclaration.class); + CommandDeclaration cdAnnotation = getClass().getAnnotation(CommandDeclaration.class); if (cdAnnotation != null) { - CommandDeclaration declaration = (CommandDeclaration) cdAnnotation; - init(declaration); + init(cdAnnotation); } for (final Method method : getClass().getDeclaredMethods()) { if (method.isAnnotationPresent(CommandDeclaration.class)) { @@ -70,14 +69,16 @@ public abstract class Command { && types[2] == String[].class && types[3] == RunnableVal3.class && types[4] == RunnableVal2.class) { Command tmp = new Command(this, true) { - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { try { method.invoke(Command.this, this, player, args, confirm, whenDone); + return CompletableFuture.completedFuture(true); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } + return CompletableFuture.completedFuture(false); } }; tmp.init(method.getAnnotation(CommandDeclaration.class)); @@ -263,9 +264,10 @@ public abstract class Command { * @param player Caller * @param args Arguments * @param confirm Instance, Success, Failure - * @return + * @return CompletableFuture true if the command executed fully, false in + * any other case */ - public void 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) { @@ -274,28 +276,28 @@ public abstract class Command { } else { C.COMMAND_SYNTAX.send(player, getUsage()); } - return; + return CompletableFuture.completedFuture(false); } - if (this.allCommands == null || this.allCommands.isEmpty()) { + if (this.allCommands.isEmpty()) { player.sendMessage( "Not Implemented: https://github.com/IntellectualSites/PlotSquared/issues/new"); - return; + return CompletableFuture.completedFuture(false); } Command cmd = getCommand(args[0]); if (cmd == null) { if (this.parent != null) { C.COMMAND_SYNTAX.send(player, getUsage()); - return; + return CompletableFuture.completedFuture(false); } // Help command try { - if (args.length == 0 || MathMan.isInteger(args[0]) - || CommandCategory.valueOf(args[0].toUpperCase()) != null) { - // This will default certain syntax to the help command - // e.g. /plot, /plot 1, /plot claiming - MainCommand.getInstance().help.execute(player, args, null, null); - return; + if (!MathMan.isInteger(args[0])) { + CommandCategory.valueOf(args[0].toUpperCase()); } + // This will default certain syntax to the help command + // e.g. /plot, /plot 1, /plot claiming + MainCommand.getInstance().help.execute(player, args, null, null); + return CompletableFuture.completedFuture(false); } catch (IllegalArgumentException ignored) { } // Command recommendation @@ -304,16 +306,16 @@ public abstract class Command { if (commands.isEmpty()) { MainUtil .sendMessage(player, C.DID_YOU_MEAN, MainCommand.getInstance().help.getUsage()); - return; + return CompletableFuture.completedFuture(false); } - HashSet setargs = new HashSet<>(args.length); + HashSet setArgs = new HashSet<>(args.length); for (String arg : args) { - setargs.add(arg.toLowerCase()); + setArgs.add(arg.toLowerCase()); } - String[] allargs = setargs.toArray(new String[setargs.size()]); + String[] allArgs = setArgs.toArray(new String[0]); int best = 0; for (Command current : commands) { - int match = getMatch(allargs, current); + int match = getMatch(allArgs, current); if (match > best) { cmd = current; } @@ -322,17 +324,18 @@ public abstract class Command { cmd = new StringComparison<>(args[0], this.allCommands).getMatchObject(); } MainUtil.sendMessage(player, C.DID_YOU_MEAN, cmd.getUsage()); - return; + return CompletableFuture.completedFuture(false); } String[] newArgs = Arrays.copyOfRange(args, 1, args.length); if (!cmd.checkArgs(player, newArgs) || !cmd.canExecute(player, true)) { - return; + return CompletableFuture.completedFuture(false); } try { cmd.execute(player, newArgs, confirm, whenDone); } catch (CommandException e) { e.perform(player); } + return CompletableFuture.completedFuture(true); } public boolean checkArgs(PlotPlayer player, String[] args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java index 03d27555a..ed70d96d6 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java @@ -15,6 +15,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import java.util.Iterator; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "add", description = "Allow a user to build in a plot while you are online", @@ -25,7 +26,7 @@ import java.util.UUID; super(MainCommand.getInstance(), true); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT); @@ -61,22 +62,22 @@ import java.util.UUID; checkTrue(!uuids.isEmpty(), null); checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions .hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.PLOT_MAX_MEMBERS); - confirm.run(this, new Runnable() { - @Override // Success - public void run() { - for (UUID uuid : uuids) { - if (uuid != DBFunc.EVERYONE) { - if (!plot.removeTrusted(uuid)) { - if (plot.getDenied().contains(uuid)) { - plot.removeDenied(uuid); - } + // 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); - EventUtil.manager.callMember(player, plot, uuid, true); - MainUtil.sendMessage(player, C.MEMBER_ADDED); } + plot.addMember(uuid); + EventUtil.manager.callMember(player, plot, uuid, true); + MainUtil.sendMessage(player, C.MEMBER_ADDED); } }, null); + + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java index 25f9484b1..5c6a88b93 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Buy.java @@ -14,6 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import java.util.Optional; import java.util.Set; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "buy", description = "Buy the plot you are standing on", usage = "/plot buy", permission = "plots.buy", category = CommandCategory.CLAIMING, @@ -23,7 +24,7 @@ import java.util.Set; super(MainCommand.getInstance(), true); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, final RunnableVal2 whenDone) { check(EconHandler.manager, C.ECON_DISABLED); @@ -46,27 +47,24 @@ import java.util.Set; final double price = flag.get(); checkTrue(player.getMoney() >= price, C.CANNOT_AFFORD_PLOT); player.withdraw(price); - confirm.run(this, new Runnable() { - @Override // Success - public void run() { - C.REMOVED_BALANCE.send(player, price); - EconHandler.manager - .depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price); - PlotPlayer owner = UUIDHandler.getPlayer(plot.owner); - if (owner != null) { - C.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); - } - plot.removeFlag(Flags.PRICE); - plot.setOwner(player.getUUID()); - C.CLAIMED.send(player); - whenDone.run(Buy.this, CommandResult.SUCCESS); - } - }, new Runnable() { - @Override // Failure - public void run() { - player.deposit(price); - whenDone.run(Buy.this, CommandResult.FAILURE); + // Failure + // Success + confirm.run(this, () -> { + C.REMOVED_BALANCE.send(player, price); + EconHandler.manager + .depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price); + PlotPlayer owner = UUIDHandler.getPlayer(plot.owner); + if (owner != null) { + C.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); } + plot.removeFlag(Flags.PRICE); + plot.setOwner(player.getUUID()); + C.CLAIMED.send(player); + whenDone.run(Buy.this, CommandResult.SUCCESS); + }, () -> { + player.deposit(price); + whenDone.run(Buy.this, CommandResult.FAILURE); }); + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java index efd6b1525..b4de09259 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Clear.java @@ -14,6 +14,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; +import java.util.concurrent.CompletableFuture; + @CommandDeclaration(command = "clear", description = "Clear the plot you stand on", permission = "plots.clear", category = CommandCategory.APPEARANCE, usage = "/plot clear", aliases = "reset", confirmation = true) public class Clear extends Command { @@ -25,7 +27,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue super(MainCommand.getInstance(), true); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { checkTrue(args.length == 0, C.COMMAND_SYNTAX, getUsage()); @@ -35,34 +37,29 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue checkTrue(plot.getRunning() == 0, C.WAIT_FOR_TIMER); checkTrue(!Settings.Done.RESTRICT_BUILDING || !Flags.DONE.isSet(plot) || Permissions .hasPermission(player, C.PERMISSION_CONTINUE), C.DONE_ALREADY_DONE); - confirm.run(this, new Runnable() { - @Override public void run() { - final long start = System.currentTimeMillis(); - boolean result = plot.clear(true, false, new Runnable() { - @Override public void run() { - plot.unlink(); - GlobalBlockQueue.IMP.addTask(new Runnable() { - @Override public void run() { - plot.removeRunning(); - // If the state changes, then mark it as no longer done - if (plot.getFlag(Flags.DONE).isPresent()) { - FlagManager.removePlotFlag(plot, Flags.DONE); - } - if (plot.getFlag(Flags.ANALYSIS).isPresent()) { - FlagManager.removePlotFlag(plot, Flags.ANALYSIS); - } - MainUtil.sendMessage(player, C.CLEARING_DONE, - "" + (System.currentTimeMillis() - start)); - } - }); + confirm.run(this, () -> { + final long start = System.currentTimeMillis(); + boolean result = plot.clear(true, false, () -> { + plot.unlink(); + GlobalBlockQueue.IMP.addTask(() -> { + plot.removeRunning(); + // If the state changes, then mark it as no longer done + if (plot.getFlag(Flags.DONE).isPresent()) { + FlagManager.removePlotFlag(plot, Flags.DONE); } + if (plot.getFlag(Flags.ANALYSIS).isPresent()) { + FlagManager.removePlotFlag(plot, Flags.ANALYSIS); + } + MainUtil.sendMessage(player, C.CLEARING_DONE, + "" + (System.currentTimeMillis() - start)); }); - if (!result) { - MainUtil.sendMessage(player, C.WAIT_FOR_TIMER); - } else { - plot.addRunning(); - } + }); + if (!result) { + MainUtil.sendMessage(player, C.WAIT_FOR_TIMER); + } else { + plot.addRunning(); } }, null); + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java index dfcda68ae..f0f4e148a 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.sql.Timestamp; import java.util.*; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "debugexec", permission = "plots.admin", description = "Mutli-purpose debug command", aliases = {"exec", "$"}, @@ -265,7 +266,7 @@ import java.util.*; System.getProperty("line.separator")); new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null, RequiredType.NONE, CommandCategory.DEBUG) { - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { try { @@ -276,6 +277,7 @@ import java.util.*; e.printStackTrace(); MainUtil.sendMessage(player, C.COMMAND_WENT_WRONG); } + return CompletableFuture.completedFuture(true); } }; return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java index ddffaf744..8a4cfe613 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java @@ -16,6 +16,7 @@ import com.google.common.base.Charsets; import java.io.File; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "debugimportworlds", permission = "plots.admin", description = "Import worlds by player name", requiredType = RequiredType.CONSOLE, @@ -24,14 +25,14 @@ import java.util.UUID; super(MainCommand.getInstance(), true); } - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { // UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)) PlotAreaManager pam = PlotSquared.get().getPlotAreaManager(); if (!(pam instanceof SinglePlotAreaManager)) { player.sendMessage("Must be a single plot area!"); - return; + return CompletableFuture.completedFuture(false); } SinglePlotArea area = ((SinglePlotAreaManager) pam).getArea(); PlotId id = new PlotId(0, 0); @@ -54,5 +55,6 @@ import java.util.UUID; } } player.sendMessage("Done!"); + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java index d29bd76bb..18938f2ee 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Grant.java @@ -14,6 +14,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "grant", category = CommandCategory.CLAIMING, usage = "/plot grant [player]", permission = "plots.grant", @@ -23,7 +24,7 @@ import java.util.UUID; super(MainCommand.getInstance(), true); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { checkTrue(args.length >= 1 && args.length <= 2, C.COMMAND_SYNTAX, getUsage()); @@ -33,7 +34,7 @@ import java.util.UUID; case "check": if (!Permissions.hasPermission(player, C.PERMISSION_GRANT.f(arg0))) { C.NO_PERMISSION.send(player, C.PERMISSION_GRANT.f(arg0)); - return; + return CompletableFuture.completedFuture(false); } if (args.length > 2) { break; @@ -42,7 +43,7 @@ import java.util.UUID; args.length == 2 ? UUIDHandler.getUUIDFromString(args[1]) : player.getUUID(); if (uuid == null) { C.INVALID_PLAYER.send(player, args[1]); - return; + return CompletableFuture.completedFuture(false); } MainUtil.getPersistentMeta(uuid, "grantedPlots", new RunnableVal() { @Override public void run(byte[] array) { @@ -65,7 +66,9 @@ import java.util.UUID; } } }); + return CompletableFuture.completedFuture(true); } C.COMMAND_SYNTAX.send(player, getUsage()); + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java index f0ff64af1..a62d1ab6f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java @@ -11,6 +11,8 @@ import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.helpmenu.HelpMenu; +import java.util.concurrent.CompletableFuture; + @CommandDeclaration(command = "help", description = "Get this help menu", aliases = {"he", "?"}, category = CommandCategory.INFO, usage = "help [category|#]", permission = "plots.use") public class Help extends Command { @@ -22,72 +24,73 @@ public class Help extends Command { return true; } - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { switch (args.length) { case 0: - displayHelp(player, null, 0); - return; + return displayHelp(player, null, 0); case 1: if (MathMan.isInteger(args[0])) { try { - displayHelp(player, null, Integer.parseInt(args[0])); + return displayHelp(player, null, Integer.parseInt(args[0])); } catch (NumberFormatException ignored) { - displayHelp(player, null, 1); + return displayHelp(player, null, 1); } } else { - displayHelp(player, args[0], 1); + return displayHelp(player, args[0], 1); } - return; case 2: if (MathMan.isInteger(args[1])) { try { - displayHelp(player, args[0], Integer.parseInt(args[1])); + return displayHelp(player, args[0], Integer.parseInt(args[1])); } catch (NumberFormatException ignored) { - displayHelp(player, args[0], 1); + return displayHelp(player, args[0], 1); } } - return; + return CompletableFuture.completedFuture(false); default: C.COMMAND_SYNTAX.send(player, getUsage()); } + return CompletableFuture.completedFuture(true); } - public void displayHelp(PlotPlayer player, String cat, int page) { - CommandCategory catEnum = null; - if (cat != null) { - if (StringMan.isEqualIgnoreCase(cat, "all")) { - catEnum = null; - } else { - for (CommandCategory c : CommandCategory.values()) { - if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString())) { - catEnum = c; - cat = c.name(); - break; + public CompletableFuture displayHelp(final PlotPlayer player, final String catRaw, final int page) { + return CompletableFuture.supplyAsync(() -> { + String cat = catRaw; + + CommandCategory catEnum = null; + if (cat != null) { + if (!StringMan.isEqualIgnoreCase(cat, "all")) { + for (CommandCategory c : CommandCategory.values()) { + if (StringMan.isEqualIgnoreCaseToAny(cat, c.name(), c.toString())) { + catEnum = c; + cat = c.name(); + break; + } + } + if (catEnum == null) { + cat = null; } } - if (catEnum == null) { - cat = null; + } + if (cat == null && page == 0) { + StringBuilder builder = new StringBuilder(); + builder.append(C.HELP_HEADER.s()); + for (CommandCategory c : CommandCategory.values()) { + builder.append("\n").append(StringMan + .replaceAll(C.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), + "%category_desc%", c.toString())); } + builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all") + .replaceAll("%category_desc%", "Display all commands")); + builder.append("\n").append(C.HELP_FOOTER.s()); + MainUtil.sendMessage(player, builder.toString(), false); + return true; } - } - if (cat == null && page == 0) { - StringBuilder builder = new StringBuilder(); - builder.append(C.HELP_HEADER.s()); - for (CommandCategory c : CommandCategory.values()) { - builder.append("\n" + StringMan - .replaceAll(C.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), - "%category_desc%", c.toString())); - } - builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all") - .replaceAll("%category_desc%", "Display all commands")); - builder.append("\n" + C.HELP_FOOTER.s()); - MainUtil.sendMessage(player, builder.toString(), false); - return; - } - page--; - new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages() - .generatePage(page, getParent().toString()).render(); + new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages() + .generatePage(page - 1, getParent().toString()).render(); + return true; + }); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java index 5504ce777..cf49be592 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Leave.java @@ -11,6 +11,7 @@ import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "leave", description = "Removes self from being trusted or a member of the plot", @@ -20,7 +21,7 @@ import java.util.UUID; super(MainCommand.getInstance(), true); } - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT); @@ -44,5 +45,6 @@ import java.util.UUID; MainUtil.sendMessage(player, C.REMOVED_PLAYERS, 1); } } + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java index 0e1630e76..c50c5a221 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/MainCommand.java @@ -10,6 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.Permissions; import java.util.Arrays; +import java.util.concurrent.CompletableFuture; /** * PlotSquared command class. @@ -126,27 +127,25 @@ public class MainCommand extends Command { @Override public void run(final Command cmd, final Runnable success, final Runnable failure) { if (cmd.hasConfirmation(player)) { - CmdConfirm.addPending(player, cmd.getUsage(), new Runnable() { - @Override public void run() { - if (EconHandler.manager != null) { - PlotArea area = player.getApplicablePlotArea(); - if (area != null) { - Expression priceEval = - area.PRICES.get(cmd.getFullId()); - Double price = - priceEval != null ? priceEval.evaluate(0d) : 0d; - if (price != null - && EconHandler.manager.getMoney(player) < price) { - if (failure != null) { - failure.run(); - } - return; + CmdConfirm.addPending(player, cmd.getUsage(), () -> { + if (EconHandler.manager != null) { + PlotArea area = player.getApplicablePlotArea(); + if (area != null) { + Expression priceEval = + area.PRICES.get(cmd.getFullId()); + Double price = + priceEval != null ? priceEval.evaluate(0d) : 0d; + if (price != null + && EconHandler.manager.getMoney(player) < price) { + if (failure != null) { + failure.run(); } + return; } } - if (success != null) { - success.run(); - } + } + if (success != null) { + success.run(); } }); return; @@ -172,6 +171,8 @@ public class MainCommand extends Command { @Override public void run(Command cmd, CommandResult result) { // Post command stuff!? } + }).thenAccept(result -> { + // TODO: Something with the command result }); } catch (CommandException e) { e.perform(player); @@ -187,7 +188,7 @@ public class MainCommand extends Command { PlotSquared.debug("Command registration is now done during instantiation"); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { // Clear perm caching // @@ -218,37 +219,32 @@ public class MainCommand extends Command { args = Arrays.copyOfRange(args, 1, args.length); } if (args.length >= 2 && !args[0].isEmpty() && args[0].charAt(0) == '-') { - switch (args[0].substring(1)) { - case "f": - confirm = new RunnableVal3() { - @Override - public void run(Command cmd, Runnable success, Runnable failure) { - if (EconHandler.manager != null) { - PlotArea area = player.getApplicablePlotArea(); - if (area != null) { - Expression priceEval = - area.PRICES.get(cmd.getFullId()); - Double price = - priceEval != null ? priceEval.evaluate(0d) : 0d; - if (price != 0d - && EconHandler.manager.getMoney(player) < price) { - if (failure != null) { - failure.run(); - } - return; + if ("f".equals(args[0].substring(1))) { + confirm = new RunnableVal3() { + @Override public void run(Command cmd, Runnable success, Runnable failure) { + if (EconHandler.manager != null) { + PlotArea area = player.getApplicablePlotArea(); + if (area != null) { + Expression priceEval = area.PRICES.get(cmd.getFullId()); + Double price = priceEval != null ? priceEval.evaluate(0d) : 0d; + if (price != 0d + && EconHandler.manager.getMoney(player) < price) { + if (failure != null) { + failure.run(); } + return; } } - if (success != null) { - success.run(); - } } - }; - args = Arrays.copyOfRange(args, 1, args.length); - break; - default: - C.INVALID_COMMAND_FLAG.send(player); - return; + if (success != null) { + success.run(); + } + } + }; + args = Arrays.copyOfRange(args, 1, args.length); + } else { + C.INVALID_COMMAND_FLAG.send(player); + return CompletableFuture.completedFuture(false); } } } @@ -278,6 +274,7 @@ public class MainCommand extends Command { player.setMeta(PlotPlayer.META_LAST_PLOT, plot); } } + return CompletableFuture.completedFuture(true); } @Override public boolean canExecute(PlotPlayer player, boolean message) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java index c3e9c5f9e..e2278c4e2 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Near.java @@ -9,16 +9,19 @@ import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; import com.github.intellectualsites.plotsquared.plot.util.StringMan; +import java.util.concurrent.CompletableFuture; + @CommandDeclaration(command = "near", aliases = "n", description = "Display nearby players", usage = "/plot near", category = CommandCategory.INFO) public class Near extends Command { public Near() { super(MainCommand.getInstance(), true); } - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT); C.PLOT_NEAR.send(player, StringMan.join(plot.getPlayersInPlot(), ", ")); + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java index 79a87b887..0d3638fe3 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Relight.java @@ -7,7 +7,7 @@ import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; -import java.util.HashSet; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "relight", description = "Relight your plot", usage = "/plot relight", category = CommandCategory.DEBUG) public class Relight extends Command { @@ -15,25 +15,24 @@ import java.util.HashSet; super(MainCommand.getInstance(), true); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { final Plot plot = player.getCurrentPlot(); if (plot == null) { C.NOT_IN_PLOT.send(player); - return; + return CompletableFuture.completedFuture(false); } - HashSet regions = plot.getRegions(); final LocalBlockQueue queue = plot.getArea().getQueue(false); ChunkManager.chunkTask(plot, new RunnableVal() { @Override public void run(int[] value) { queue.fixChunkLighting(value[0], value[1]); } - }, new Runnable() { - @Override public void run() { - plot.refreshChunks(); - C.SET_BLOCK_ACTION_FINISHED.send(player); - } + }, () -> { + plot.refreshChunks(); + C.SET_BLOCK_ACTION_FINISHED.send(player); }, 5); + + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SubCommand.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SubCommand.java index 396185e29..f0055829d 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SubCommand.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SubCommand.java @@ -7,6 +7,8 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3; +import java.util.concurrent.CompletableFuture; + /** * SubCommand class * @@ -23,13 +25,12 @@ public abstract class SubCommand extends Command { setRequiredArguments(arguments); } - @Override public void execute(PlotPlayer player, String[] args, + @Override public CompletableFuture execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { - onCommand(player, args); + return CompletableFuture.completedFuture(onCommand(player, args)); } - public abstract boolean onCommand(PlotPlayer player, String[] args); public boolean sendMessage(PlotPlayer player, C message, Object... args) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java index 6e6f0c5ab..7b6dfb761 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java @@ -15,6 +15,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import java.util.Iterator; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "trust", aliases = {"t"}, requiredType = RequiredType.NONE, usage = "/plot trust ", @@ -25,7 +26,7 @@ import java.util.UUID; super(MainCommand.getInstance(), true); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { final Plot plot = check(player.getCurrentPlot(), C.NOT_IN_PLOT); @@ -61,22 +62,22 @@ import java.util.UUID; checkTrue(!uuids.isEmpty(), null); checkTrue(size <= plot.getArea().MAX_PLOT_MEMBERS || Permissions .hasPermission(player, C.PERMISSION_ADMIN_COMMAND_TRUST), C.PLOT_MAX_MEMBERS); - confirm.run(this, new Runnable() { - @Override // Success - public void run() { - for (UUID uuid : uuids) { - if (uuid != DBFunc.EVERYONE) { - if (!plot.removeMember(uuid)) { - if (plot.getDenied().contains(uuid)) { - plot.removeDenied(uuid); - } + // Success + confirm.run(this, () -> { + for (UUID uuid : uuids) { + if (uuid != DBFunc.EVERYONE) { + if (!plot.removeMember(uuid)) { + if (plot.getDenied().contains(uuid)) { + plot.removeDenied(uuid); } } - plot.addTrusted(uuid); - EventUtil.manager.callTrusted(player, plot, uuid, true); - MainUtil.sendMessage(player, C.TRUSTED_ADDED); } + plot.addTrusted(uuid); + EventUtil.manager.callTrusted(player, plot, uuid, true); + MainUtil.sendMessage(player, C.TRUSTED_ADDED); } }, null); + + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java index 8f1e50f16..6bd269968 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java @@ -12,6 +12,7 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions; import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import java.util.*; +import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "visit", permission = "plots.visit", description = "Visit someones plot", usage = "/plot visit [|||] [#]", @@ -26,7 +27,7 @@ import java.util.*; return tabOf(player, args, space, getUsage()); } - @Override public void execute(final PlotPlayer player, String[] args, + @Override public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, final RunnableVal2 whenDone) throws CommandException { if (args.length == 1 && args[0].contains(":")) { @@ -41,7 +42,7 @@ import java.util.*; if (!MathMan.isInteger(args[1])) { C.NOT_VALID_NUMBER.send(player, "(1, ∞)"); C.COMMAND_SYNTAX.send(player, getUsage()); - return; + return CompletableFuture.completedFuture(false); } page = Integer.parseInt(args[2]); case 2: @@ -50,12 +51,12 @@ import java.util.*; if (sortByArea == null) { C.NOT_VALID_NUMBER.send(player, "(1, ∞)"); C.COMMAND_SYNTAX.send(player, getUsage()); - return; + return CompletableFuture.completedFuture(false); } UUID user = UUIDHandler.getUUIDFromString(args[0]); if (user == null) { C.COMMAND_SYNTAX.send(player, getUsage()); - return; + return CompletableFuture.completedFuture(false); } unsorted = PlotSquared.get().getBasePlots(user); shouldSortByArea = true; @@ -92,13 +93,13 @@ import java.util.*; } if (unsorted == null || unsorted.isEmpty()) { C.FOUND_NO_PLOTS.send(player); - return; + return CompletableFuture.completedFuture(false); } unsorted = new ArrayList<>(unsorted); unsorted.removeIf(plot -> !plot.isBasePlot()); if (page < 1 || page > unsorted.size()) { C.NOT_VALID_NUMBER.send(player, "(1, " + unsorted.size() + ")"); - return; + return CompletableFuture.completedFuture(false); } List plots; if (shouldSortByArea) { @@ -111,23 +112,23 @@ import java.util.*; if (!plot.hasOwner()) { if (!Permissions.hasPermission(player, C.PERMISSION_VISIT_UNOWNED)) { C.NO_PERMISSION.send(player, C.PERMISSION_VISIT_UNOWNED); - return; + return CompletableFuture.completedFuture(false); } } else if (plot.isOwner(player.getUUID())) { if (!Permissions.hasPermission(player, C.PERMISSION_VISIT_OWNED) && !Permissions .hasPermission(player, C.PERMISSION_HOME)) { C.NO_PERMISSION.send(player, C.PERMISSION_VISIT_OWNED); - return; + return CompletableFuture.completedFuture(false); } } else if (plot.isAdded(player.getUUID())) { if (!Permissions.hasPermission(player, C.PERMISSION_SHARED)) { C.NO_PERMISSION.send(player, C.PERMISSION_SHARED); - return; + return CompletableFuture.completedFuture(false); } } else { if (!Permissions.hasPermission(player, C.PERMISSION_VISIT_OTHER)) { C.NO_PERMISSION.send(player, C.PERMISSION_VISIT_OTHER); - return; + return CompletableFuture.completedFuture(false); } } confirm.run(this, () -> { @@ -137,6 +138,8 @@ import java.util.*; whenDone.run(Visit.this, CommandResult.FAILURE); } }, () -> whenDone.run(Visit.this, CommandResult.FAILURE)); + + return CompletableFuture.completedFuture(true); } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java index 18a0ce7bc..62b7f2544 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/ConsolePlayer.java @@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.plot.database.DBFunc; import com.github.intellectualsites.plotsquared.plot.util.PlotGameMode; import com.github.intellectualsites.plotsquared.plot.util.PlotWeather; +import javax.annotation.Nonnull; import java.util.UUID; public class ConsolePlayer extends PlotPlayer { @@ -33,7 +34,7 @@ public class ConsolePlayer extends PlotPlayer { return instance; } - @Override public boolean canTeleport(Location loc) { + @Override public boolean canTeleport(@Nonnull Location loc) { return true; } @@ -95,14 +96,14 @@ public class ConsolePlayer extends PlotPlayer { return RequiredType.CONSOLE; } - @Override public void setWeather(PlotWeather weather) { + @Override public void setWeather(@Nonnull PlotWeather weather) { } - @Override public PlotGameMode getGameMode() { + @Nonnull @Override public PlotGameMode getGameMode() { return PlotGameMode.NOT_SET; } - @Override public void setGameMode(PlotGameMode gameMode) { + @Override public void setGameMode(@Nonnull PlotGameMode gameMode) { } @Override public void setTime(long time) { @@ -115,7 +116,7 @@ public class ConsolePlayer extends PlotPlayer { @Override public void setFlight(boolean fly) { } - @Override public void playMusic(Location location, PlotBlock id) { + @Override public void playMusic(@Nonnull Location location, @Nonnull PlotBlock id) { } @Override public void kick(String message) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java index d535c625e..4c3a2f6de 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotPlayer.java @@ -12,8 +12,10 @@ import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAre import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager; import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; +import com.google.common.base.Preconditions; import lombok.NonNull; +import javax.annotation.Nonnull; import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -335,8 +337,9 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { */ @Override public abstract UUID getUUID(); - public boolean canTeleport(Location loc) { - Location current = getLocationFull(); + public boolean canTeleport(@Nonnull final Location loc) { + Preconditions.checkNotNull(loc, "Specified location cannot be null"); + final Location current = getLocationFull(); teleport(loc); boolean result = true; if (!getLocation().equals(loc)) { @@ -409,21 +412,21 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { * * @param weather the weather visible to the player */ - public abstract void setWeather(PlotWeather weather); + public abstract void setWeather(@Nonnull PlotWeather weather); /** * Get this player's gamemode. * * @return the gamemode of the player. */ - public abstract PlotGameMode getGameMode(); + @Nonnull public abstract PlotGameMode getGameMode(); /** * Set this player's gameMode. * * @param gameMode the gamemode to set */ - public abstract void setGameMode(PlotGameMode gameMode); + public abstract void setGameMode(@Nonnull PlotGameMode gameMode); /** * Set this player's local time (ticks). @@ -447,7 +450,7 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { * @param location where to play the music * @param id the record item id */ - public abstract void playMusic(Location location, PlotBlock id); + public abstract void playMusic(@Nonnull Location location, @Nonnull PlotBlock id); /** * Check if this player is banned. From feda094273a95b53401c188dd0f0b7df75132354 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sat, 20 Jul 2019 01:29:30 +0200 Subject: [PATCH 2/9] Add kelp-grow flag Simply as the name says, add a controlled way to let kelp grow. --- .../plotsquared/bukkit/listeners/PlayerEvents.java | 5 +++++ .../intellectualsites/plotsquared/plot/flag/Flags.java | 1 + 2 files changed, 6 insertions(+) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index f7210f108..0d936b469 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1223,6 +1223,11 @@ import java.util.regex.Pattern; event.setCancelled(true); } break; + case KELP: + if (Flags.KELP_GROW.isFalse(plot)) { + event.setCancelled(true); + } + break; } } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index 12d9e2b06..fc203a00b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -46,6 +46,7 @@ public final class Flags { public static final BooleanFlag GRASS_GROW = new BooleanFlag("grass-grow"); public static final BooleanFlag VINE_GROW = new BooleanFlag("vine-grow"); public static final BooleanFlag MYCEL_GROW = new BooleanFlag("mycel-grow"); + public static final BooleanFlag KELP_GROW = new BooleanFlag("kelp-grow"); public static final BooleanFlag DISABLE_PHYSICS = new BooleanFlag("disable-physics"); public static final BooleanFlag LIQUID_FLOW = new BooleanFlag("liquid-flow"); public static final BooleanFlag SNOW_MELT = new BooleanFlag("snow-melt"); From dbf5084fa139f271a626614f6b55b8b6584bf6fe Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 25 Jul 2019 20:02:39 +0200 Subject: [PATCH 3/9] Reformat debugpaste And upgrade from IC -> IS --- .../plotsquared/plot/commands/DebugPaste.java | 25 ++++++++++--------- .../plotsquared/plot/commands/PluginCmd.java | 2 +- README.md | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java index 7fe7bfdd1..ba4e1b4ff 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugPaste.java @@ -17,6 +17,8 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; import java.nio.file.Files; import java.util.List; import java.util.stream.Collectors; @@ -47,11 +49,11 @@ import java.util.stream.Collectors; "# Welcome to this paste\n# It is meant to provide us at IntellectualSites with better information about your " + "problem\n\n"); b.append("# Server Information\n"); - b.append("server.version: ").append(PlotSquared.get().IMP.getServerImplementation()) + b.append("Server Version: ").append(PlotSquared.get().IMP.getServerImplementation()) .append("\n"); b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper()).append(';') .append(!Settings.UUID.OFFLINE).append('\n'); - b.append("plugins:"); + b.append("Plugins:"); for (String id : PlotSquared.get().IMP.getPluginIds()) { String[] split = id.split(":"); String[] split2 = split[0].split(";"); @@ -63,16 +65,15 @@ import java.util.stream.Collectors; } b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n"); Runtime runtime = Runtime.getRuntime(); - b.append("memory.free: ").append(runtime.freeMemory()).append('\n'); - b.append("memory.max: ").append(runtime.maxMemory()).append('\n'); - b.append("java.specification.version: '") - .append(System.getProperty("java.specification.version")).append("'\n"); - b.append("java.vendor: '").append(System.getProperty("java.vendor")).append("'\n"); - b.append("java.version: '").append(System.getProperty("java.version")) - .append("'\n"); - b.append("os.arch: '").append(System.getProperty("os.arch")).append("'\n"); - b.append("os.name: '").append(System.getProperty("os.name")).append("'\n"); - b.append("os.version: '").append(System.getProperty("os.version")).append("'\n\n"); + RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); + b.append("Free Memory: ").append(runtime.freeMemory() / 1024 / 1024 + " MB").append('\n'); + b.append("Max Memory: ").append(runtime.maxMemory() / 1024 / 1024 + " MB").append('\n'); + b.append("Java Name: ").append(rb.getVmName()).append('\n'); + b.append("Java Version: '").append(System.getProperty("java.version")).append("'\n"); + b.append("Java Vendor: '").append(System.getProperty("java.vendor")).append("'\n"); + b.append("Operating System: '").append(System.getProperty("os.name")).append("'\n"); + b.append("OS Version: ").append(System.getProperty("os.version")).append('\n'); + 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"); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java index 81047ec9b..d284ce708 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/PluginCmd.java @@ -21,7 +21,7 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager; MainUtil.sendMessage(player, "$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21"); MainUtil.sendMessage(player, - "$2>> $1&lWiki$2: $1https://github.com/IntellectualCrafters/PlotSquared/wiki"); + "$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki"); MainUtil.sendMessage(player, "$2>> $1&lNewest Version$2: $1" + getNewestVersionString()); } diff --git a/README.md b/README.md index a00ec16ee..85ceaea93 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ is to provide a lag-free and smooth experience. * [[Jenkins (Dev Builds)](https://ci.athion.net/job/PlotSquared-Breaking/)] [[Jenkins (Releases)](https://ci.athion.net/job/PlotSquared-Releases/)] * [Spigot Page](https://www.spigotmc.org/resources/plotsquared.1177/) * [Discord](https://discord.gg/ngZCzbU) -* [Wiki](https://github.com/intellectualcrafters/plotsquared/wiki) +* [Wiki](https://github.com/IntellectualSites/PlotSquared/wiki) ### Developer Resources * [[JavaDoc](https://ci.athion.net/job/PlotSquared-Breaking/javadoc/)] From 16fcb2f505d63c3585ae921a900cab211de9fe74 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Tue, 30 Jul 2019 23:58:48 +0200 Subject: [PATCH 4/9] Update DebugUUID.java --- .../plotsquared/bukkit/commands/DebugUUID.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java index fdee5edf6..bb5930228 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/commands/DebugUUID.java @@ -63,7 +63,7 @@ import java.util.Map.Entry; if (args.length != 2 || !"-o".equals(args[1])) { MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX, - "/plot uuidconvert " + args[0] + " - o"); + "/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"); From 1eba425087b2a97d8e082b208e06b79562b5c12e Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sat, 3 Aug 2019 23:18:50 +0200 Subject: [PATCH 5/9] Migrate Templates to new format --- .../bug-issue-report-for-plotsquared.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug-issue-report-for-plotsquared.md diff --git a/.github/ISSUE_TEMPLATE/bug-issue-report-for-plotsquared.md b/.github/ISSUE_TEMPLATE/bug-issue-report-for-plotsquared.md new file mode 100644 index 000000000..7badf3ae8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-issue-report-for-plotsquared.md @@ -0,0 +1,40 @@ +--- +name: Bug/Issue report for PlotSquared +about: Bug / Issue report about this plugin +title: '' +labels: '' +assignees: '' + +--- + +__*NOTICE: Bukkit/Spigot versions 1.7.10 to 1.12.2 are considered legacy and will receive limited support. Please consider upgrading to 1.13 for future support. Plugins exist for 1.13+ that bring back old behaviors found in 1.8*__ +# Bug report template + + + +**[REQUIRED] PlotSquared Version Number:** + +**[REQUIRED] Spigot/Paper Version Number:** + + +**[REQUIRED] Minecraft Version Number:** + +**Links to worlds.yml file and settings.yml file:** + + +**[REQUIRED] Description of the problem:** + +**Any relevant console output or screenshots:** + +**Plugins being used on the server:** + + +**How to replicate:** + + +**Checklist**: + +- [] I included all information required in the sections above +- [] I made sure there are no duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues?utf8=%E2%9C%93&q=is%3Aissue) +- [] I made sure I am using an up-to-date version of PlotSquared +- [] I made sure the bug/error is not caused by any other plugin From 59517647b5d469dcb71b0b0460643f27d44a40d3 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sat, 3 Aug 2019 23:20:21 +0200 Subject: [PATCH 6/9] Remove old files --- .github/CONTRIBUTING.md | 2 - pom.xml | 103 ---------------------------------------- 2 files changed, 105 deletions(-) delete mode 100644 .github/CONTRIBUTING.md delete mode 100644 pom.xml diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md deleted file mode 100644 index 9e26f91a6..000000000 --- a/.github/CONTRIBUTING.md +++ /dev/null @@ -1,2 +0,0 @@ -### Bugs -Please provide a `/plot debugpaste` if you are reporting a bug. diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 498ef295f..000000000 --- a/pom.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - 4.0.0 - com.intellectualcrafters - - UTF-8 - - PlotSquared - 3.5.1-SNAPSHOT - PlotSquared - jar - - PlotSquared-Bukkit-${project.version} - Bukkit/src - - - true - - **/*.* - - Bukkit/src/main/resources/ - - - true - - **/*.* - - Core/src/main/resources/ - - - - - maven-compiler-plugin - 2.3.2 - - - **/Sponge/src/main/**/*.* - - 1.7 - 1.7 - - - - org.codehaus.mojo - build-helper-maven-plugin - - - generate-sources - - add-source - - - - Core/src - - - - - - - - - - spigot-repo - http://hub.spigotmc.org/nexus/content/groups/public/ - - - sk80q - http://maven.sk89q.com/artifactory/repo/ - - - vault - http://nexus.hc.to/content/repositories/pub_releases/ - - - empcraft-repo - http://empcraft.com/maven2 - - - - - org.spigotmc - spigot-api - 1.12-R0.1-SNAPSHOT - provided - - - com.sk89q - worldedit - 6.0.0-SNAPSHOT - jar - compile - - - net.milkbowl.vault - VaultAPI - 1.5 - provided - - - From 01dfdbe2ef5b8dbe2d3d622a36ed1071d7b35406 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Sat, 3 Aug 2019 23:26:16 -0400 Subject: [PATCH 7/9] Merge with breaking --- .../plotsquared/plot/commands/DebugImportWorlds.java | 2 +- .../intellectualsites/plotsquared/plot/commands/Help.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java index 6ce41e749..978c95e34 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugImportWorlds.java @@ -40,7 +40,7 @@ import java.util.concurrent.CompletableFuture; if (container.equals(new File("."))) { player.sendMessage( "World container must be configured to be a separate directory to your base files!"); - return; + return CompletableFuture.completedFuture(false); } for (File folder : container.listFiles()) { String name = folder.getName(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java index afd0ec320..9e37441f5 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Help.java @@ -83,9 +83,10 @@ public class Help extends Command { .replaceAll(Captions.HELP_INFO_ITEM.s(), "%category%", c.toString().toLowerCase(), "%category_desc%", c.toString())); } - builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", "all") + builder.append("\n") + .append(Captions.HELP_INFO_ITEM.s().replaceAll("%category%", "all") .replaceAll("%category_desc%", "Display all commands")); - builder.append("\n").append(C.HELP_FOOTER.s()); + builder.append("\n").append(Captions.HELP_FOOTER.s()); MainUtil.sendMessage(player, builder.toString(), false); return true; } From 7542dbeab8a5e90f9461575f06d4fe3b6539b21c Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Sun, 4 Aug 2019 18:40:39 +0200 Subject: [PATCH 8/9] Fix gradle script --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index ce53e06c8..5739869c8 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ def revision = "" def buildNumber = "" def date = "" ext { - git = Grgit.open(dir: '.git') + git = Grgit.open(dir: new File(rootDir.toString()+'/.git')) date = git.head().getDate().format("yy.MM.dd") revision = "-${git.head().abbreviatedId}" parents = git.head().parentIds; @@ -43,7 +43,6 @@ ext { } } -// version = String.format("%s.%s%s%s", rootVersion, date, revision, buildNumber) version = String.format("%s.%s", rootVersion, buildNumber) description = rootProject.name From bd51292f4c806223b847986316541f358c745c66 Mon Sep 17 00:00:00 2001 From: MattBDev <4009945+MattBDev@users.noreply.github.com> Date: Mon, 5 Aug 2019 13:33:27 -0400 Subject: [PATCH 9/9] Get chunks asynchronously --- Bukkit/build.gradle | 10 +++--- .../plotsquared/bukkit/BukkitMain.java | 31 ++++++++++--------- .../bukkit/util/block/BukkitLocalQueue.java | 16 +++++++--- .../plot/util/block/BasicLocalBlockQueue.java | 17 ++++------ 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Bukkit/build.gradle b/Bukkit/build.gradle index 9d00d7b99..6946b457b 100644 --- a/Bukkit/build.gradle +++ b/Bukkit/build.gradle @@ -10,14 +10,16 @@ repositories { mavenLocal() } +apply plugin: "com.github.johnrengelman.shadow" + dependencies { implementation project(':Core') compile project(':Core') - compile 'com.destroystokyo.paper:paper-api:1.14.3-R0.1-SNAPSHOT' + compile 'com.destroystokyo.paper:paper-api:1.14.4-R0.1-SNAPSHOT' //implementation 'com.onarandombox.multiversecore:Multiverse-Core:3.0.0-SNAPSHOT' - implementation 'org.spigotmc:spigot-api:1.14.3-R0.1-SNAPSHOT' + implementation 'org.spigotmc:spigot-api:1.14.4-R0.1-SNAPSHOT' compile(group: 'com.sk89q.worldedit', name: 'worldedit-bukkit', version: '7.0.0') - compile "io.papermc:paperlib:1.0.1" + compile "io.papermc:paperlib:1.0.2" compile("net.milkbowl.vault:VaultAPI:1.7") { exclude module: 'bukkit' } @@ -47,7 +49,7 @@ shadowJar { include(dependency('com.squareup.okhttp3:okhttp:3.14.0')) include(dependency('com.squareup.okio:okio:2.2.2')) include(dependency('org.jetbrains.kotlin:kotlin-stdlib:1.3.30')) - include(dependency("io.papermc:paperlib:1.0.1")) + include(dependency("io.papermc:paperlib:1.0.2")) } relocate 'io.papermc.lib', 'com.github.intellectualsites.plotsquared.bukkit.paperlib' // relocate('org.mcstats', 'com.plotsquared.stats') diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java index 89bd5678b..b5e4ecf1b 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java @@ -1,11 +1,19 @@ package com.github.intellectualsites.plotsquared.bukkit; import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator; -import com.github.intellectualsites.plotsquared.bukkit.listeners.*; -import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111; +import com.github.intellectualsites.plotsquared.bukkit.listeners.ChunkListener; +import com.github.intellectualsites.plotsquared.bukkit.listeners.EntitySpawnListener; +import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents; +import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener; +import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener; +import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents; import com.github.intellectualsites.plotsquared.bukkit.util.*; import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue; -import com.github.intellectualsites.plotsquared.bukkit.uuid.*; +import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper; +import com.github.intellectualsites.plotsquared.bukkit.uuid.FileUUIDHandler; +import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; +import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper; +import com.github.intellectualsites.plotsquared.bukkit.uuid.SQLUUIDHandler; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.plot.IPlotMain; import com.github.intellectualsites.plotsquared.plot.PlotSquared; @@ -16,7 +24,12 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper; import com.github.intellectualsites.plotsquared.plot.generator.HybridGen; import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils; import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator; -import com.github.intellectualsites.plotsquared.plot.object.*; +import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry; +import com.github.intellectualsites.plotsquared.plot.object.Plot; +import com.github.intellectualsites.plotsquared.plot.object.PlotArea; +import com.github.intellectualsites.plotsquared.plot.object.PlotId; +import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer; +import com.github.intellectualsites.plotsquared.plot.object.SetupObject; import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager; import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea; @@ -26,12 +39,9 @@ import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider; import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper; import com.sk89q.worldedit.WorldEdit; -import com.sk89q.worldedit.bukkit.WorldEditPlugin; -import com.sk89q.worldedit.extension.platform.Capability; import io.papermc.lib.PaperLib; import lombok.Getter; import lombok.NonNull; -import org.bukkit.Location; import org.bukkit.*; import org.bukkit.command.PluginCommand; import org.bukkit.entity.Entity; @@ -56,13 +66,6 @@ import java.util.UUID; import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; -import javax.annotation.Nullable; -import java.io.File; -import java.lang.reflect.Method; -import java.util.*; - -import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass; - public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain { @Getter private static WorldEdit worldEdit; diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java index 5d8f53355..28bb36efa 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/block/BukkitLocalQueue.java @@ -10,6 +10,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.BasicLocalBlockQ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.world.block.BaseBlock; +import io.papermc.lib.PaperLib; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -20,6 +21,7 @@ import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import java.util.Locale; +import java.util.concurrent.ExecutionException; public class BukkitLocalQueue extends BasicLocalBlockQueue { @@ -69,7 +71,8 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { } } - @Override public final void setComponents(LocalChunk lc) { + @Override public final void setComponents(LocalChunk lc) + throws ExecutionException, InterruptedException { setBaseBlocks(lc); } @@ -77,14 +80,17 @@ public class BukkitLocalQueue extends BasicLocalBlockQueue { return Bukkit.getWorld(getWorld()); } - public Chunk getChunk(int x, int z) { - return getBukkitWorld().getChunkAt(x, z); + public Chunk getChunk(int x, int z) throws ExecutionException, InterruptedException { + return PaperLib.getChunkAtAsync(getBukkitWorld(), x, z).get(); } - public void setBaseBlocks(LocalChunk lc) { + public void setBaseBlocks(LocalChunk lc) throws ExecutionException, InterruptedException { World worldObj = Bukkit.getWorld(getWorld()); + if (worldObj == null) { + throw new NullPointerException("World cannot be null."); + } + PaperLib.getChunkAtAsync(worldObj, lc.getX(), lc.getZ(), true).get(); Chunk chunk = worldObj.getChunkAt(lc.getX(), lc.getZ()); - chunk.load(true); for (int layer = 0; layer < lc.baseblocks.length; layer++) { BaseBlock[] blocksLayer = lc.baseblocks[layer]; if (blocksLayer != null) { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java index 4ca62eb58..6993c3208 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/block/BasicLocalBlockQueue.java @@ -1,19 +1,16 @@ package com.github.intellectualsites.plotsquared.plot.util.block; -import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.RunnableVal; -import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; import com.github.intellectualsites.plotsquared.plot.util.TaskManager; import com.sk89q.worldedit.world.block.BaseBlock; -import com.sk89q.worldedit.world.block.BlockTypes; -import com.sk89q.worldedit.world.registry.LegacyMapper; -import lombok.Getter; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; +import java.util.concurrent.ExecutionException; public abstract class BasicLocalBlockQueue extends LocalBlockQueue { @@ -35,7 +32,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { @Override public abstract PlotBlock getBlock(int x, int y, int z); - public abstract void setComponents(LocalChunk lc); + public abstract void setComponents(LocalChunk lc) + throws ExecutionException, InterruptedException; @Override public final String getWorld() { return world; @@ -62,10 +60,8 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { return false; } - public final boolean execute(final LocalChunk lc) { - if (lc == null) { - return false; - } + public final boolean execute(@NotNull LocalChunk lc) + throws ExecutionException, InterruptedException { this.setComponents(lc); return true; } @@ -154,7 +150,6 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue { TaskManager.IMP.sync(new RunnableVal() { @Override public void run(Object value) { while (next()) { - ; } } });