Permalink
Browse files

Abstracted the commands away from the Bukkit platform (#391)

* Start work on abstracting commands out of worldedit-legacy

* A lot more work towards abstract commands

* Move a lot of code to WorldEdit

* Setup the exception converter

* Use WorldEdit styling and move more of the RegionContainer across.

* Abstract away the debug commands and a few other things - Only the matcher to go.

* It compiles

* It now seems to run fine

* Fixed version typo
  • Loading branch information...
me4502 committed Dec 26, 2018
1 parent 803c205 commit fdd9064170af7b67d180ee642faaa91fff82be88
Showing with 2,117 additions and 3,715 deletions.
  1. +0 −1 worldguard-core/build.gradle
  2. +37 −0 worldguard-core/src/main/java/com/sk89q/worldguard/LocalPlayer.java
  3. +64 −3 worldguard-core/src/main/java/com/sk89q/worldguard/WorldGuard.java
  4. +3 −2 worldguard-core/src/main/java/com/sk89q/worldguard/blacklist/Blacklist.java
  5. +114 −0 worldguard-core/src/main/java/com/sk89q/worldguard/commands/CommandUtils.java
  6. +71 −0 worldguard-core/src/main/java/com/sk89q/worldguard/commands/DebuggingCommands.java
  7. +241 −0 worldguard-core/src/main/java/com/sk89q/worldguard/commands/GeneralCommands.java
  8. +10 −11 ...ard/bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/ProtectionCommands.java
  9. +44 −57 ...ldguard/bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/ToggleCommands.java
  10. +52 −66 ...ard/bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/WorldGuardCommands.java
  11. +34 −40 .../bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/region/MemberCommands.java
  12. +127 −151 .../bukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/region/RegionCommands.java
  13. +24 −31 ...kit → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/region/RegionCommandsBase.java
  14. +25 −25 ... → worldguard-core/src/main/java/com/sk89q/worldguard}/commands/region/RegionPrintoutBuilder.java
  15. +17 −0 worldguard-core/src/main/java/com/sk89q/worldguard/config/WorldConfiguration.java
  16. +9 −18 ...rc/main/java/com/sk89q/worldguard/{util/paste/Pasters.java → internal/platform/DebugHandler.java}
  17. +173 −0 worldguard-core/src/main/java/com/sk89q/worldguard/internal/platform/StringMatcher.java
  18. +40 −30 worldguard-core/src/main/java/com/sk89q/worldguard/internal/platform/WorldGuardPlatform.java
  19. +1 −1 worldguard-core/src/main/java/com/sk89q/worldguard/protection/flags/LazyLocation.java
  20. +104 −1 worldguard-core/src/main/java/com/sk89q/worldguard/protection/regions/RegionContainer.java
  21. +177 −0 worldguard-core/src/main/java/com/sk89q/worldguard/session/AbstractSessionManager.java
  22. +2 −1 worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/EntryFlag.java
  23. +2 −1 worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/ExitFlag.java
  24. +3 −2 worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/FarewellFlag.java
  25. +3 −2 worldguard-core/src/main/java/com/sk89q/worldguard/session/handler/GreetingFlag.java
  26. +48 −0 worldguard-core/src/main/java/com/sk89q/worldguard/util/Entities.java
  27. +91 −0 worldguard-core/src/main/java/com/sk89q/worldguard/util/WorldGuardExceptionConverter.java
  28. +6 −7 ...ukkit → worldguard-core/src/main/java/com/sk89q/worldguard}/util/logging/LoggerToChatHandler.java
  29. +0 −490 worldguard-core/src/main/java/com/sk89q/worldguard/util/net/HttpRequest.java
  30. +0 −79 worldguard-core/src/main/java/com/sk89q/worldguard/util/paste/EngineHubPaste.java
  31. +0 −94 worldguard-core/src/main/java/com/sk89q/worldguard/util/paste/Pastebin.java
  32. +0 −30 worldguard-core/src/main/java/com/sk89q/worldguard/util/paste/Paster.java
  33. +0 −74 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/AbstractTask.java
  34. +0 −121 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/FutureForwardingTask.java
  35. +0 −62 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/SimpleSupervisor.java
  36. +0 −44 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/Supervisor.java
  37. +0 −97 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/Task.java
  38. +0 −43 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/TaskStateComparator.java
  39. +0 −183 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/progress/Progress.java
  40. +0 −100 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/progress/ProgressIterator.java
  41. +0 −34 worldguard-core/src/main/java/com/sk89q/worldguard/util/task/progress/ProgressObservable.java
  42. +6 −0 worldguard-legacy/build.gradle
  43. +67 −57 ...main/java/com/sk89q/worldguard/bukkit/{commands/DebuggingCommands.java → BukkitDebugHandler.java}
  44. +15 −0 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitOfflinePlayer.java
  45. +33 −4 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitPlayer.java
  46. +9 −128 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitRegionContainer.java
  47. +242 −0 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitStringMatcher.java
  48. +0 −73 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java
  49. +3 −17 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldConfiguration.java
  50. +109 −31 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/BukkitWorldGuardPlatform.java
  51. +32 −376 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java
  52. +2 −2 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/cause/Cause.java
  53. +0 −136 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/AsyncCommandHelper.java
  54. +0 −194 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/CommandUtils.java
  55. +0 −55 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/FutureProgressListener.java
  56. +0 −315 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/GeneralCommands.java
  57. +0 −103 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/MessageFutureCallback.java
  58. +0 −46 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/commands/MessageTimerTask.java
  59. +1 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/RegionFlagsListener.java
  60. +5 −3 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardEntityListener.java
  61. +2 −1 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardPlayerListener.java
  62. +9 −9 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/listener/WorldGuardWorldListener.java
  63. +4 −243 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/session/BukkitSessionManager.java
  64. +27 −20 worldguard-legacy/src/main/java/com/sk89q/worldguard/bukkit/util/Entities.java
  65. +29 −0 worldguard-legacy/src/test/java/com/sk89q/worldguard/TestPlayer.java
@@ -8,7 +8,6 @@ dependencies {
compile 'org.flywaydb:flyway-core:3.0'
compile 'org.khelekore:prtree:1.5.0'
compile 'net.sf.opencsv:opencsv:2.0'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.google.code.findbugs:jsr305:1.3.9'
}

@@ -20,6 +20,7 @@
package com.sk89q.worldguard;

import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.weather.WeatherType;
import com.sk89q.worldguard.domains.Association;
import com.sk89q.worldguard.protection.association.RegionAssociable;
@@ -115,6 +116,20 @@ default Association getAssociation(List<ProtectedRegion> regions) {
*/
void setSaturation(double saturation);

/**
* Gets the exhaustion of this player.
*
* @return The exhaustion
*/
float getExhaustion();

/**
* Sets the exhaustion of this player.
*
* @param exhaustion The exhaustion
*/
void setExhaustion(float exhaustion);

/**
* Gets the players weather
*
@@ -160,4 +175,26 @@ default Association getAssociation(List<ProtectedRegion> regions) {
* Resets the players time to normal.
*/
void resetPlayerTime();

// TODO Move this to WorldEdit's Entity class - honestly most of this class could be a Facet
/**
* Gets the number of ticks the player is on fire for.
*
* @return The number of fire ticks
*/
int getFireTicks();

/**
* Sets the number of ticks the player is on fire for.
*
* @param fireTicks The fire ticks
*/
void setFireTicks(int fireTicks);

/**
* Sets the target of the compass
*
* @param location The location
*/
void setCompassTarget(Location location);
}
@@ -24,6 +24,7 @@
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.squirrelid.cache.HashMapCache;
import com.sk89q.squirrelid.cache.ProfileCache;
import com.sk89q.squirrelid.cache.SQLiteCache;
@@ -32,14 +33,17 @@
import com.sk89q.squirrelid.resolver.CombinedProfileService;
import com.sk89q.squirrelid.resolver.HttpRepositoryService;
import com.sk89q.squirrelid.resolver.ProfileService;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.task.SimpleSupervisor;
import com.sk89q.worldedit.util.task.Supervisor;
import com.sk89q.worldedit.util.task.Task;
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
import com.sk89q.worldguard.protection.flags.Flags;
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
import com.sk89q.worldguard.protection.flags.registry.SimpleFlagRegistry;
import com.sk89q.worldguard.util.WorldGuardExceptionConverter;
import com.sk89q.worldguard.util.concurrent.EvenMoreExecutors;
import com.sk89q.worldguard.util.task.SimpleSupervisor;
import com.sk89q.worldguard.util.task.Supervisor;
import com.sk89q.worldguard.util.task.Task;

import java.io.File;
import java.io.IOException;
@@ -53,13 +57,16 @@

public static final Logger logger = Logger.getLogger(WorldGuard.class.getCanonicalName());

private static String version;
private static final WorldGuard instance = new WorldGuard();

private WorldGuardPlatform platform;
private final SimpleFlagRegistry flagRegistry = new SimpleFlagRegistry();
private final Supervisor supervisor = new SimpleSupervisor();
private ProfileCache profileCache;
private ProfileService profileService;
private ListeningExecutorService executorService;
private WorldGuardExceptionConverter exceptionConverter = new WorldGuardExceptionConverter(this);

public static WorldGuard getInstance() {
return instance;
@@ -152,6 +159,30 @@ public ProfileCache getProfileCache() {
return profileCache;
}

/**
* Get the exception converter
*
* @return the exception converter
*/
public WorldGuardExceptionConverter getExceptionConverter() {
return exceptionConverter;
}

/**
* Checks to see if the sender is a player, otherwise throw an exception.
*
* @param sender The sender
* @return The player
* @throws CommandException if it isn't a player
*/
public LocalPlayer checkPlayer(Actor sender) throws CommandException {
if (sender instanceof LocalPlayer) {
return (LocalPlayer) sender;
} else {
throw new CommandException("A player is expected.");
}
}

/**
* Called when WorldGuard should be disabled.
*/
@@ -181,4 +212,34 @@ public void disable() {

platform.unload();
}

/**
* Get the version.
*
* @return the version of WorldEdit
*/
public static String getVersion() {
if (version != null) {
return version;
}

Package p = WorldGuard.class.getPackage();

if (p == null) {
p = Package.getPackage("com.sk89q.worldguard");
}

if (p == null) {
version = "(unknown)";
} else {
version = p.getImplementationVersion();

if (version == null) {
version = "(unknown)";
}
}

return version;
}

}
@@ -33,6 +33,7 @@
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.sk89q.worldguard.commands.CommandUtils;

import java.io.BufferedReader;
import java.io.File;
@@ -185,10 +186,10 @@ public void load(File file) throws IOException {
entry.setIgnorePermissions(parts[1].split(","));

} else if (parts[0].equalsIgnoreCase("message")) {
entry.setMessage(WorldGuard.getInstance().getPlatform().replaceColorMacros(parts[1].trim()));
entry.setMessage(CommandUtils.replaceColorMacros(parts[1].trim()));

} else if (parts[0].equalsIgnoreCase("comment")) {
entry.setComment(WorldGuard.getInstance().getPlatform().replaceColorMacros(parts[1].trim()));
entry.setComment(CommandUtils.replaceColorMacros(parts[1].trim()));

} else {
boolean found = false;
@@ -0,0 +1,114 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldguard.commands;

import com.google.common.base.Function;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.Style;

import javax.annotation.Nullable;

/**
* Command-related utility methods.
*/
public final class CommandUtils {

private CommandUtils() {
}

/**
* Replace color macros in a string.
*
* @param str the string
* @return the new string
*/
public static String replaceColorMacros(String str) {
// TODO: Make this more efficient

str = str.replace("`r", Style.RED.toString());
str = str.replace("`R", Style.RED_DARK.toString());

str = str.replace("`y", Style.YELLOW.toString());
str = str.replace("`Y", Style.YELLOW_DARK.toString());

str = str.replace("`g", Style.GREEN.toString());
str = str.replace("`G", Style.GREEN_DARK.toString());

str = str.replace("`c", Style.CYAN.toString());
str = str.replace("`C", Style.CYAN_DARK.toString());

str = str.replace("`b", Style.BLUE.toString());
str = str.replace("`B", Style.BLUE_DARK.toString());

str = str.replace("`p", Style.PURPLE.toString());
str = str.replace("`P", Style.PURPLE_DARK.toString());

str = str.replace("`0", Style.BLACK.toString());
str = str.replace("`1", Style.GRAY_DARK.toString());
str = str.replace("`2", Style.GRAY.toString());
str = str.replace("`w", Style.WHITE.toString());

str = str.replace("`k", Style.RANDOMIZE.toString());

str = str.replace("`l", Style.BOLD.toString());
str = str.replace("`m", Style.STRIKETHROUGH.toString());
str = str.replace("`n", Style.UNDERLINE.toString());
str = str.replace("`o", Style.ITALIC.toString());

str = str.replace("`x", Style.RESET.toString());

// MC classic
str = Style.translateAlternateColorCodes('&', str);

return str;
}


/**
* Get the name of the given owner object.
*
* @param owner the owner object
* @return a name
*/
public static String getOwnerName(@Nullable Object owner) {
if (owner == null) {
return "?";
} else if (owner instanceof Actor) {
return ((Actor) owner).getName();
} else {
return "?";
}
}

/**
* Return a function that accepts a string to send a message to the
* given sender.
*
* @param sender the sender
* @return a function
*/
public static java.util.function.Function<String, ?> messageFunction(final Actor sender) {
return (Function<String, Object>) s -> {
sender.printRaw(s);
return null;
};
}

}
@@ -0,0 +1,71 @@
/*
* WorldGuard, a suite of tools for Minecraft
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldGuard team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.sk89q.worldguard.commands;

import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.WorldGuard;

public class DebuggingCommands {

private final WorldGuard worldGuard;

/**
* Create a new instance.
*
* @param worldGuard The worldGuard instance
*/
public DebuggingCommands(WorldGuard worldGuard) {
this.worldGuard = worldGuard;
}

@Command(aliases = {"testbreak"}, usage = "[player]", desc = "Simulate a block break", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void fireBreakEvent(CommandContext args, final Actor sender) throws CommandException {
LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
worldGuard.getPlatform().getDebugHandler().testBreak(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}


@Command(aliases = {"testplace"}, usage = "[player]", desc = "Simulate a block place", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void firePlaceEvent(CommandContext args, final Actor sender) throws CommandException {
LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
worldGuard.getPlatform().getDebugHandler().testPlace(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}

@Command(aliases = {"testinteract"}, usage = "[player]", desc = "Simulate a block interact", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void fireInteractEvent(CommandContext args, final Actor sender) throws CommandException {
LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
worldGuard.getPlatform().getDebugHandler().testInteract(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}

@Command(aliases = {"testdamage"}, usage = "[player]", desc = "Simulate an entity damage", min = 1, max = 1, flags = "ts")
@CommandPermissions("worldguard.debug.event")
public void fireDamageEvent(CommandContext args, final Actor sender) throws CommandException {
LocalPlayer target = worldGuard.getPlatform().getMatcher().matchSinglePlayer(sender, args.getString(0));
worldGuard.getPlatform().getDebugHandler().testDamage(sender, target, args.hasFlag('t'), args.hasFlag('s'));
}
}
Oops, something went wrong.

0 comments on commit fdd9064

Please sign in to comment.