diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java index d7a81d57c..f5c8bea56 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java @@ -21,8 +21,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { } @Override - public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel, - String[] args) { + public boolean onCommand(final CommandSender commandSender, org.bukkit.command.Command command, final String commandLabel, String[] args) { if (commandSender instanceof Player) { return MainCommand.onCommand(BukkitUtil.getPlayer((Player) commandSender), args); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index abe577707..5caae7cb6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -1465,13 +1465,16 @@ public class PS { } for (String areaId : areasSection.getKeys(false)) { log(C.PREFIX + "&3 - " + areaId); - String[] split = areaId.split("([^\\-]+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)(?:-{1})(-{0,1}\\d+\\;-{0,1}\\d+)"); - if (split.length != 3) { + int i1 = areaId.indexOf("-"); + int i2 = areaId.indexOf(";"); + if (i1 == -1 || i2 == -1) { throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `--`"); } - String name = split[0]; - PlotId pos1 = PlotId.fromString(split[1]); - PlotId pos2 = PlotId.fromString(split[2]); + String name = areaId.substring(0, i1); + String rest = areaId.substring(i1 + 1); + int i3 = rest.indexOf("-", i2); + PlotId pos1 = PlotId.fromString(rest.substring(0, i3)); + PlotId pos2 = PlotId.fromString(rest.substring(i3 + 1)); if (pos1 == null || pos2 == null || name.isEmpty()) { throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `--`"); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java index bd993ecfe..78ffa5639 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Trim.java @@ -174,6 +174,9 @@ public class Trim extends SubCommand { public void run(Set viable, final Set nonViable) { Runnable regenTask; if (regen) { + PS.log("Starting regen task:"); + PS.log(" - This is a VERY slow command"); + PS.log(" - It will say `Trim done!` when complete"); regenTask = new Runnable() { @Override public void run() { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java index 7ff942069..15ea7e549 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -80,9 +80,10 @@ import java.util.UUID; * Created by robin on 01/11/2014 */ -@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.1") +@Plugin(id = "com.plotsquared", name = "PlotSquared", description = "Easy, yet powerful Plot World generation and management.", url = "https://github.com/IntellectualSites/PlotSquared", version = "3.3.2") public class SpongeMain implements IPlotMain { public static SpongeMain THIS; + public PluginContainer plugin; @Inject private Logger logger; @@ -130,6 +131,7 @@ public class SpongeMain implements IPlotMain { public void onServerAboutToStart(GameAboutToStartServerEvent event) { log("PlotSquared: Server init"); THIS = this; + THIS.plugin = this.game.getPluginManager().fromInstance(this).get(); new PS(this, "Sponge"); this.server = this.game.getServer(); this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify()); @@ -304,7 +306,7 @@ public class SpongeMain implements IPlotMain { @Override public void startMetrics() { try { - Metrics metrics = new Metrics(this.game, (PluginContainer) this); + Metrics metrics = new Metrics(this.game, plugin); metrics.start(); log(C.PREFIX.s() + "&6Metrics enabled."); } catch (IOException e) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java index d3f877f3c..fe4a9111a 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeCommand.java @@ -3,11 +3,14 @@ package com.plotsquared.sponge.util; import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.general.commands.Command; import com.plotsquared.sponge.SpongeMain; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; @@ -15,67 +18,44 @@ import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.Text; -import java.util.*; - public class SpongeCommand implements CommandCallable { @Override public CommandResult process(final CommandSource cmd, final String string) throws CommandException { - TaskManager.runTask(new Runnable() { - @Override - public void run() { - final String id = cmd.getIdentifier(); - PlotPlayer pp; - try { - final UUID uuid = UUID.fromString(id); - final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); - pp = SpongeUtil.getPlayer(player); - } catch (final Exception e) { - pp = ConsolePlayer.getConsole(); - } - MainCommand.onCommand(pp, cmd.getName(), string.isEmpty() ? new String[]{} : string.split(" ")); + TaskManager.runTask(() -> { + final String id = cmd.getIdentifier(); + PlotPlayer pp; + try { + final UUID uuid = UUID.fromString(id); + final Player player = SpongeMain.THIS.getServer().getPlayer(uuid).get(); + pp = SpongeUtil.getPlayer(player); + } catch (final Exception e) { + pp = ConsolePlayer.getConsole(); } + MainCommand.onCommand(pp, string.isEmpty() ? new String[]{} : string.split(" ")); }); return CommandResult.success(); } @Override - public List getSuggestions(final CommandSource source, final String string) throws CommandException { + public List getSuggestions(final CommandSource source, final String s) throws CommandException { if (!(source instanceof Player)) { return null; } final PlotPlayer player = SpongeUtil.getPlayer((Player) source); - String[] split = string.split(" "); - if (split.length < 1) { - return Collections.singletonList("plots"); + String[] args = s.split(" "); + if (args.length == 0) { + return Collections.singletonList(MainCommand.getInstance().toString()); } - if (split.length > 1) { - return Collections.emptyList(); + Collection objects = MainCommand.getInstance().tab(player, args, s.endsWith(" ")); + if (objects == null) { + return null; } - final Set tabOptions = new HashSet<>(); - final String arg = split[0].toLowerCase(); - ArrayList labels = new ArrayList<>(); - for (final Command cmd : MainCommand.getInstance().getCommands()) { - final String label = cmd.toS(); - HashSet aliases = new HashSet<>(cmd.getAliases()); - aliases.add(label); - for (String alias : aliases) { - labels.add(alias); - if (alias.startsWith(arg)) { - if (Permissions.hasPermission(player, cmd.getPermission())) { - tabOptions.add(label); - } else { - break; - } - } - } + List result = new ArrayList<>(); + for (Object o : objects) { + result.add(o.toString()); } - String best = new StringComparison<>(arg, labels).getBestMatch(); - tabOptions.add(best); - if (!tabOptions.isEmpty()) { - return new ArrayList<>(tabOptions); - } - return Collections.emptyList(); + return result; } @Override @@ -90,7 +70,7 @@ public class SpongeCommand implements CommandCallable { @Override public Optional getHelp(final CommandSource cmd) { - return Optional.of(Text.of("/plot help")); + return Optional.of(Text.of("/plot")); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java index 68e746b7d..f35dc651a 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEconHandler.java @@ -64,12 +64,6 @@ public class SpongeEconHandler extends EconHandler { } } - @Override - public void setPermission(String world, String player, String perm, boolean value) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("TODO/WIP/NOT IMPLEMENTED!"); - } - @Override public boolean hasPermission(String world, String player, String perm) { SpongePlayer obj = (SpongePlayer) UUIDHandler.getPlayer(player);