From 697fee8c4c99f03c61c8628024135e37671bf5c3 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 2 Feb 2023 14:21:11 +0800 Subject: [PATCH 001/725] chore: Bump version to 5.0.0-SNAPSHOT for continued development. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 55b9239d6..87df41835 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.onarandombox.multiversecore Multiverse-Core - 4.3.2-SNAPSHOT + 5.0.0-SNAPSHOT Multiverse-Core World Management Plugin From 27c2f7b9e94f8118a0e883d59b2bb840fea1ecec Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:01:07 +0800 Subject: [PATCH 002/725] feat: Update to 1.16.5-R0.1-SNAPSHOT dependency --- pom.xml | 8 +- .../MultiverseCore/MultiverseCore.java | 7 +- .../queue/DummyCommandBlockSender.java | 17 +++ .../listeners/MVEntityListener.java | 5 +- .../listeners/MVPlayerListener.java | 22 +--- .../utils/BukkitTravelAgent.java | 111 ------------------ .../utils/CompatibilityLayer.java | 106 ----------------- 7 files changed, 30 insertions(+), 246 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java diff --git a/pom.xml b/pom.xml index 87df41835..e714385f0 100644 --- a/pom.xml +++ b/pom.xml @@ -280,10 +280,10 @@ - org.bukkit - bukkit - 1.13.2-R0.1-SNAPSHOT - provided + org.spigotmc + spigot-api + 1.16.5-R0.1-SNAPSHOT + provided diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 6fda9ae95..aa952101f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -89,20 +89,19 @@ import com.onarandombox.MultiverseCore.listeners.MVWorldInitListener; import com.onarandombox.MultiverseCore.listeners.MVWorldListener; import com.onarandombox.MultiverseCore.utils.AnchorManager; -import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import com.onarandombox.MultiverseCore.utils.MVEconomist; import com.onarandombox.MultiverseCore.utils.MVMessaging; import com.onarandombox.MultiverseCore.utils.MVPermissions; import com.onarandombox.MultiverseCore.utils.MVPlayerSession; import com.onarandombox.MultiverseCore.utils.MaterialConverter; -import com.onarandombox.MultiverseCore.utils.TestingMode; -import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator; import com.onarandombox.MultiverseCore.utils.SimpleBlockSafety; import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation; import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter; +import com.onarandombox.MultiverseCore.utils.TestingMode; import com.onarandombox.MultiverseCore.utils.UnsafeCallWrapper; import com.onarandombox.MultiverseCore.utils.VaultHandler; import com.onarandombox.MultiverseCore.utils.WorldManager; +import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator; import com.pneumaticraft.commandhandler.CommandHandler; import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.SerializationConfig; @@ -257,8 +256,6 @@ public void onLoad() { // Setup our SafeTTeleporter this.safeTTeleporter = new SimpleSafeTTeleporter(this); this.unsafeCallWrapper = new UnsafeCallWrapper(this); - // Setup our CompatibilityLayer - CompatibilityLayer.init(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java index 7ec3dfe03..181e8e50a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/queue/DummyCommandBlockSender.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Set; +import java.util.UUID; /** * Used by {@link CommandQueueManager}, so different commands block can be recognised as one. @@ -27,6 +28,16 @@ public void sendMessage(@NotNull String[] messages) { throw new UnsupportedOperationException(); } + @Override + public void sendMessage(@Nullable UUID uuid, @NotNull String s) { + throw new UnsupportedOperationException(); + } + + @Override + public void sendMessage(@Nullable UUID uuid, @NotNull String[] strings) { + throw new UnsupportedOperationException(); + } + @Override public @NotNull Server getServer() { return Bukkit.getServer(); @@ -37,6 +48,12 @@ public void sendMessage(@NotNull String[] messages) { return "DummyCommandBlockSender"; } + @NotNull + @Override + public Spigot spigot() { + throw new UnsupportedOperationException(); + } + @Override public boolean isPermissionSet(@NotNull String name) { throw new UnsupportedOperationException(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index fd81e6948..509f7bbd8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -11,7 +11,6 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -24,8 +23,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.FoodLevelChangeEvent; -import java.util.logging.Level; - /** * Multiverse's Entity {@link Listener}. */ @@ -119,7 +116,7 @@ public void entityPortal(EntityPortalEvent event) { return; } if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) { - CompatibilityLayer.setPortalSearchRadius(event, this.plugin.getMVConfig().getPortalSearchRadius()); + event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius()); } } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index 2921f9c56..72600132e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -7,13 +7,14 @@ package com.onarandombox.MultiverseCore.listeners; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.enums.RespawnType; import com.onarandombox.MultiverseCore.event.MVRespawnEvent; -import com.onarandombox.MultiverseCore.utils.CompatibilityLayer; import com.onarandombox.MultiverseCore.utils.PermissionTools; import org.bukkit.GameMode; import org.bukkit.Location; @@ -31,9 +32,6 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * Multiverse's {@link Listener} for players. */ @@ -70,16 +68,8 @@ public void playerRespawn(PlayerRespawnEvent event) { return; } - RespawnType respawnType = RespawnType.OTHER; - if (event.isBedSpawn()) { - respawnType = RespawnType.BED; - } - if (CompatibilityLayer.isAnchorSpawn(event)) { - respawnType = RespawnType.ANCHOR; - } - - if (mvWorld.getBedRespawn() && (respawnType == RespawnType.BED || respawnType == RespawnType.ANCHOR)) { - Logging.fine("Spawning %s at their %s", event.getPlayer().getName(), respawnType); + if (mvWorld.getBedRespawn() && (event.isBedSpawn() || event.isAnchorSpawn())) { + Logging.fine("Spawning %s at their %s.", event.getPlayer().getName(), event.isBedSpawn() ? "BED" : "ANCHOR"); return; } @@ -313,7 +303,7 @@ public void playerPortal(PlayerPortalEvent event) { + "' because enforceaccess is off."); } if (!this.plugin.getMVConfig().isUsingDefaultPortalSearch()) { - CompatibilityLayer.setPortalSearchRadius(event, this.plugin.getMVConfig().getPortalSearchRadius()); + event.setSearchRadius(this.plugin.getMVConfig().getPortalSearchRadius()); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java b/src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java deleted file mode 100644 index e2f658fa5..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/BukkitTravelAgent.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.onarandombox.MultiverseCore.utils; - -import java.util.logging.Level; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.destination.CannonDestination; -import org.bukkit.Location; -import org.bukkit.TravelAgent; -import org.bukkit.event.player.PlayerPortalEvent; - -public class BukkitTravelAgent implements TravelAgent { - private final MVTravelAgent agent; - - public BukkitTravelAgent(MVTravelAgent agent) { - this.agent = agent; - } - - /** - * {@inheritDoc} - */ - @Override - public BukkitTravelAgent setSearchRadius(int radius) { - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public int getSearchRadius() { - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - public BukkitTravelAgent setCreationRadius(int radius) { - return this; - } - - /** - * {@inheritDoc} - */ - @Override - public int getCreationRadius() { - return 0; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean getCanCreatePortal() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public void setCanCreatePortal(boolean create) { - } - - /** - * {@inheritDoc} - */ - @Override - public Location findOrCreate(Location location) { - return this.getSafeLocation(); - } - - /** - * {@inheritDoc} - */ - @Override - public Location findPortal(Location location) { - return this.getSafeLocation(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean createPortal(Location location) { - return false; - } - - private Location getSafeLocation() { - // At this time, these can never use the velocity. - if (agent.destination instanceof CannonDestination) { - Logging.fine("Using Stock TP method. This cannon will have 0 velocity"); - } - SafeTTeleporter teleporter = agent.core.getSafeTTeleporter(); - Location newLoc = agent.destination.getLocation(agent.player); - if (agent.destination.useSafeTeleporter()) { - newLoc = teleporter.getSafeLocation(agent.player, agent.destination); - } - if (newLoc == null) { - return agent.player.getLocation(); - } - return newLoc; - - } - - public void setPortalEventTravelAgent(PlayerPortalEvent event) { - event.setPortalTravelAgent(this); - event.useTravelAgent(true); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java b/src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java deleted file mode 100644 index 2a83a7e20..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/CompatibilityLayer.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.onarandombox.MultiverseCore.utils; - -import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.event.entity.EntityPortalEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerRespawnEvent; - -import java.lang.reflect.Method; - -/** - * Utility class to enable version specific minecraft features. - */ -public class CompatibilityLayer { - - private static Method checkAnchorSpawn; - private static boolean useTravelAgent; - private static Method playerPortalSearchRadius; - private static Method entityPortalSearchRadius; - - /** - * Initialise the reflection class, methods and fields. - */ - public static void init() { - checkAnchorSpawn = ReflectHelper.getMethod(PlayerRespawnEvent.class, "isAnchorSpawn"); - useTravelAgent = ReflectHelper.hasClass("org.bukkit.TravelAgent"); - playerPortalSearchRadius = ReflectHelper.getMethod(PlayerPortalEvent.class, "setSearchRadius", int.class); - entityPortalSearchRadius = ReflectHelper.getMethod(EntityPortalEvent.class, "setSearchRadius", int.class); - } - - /** - *

Check if the respawn point is of respawn anchor type.

- *

Introduced in minecraft 1.16

- * - * @param event A player respawn event. - * @return If the respawn location is an anchor point. - */ - public static boolean isAnchorSpawn(PlayerRespawnEvent event) { - if (checkAnchorSpawn == null) { - return false; - } - Boolean result = ReflectHelper.invokeMethod(event, checkAnchorSpawn); - if (result == null) { - Logging.warning("Unable to check if spawning at respawn anchor!"); - return false; - } - return result; - } - - /** - *

Gets if Travel Agent is supported on the server's minecraft version.

- *

Removed in minecraft 1.14

- * - * @return True if Travel Agent is supported, else false. - */ - public static boolean isUseTravelAgent() { - return useTravelAgent; - } - - /** - *

Sets search radius for a PlayerPortalEvent.

- * - *

Use travel agent if available, else using new PlayerPortalEvent.setSearchRadius(int) method - * introduced in minecraft 1.15

- * - * @param event A Player Portal Event. - * @param searchRadius Target search radius to set to. - */ - public static void setPortalSearchRadius(PlayerPortalEvent event, int searchRadius) { - if (useTravelAgent) { - event.getPortalTravelAgent().setSearchRadius(searchRadius); - event.useTravelAgent(true); - Logging.finer("Used travel agent to set player portal search radius."); - return; - } - if (playerPortalSearchRadius == null) { - Logging.warning("Unable to set player portal search radius!"); - return; - } - ReflectHelper.invokeMethod(event, playerPortalSearchRadius, searchRadius); - Logging.finer("Used new method to set player portal search radius."); - } - - /** - *

Sets search radius for a EntityPortalEvent.

- * - *

Use travel agent if available, else using new EntityPortalEvent.setSearchRadius(int) method - * introduced in minecraft 1.15

- * - * @param event A Entity Portal Event. - * @param searchRadius Target search radius to set to. - */ - public static void setPortalSearchRadius(EntityPortalEvent event, int searchRadius) { - if (useTravelAgent) { - event.getPortalTravelAgent().setSearchRadius(searchRadius); - event.useTravelAgent(true); - Logging.finer("Used travel agent to set entity portal search radius."); - return; - } - if (entityPortalSearchRadius == null) { - Logging.warning("Unable to set entity portal search radius!"); - return; - } - ReflectHelper.invokeMethod(event, entityPortalSearchRadius, searchRadius); - Logging.finer("Used new method to set entity portal search radius."); - } -} From 9d34e5d75c72030bc56da02758c5bad84e810434 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 2 Feb 2023 15:13:00 +0800 Subject: [PATCH 003/725] fix: Replace deprecated EntityCreatePortalEvent with PortalCreateEvent Use PortalCreateEvent which allows better checking of nether portal creation. --- .../MultiverseCore/MultiverseCore.java | 1 - .../listeners/MVPortalListener.java | 74 ++++++++++++------- 2 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index aa952101f..a66f95de0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -391,7 +391,6 @@ private void registerEvents() { pm.registerEvents(this.entityListener, this); pm.registerEvents(this.weatherListener, this); pm.registerEvents(this.portalListener, this); - Logging.info(ChatColor.GREEN + "We are aware of the warning about the deprecated event. There is no alternative that allows us to do what we need to do and performance impact is negligible. It is safe to ignore."); pm.registerEvents(this.worldListener, this); pm.registerEvents(new MVMapListener(this), this); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java index c348ac3da..dee9f7b5e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPortalListener.java @@ -12,15 +12,13 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import org.bukkit.Material; import org.bukkit.PortalType; +import org.bukkit.block.BlockState; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityCreatePortalEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.world.PortalCreateEvent; -import java.util.logging.Level; - /** * A custom listener for portal related events. */ @@ -33,31 +31,48 @@ public MVPortalListener(MultiverseCore core) { } /** - * This is called when an entity creates a portal. - * - * @param event The event where an entity created a portal. + * This is called when a portal is formed. + * @param event The event where a portal was created or formed due to a world link */ - @EventHandler - public void entityPortalCreate(EntityCreatePortalEvent event) { - if (event.isCancelled() || event.getBlocks().size() == 0) { + @EventHandler(ignoreCancelled = true) + public void portalForm(PortalCreateEvent event) { + Logging.fine("Attempting to create portal at '%s' with reason: %s", event.getWorld().getName(), event.getReason()); + + MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld()); + if (world == null) { + Logging.fine("World '%s' is not managed by Multiverse! Ignoring at PortalCreateEvent.", event.getWorld().getName()); return; } - MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getEntity().getWorld()); - // We have to do it like this due to a bug in 1.1-R3 - if (world != null && !world.getAllowedPortals().isPortalAllowed(event.getPortalType())) { - event.setCancelled(true); + + PortalType targetType; + switch (event.getReason()) { + case FIRE: + // Ensure portal by flint and steel actually creates nether + boolean isNether = false; + for (BlockState block : event.getBlocks()) { + if (block.getType() == Material.NETHER_PORTAL) { + isNether = true; + break; + } + } + if (!isNether) { + return; + } + targetType = PortalType.NETHER; + break; + case NETHER_PAIR: + targetType = PortalType.NETHER; + break; + case END_PLATFORM: + targetType = PortalType.ENDER; + break; + default: + Logging.fine("Portal created is not NETHER or ENDER type. Ignoring..."); + return; } - } - /** - * This is called when a portal is created as the result of another world being linked. - * @param event The event where a portal was formed due to a world link - */ - @EventHandler(ignoreCancelled = true) - public void portalForm(PortalCreateEvent event) { - MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getWorld()); - if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.NETHER)) { - Logging.fine("Cancelling creation of nether portal because portalForm disallows."); + if (!world.getAllowedPortals().isPortalAllowed(targetType)) { + Logging.fine("Cancelling creation of %s portal because portalForm disallows.", targetType); event.setCancelled(true); } } @@ -72,15 +87,22 @@ public void portalForm(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { return; } - if (event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) { + if (event.getClickedBlock() == null || event.getClickedBlock().getType() != Material.END_PORTAL_FRAME) { return; } if (event.getItem() == null || event.getItem().getType() != Material.ENDER_EYE) { return; } + MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(event.getPlayer().getWorld()); - if (world != null && !world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) { - Logging.fine("Cancelling creation of ender portal because portalForm disallows."); + if (world == null) { + Logging.fine("World '%s' is not managed by Multiverse! Ignoring at PlayerInteractEvent.", + event.getPlayer().getWorld().getName()); + return; + } + + if (!world.getAllowedPortals().isPortalAllowed(PortalType.ENDER)) { + Logging.fine("Cancelling creation of ENDER portal because portalForm disallows."); event.setCancelled(true); } } From 3fb99bc15628fe2e1f1120f43ef46fb2c3809c49 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 2 Feb 2023 16:49:45 +0800 Subject: [PATCH 004/725] feat: Add ACF dependency and prep command migration --- config/mv_checks.xml | 2 +- pom.xml | 18 ++++ .../MultiverseCore/MultiverseCore.java | 84 +++++++++++-------- .../onarandombox/MultiverseCore/api/Core.java | 9 ++ .../MultiverseCore/commands/DebugCommand.java | 80 +++++++----------- .../commands/MultiverseCommand.java | 35 +------- .../MultiverseCore/commands/package-info.java | 4 - .../AnchorCommand.java | 2 +- .../CheckCommand.java | 2 +- .../CloneCommand.java | 2 +- .../ConfigCommand.java | 2 +- .../ConfirmCommand.java | 2 +- .../CoordCommand.java | 3 +- .../CreateCommand.java | 2 +- .../commandsold/DebugCommand.java | 66 +++++++++++++++ .../DeleteCommand.java | 3 +- .../EnvironmentCommand.java | 2 +- .../GameruleCommand.java | 2 +- .../GamerulesCommand.java | 2 +- .../GeneratorCommand.java | 2 +- .../HelpCommand.java | 2 +- .../ImportCommand.java | 2 +- .../InfoCommand.java | 2 +- .../ListCommand.java | 2 +- .../LoadCommand.java | 2 +- .../ModifyAddCommand.java | 2 +- .../ModifyClearCommand.java | 2 +- .../ModifyCommand.java | 2 +- .../ModifyRemoveCommand.java | 2 +- .../ModifySetCommand.java | 2 +- .../commandsold/MultiverseCommand.java | 40 +++++++++ .../PaginatedCommand.java | 2 +- .../PaginatedCoreCommand.java | 2 +- .../PurgeCommand.java | 2 +- .../RegenCommand.java | 2 +- .../ReloadCommand.java | 2 +- .../RemoveCommand.java | 2 +- .../ScriptCommand.java | 2 +- .../SetSpawnCommand.java | 2 +- .../SilentCommand.java | 2 +- .../SleepCommand.java | 2 +- .../SpawnCommand.java | 2 +- .../TeleportCommand.java | 3 +- .../UnloadCommand.java | 2 +- .../VersionCommand.java | 2 +- .../{commands => commandsold}/WhoCommand.java | 2 +- .../commandsold/package-info.java | 4 + .../commandtools/MVCommandCompletions.java | 9 ++ .../commandtools/MVCommandContexts.java | 9 ++ .../commandtools/MVCommandManager.java | 54 ++++++++++++ .../destination/DestinationFactory.java | 4 +- 51 files changed, 331 insertions(+), 164 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commands/package-info.java rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/AnchorCommand.java (99%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/CheckCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/CloneCommand.java (97%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ConfigCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ConfirmCommand.java (96%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/CoordCommand.java (97%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/CreateCommand.java (99%) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/DeleteCommand.java (96%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/EnvironmentCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/GameruleCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/GamerulesCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/GeneratorCommand.java (97%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/HelpCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ImportCommand.java (99%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/InfoCommand.java (99%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ListCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/LoadCommand.java (96%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ModifyAddCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ModifyClearCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ModifyCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ModifyRemoveCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ModifySetCommand.java (99%) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/PaginatedCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/PaginatedCoreCommand.java (94%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/PurgeCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/RegenCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ReloadCommand.java (97%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/RemoveCommand.java (96%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/ScriptCommand.java (97%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/SetSpawnCommand.java (99%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/SilentCommand.java (97%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/SleepCommand.java (96%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/SpawnCommand.java (98%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/TeleportCommand.java (99%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/UnloadCommand.java (96%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/VersionCommand.java (99%) rename src/main/java/com/onarandombox/MultiverseCore/{commands => commandsold}/WhoCommand.java (99%) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java diff --git a/config/mv_checks.xml b/config/mv_checks.xml index 0c660d8d9..2048eff59 100644 --- a/config/mv_checks.xml +++ b/config/mv_checks.xml @@ -69,7 +69,7 @@ - + diff --git a/pom.xml b/pom.xml index e714385f0..44d3ab20a 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,10 @@ minebench-repo https://repo.minebench.de/ + + aikar + https://repo.aikar.co/content/groups/aikar/ + @@ -154,6 +158,7 @@ maven-surefire-plugin 3.0.0-M3 + true **/TestCommandSender.java **/TestInstanceCreator.java @@ -251,6 +256,14 @@ de.themoep.idconverter com.onarandombox.idconverter + + co.aikar.commands + com.onarandombox.acf + + + co.aikar.locales + com.onarandombox.locales + @@ -307,6 +320,11 @@
+ + co.aikar + acf-paper + 0.5.1-SNAPSHOT + com.pneumaticraft.commandhandler CommandHandler diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index a66f95de0..15700950a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -33,41 +33,42 @@ import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig; import com.onarandombox.MultiverseCore.api.MultiverseMessaging; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.commands.AnchorCommand; -import com.onarandombox.MultiverseCore.commands.CheckCommand; -import com.onarandombox.MultiverseCore.commands.CloneCommand; -import com.onarandombox.MultiverseCore.commands.ConfigCommand; -import com.onarandombox.MultiverseCore.commands.ConfirmCommand; -import com.onarandombox.MultiverseCore.commands.CoordCommand; -import com.onarandombox.MultiverseCore.commands.CreateCommand; import com.onarandombox.MultiverseCore.commands.DebugCommand; -import com.onarandombox.MultiverseCore.commands.DeleteCommand; -import com.onarandombox.MultiverseCore.commands.EnvironmentCommand; -import com.onarandombox.MultiverseCore.commands.GameruleCommand; -import com.onarandombox.MultiverseCore.commands.GamerulesCommand; -import com.onarandombox.MultiverseCore.commands.GeneratorCommand; -import com.onarandombox.MultiverseCore.commands.HelpCommand; -import com.onarandombox.MultiverseCore.commands.ImportCommand; -import com.onarandombox.MultiverseCore.commands.InfoCommand; -import com.onarandombox.MultiverseCore.commands.ListCommand; -import com.onarandombox.MultiverseCore.commands.LoadCommand; -import com.onarandombox.MultiverseCore.commands.ModifyAddCommand; -import com.onarandombox.MultiverseCore.commands.ModifyClearCommand; -import com.onarandombox.MultiverseCore.commands.ModifyCommand; -import com.onarandombox.MultiverseCore.commands.ModifyRemoveCommand; -import com.onarandombox.MultiverseCore.commands.ModifySetCommand; -import com.onarandombox.MultiverseCore.commands.PurgeCommand; -import com.onarandombox.MultiverseCore.commands.RegenCommand; -import com.onarandombox.MultiverseCore.commands.ReloadCommand; -import com.onarandombox.MultiverseCore.commands.RemoveCommand; -import com.onarandombox.MultiverseCore.commands.ScriptCommand; -import com.onarandombox.MultiverseCore.commands.SetSpawnCommand; -import com.onarandombox.MultiverseCore.commands.SilentCommand; -import com.onarandombox.MultiverseCore.commands.SpawnCommand; -import com.onarandombox.MultiverseCore.commands.TeleportCommand; -import com.onarandombox.MultiverseCore.commands.UnloadCommand; -import com.onarandombox.MultiverseCore.commands.VersionCommand; -import com.onarandombox.MultiverseCore.commands.WhoCommand; +import com.onarandombox.MultiverseCore.commandsold.AnchorCommand; +import com.onarandombox.MultiverseCore.commandsold.CheckCommand; +import com.onarandombox.MultiverseCore.commandsold.CloneCommand; +import com.onarandombox.MultiverseCore.commandsold.ConfigCommand; +import com.onarandombox.MultiverseCore.commandsold.ConfirmCommand; +import com.onarandombox.MultiverseCore.commandsold.CoordCommand; +import com.onarandombox.MultiverseCore.commandsold.CreateCommand; +import com.onarandombox.MultiverseCore.commandsold.DeleteCommand; +import com.onarandombox.MultiverseCore.commandsold.EnvironmentCommand; +import com.onarandombox.MultiverseCore.commandsold.GameruleCommand; +import com.onarandombox.MultiverseCore.commandsold.GamerulesCommand; +import com.onarandombox.MultiverseCore.commandsold.GeneratorCommand; +import com.onarandombox.MultiverseCore.commandsold.HelpCommand; +import com.onarandombox.MultiverseCore.commandsold.ImportCommand; +import com.onarandombox.MultiverseCore.commandsold.InfoCommand; +import com.onarandombox.MultiverseCore.commandsold.ListCommand; +import com.onarandombox.MultiverseCore.commandsold.LoadCommand; +import com.onarandombox.MultiverseCore.commandsold.ModifyAddCommand; +import com.onarandombox.MultiverseCore.commandsold.ModifyClearCommand; +import com.onarandombox.MultiverseCore.commandsold.ModifyCommand; +import com.onarandombox.MultiverseCore.commandsold.ModifyRemoveCommand; +import com.onarandombox.MultiverseCore.commandsold.ModifySetCommand; +import com.onarandombox.MultiverseCore.commandsold.PurgeCommand; +import com.onarandombox.MultiverseCore.commandsold.RegenCommand; +import com.onarandombox.MultiverseCore.commandsold.ReloadCommand; +import com.onarandombox.MultiverseCore.commandsold.RemoveCommand; +import com.onarandombox.MultiverseCore.commandsold.ScriptCommand; +import com.onarandombox.MultiverseCore.commandsold.SetSpawnCommand; +import com.onarandombox.MultiverseCore.commandsold.SilentCommand; +import com.onarandombox.MultiverseCore.commandsold.SpawnCommand; +import com.onarandombox.MultiverseCore.commandsold.TeleportCommand; +import com.onarandombox.MultiverseCore.commandsold.UnloadCommand; +import com.onarandombox.MultiverseCore.commandsold.VersionCommand; +import com.onarandombox.MultiverseCore.commandsold.WhoCommand; +import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager; import com.onarandombox.MultiverseCore.destination.AnchorDestination; import com.onarandombox.MultiverseCore.destination.BedDestination; @@ -204,6 +205,7 @@ public int getProtocolVersion() { // Setup our Map for our Commands using the CommandHandler. private CommandHandler commandHandler; + private MVCommandManager commandManager; private CommandQueueManager commandQueueManager; private static final String LOG_TAG = "[Multiverse-Core]"; @@ -287,6 +289,7 @@ public void onEnable() { // Setup the command manager this.commandHandler = new CommandHandler(this, this.ph); + this.commandManager = new MVCommandManager(this); this.commandQueueManager = new CommandQueueManager(this); // Call the Function to assign all the Commands to their Class. this.registerCommands(); @@ -781,13 +784,16 @@ private void registerCommands() { this.commandHandler.registerCommand(new AnchorCommand(this)); // Misc Commands this.commandHandler.registerCommand(new EnvironmentCommand(this)); - this.commandHandler.registerCommand(new DebugCommand(this)); + // this.commandHandler.registerCommand(new DebugCommand(this)); this.commandHandler.registerCommand(new SilentCommand(this)); this.commandHandler.registerCommand(new GeneratorCommand(this)); this.commandHandler.registerCommand(new CheckCommand(this)); this.commandHandler.registerCommand(new ScriptCommand(this)); this.commandHandler.registerCommand(new GameruleCommand(this)); this.commandHandler.registerCommand(new GamerulesCommand(this)); + + //**NEW ACF COMMAND HANDLER** + this.commandManager.registerCommand(new DebugCommand(this)); } /** @@ -918,6 +924,14 @@ public CommandHandler getCommandHandler() { return this.commandHandler; } + /** + * {@inheritDoc} + */ + @Override + public MVCommandManager getCommandManager() { + return this.commandManager; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index 5f66cddb1..d1d4e9e87 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -8,6 +8,7 @@ package com.onarandombox.MultiverseCore.api; import buscript.Buscript; +import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager; import com.onarandombox.MultiverseCore.destination.DestinationFactory; import com.onarandombox.MultiverseCore.utils.AnchorManager; @@ -87,6 +88,14 @@ public interface Core { */ CommandHandler getCommandHandler(); + /** + * Multiverse uses {@link MVCommandManager} to make adding and using commands + * a piece of cake. + * + * @return A non-null {@link MVCommandManager}. + */ + MVCommandManager getCommandManager(); + /** * Manager for command that requires /mv confirm before execution. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java index b2ccd99e4..3c1830379 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java @@ -1,67 +1,47 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - package com.onarandombox.MultiverseCore.commands; +import co.aikar.commands.CommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Conditions; +import co.aikar.commands.annotation.Subcommand; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; -import java.util.logging.Level; +import org.jetbrains.annotations.NotNull; -/** - * Enables debug-information. - */ +@CommandAlias("mv") public class DebugCommand extends MultiverseCommand { public DebugCommand(MultiverseCore plugin) { super(plugin); - this.setName("Turn Debug on/off?"); - this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]"); - this.setArgRange(0, 1); - this.addKey("mv debug"); - this.addKey("mv d"); - this.addKey("mvdebug"); - this.addCommandExample("/mv debug " + ChatColor.GOLD + "2"); - this.setPermission("multiverse.core.debug", "Spams the console a bunch.", PermissionDefault.OP); } - @Override - public void runCommand(CommandSender sender, List args) { - if (args.size() == 1) { - if (args.get(0).equalsIgnoreCase("off")) { - plugin.getMVConfig().setGlobalDebug(0); - } else { - try { - int debugLevel = Integer.parseInt(args.get(0)); - if (debugLevel > 3 || debugLevel < 0) { - throw new NumberFormatException(); - } - plugin.getMVConfig().setGlobalDebug(debugLevel); - } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE - + " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)"); - } - } - plugin.saveMVConfigs(); - } - this.displayDebugMode(sender); + @Subcommand("debug") + @CommandPermission("multiverse.core.debug") + public void onShowDebugCommand(@NotNull CommandIssuer issuer) { + this.displayDebugMode(issuer); + } + + + @Subcommand("debug") + @CommandPermission("multiverse.core.debug") + @CommandCompletion("@range:3") + public void onChangeDebugCommand(@NotNull CommandIssuer issuer, + @Conditions("debuglevel") int level) { + + this.plugin.getMVConfig().setGlobalDebug(level); + this.plugin.saveMVConfigs(); + this.displayDebugMode(issuer); } - private void displayDebugMode(CommandSender sender) { - final int debugLevel = plugin.getMVConfig().getGlobalDebug(); + private void displayDebugMode(@NotNull CommandIssuer issuer) { + final int debugLevel = this.plugin.getMVConfig().getGlobalDebug(); if (debugLevel == 0) { - sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF"); - } else { - sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel); - Logging.fine("Multiverse Debug ENABLED"); + issuer.sendMessage("§fMultiverse Debug mode is §cOFF§f."); + return; } + issuer.sendMessage("§fMultiverse Debug mode is at §alevel {level}§f."); + Logging.fine("Multiverse Debug ENABLED."); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java index ae54a9b8f..42a65604e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java @@ -1,40 +1,13 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - package com.onarandombox.MultiverseCore.commands; +import co.aikar.commands.BaseCommand; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MultiverseMessaging; -import com.pneumaticraft.commandhandler.Command; -import org.bukkit.command.CommandSender; - -import java.util.List; -/** - * A generic Multiverse-command. - */ -public abstract class MultiverseCommand extends Command { +public class MultiverseCommand extends BaseCommand { - /** - * The reference to the core. - */ - protected MultiverseCore plugin; - /** - * The reference to {@link MultiverseMessaging}. - */ - protected MultiverseMessaging messaging; + protected final MultiverseCore plugin; - public MultiverseCommand(MultiverseCore plugin) { - super(plugin); + protected MultiverseCommand(MultiverseCore plugin) { this.plugin = plugin; - this.messaging = this.plugin.getMessaging(); } - - @Override - public abstract void runCommand(CommandSender sender, List args); - } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/package-info.java b/src/main/java/com/onarandombox/MultiverseCore/commands/package-info.java deleted file mode 100644 index 53d7f9b3f..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * This package contains all Commands. - */ -package com.onarandombox.MultiverseCore.commands; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java index 55d0b2cff..5009c2702 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java index 7bc4ba480..519dfa21a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java similarity index 97% rename from src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java index 95a0bf146..7f2a2efe8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import java.util.List; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java index 55424a941..e454dd959 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfirmCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java similarity index 96% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ConfirmCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java index 498a1431b..c216ca373 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfirmCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java similarity index 97% rename from src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java index 485cc3701..b7ce8553a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java @@ -5,13 +5,12 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import org.bukkit.ChatColor; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java index 6d8f3833b..750c9e625 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java new file mode 100644 index 000000000..81a7f74f4 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java @@ -0,0 +1,66 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + +package com.onarandombox.MultiverseCore.commandsold; + +import com.dumptruckman.minecraft.util.Logging; +import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.permissions.PermissionDefault; + +import java.util.List; + +/** + * Enables debug-information. + */ +public class DebugCommand extends MultiverseCommand { + + public DebugCommand(MultiverseCore plugin) { + super(plugin); + this.setName("Turn Debug on/off?"); + this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]"); + this.setArgRange(0, 1); + this.addKey("mv debug"); + this.addKey("mv d"); + this.addKey("mvdebug"); + this.addCommandExample("/mv debug " + ChatColor.GOLD + "2"); + this.setPermission("multiverse.core.debug", "Spams the console a bunch.", PermissionDefault.OP); + } + + @Override + public void runCommand(CommandSender sender, List args) { + if (args.size() == 1) { + if (args.get(0).equalsIgnoreCase("off")) { + plugin.getMVConfig().setGlobalDebug(0); + } else { + try { + int debugLevel = Integer.parseInt(args.get(0)); + if (debugLevel > 3 || debugLevel < 0) { + throw new NumberFormatException(); + } + plugin.getMVConfig().setGlobalDebug(debugLevel); + } catch (NumberFormatException e) { + sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE + + " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)"); + } + } + plugin.saveMVConfigs(); + } + this.displayDebugMode(sender); + } + + private void displayDebugMode(CommandSender sender) { + final int debugLevel = plugin.getMVConfig().getGlobalDebug(); + if (debugLevel == 0) { + sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF"); + } else { + sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel); + Logging.fine("Multiverse Debug ENABLED"); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java similarity index 96% rename from src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java index 603454935..85157d161 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; @@ -14,7 +14,6 @@ import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.List; /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java index f9ac88600..9fc85cd4e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java index ca0e1e076..053c9f236 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GameruleCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.Bukkit; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java index 448b5c134..ade81ae4e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GamerulesCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.display.ColorAlternator; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java similarity index 97% rename from src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java index 72d4379b6..342d71a18 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java index 59a429e44..42cbf9788 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/HelpCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.pneumaticraft.commandhandler.Command; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java index 7a52d5a15..9d44dbcf9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java index 701424e70..579f271db 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.FancyText; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java index db8ee1a45..c43c7fa5a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java similarity index 96% rename from src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java index 4a96ef36c..2b60a8dad 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java index 1175d3408..93229d325 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyAddCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java index 788b7452b..93e576635 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyClearCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java index d8c74ac3d..c87a0761f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.enums.Action; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java index f714be763..51792d99f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyRemoveCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java index 54bf8a11e..57a487682 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifySetCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java new file mode 100644 index 000000000..ac0aa7ba2 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java @@ -0,0 +1,40 @@ +/****************************************************************************** + * Multiverse 2 Copyright (c) the Multiverse Team 2011. * + * Multiverse 2 is licensed under the BSD License. * + * For more information please check the README.md file included * + * with this project. * + ******************************************************************************/ + +package com.onarandombox.MultiverseCore.commandsold; + +import java.util.List; + +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MultiverseMessaging; +import com.pneumaticraft.commandhandler.Command; +import org.bukkit.command.CommandSender; + +/** + * A generic Multiverse-command. + */ +public abstract class MultiverseCommand extends Command { + + /** + * The reference to the core. + */ + protected MultiverseCore plugin; + /** + * The reference to {@link MultiverseMessaging}. + */ + protected MultiverseMessaging messaging; + + public MultiverseCommand(MultiverseCore plugin) { + super(plugin); + this.plugin = plugin; + this.messaging = this.plugin.getMessaging(); + } + + @Override + public abstract void runCommand(CommandSender sender, List args); + +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java index 2dd11a2aa..3e603e87d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.pneumaticraft.commandhandler.Command; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCoreCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java similarity index 94% rename from src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCoreCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java index 7071311aa..ebd407b7e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/PaginatedCoreCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java index 8b7c4a26c..38f32ca69 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java index 4efe7ad51..2d2498424 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ReloadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java similarity index 97% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ReloadCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java index abe2b0a64..680de34a7 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ReloadCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java similarity index 96% rename from src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java index ff24e7408..aa821b33b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java similarity index 97% rename from src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java index 665f6aa71..baec84fbd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java index 26dad442c..5e9fa3c6e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/SetSpawnCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.BlockSafety; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SilentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java similarity index 97% rename from src/main/java/com/onarandombox/MultiverseCore/commands/SilentCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java index 4d0bfd735..455022968 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/SilentCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SleepCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java similarity index 96% rename from src/main/java/com/onarandombox/MultiverseCore/commands/SleepCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java index 08156d200..c258b8f09 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/SleepCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.command.CommandSender; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java similarity index 98% rename from src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java index 8e865545c..ae6c97dd3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/SpawnCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java index 9507236cd..15571fd48 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -28,7 +28,6 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; -import java.util.ArrayList; import java.util.List; /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/UnloadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java similarity index 96% rename from src/main/java/com/onarandombox/MultiverseCore/commands/UnloadCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java index 52f92c6ca..04a35e177 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/UnloadCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.ChatColor; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java index f032fd20c..c0a938add 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java similarity index 99% rename from src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java rename to src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java index 1a03df281..fa9ab935f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/WhoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java @@ -5,7 +5,7 @@ * with this project. * ******************************************************************************/ -package com.onarandombox.MultiverseCore.commands; +package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVWorldManager; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java new file mode 100644 index 000000000..a7559b959 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java @@ -0,0 +1,4 @@ +/** + * This package contains all Commands. + */ +package com.onarandombox.MultiverseCore.commandsold; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java new file mode 100644 index 000000000..7b5cbd9ff --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java @@ -0,0 +1,9 @@ +package com.onarandombox.MultiverseCore.commandtools; + +import co.aikar.commands.PaperCommandCompletions; + +public class MVCommandCompletions extends PaperCommandCompletions { + public MVCommandCompletions(MVCommandManager mvCommandManager) { + super(mvCommandManager); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java new file mode 100644 index 000000000..0ed2ac902 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java @@ -0,0 +1,9 @@ +package com.onarandombox.MultiverseCore.commandtools; + +import co.aikar.commands.PaperCommandContexts; + +public class MVCommandContexts extends PaperCommandContexts { + public MVCommandContexts(MVCommandManager mvCommandManager) { + super(mvCommandManager); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java new file mode 100644 index 000000000..d84689f2c --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java @@ -0,0 +1,54 @@ +package com.onarandombox.MultiverseCore.commandtools; + +import java.util.Locale; + +import co.aikar.commands.BukkitCommandCompletionContext; +import co.aikar.commands.BukkitCommandExecutionContext; +import co.aikar.commands.CommandCompletions; +import co.aikar.commands.CommandContexts; +import co.aikar.commands.PaperCommandManager; +import com.onarandombox.MultiverseCore.MultiverseCore; + +/** + * Main class to manage permissions. + */ +public class MVCommandManager extends PaperCommandManager { + + private final MultiverseCore plugin; + + public MVCommandManager(MultiverseCore plugin) { + super(plugin); + this.plugin = plugin; + + // Setup locale + this.addSupportedLanguage(Locale.ENGLISH); + this.locales.addMessageBundles("multiverse-core"); + this.locales.loadLanguages(); + } + + /** + * Gets class responsible for parsing string args into objects. + * + * @return A not-null {@link CommandContexts}. + */ + @Override + public synchronized CommandContexts getCommandContexts() { + if (this.contexts == null) { + this.contexts = new MVCommandContexts(this); + } + return this.contexts; + } + + /** + * Gets class responsible for tab-completion handling. + * + * @return A not-null {@link CommandCompletions}. + */ + @Override + public synchronized CommandCompletions getCommandCompletions() { + if (this.completions == null) { + this.completions = new MVCommandCompletions(this); + } + return this.completions; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java index 402342c3d..7f00248c9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java @@ -9,17 +9,15 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.commands.TeleportCommand; +import com.onarandombox.MultiverseCore.commandsold.TeleportCommand; import com.onarandombox.MultiverseCore.utils.PermissionTools; import com.onarandombox.MultiverseCore.utils.PlayerFinder; import com.pneumaticraft.commandhandler.Command; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Collection; import java.util.HashMap; From a034eaa55544b052fc9b62dc67e753da168ca737 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 2 Feb 2023 17:06:36 +0800 Subject: [PATCH 005/725] feat: Implement basic localisation --- .../MultiverseCore/commands/DebugCommand.java | 16 +++++++++++++--- .../MultiverseCore/locale/MVCorei18n.java | 18 ++++++++++++++++++ .../resources/multiverse-core_en.properties | 7 +++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/locale/MVCorei18n.java create mode 100644 src/main/resources/multiverse-core_en.properties diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java index 3c1830379..e4cabe2a4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java @@ -5,9 +5,12 @@ import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Conditions; +import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.locale.MVCorei18n; import org.jetbrains.annotations.NotNull; @CommandAlias("mv") @@ -19,6 +22,7 @@ public DebugCommand(MultiverseCore plugin) { @Subcommand("debug") @CommandPermission("multiverse.core.debug") + @Description("{@@mv-core.debug_info_description}") public void onShowDebugCommand(@NotNull CommandIssuer issuer) { this.displayDebugMode(issuer); } @@ -26,9 +30,15 @@ public void onShowDebugCommand(@NotNull CommandIssuer issuer) { @Subcommand("debug") @CommandPermission("multiverse.core.debug") + @Syntax("<{@@mv-core.debug_change_syntax}>") @CommandCompletion("@range:3") + @Description("{@@mv-core.debug_change_description}") public void onChangeDebugCommand(@NotNull CommandIssuer issuer, - @Conditions("debuglevel") int level) { + + @Conditions("debuglevel") + @Syntax("<{@@mv-core.debug_change_syntax}>") + @Description("{@@mv-core.debug_change_level_description}") + int level) { this.plugin.getMVConfig().setGlobalDebug(level); this.plugin.saveMVConfigs(); @@ -38,10 +48,10 @@ public void onChangeDebugCommand(@NotNull CommandIssuer issuer, private void displayDebugMode(@NotNull CommandIssuer issuer) { final int debugLevel = this.plugin.getMVConfig().getGlobalDebug(); if (debugLevel == 0) { - issuer.sendMessage("§fMultiverse Debug mode is §cOFF§f."); + issuer.sendInfo(MVCorei18n.DEBUG_INFO_OFF); return; } - issuer.sendMessage("§fMultiverse Debug mode is at §alevel {level}§f."); + issuer.sendInfo(MVCorei18n.DEBUG_INFO_ON, "{level}", String.valueOf(debugLevel)); Logging.fine("Multiverse Debug ENABLED."); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/locale/MVCorei18n.java b/src/main/java/com/onarandombox/MultiverseCore/locale/MVCorei18n.java new file mode 100644 index 000000000..f91073d04 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/locale/MVCorei18n.java @@ -0,0 +1,18 @@ +package com.onarandombox.MultiverseCore.locale; + +import co.aikar.locales.MessageKey; +import co.aikar.locales.MessageKeyProvider; + +public enum MVCorei18n implements MessageKeyProvider { + + CONFIG_SAVE_FAILED, + DEBUG_INFO_OFF, + DEBUG_INFO_ON; + + private final MessageKey key = MessageKey.of("mv-core." + this.name().toLowerCase()); + + @Override + public MessageKey getMessageKey() { + return this.key; + } + } diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties new file mode 100644 index 000000000..be09fb1f7 --- /dev/null +++ b/src/main/resources/multiverse-core_en.properties @@ -0,0 +1,7 @@ +mv-core.config_save_failed=§cUnable to save Multiverse-Core config.yml. Your changes will be temporary! +mv-core.debug_info_description=Show the current debug level. +mv-core.debug_info_off=§fMultiverse Debug mode is §cOFF§f. +mv-core.debug_info_on=§fMultiverse Debug mode is at §alevel {level}§f. +mv-core.debug_change_description=Change debug level. +mv-core.debug_change_syntax=level +mv-core.debug_change_level_description=Debug level to set to. From 83f5a4a70131b01b59a3e06a2ac4159afd39dc67 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 19:50:04 +0800 Subject: [PATCH 006/725] fix: Remove unused TravelAgent class --- .../MultiverseCore/utils/MVTravelAgent.java | 27 ------------------- 1 file changed, 27 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/MVTravelAgent.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVTravelAgent.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVTravelAgent.java deleted file mode 100644 index a86def8a5..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVTravelAgent.java +++ /dev/null @@ -1,27 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.utils; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.entity.Player; - -/** - * The Multiverse TravelAgent. - */ -public class MVTravelAgent { - protected MVDestination destination; - protected MultiverseCore core; - protected Player player; - - public MVTravelAgent(MultiverseCore multiverseCore, MVDestination d, Player p) { - this.destination = d; - this.core = multiverseCore; - this.player = p; - } -} From ccf802e32fe38f64410ff84fc0dd019a384e0d4e Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 20:15:46 +0800 Subject: [PATCH 007/725] perf: Update to use json-smart --- pom.xml | 6 ++++++ .../MultiverseCore/utils/webpaste/BitlyURLShortener.java | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 44d3ab20a..2628624a5 100644 --- a/pom.xml +++ b/pom.xml @@ -330,6 +330,12 @@ CommandHandler 11 + + + net.minidev + json-smart + 2.4.1 + com.dumptruckman.minecraft buscript diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/BitlyURLShortener.java b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/BitlyURLShortener.java index 0dbb8397e..3c1e7234c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/BitlyURLShortener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/webpaste/BitlyURLShortener.java @@ -1,12 +1,12 @@ package com.onarandombox.MultiverseCore.utils.webpaste; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; - import java.io.IOException; import java.util.Map; +import net.minidev.json.JSONObject; +import net.minidev.json.parser.JSONParser; +import net.minidev.json.parser.ParseException; + /** * A {@link URLShortener} using {@code bit.ly}. Requires an access token. */ From 0117159159ca269ca16590c61519c38339faaa72 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 20:23:53 +0800 Subject: [PATCH 008/725] feat: @benwoo1110 Revamp content display API commit 1211dfb0574a5d49740b3922147bbcc23540decc Author: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue Aug 17 16:29:31 2021 +0800 Implement suggested improvements. * Use singleton pattern for DefaultContentFilter with getInstance method. * Have a default SendHandler. * Don't need streams for small dataset. * Private WorldListContentParser class to improve readability. commit 562eed82558eadb9107557823ae170f6352f8cb2 Author: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue Aug 17 00:26:57 2021 +0800 Revamp content display API. --- .../commandsold/GamerulesCommand.java | 48 ++-- .../commandsold/ListCommand.java | 107 +++---- .../display/ColorAlternator.java | 62 ---- .../MultiverseCore/display/ColorTool.java | 22 -- .../display/ContentDisplay.java | 267 +++--------------- .../MultiverseCore/display/ContentFilter.java | 153 ---------- .../display/DisplayFormatException.java | 25 -- .../display/DisplayHandler.java | 68 ----- .../display/DisplayHandlers.java | 47 --- .../display/filters/ContentFilter.java | 21 ++ .../display/filters/DefaultContentFilter.java | 35 +++ .../display/filters/RegexContentFilter.java | 99 +++++++ .../display/handlers/BaseSendHandler.java | 99 +++++++ .../display/handlers/DefaultSendHandler.java | 29 ++ .../handlers/InlineListDisplayHandler.java | 36 --- .../handlers/InlineMapDisplayHandler.java | 44 --- .../display/handlers/InlineSendHandler.java | 53 ++++ .../display/handlers/ListDisplayHandler.java | 22 -- .../handlers/PagedListDisplayHandler.java | 105 ------- .../display/handlers/PagedSendHandler.java | 170 +++++++++++ .../display/handlers/SendHandler.java | 20 ++ .../display/parsers/ContentParser.java | 20 ++ .../display/parsers/ListContentParser.java | 60 ++++ .../display/parsers/MapContentParser.java | 112 ++++++++ .../display/settings/DisplaySetting.java | 19 -- .../settings/InlineDisplaySettings.java | 15 - .../display/settings/MapDisplaySettings.java | 15 - .../settings/PagedDisplaySettings.java | 30 -- 28 files changed, 838 insertions(+), 965 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/ColorAlternator.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/ColorTool.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/ContentFilter.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/DisplayFormatException.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandler.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandlers.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/filters/ContentFilter.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineListDisplayHandler.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineMapDisplayHandler.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/ListDisplayHandler.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedListDisplayHandler.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/handlers/SendHandler.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentParser.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentParser.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentParser.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/settings/DisplaySetting.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/settings/InlineDisplaySettings.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/settings/MapDisplaySettings.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/display/settings/PagedDisplaySettings.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java index ade81ae4e..4a8726df8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java @@ -8,9 +8,12 @@ package com.onarandombox.MultiverseCore.commandsold; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.display.ColorAlternator; import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.settings.MapDisplaySettings; +import com.onarandombox.MultiverseCore.display.filters.ContentFilter; +import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter; +import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter; +import com.onarandombox.MultiverseCore.display.handlers.InlineSendHandler; +import com.onarandombox.MultiverseCore.display.parsers.MapContentParser; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.GameRule; @@ -31,8 +34,8 @@ public class GamerulesCommand extends MultiverseCommand { public GamerulesCommand(MultiverseCore plugin) { super(plugin); this.setName("List the Minecraft Game Rules for a World."); - this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD]"); - this.setArgRange(0, 1); + this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD] [FILTER]"); + this.setArgRange(0, 2); this.addKey("mv gamerules"); this.addKey("mv rules"); this.addKey("mvgamerules"); @@ -42,11 +45,13 @@ public GamerulesCommand(MultiverseCore plugin) { this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP); } - @Override public void runCommand(CommandSender sender, List args) { // We NEED a world from the command line - final Player p; + Player p; + World world; + ContentFilter filter = DefaultContentFilter.getInstance(); + if (sender instanceof Player) { p = (Player) sender; } else { @@ -61,9 +66,20 @@ public void runCommand(CommandSender sender, List args) { return; } - final World world; + // Not the best way, need to fix with ACF soon... if (args.size() == 0) { world = p.getWorld(); + } else if (args.size() == 1) { + world = Bukkit.getWorld(args.get(0)); + if (world == null) { + if (p == null) { + sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0) + + ChatColor.WHITE + " does not exist."); + return; + } + world = p.getWorld(); + filter = RegexContentFilter.fromString(args.get(0)); + } } else { world = Bukkit.getWorld(args.get(0)); if (world == null) { @@ -71,23 +87,23 @@ public void runCommand(CommandSender sender, List args) { + ChatColor.WHITE + " does not exist."); return; } + filter = RegexContentFilter.fromString(args.get(1)); } - ContentDisplay.forContent(getGameRuleMap(world)) - .header("=== Gamerules for %s%s%s ===", ChatColor.AQUA, world.getName(), ChatColor.WHITE) - .colorTool(ColorAlternator.with(ChatColor.GREEN, ChatColor.GOLD)) - .setting(MapDisplaySettings.OPERATOR, ": ") - .show(sender); + ContentDisplay.create() + .addContentParser(MapContentParser.forContent(getGameRuleMap(world)) + .withKeyColor(ChatColor.GREEN) + .withValueColor(ChatColor.YELLOW)) + .withSendHandler(InlineSendHandler.create() + .withHeader("====[ Gamerules for %s%s%s ]====", ChatColor.AQUA, world.getName(), ChatColor.WHITE) + .withFilter(filter)) + .send(sender); } private Map getGameRuleMap(World world) { Map gameRuleMap = new HashMap<>(); for (GameRule rule : GameRule.values()) { Object value = world.getGameRuleValue(rule); - if (value == null) { - gameRuleMap.put(rule.getName(), "null"); - continue; - } gameRuleMap.put(rule.getName(), value); } return gameRuleMap; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java index c43c7fa5a..9b6c1a73a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java @@ -9,11 +9,12 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.display.ColorAlternator; import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.ContentFilter; -import com.onarandombox.MultiverseCore.display.DisplayHandlers; -import com.onarandombox.MultiverseCore.display.settings.PagedDisplaySettings; +import com.onarandombox.MultiverseCore.display.filters.ContentFilter; +import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter; +import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter; +import com.onarandombox.MultiverseCore.display.handlers.PagedSendHandler; +import com.onarandombox.MultiverseCore.display.parsers.ContentParser; import org.bukkit.ChatColor; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -21,9 +22,7 @@ import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; -import java.util.Collection; import java.util.List; -import java.util.stream.Collectors; /** * Displays a listing of all worlds that a player can enter. @@ -43,7 +42,7 @@ public ListCommand(MultiverseCore plugin) { @Override public void runCommand(CommandSender sender, List args) { - ContentFilter filter = ContentFilter.DEFAULT; + ContentFilter filter = DefaultContentFilter.getInstance(); int page = 1; // Either page or filter. @@ -51,13 +50,13 @@ public void runCommand(CommandSender sender, List args) { try { page = Integer.parseInt(args.get(0)); } catch (NumberFormatException ignore) { - filter = new ContentFilter(args.get(0)); + filter = RegexContentFilter.fromString(args.get(0)); } } // Filter then page. if (args.size() == 2) { - filter = new ContentFilter(args.get(0)); + filter = RegexContentFilter.fromString(args.get(0)); try { page = Integer.parseInt(args.get(1)); } catch (NumberFormatException ignore) { @@ -65,55 +64,57 @@ public void runCommand(CommandSender sender, List args) { } } - ContentDisplay.forContent(getListContents(sender)) - .header("%s====[ Multiverse World List ]====", ChatColor.GOLD) - .displayHandler(DisplayHandlers.PAGE_LIST) - .colorTool(ColorAlternator.with(ChatColor.AQUA, ChatColor.GOLD)) - .filter(filter) - .setting(PagedDisplaySettings.SHOW_PAGE, page) - .show(sender); + ContentDisplay.create() + .addContentParser(new WorldListContentParser()) + .withSendHandler(PagedSendHandler.create() + .withHeader("%s====[ Multiverse World List ]====", ChatColor.GOLD) + .withFilter(filter) + .withTargetPage(page)) + .send(sender); } - private Collection getListContents(@NotNull CommandSender sender) { - Player player = (sender instanceof Player) ? (Player) sender : null; - - List worldList = this.plugin.getMVWorldManager().getMVWorlds().stream() - .filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world)) - .filter(world -> canSeeWorld(player, world)) - .map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment())) - .collect(Collectors.toList()); - - this.plugin.getMVWorldManager().getUnloadedWorlds().stream() - .filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true)) - .map(world -> ChatColor.GRAY + world + " - UNLOADED") - .forEach(worldList::add); - - return worldList; - } + private class WorldListContentParser implements ContentParser { - private boolean canSeeWorld(Player player, MultiverseWorld world) { - return !world.isHidden() - || player == null - || this.plugin.getMVPerms().hasPermission(player, "multiverse.core.modify", true); - } + @Override + public void parse(@NotNull CommandSender sender, @NotNull List content) { + Player player = (sender instanceof Player) ? (Player) sender : null; - private String hiddenText(MultiverseWorld world) { - return (world.isHidden()) ? String.format("%s[H] ", ChatColor.GRAY) : ""; - } + plugin.getMVWorldManager().getMVWorlds().stream() + .filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world)) + .filter(world -> canSeeWorld(player, world)) + .map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment())) + .forEach(content::add); + + plugin.getMVWorldManager().getUnloadedWorlds().stream() + .filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true)) + .map(world -> ChatColor.GRAY + world + " - UNLOADED") + .forEach(content::add); + } - private String parseColouredEnvironment(World.Environment env) { - ChatColor color = ChatColor.GOLD; - switch (env) { - case NETHER: - color = ChatColor.RED; - break; - case NORMAL: - color = ChatColor.GREEN; - break; - case THE_END: - color = ChatColor.AQUA; - break; + private boolean canSeeWorld(Player player, MultiverseWorld world) { + return !world.isHidden() + || player == null + || plugin.getMVPerms().hasPermission(player, "multiverse.core.modify", true); + } + + private String hiddenText(MultiverseWorld world) { + return (world.isHidden()) ? String.format("%s[H] ", ChatColor.GRAY) : ""; + } + + private String parseColouredEnvironment(World.Environment env) { + ChatColor color = ChatColor.GOLD; + switch (env) { + case NETHER: + color = ChatColor.RED; + break; + case NORMAL: + color = ChatColor.GREEN; + break; + case THE_END: + color = ChatColor.AQUA; + break; + } + return color + env.toString(); } - return color + env.toString(); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/ColorAlternator.java b/src/main/java/com/onarandombox/MultiverseCore/display/ColorAlternator.java deleted file mode 100644 index 561394a91..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/ColorAlternator.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.onarandombox.MultiverseCore.display; - -import org.bukkit.ChatColor; -import org.jetbrains.annotations.NotNull; - -/** - * Helper class to switch between 2 {@link ChatColor}. - */ -public class ColorAlternator implements ColorTool { - - /** - * Creates a new {@link ColorAlternator} with 2 {@link ChatColor}s. - * - * @param colorThis The first color. - * @param colorThat The second color. - * @return The {@link ColorAlternator} created for you. - */ - public static ColorAlternator with(@NotNull ChatColor colorThis, - @NotNull ChatColor colorThat) { - - return new ColorAlternator(colorThis, colorThat); - } - - private boolean switcher; - private final ChatColor thisColor; - private final ChatColor thatColor; - - /** - * @param colorThis The first color. - * @param colorThat The second color. - */ - public ColorAlternator(@NotNull ChatColor colorThis, - @NotNull ChatColor colorThat) { - - this.thisColor = colorThis; - this.thatColor = colorThat; - } - - /** - * Gets the color. Everytime this method is called, it swaps the color that it returns. - * - * @return The color. - */ - @Override - public ChatColor get() { - return (this.switcher ^= true) ? this.thisColor : this.thatColor; - } - - /** - * @return The first color. - */ - public ChatColor getThisColor() { - return thisColor; - } - - /** - * @return The second color. - */ - public ChatColor getThatColor() { - return thatColor; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/ColorTool.java b/src/main/java/com/onarandombox/MultiverseCore/display/ColorTool.java deleted file mode 100644 index 1c4fae679..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/ColorTool.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.onarandombox.MultiverseCore.display; - -import org.bukkit.ChatColor; - -/** - * Tools to allow customisation. - */ -@FunctionalInterface -public interface ColorTool { - - /** - * Gets a chat color. - * - * @return The color. - */ - ChatColor get(); - - /** - * Default implementation of this interface. Returns a default white color. - */ - ColorTool DEFAULT = () -> ChatColor.WHITE; -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java b/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java index c5d9e39c6..b2303c54e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java +++ b/src/main/java/com/onarandombox/MultiverseCore/display/ContentDisplay.java @@ -1,268 +1,69 @@ package com.onarandombox.MultiverseCore.display; -import com.onarandombox.MultiverseCore.display.settings.DisplaySetting; -import org.bukkit.ChatColor; +import com.onarandombox.MultiverseCore.display.handlers.DefaultSendHandler; +import com.onarandombox.MultiverseCore.display.handlers.SendHandler; +import com.onarandombox.MultiverseCore.display.parsers.ContentParser; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -import java.util.Collection; -import java.util.Map; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; -import java.util.WeakHashMap; /** * Helps to display contents such as list and maps in a nicely formatted fashion. - * - * @param Type of content to display. */ -public class ContentDisplay { - - public static final String LINE_BREAK = "%br%"; - - /** - * Creates a ContentDisplay.Builder for the given content. - * - * @param content The content to be displayed. - * @param The type of the content which can be inferred. - * @return A new Builder. - */ - public static Builder forContent(T content) { - return new Builder<>(content); - } - - /** - * Creates a ContentDisplay.Builder for the given collection of content. - * - * @param content The content to be displayed. - * @return A new Builder. - */ - public static Builder> forContent(Collection content) { - return new Builder<>(content).displayHandler(DisplayHandlers.LIST); - } - - /** - * Creates a ContentDisplay.Builder for the given map of content. - * - * @param content The content to be displayed. - * @return A new Builder. - */ - public static Builder> forContent(Map content) { - return new Builder<>(content).displayHandler(DisplayHandlers.INLINE_MAP); - } - - private final T contents; - - private String header; - private String emptyMessage = "No matching content to display."; - private DisplayHandler displayHandler; - private ColorTool colorTool = ColorTool.DEFAULT; - private ContentFilter filter = ContentFilter.DEFAULT; - private final Map, Object> settingsMap = new WeakHashMap<>(); - - private ContentDisplay(T contents) { - this.contents = contents; - } +public class ContentDisplay { /** - * Do the actual displaying of contents to the sender. + * Makes a new {@link ContentDisplay} instance to use. * - * @param sender The CommandSender to show the display to. - */ - public void show(@NotNull CommandSender sender) { - Collection formattedContent; - try { - formattedContent = (this.contents == null) ? null : this.displayHandler.format(sender, this); - } catch (DisplayFormatException e) { - sender.sendMessage(String.format("%sError: %s", ChatColor.RED, e.getMessage())); - return; - } - this.displayHandler.sendHeader(sender, this); - this.displayHandler.sendSubHeader(sender, this); - this.displayHandler.sendBody(sender, this, formattedContent); - } - - /** - * @return Gets the header to display. - */ - public String getHeader() { - return header; - } - - /** - * Sets the header text. - */ - public void setHeader(@NotNull String header) { - this.header = header; - } - - /** - * @return Gets the contents to display. - */ - public T getContents() { - return contents; - } - - /** - * @return Gets the message to display when no content is shown. + * @return New {@link ContentDisplay} instance. */ @NotNull - public String getEmptyMessage() { - return emptyMessage; + public static ContentDisplay create() { + return new ContentDisplay(); } - /** - * @return Gets the display handler that formats and sends content to sender. - */ - @NotNull - public DisplayHandler getDisplayHandler() { - return displayHandler; - } - - /** - * @return Gets the color tool used. - */ - @NotNull - public ColorTool getColorTool() { - return colorTool; - } + private final List contentParsers = new ArrayList<>(); + private SendHandler sendHandler = DefaultSendHandler.getInstance(); - /** - * @return Gets the filter used. - */ - @NotNull - public ContentFilter getFilter() { - return filter; + public ContentDisplay() { } /** - * Gets the value for a given setting option. + * Adds content to be displayed. * - * @param setting The setting option. - * @param The setting type. - * @return Value set for the given setting. + * @param parser The content parser to add. + * @return Same {@link ContentDisplay} for method chaining. */ - public S getSetting(@NotNull DisplaySetting setting) { - return (S) settingsMap.getOrDefault(setting, setting.defaultValue()); + @NotNull + public ContentDisplay addContentParser(@NotNull ContentParser parser) { + contentParsers.add(parser); + return this; } /** - * Sets other specific settings that may be used by the {@link DisplayHandler}. + * Sets the handler for displaying the message to command sender. * - * @param setting The settings option. - * @param value The value to set. - * @param The type of setting. + * @param handler The send handler to use. + * @return Same {@link ContentDisplay} for method chaining. */ - public void setSetting(@NotNull DisplaySetting setting, S value) { - this.settingsMap.put(setting, value); + @NotNull + public ContentDisplay withSendHandler(@NotNull SendHandler handler) { + sendHandler = handler; + return this; } /** - * Builds a {@link ContentDisplay}. + * Format and display the message to command sender. * - * @param Type of content to display. + * @param sender The target command sender to show the display to. */ - public static class Builder { - - private final ContentDisplay display; - - private Builder(T content) { - this.display = new ContentDisplay<>(content); - } - - /** - * Sets header to be displayed. - * - * @param header The header text. - * @param replacements String formatting replacements. - * @return The builder. - */ - @NotNull - public Builder header(@NotNull String header, Object...replacements) { - this.display.header = String.format(header, replacements); - return this; - } - - /** - * Sets the message to show when no content is available for display. - * - * @param emptyMessage The message text. - * @param replacements String formatting replacements. - * @return The builder. - */ - @NotNull - public Builder emptyMessage(@NotNull String emptyMessage, Object...replacements) { - this.display.emptyMessage = String.format(emptyMessage, replacements); - return this; - } - - /** - * Sets the display handler that does the formatting and sending of content. Required. - * - * @param displayHandler The display handler for the given content type. - * @return The builder. - */ - @NotNull - public Builder displayHandler(@NotNull DisplayHandler displayHandler) { - this.display.displayHandler = displayHandler; - return this; - } - - /** - * Sets the color tool used to make messages more colourful. - * - * @param colorTool The color tool to use. - * @return The builder. - */ - @NotNull - public Builder colorTool(@NotNull ColorTool colorTool) { - this.display.colorTool = colorTool; - return this; - } - - /** - * Sets content filter used to match specific content to be displayed. - * - * @param filter The filter to use. - * @return The builder. - */ - @NotNull - public Builder filter(@NotNull ContentFilter filter) { - this.display.filter = filter; - return this; - } - - /** - * Sets other specific settings that may be used by the {@link DisplayHandler}. - * - * @param setting The settings option. - * @param value The value to set. - * @param The type of setting. - * @return The builder. - */ - @NotNull - public Builder setting(@NotNull DisplaySetting setting, S value) { - this.display.settingsMap.put(setting, value); - return this; - } - - /** - * Validates and build the content display. - * - * @return The content display. - */ - @NotNull - public ContentDisplay build() { - Objects.requireNonNull(this.display.displayHandler); - return this.display; - } - - /** - * Build and show the content to the sender. - * - * @param sender The CommandSender to show the display to. - */ - public void show(CommandSender sender) { - this.build().show(sender); - } + public void send(@NotNull CommandSender sender) { + Objects.requireNonNull(sendHandler, "No send handler set for content display"); + List parsedContent = new ArrayList<>(); + contentParsers.forEach(parser -> parser.parse(sender, parsedContent)); + sendHandler.send(sender, parsedContent); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/ContentFilter.java b/src/main/java/com/onarandombox/MultiverseCore/display/ContentFilter.java deleted file mode 100644 index cd0bed8cc..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/ContentFilter.java +++ /dev/null @@ -1,153 +0,0 @@ -package com.onarandombox.MultiverseCore.display; - -import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.ChatColor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.regex.Pattern; -import java.util.regex.PatternSyntaxException; - -/** - *

Filter content and text based on regex matching.

- * - *

Compile regex pattern based on {@link ContentFilter#filterString}. When prefixed with 'r=', - * use {@link ContentFilter#filterString} as the full regex pattern. Else, set to any match that - * contains the {@link ContentFilter#filterString}.

- */ -public class ContentFilter { - - public static final ContentFilter DEFAULT = new ContentFilter(); - private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]"); - - private String filterString; - private Pattern filterPattern; - private boolean exactMatch; - - private ContentFilter() { - } - - /** - * @param filterString The text to do matching, either plaintext or regex. - */ - public ContentFilter(@NotNull String filterString) { - this(filterString, false); - } - - /** - * @param filterString The text to do matching, else plaintext or regex. - * @param exactMatch Should check for exact match when doing regex matching. - */ - public ContentFilter(@NotNull String filterString, - boolean exactMatch) { - - this.filterString = filterString; - this.exactMatch = exactMatch; - parseFilter(); - } - - private void parseFilter() { - if (filterString == null) { - return; - } - if (filterString.startsWith("r=")) { - convertToMatcher(filterString.substring(2)); - return; - } - String cleanedFilter = REGEX_SPECIAL_CHARS.matcher(filterString.toLowerCase()).replaceAll("\\\\$0"); - convertToMatcher("(?i).*" + cleanedFilter + ".*"); - } - - /** - * Compile and store the regex into a {@link Pattern}. - * - * @param regex The regex text. - */ - private void convertToMatcher(@NotNull String regex) { - try { - this.filterPattern = Pattern.compile(regex); - Logging.finest("Parsed regex pattern: %s", this.filterPattern.toString()); - } - catch (PatternSyntaxException ignored) { - Logging.warning("Error parsing regex: %s", filterString); - } - } - - /** - * Do regex matching. - * - * @param text String to check regex on. - * @return True of matches regex pattern, false otherwise. - */ - public boolean checkMatch(@Nullable Object text) { - if (!hasFilter()) { - return true; - } - if (text == null || !hasValidPattern()) { - return false; - } - text = ChatColor.stripColor(String.valueOf(text)); - return (exactMatch) - ? filterPattern.matcher((CharSequence) text).matches() - : filterPattern.matcher((CharSequence) text).find(); - } - - /** - * Checks if a filter string is present. - * - * @return True if there is a filter string, else false. - */ - public boolean hasFilter() { - return filterString != null; - } - - /** - * Checks if regex pattern syntax is valid. - * - * @return True if valid, else false. - */ - public boolean hasValidPattern() { - return filterPattern != null; - } - - /** - * @return The filter string. - */ - @Nullable - public String getString() { - return filterString; - } - - /** - * @return The regex pattern. - */ - @Nullable - public Pattern getPattern() { - return filterPattern; - } - - /** - * @return True if filter is set to do exact matching, else false. - */ - public boolean isExactMatch() { - return exactMatch; - } - - /** - * Nicely format the filter string to be used for showing the sender. - * - * @return The formatted filter string. - */ - public @NotNull String getFormattedString() { - return String.format("%sFilter: '%s'", ChatColor.ITALIC, filterString); - } - - @Override - public String toString() { - return "ContentFilter{" + - "filterString='" + filterString + '\'' + - ", filterPattern=" + filterPattern + - ", exactMatch=" + exactMatch + - '}'; - } -} \ No newline at end of file diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/DisplayFormatException.java b/src/main/java/com/onarandombox/MultiverseCore/display/DisplayFormatException.java deleted file mode 100644 index 604d6acdc..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/DisplayFormatException.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.onarandombox.MultiverseCore.display; - -/** - * Thrown when an issue occur while formatting content. - */ -public class DisplayFormatException extends Exception { - public DisplayFormatException() { - } - - public DisplayFormatException(String message) { - super(message); - } - - public DisplayFormatException(String message, Throwable cause) { - super(message, cause); - } - - public DisplayFormatException(Throwable cause) { - super(cause); - } - - public DisplayFormatException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandler.java deleted file mode 100644 index 7971a11f5..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.onarandombox.MultiverseCore.display; - -import com.google.common.base.Strings; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -/** - * Handles the formatting and sending of all content by the {@link ContentDisplay}. - * - * @param Type of content to display. - */ -@FunctionalInterface -public interface DisplayHandler { - - /** - * Formats the raw content into a {@link Collection} for displaying to the given sender. - * - * @param sender The {@link CommandSender} who will the content will be displayed to. - * @param display The responsible {@link ContentDisplay}. - * @return The formatted content. - * @throws DisplayFormatException Issue occurred while formatting content. E.g. invalid page. - */ - Collection format(@NotNull CommandSender sender, @NotNull ContentDisplay display) - throws DisplayFormatException; - - /** - * Sends the header. - * - * @param sender The {@link CommandSender} who will the header will be displayed to. - * @param display The responsible {@link ContentDisplay}. - */ - default void sendHeader(@NotNull CommandSender sender, @NotNull ContentDisplay display) { - if (!Strings.isNullOrEmpty(display.getHeader())) { - sender.sendMessage(display.getHeader()); - } - } - - /** - * Sends info such as filter and page. - * - * @param sender The {@link CommandSender} who will the sub header will be displayed to. - * @param display The responsible {@link ContentDisplay}. - */ - default void sendSubHeader(@NotNull CommandSender sender, @NotNull ContentDisplay display) { - if (display.getFilter().hasFilter()) { - sender.sendMessage(String.format("%s[ %s ]", ChatColor.GRAY, display.getFilter().getFormattedString())); - } - } - - /** - * Sends the content. - * - * @param sender The {@link CommandSender} who will the body will be displayed to. - * @param display The responsible {@link ContentDisplay}. - * @param formattedContent The content after being formatted by {@link #format(CommandSender, ContentDisplay)} - */ - default void sendBody(@NotNull CommandSender sender, @NotNull ContentDisplay display, - Collection formattedContent) { - if (formattedContent == null || formattedContent.size() == 0) { - sender.sendMessage(display.getEmptyMessage()); - return; - } - sender.sendMessage(formattedContent.toArray(new String[0])); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandlers.java b/src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandlers.java deleted file mode 100644 index 7343c6ad5..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/DisplayHandlers.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.onarandombox.MultiverseCore.display; - -import com.onarandombox.MultiverseCore.display.handlers.InlineListDisplayHandler; -import com.onarandombox.MultiverseCore.display.handlers.InlineMapDisplayHandler; -import com.onarandombox.MultiverseCore.display.handlers.ListDisplayHandler; -import com.onarandombox.MultiverseCore.display.handlers.PagedListDisplayHandler; -import com.onarandombox.MultiverseCore.display.settings.InlineDisplaySettings; -import com.onarandombox.MultiverseCore.display.settings.PagedDisplaySettings; -import com.onarandombox.MultiverseCore.display.settings.MapDisplaySettings; - -import java.util.Collection; -import java.util.Map; - -/** - * Various implementations of {@link DisplayHandler}. - */ -public class DisplayHandlers { - - /** - * Standard list display. - * - * Supported settings: none. - */ - public static final DisplayHandler> LIST = new ListDisplayHandler(); - - /** - * List display with paging. - * - * Supported settings: {@link PagedDisplaySettings#SHOW_PAGE}, {@link PagedDisplaySettings#LINES_PER_PAGE}, - * {@link PagedDisplaySettings#PAGE_IN_CONSOLE}, {@link PagedDisplaySettings#DO_END_PADDING}. - */ - public static final DisplayHandler> PAGE_LIST = new PagedListDisplayHandler(); - - /** - * Display a list inline. - * - * Supported settings: {@link InlineDisplaySettings#SEPARATOR}. - */ - public static final DisplayHandler> INLINE_LIST = new InlineListDisplayHandler(); - - /** - * Display key value pair inline. - * - * Supported settings: {@link InlineDisplaySettings#SEPARATOR}, {@link MapDisplaySettings#OPERATOR}. - */ - public static final DisplayHandler> INLINE_MAP = new InlineMapDisplayHandler(); -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/filters/ContentFilter.java b/src/main/java/com/onarandombox/MultiverseCore/display/filters/ContentFilter.java new file mode 100644 index 000000000..240d7d92d --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/filters/ContentFilter.java @@ -0,0 +1,21 @@ +package com.onarandombox.MultiverseCore.display.filters; + +/** + * Filter display content for it show only certain string. + */ +public interface ContentFilter { + /** + * Checks if a particular string should be displayed. + * + * @param value String to check on. + * @return True if should be display, false otherwise. + */ + boolean checkMatch(String value); + + /** + * Gets whether content needs to be filtered by this filter. + * + * @return True if content should be filtered, false otherwise. + */ + boolean needToFilter(); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java b/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java new file mode 100644 index 000000000..5070d647a --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/filters/DefaultContentFilter.java @@ -0,0 +1,35 @@ +package com.onarandombox.MultiverseCore.display.filters; + +/** + * Default implementation of {@link ContentFilter} that doesn't filter anything. + */ +public class DefaultContentFilter implements ContentFilter { + + public static DefaultContentFilter instance; + + public static DefaultContentFilter getInstance() { + if (instance == null) { + instance = new DefaultContentFilter(); + } + return instance; + } + + private DefaultContentFilter() { + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkMatch(String value) { + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean needToFilter() { + return false; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java b/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java new file mode 100644 index 000000000..e83611e9d --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/filters/RegexContentFilter.java @@ -0,0 +1,99 @@ +package com.onarandombox.MultiverseCore.display.filters; + +import com.dumptruckman.minecraft.util.Logging; +import com.google.common.base.Strings; +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; + +/** + * Filter content and text based on regex matching. + */ +public class RegexContentFilter implements ContentFilter { + + private static final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]"); + + /** + * Compile regex pattern to create a regex filter. + * + * When prefixed with 'r=', filter string is used as the full regex pattern. + * Else, set to regex that contains the filterString. + * + * @param filterString The target string to create filter. + * @return A new instance of {@link RegexContentFilter} with filter applied. + */ + @NotNull + public static RegexContentFilter fromString(@Nullable String filterString) { + if (filterString == null) { + return new RegexContentFilter(null); + } + if (filterString.startsWith("r=")) { + return new RegexContentFilter(filterString.substring(2)); + } + String cleanedFilter = REGEX_SPECIAL_CHARS.matcher(filterString.toLowerCase()).replaceAll("\\\\$0"); + return new RegexContentFilter("(?i).*" + cleanedFilter + ".*"); + } + + private final String regexString; + private Pattern regexPattern; + + public RegexContentFilter(@Nullable String regexString) { + this.regexString = regexString; + convertToPattern(); + } + + /** + * Try to compile and store the regex into a {@link Pattern}. + */ + private void convertToPattern() { + if (Strings.isNullOrEmpty(regexString)) { + return; + } + try { + regexPattern = Pattern.compile(regexString); + } catch (PatternSyntaxException ignored) { + regexPattern = null; + Logging.fine("Error parsing regex: %s", regexString); + } + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkMatch(String value) { + if (!hasValidRegex()) { + return false; + } + String text = ChatColor.stripColor(String.valueOf(value)); + return regexPattern.matcher(text).find(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean needToFilter() { + return hasValidRegex(); + } + + public boolean hasValidRegex() { + return regexPattern != null; + } + + public String getRegexString() { + return regexString; + } + + public Pattern getRegexPattern() { + return regexPattern; + } + + @Override + public String toString() { + return regexString; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java new file mode 100644 index 000000000..46e11b29e --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/BaseSendHandler.java @@ -0,0 +1,99 @@ +package com.onarandombox.MultiverseCore.display.handlers; + +import com.google.common.base.Strings; +import com.onarandombox.MultiverseCore.display.filters.ContentFilter; +import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * Base implementation of {@link SendHandler} with some common parameters. + * + * @param The subclass that inherited this baseclass. + */ +public abstract class BaseSendHandler> implements SendHandler { + + protected String header = ""; + protected ContentFilter filter = DefaultContentFilter.getInstance(); + + /** + * {@inheritDoc} + */ + @Override + public void send(@NotNull CommandSender sender, @NotNull List content) { + sendHeader(sender); + List filteredContent = filterContent(content); + if (filteredContent.isEmpty()) { + sender.sendMessage(String.format("%sThere is no content to display.", ChatColor.RED)); + return; + } + sendContent(sender, filteredContent); + } + + /** + * Sends the header if header is present. + * + * @param sender The target which the header will be displayed to. + */ + protected void sendHeader(CommandSender sender) { + if (!Strings.isNullOrEmpty(header)) { + sender.sendMessage(header); + } + } + + /** + * Filter to keep only contents that matches the filter. + * + * @param content The content to filter on. + * @return The filtered list of content. + */ + protected List filterContent(@NotNull List content) { + if (filter.needToFilter()) { + return content.stream().filter(filter::checkMatch).collect(Collectors.toList()); + } + return content; + } + + /** + * Display the contents. + * + * @param sender The target which the content will be displayed to. + * @param content The content to display. + */ + protected abstract void sendContent(@NotNull CommandSender sender, @NotNull List content); + + /** + * Sets header to be displayed. + * + * @param header The header text. + * @param replacements String formatting replacements. + * @return Same {@link T} for method chaining. + */ + public T withHeader(@NotNull String header, @NotNull Object...replacements) { + this.header = String.format(header, replacements); + return (T) this; + } + + /** + * Sets content filter used to match specific content to be displayed. + * + * @param filter The filter to use. + * @return Same {@link T} for method chaining. + */ + public T withFilter(@NotNull ContentFilter filter) { + this.filter = filter; + return (T) this; + } + + public String getHeader() { + return header; + } + + public ContentFilter getFilter() { + return filter; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java new file mode 100644 index 000000000..e02997850 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/DefaultSendHandler.java @@ -0,0 +1,29 @@ +package com.onarandombox.MultiverseCore.display.handlers; + +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public class DefaultSendHandler implements SendHandler { + + private static DefaultSendHandler instance; + + public static DefaultSendHandler getInstance() { + if (instance == null) { + instance = new DefaultSendHandler(); + } + return instance; + } + + private DefaultSendHandler() { + } + + /** + * {@inheritDoc} + */ + @Override + public void send(@NotNull CommandSender sender, @NotNull List content) { + sender.sendMessage(content.toArray(new String[0])); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineListDisplayHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineListDisplayHandler.java deleted file mode 100644 index 53aa196b4..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineListDisplayHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.onarandombox.MultiverseCore.display.handlers; - -import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.DisplayFormatException; -import com.onarandombox.MultiverseCore.display.DisplayHandler; -import com.onarandombox.MultiverseCore.display.settings.InlineDisplaySettings; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -public class InlineListDisplayHandler implements DisplayHandler> { - - @Override - public Collection format(@NotNull CommandSender sender, @NotNull ContentDisplay> display) - throws DisplayFormatException { - StringBuilder builder = new StringBuilder(); - String separator = display.getSetting(InlineDisplaySettings.SEPARATOR); - - for (Iterator iterator = display.getContents().iterator(); iterator.hasNext(); ) { - String content = iterator.next(); - if (!display.getFilter().checkMatch(content)) { - continue; - } - builder.append(display.getColorTool().get()).append(content); - if (iterator.hasNext()) { - builder.append(separator); - } - } - return (builder.length() == 0) - ? Collections.singletonList(display.getEmptyMessage()) - : Collections.singleton(builder.toString()); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineMapDisplayHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineMapDisplayHandler.java deleted file mode 100644 index 312ccb86c..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineMapDisplayHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.onarandombox.MultiverseCore.display.handlers; - -import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.DisplayFormatException; -import com.onarandombox.MultiverseCore.display.DisplayHandler; -import com.onarandombox.MultiverseCore.display.settings.InlineDisplaySettings; -import com.onarandombox.MultiverseCore.display.settings.MapDisplaySettings; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; - -public class InlineMapDisplayHandler implements DisplayHandler> { - - @Override - public Collection format(@NotNull CommandSender sender, - @NotNull ContentDisplay> display) - throws DisplayFormatException { - StringBuilder builder = new StringBuilder(); - String separator = display.getSetting(InlineDisplaySettings.SEPARATOR); - String operator = display.getSetting(MapDisplaySettings.OPERATOR); - - for (Iterator> iterator = display.getContents().entrySet().iterator(); iterator.hasNext(); ) { - Map.Entry entry = iterator.next(); - if (!display.getFilter().checkMatch(entry.getKey()) && !display.getFilter().checkMatch(entry.getValue())) { - continue; - } - builder.append(display.getColorTool().get()) - .append(entry.getKey()) - .append(operator) - .append(display.getColorTool().get()) - .append(entry.getValue()); - if (iterator.hasNext()) { - builder.append(separator); - } - } - return (builder.length() == 0) - ? Collections.singletonList(display.getEmptyMessage()) - : Collections.singleton(builder.toString()); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java new file mode 100644 index 000000000..5d8a1d100 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/InlineSendHandler.java @@ -0,0 +1,53 @@ +package com.onarandombox.MultiverseCore.display.handlers; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Display the contents in a single line. + */ +public class InlineSendHandler extends BaseSendHandler { + + /** + * Makes a new {@link InlineSendHandler} instance to use. + * + * @return New {@link InlineSendHandler} instance. + */ + public static InlineSendHandler create() { + return new InlineSendHandler(); + } + + private String delimiter = ChatColor.WHITE + ", "; + + public InlineSendHandler() { + } + + /** + * {@inheritDoc} + */ + @Override + public void sendContent(@NotNull CommandSender sender, @NotNull List content) { + if (filter.needToFilter()) { + sender.sendMessage(String.format("%s[Filter '%s']", ChatColor.GRAY, filter)); + } + sender.sendMessage(String.join(delimiter, content)); + } + + /** + * Sets the delimiter. A sequence of characters that is used to separate each of the elements in content. + * + * @param delimiter The delimiter to use. + * @return Same {@link InlineSendHandler} for method chaining. + */ + public InlineSendHandler withDelimiter(String delimiter) { + this.delimiter = delimiter; + return this; + } + + public String getDelimiter() { + return delimiter; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/ListDisplayHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/ListDisplayHandler.java deleted file mode 100644 index c2b0979fd..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/ListDisplayHandler.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.onarandombox.MultiverseCore.display.handlers; - -import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.DisplayFormatException; -import com.onarandombox.MultiverseCore.display.DisplayHandler; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.stream.Collectors; - -public class ListDisplayHandler implements DisplayHandler> { - - @Override - public Collection format(@NotNull CommandSender sender, @NotNull ContentDisplay> display) - throws DisplayFormatException { - return display.getContents().stream() - .filter(display.getFilter()::checkMatch) - .map(s -> (ContentDisplay.LINE_BREAK.equals(s)) ? "" : display.getColorTool().get() + s) - .collect(Collectors.toList()); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedListDisplayHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedListDisplayHandler.java deleted file mode 100644 index 17f0825e5..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedListDisplayHandler.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.onarandombox.MultiverseCore.display.handlers; - -import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.DisplayFormatException; -import com.onarandombox.MultiverseCore.display.settings.PagedDisplaySettings; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.IntStream; - -public class PagedListDisplayHandler extends ListDisplayHandler { - - @Override - public Collection format(@NotNull CommandSender sender, @NotNull ContentDisplay> display) - throws DisplayFormatException { - if (dontNeedPaging(sender, display)) { - return super.format(sender, display); - } - - int pages = 1; - int currentLength = 0; - int targetPage = display.getSetting(PagedDisplaySettings.SHOW_PAGE); - int linesPerPage = display.getSetting(PagedDisplaySettings.LINES_PER_PAGE); - List content = new ArrayList<>(linesPerPage); - - // Calculate the paging. - for (String line : display.getContents()) { - if (!display.getFilter().checkMatch(line)) { - continue; - } - // When it's the next page. - boolean isLineBreak = ContentDisplay.LINE_BREAK.equals(line); - if (isLineBreak || ++currentLength > linesPerPage) { - pages++; - currentLength = 0; - if (isLineBreak) { - continue; - } - } - if (pages == targetPage) { - // Let first line be the header when no header is defined. - if (display.getHeader() == null) { - display.setHeader(line); - currentLength--; - continue; - } - content.add(display.getColorTool().get() + line); - } - } - - // Page out of range. - if (targetPage < 1 || targetPage > pages) { - if (pages == 1) { - throw new DisplayFormatException("There is only 1 page!"); - } - throw new DisplayFormatException("Please enter a page from 1 to " + pages + "."); - } - - // No content - if (content.size() == 0) { - content.add(display.getEmptyMessage()); - } - - // Add empty lines to make output length consistent. - if (display.getSetting(PagedDisplaySettings.DO_END_PADDING)) { - IntStream.range(0, linesPerPage - content.size()).forEach(i -> content.add("")); - } - display.setSetting(PagedDisplaySettings.TOTAL_PAGE, pages); - - return content; - } - - @Override - public void sendSubHeader(@NotNull CommandSender sender, @NotNull ContentDisplay> display) { - if (dontNeedPaging(sender, display)) { - super.sendSubHeader(sender, display); - return; - } - - if (display.getFilter().hasFilter()) { - sender.sendMessage(String.format("%s[ Page %s of %s, %s ]", - ChatColor.GRAY, - display.getSetting(PagedDisplaySettings.SHOW_PAGE), - display.getSetting(PagedDisplaySettings.TOTAL_PAGE), - display.getFilter().getFormattedString()) - ); - return; - } - sender.sendMessage(String.format("%s[ Page %s of %s ]", - ChatColor.GRAY, - display.getSetting(PagedDisplaySettings.SHOW_PAGE), - display.getSetting(PagedDisplaySettings.TOTAL_PAGE)) - ); - } - - private boolean dontNeedPaging(CommandSender sender, ContentDisplay> display) { - return sender instanceof ConsoleCommandSender - && !display.getSetting(PagedDisplaySettings.PAGE_IN_CONSOLE); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java new file mode 100644 index 000000000..62208b5ce --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/PagedSendHandler.java @@ -0,0 +1,170 @@ +package com.onarandombox.MultiverseCore.display.handlers; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Display content as a list with optional pagination. + */ +public class PagedSendHandler extends BaseSendHandler { + + /** + * Makes a new {@link PagedSendHandler} instance to use. + * + * @return New {@link PagedSendHandler} instance. + */ + public static PagedSendHandler create() { + return new PagedSendHandler(); + } + + private boolean paginate = true; + private boolean paginateInConsole = false; + private boolean padEnd = true; + private int linesPerPage = 8; + private int targetPage = 1; + + public PagedSendHandler() { + } + + /** + * {@inheritDoc} + */ + @Override + public void sendContent(@NotNull CommandSender sender, + @NotNull List content) { + + if (!paginate || (sender instanceof ConsoleCommandSender && !paginateInConsole)) { + sendNormal(sender, content); + return; + } + sendPaged(sender, content); + } + + /** + * Send content list without pagination. + * + * @param sender The target which the content will be displayed to. + * @param content The content to display. + */ + private void sendNormal(@NotNull CommandSender sender, + @NotNull List content) { + + if (filter.needToFilter()) { + sender.sendMessage(String.format("%s[Filter '%s']", ChatColor.GRAY, filter)); + } + sender.sendMessage(content.toArray(new String[0])); + } + + /** + * Send content list with pagination. + * + * @param sender The target which the content will be displayed to. + * @param content The content to display. + */ + private void sendPaged(@NotNull CommandSender sender, + @NotNull List content) { + + int totalPages = (content.size() + linesPerPage - 1) / linesPerPage; // Basically just divide round up + if (targetPage < 1 || targetPage > totalPages) { + sender.sendMessage(String.format("%sInvalid page number. Please enter a page number between 1 and %s", ChatColor.RED, totalPages)); + return; + } + + if (filter.needToFilter()) { + sender.sendMessage(String.format("%s[Page %s of %s] [Filter '%s']", ChatColor.GRAY, targetPage, totalPages, filter)); + } else { + sender.sendMessage(String.format("%s[Page %s of %s]", ChatColor.GRAY, targetPage, totalPages)); + } + + int startIndex = (targetPage - 1) * linesPerPage; + int pageEndIndex = startIndex + linesPerPage; + int endIndex = Math.min(pageEndIndex, content.size()); + List pageContent = content.subList(startIndex, endIndex); + if (padEnd) { + for (int i = 0; i < (pageEndIndex - endIndex); i++) { + pageContent.add(""); + } + } + sender.sendMessage(pageContent.toArray(new String[0])); + } + + /** + * Sets whether display output should be paginated. + * + * @param paginate State of doing pagination. + * @return Same {@link PagedSendHandler} for method chaining. + */ + public PagedSendHandler doPagination(boolean paginate) { + this.paginate = paginate; + return this; + } + + /** + * Sets whether display output should be paginated if is for console output. + * This option will be useless of {@link PagedSendHandler#paginate} is set to false. + * + * @param paginateInConsole State of doing pagination in console. + * @return Same {@link PagedSendHandler} for method chaining. + */ + public PagedSendHandler doPaginationInConsole(boolean paginateInConsole) { + this.paginateInConsole = paginateInConsole; + return this; + } + + /** + * Sets whether empty lines should be added if content lines shown is less that {@link PagedSendHandler#linesPerPage}. + * + * @param padEnd State of doing end padding. + * @return Same {@link PagedSendHandler} for method chaining. + */ + public PagedSendHandler doEndPadding(boolean padEnd) { + this.padEnd = padEnd; + return this; + } + + /** + * Sets the max number of lines per page. This excludes header. + * + * @param linesPerPage The number of lines per page. + * @return Same {@link PagedSendHandler} for method chaining. + */ + public PagedSendHandler withLinesPerPage(int linesPerPage) { + this.linesPerPage = linesPerPage; + return this; + } + + /** + * Sets the page number to display. + * + * @param targetPage The target page number to display. + * @return Same {@link PagedSendHandler} for method chaining. + */ + public PagedSendHandler withTargetPage(int targetPage) { + this.targetPage = targetPage; + return this; + } + + public boolean isPaginate() { + return paginate; + } + + public boolean isPaginateInConsole() { + return paginateInConsole; + } + + public boolean isPadEnd() { + return padEnd; + } + + public int getLinesPerPage() { + return linesPerPage; + } + + public int getTargetPage() { + return targetPage; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/handlers/SendHandler.java b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/SendHandler.java new file mode 100644 index 000000000..6c826aa6a --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/handlers/SendHandler.java @@ -0,0 +1,20 @@ +package com.onarandombox.MultiverseCore.display.handlers; + +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Handles the sending of all content to the command sender. + */ +@FunctionalInterface +public interface SendHandler { + /** + * Sends all the content to the given command sender. + * + * @param sender The target which the content will be displayed to. + * @param content The content to display. + */ + void send(@NotNull CommandSender sender, @NotNull List content); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentParser.java b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentParser.java new file mode 100644 index 000000000..b69f7a841 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ContentParser.java @@ -0,0 +1,20 @@ +package com.onarandombox.MultiverseCore.display.parsers; + +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Parse objects into string or list of strings. + */ +@FunctionalInterface +public interface ContentParser { + /** + * Parse the object to string(s) and add it to the content. + * + * @param sender The target which the content will be displayed to. + * @param content The content to display. + */ + void parse(@NotNull CommandSender sender, @NotNull List content); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentParser.java b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentParser.java new file mode 100644 index 000000000..00a890617 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/ListContentParser.java @@ -0,0 +1,60 @@ +package com.onarandombox.MultiverseCore.display.parsers; + +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Simple parser for list object. + * + * @param List element type. + */ +public class ListContentParser implements ContentParser { + + /** + * New list content parser for the given list. + * + * @param list The list object to parse. + * @param List element type. + * @return New {@link MapContentParser} instance. + */ + public static ListContentParser forContent(List list) { + return new ListContentParser<>(list); + } + + private final List list; + + private String format = "%s"; + + public ListContentParser(List list) { + this.list = list; + } + + /** + * {@inheritDoc} + */ + @Override + public void parse(@NotNull CommandSender sender, @NotNull List content) { + list.forEach(element -> content.add(String.format(format, element))); + } + + /** + * Sets the format that will be used to parse each list entry. Uses java string format pattern. + * + * @param format The format to use. + * @return Same {@link ListContentParser} for method chaining. + */ + public ListContentParser withFormat(String format) { + this.format = format; + return this; + } + + public List getList() { + return list; + } + + public String getFormat() { + return format; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentParser.java b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentParser.java new file mode 100644 index 000000000..4aad97bc7 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/display/parsers/MapContentParser.java @@ -0,0 +1,112 @@ +package com.onarandombox.MultiverseCore.display.parsers; + +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Map; + +/** + * Simple parser for map object. + * + * @param Key type. + * @param Value type. + */ +public class MapContentParser implements ContentParser { + + /** + * New map content parser for the given map. + * + * @param map The map object to parse. + * @param Key type. + * @param Value type. + * @return New {@link MapContentParser} instance. + */ + public static MapContentParser forContent(Map map) { + return new MapContentParser<>(map); + } + + private final Map map; + + private String format = "%s%s%s%s%s"; + private ChatColor keyColor = ChatColor.WHITE; + private ChatColor valueColor = ChatColor.WHITE; + private String separator = ": "; + + public MapContentParser(Map map) { + this.map = map; + } + + /** + * {@inheritDoc} + */ + @Override + public void parse(@NotNull CommandSender sender, @NotNull List content) { + map.forEach((k, v) -> content.add(String.format(format, keyColor, k, separator, valueColor, v))); + } + + /** + * Sets the format that will be used to parse each map entry. Uses java string format pattern. + * + * @param format The format to use. + * @return Same {@link MapContentParser} for method chaining. + */ + public MapContentParser withFormat(String format) { + this.format = format; + return this; + } + + /** + * Sets the color for the key text. + * + * @param keyColor The color to use. + * @return Same {@link MapContentParser} for method chaining. + */ + public MapContentParser withKeyColor(ChatColor keyColor) { + this.keyColor = keyColor; + return this; + } + + /** + * Sets the color for the value text. + * + * @param valueColor The color to use. + * @return Same {@link MapContentParser} for method chaining. + */ + public MapContentParser withValueColor(ChatColor valueColor) { + this.valueColor = valueColor; + return this; + } + + /** + * Sets the separator between each key value pairing. + * + * @param separator The separator to use. + * @return Same {@link MapContentParser} for method chaining. + */ + public MapContentParser withSeparator(String separator) { + this.separator = separator; + return this; + } + + public Map getMap() { + return map; + } + + public String getFormat() { + return format; + } + + public ChatColor getKeyColor() { + return keyColor; + } + + public ChatColor getValueColor() { + return valueColor; + } + + public String getSeparator() { + return separator; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/settings/DisplaySetting.java b/src/main/java/com/onarandombox/MultiverseCore/display/settings/DisplaySetting.java deleted file mode 100644 index 232e432ba..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/settings/DisplaySetting.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.onarandombox.MultiverseCore.display.settings; - -import com.onarandombox.MultiverseCore.display.DisplayHandler; - -/** - * Represents a setting option that can be used by {@link DisplayHandler}. - * - * @param - */ -@FunctionalInterface -public interface DisplaySetting { - - /** - * Gets the default value of this Display Setting. - * - * @return The default value. - */ - T defaultValue(); -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/settings/InlineDisplaySettings.java b/src/main/java/com/onarandombox/MultiverseCore/display/settings/InlineDisplaySettings.java deleted file mode 100644 index 25661d121..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/settings/InlineDisplaySettings.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.onarandombox.MultiverseCore.display.settings; - -import com.onarandombox.MultiverseCore.display.DisplayHandler; -import org.bukkit.ChatColor; - -/** - * Collection of {@link DisplaySetting} that are used by various {@link DisplayHandler}. - */ -public class InlineDisplaySettings { - - /** - * Inline separator. E.g. '1, 2, 3' - */ - public static final DisplaySetting SEPARATOR = () -> ChatColor.WHITE + ", "; -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/settings/MapDisplaySettings.java b/src/main/java/com/onarandombox/MultiverseCore/display/settings/MapDisplaySettings.java deleted file mode 100644 index a78473955..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/settings/MapDisplaySettings.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.onarandombox.MultiverseCore.display.settings; - -import com.onarandombox.MultiverseCore.display.DisplayHandler; -import org.bukkit.ChatColor; - -/** - * Collection of {@link DisplaySetting} that are used by various {@link DisplayHandler}. - */ -public class MapDisplaySettings { - - /** - * The thing between a key value pair. E.g. 'Me = Smart' - */ - public static final DisplaySetting OPERATOR = () -> ChatColor.WHITE + " = "; -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/display/settings/PagedDisplaySettings.java b/src/main/java/com/onarandombox/MultiverseCore/display/settings/PagedDisplaySettings.java deleted file mode 100644 index bdc12f9ff..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/display/settings/PagedDisplaySettings.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.onarandombox.MultiverseCore.display.settings; - -public class PagedDisplaySettings { - - /** - * Page to display. - */ - public static final DisplaySetting SHOW_PAGE = () -> 1; - - /** - * Total pages available to display. - */ - public static final DisplaySetting TOTAL_PAGE = () -> 1; - - /** - * The max number of lines per page. This excludes header. - */ - public static final DisplaySetting LINES_PER_PAGE = () -> 8; - - /** - * Should add empty lines if content lines shown is less that {@link #LINES_PER_PAGE}. - */ - public static final DisplaySetting DO_END_PADDING = () -> true; - - /** - * Should display with paging when it's sent to console. - */ - public static final DisplaySetting PAGE_IN_CONSOLE = () -> false; - -} From 4ad6c53ba911912b71cd1c0bca1c4784584c9bae Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:11:38 +0800 Subject: [PATCH 009/725] refactor!: Remove redundant MapInitializeEvent (#2507) --- .../MultiverseCore/MultiverseCore.java | 2 - .../listeners/MVMapListener.java | 43 ------------------- 2 files changed, 45 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/MVMapListener.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 15700950a..b14879107 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -82,7 +82,6 @@ import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener; import com.onarandombox.MultiverseCore.listeners.MVChatListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener; -import com.onarandombox.MultiverseCore.listeners.MVMapListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPortalListener; @@ -395,7 +394,6 @@ private void registerEvents() { pm.registerEvents(this.weatherListener, this); pm.registerEvents(this.portalListener, this); pm.registerEvents(this.worldListener, this); - pm.registerEvents(new MVMapListener(this), this); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVMapListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVMapListener.java deleted file mode 100644 index 2443337a3..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVMapListener.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.onarandombox.MultiverseCore.listeners; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.server.MapInitializeEvent; -import org.bukkit.map.MapView; - -/** - * A listener for bukkit map events. - */ -public class MVMapListener implements Listener { - - private final MultiverseCore plugin; - - public MVMapListener(final MultiverseCore plugin) { - this.plugin = plugin; - } - - /** - * This method is called when a map is initialized. - * @param event The event that was fired. - */ - @EventHandler - public void mapInitialize(final MapInitializeEvent event) { - for (final Player player : Bukkit.getOnlinePlayers()) { - if ((player.getItemInHand().getType() == Material.MAP - || player.getItemInHand().getType() == Material.FILLED_MAP) - && player.getItemInHand().getDurability() == event.getMap().getId()) { - final Location playerLoc = player.getLocation(); - final MapView map = event.getMap(); - map.setCenterX(playerLoc.getBlockX()); - map.setCenterZ(playerLoc.getBlockZ()); - map.setWorld(playerLoc.getWorld()); - return; - } - } - } -} From 2acca7f330e57d55519e21dca96e75f4e403e40d Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:33:44 +0800 Subject: [PATCH 010/725] refactor!: Remove deprecated PlayChatEvent option (#2828) --- .../MultiverseCore/MultiverseCore.java | 15 +------- .../MultiverseCoreConfiguration.java | 13 ------- .../api/MultiverseCoreConfig.java | 12 ------ .../commandsold/VersionCommand.java | 9 ++--- .../listeners/AsyncChatEvent.java | 35 ------------------ .../MultiverseCore/listeners/ChatEvent.java | 29 --------------- .../listeners/MVAsyncPlayerChatListener.java | 35 ------------------ .../listeners/MVChatListener.java | 11 ++++-- .../listeners/MVPlayerChatListener.java | 36 ------------------ .../listeners/NormalChatEvent.java | 37 ------------------- .../MultiverseCore/TestWorldProperties.java | 15 ++++---- 11 files changed, 20 insertions(+), 227 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/AsyncChatEvent.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/ChatEvent.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/MVAsyncPlayerChatListener.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerChatListener.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/listeners/NormalChatEvent.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index b14879107..d665877a5 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -79,10 +79,8 @@ import com.onarandombox.MultiverseCore.destination.WorldDestination; import com.onarandombox.MultiverseCore.event.MVDebugModeEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent; -import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener; import com.onarandombox.MultiverseCore.listeners.MVChatListener; import com.onarandombox.MultiverseCore.listeners.MVEntityListener; -import com.onarandombox.MultiverseCore.listeners.MVPlayerChatListener; import com.onarandombox.MultiverseCore.listeners.MVPlayerListener; import com.onarandombox.MultiverseCore.listeners.MVPortalListener; import com.onarandombox.MultiverseCore.listeners.MVWeatherListener; @@ -323,17 +321,8 @@ public void onEnable() { // A test that had no worlds loaded was being run. This should never happen in production } this.saveMVConfig(); - // Register async or sync player chat according to config - try { - Class.forName("org.bukkit.event.player.AsyncPlayerChatEvent"); - } catch (ClassNotFoundException e) { - getMVConfig().setUseAsyncChat(false); - } - if (getMVConfig().getUseAsyncChat()) { - this.chatListener = new MVAsyncPlayerChatListener(this, this.playerListener); - } else { - this.chatListener = new MVPlayerChatListener(this, this.playerListener); - } + + this.chatListener = new MVChatListener(this, this.playerListener); getServer().getPluginManager().registerEvents(this.chatListener, this); this.initializeBuscript(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java index aaf21275c..cc9b5fce3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCoreConfiguration.java @@ -48,8 +48,6 @@ public static MultiverseCoreConfiguration getInstance() { @Property private volatile String prefixchatformat; @Property - private volatile boolean useasyncchat; - @Property private volatile boolean teleportintercept; @Property private volatile boolean firstspawnoverride; @@ -95,7 +93,6 @@ public MultiverseCoreConfiguration(Map values) { protected void setDefaults() { // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck enforceaccess = false; - useasyncchat = true; prefixchat = false; prefixchatformat = "[%world%]%chat%"; teleportintercept = true; @@ -322,16 +319,6 @@ public void setTeleportCooldown(int teleportCooldown) { this.teleportcooldown = teleportCooldown; } - @Override - public void setUseAsyncChat(boolean useAsyncChat) { - this.useasyncchat = useAsyncChat; - } - - @Override - public boolean getUseAsyncChat() { - return this.useasyncchat; - } - @Override public void setSilentStart(boolean silentStart) { Logging.setShowingConfig(!silentStart); diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java index 07b2bb91d..ee8d0b16c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseCoreConfig.java @@ -158,18 +158,6 @@ public interface MultiverseCoreConfig extends ConfigurationSerializable { */ boolean getEnforceAccess(); - /** - * Sets useasyncchat. - * @param useAsyncChat The new value. - */ - void setUseAsyncChat(boolean useAsyncChat); - - /** - * Gets useasyncchat. - * @return useasyncchat. - */ - boolean getUseAsyncChat(); - /** * Sets whether to suppress startup messages. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java index c0a938add..941e4713d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java @@ -7,6 +7,10 @@ package com.onarandombox.MultiverseCore.commandsold; +import java.io.File; +import java.util.List; +import java.util.Map; + import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.event.MVVersionEvent; @@ -26,10 +30,6 @@ import org.bukkit.permissions.PermissionDefault; import org.bukkit.scheduler.BukkitRunnable; -import java.io.File; -import java.util.List; -import java.util.Map; - /** * Dumps version info to the console. */ @@ -63,7 +63,6 @@ private String getLegacyString() { + "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + '\n' + "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + '\n' + "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + '\n' - + "[Multiverse-Core] useasyncchat: " + plugin.getMVConfig().getUseAsyncChat() + '\n' + "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + '\n' + "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + '\n' + "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + '\n' diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/AsyncChatEvent.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/AsyncChatEvent.java deleted file mode 100644 index 38d48bef6..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/AsyncChatEvent.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.onarandombox.MultiverseCore.listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.player.AsyncPlayerChatEvent; - -/** - * A wrapper for the {@link AsyncPlayerChatEvent}. - */ -public class AsyncChatEvent implements ChatEvent { - private final AsyncPlayerChatEvent event; - - public AsyncChatEvent(AsyncPlayerChatEvent event) { - this.event = event; - } - - @Override - public boolean isCancelled() { - return event.isCancelled(); - } - - @Override - public String getFormat() { - return event.getFormat(); - } - - @Override - public void setFormat(String s) { - event.setFormat(s); - } - - @Override - public Player getPlayer() { - return event.getPlayer(); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/ChatEvent.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/ChatEvent.java deleted file mode 100644 index 16cafb81a..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/ChatEvent.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.onarandombox.MultiverseCore.listeners; - -import org.bukkit.entity.Player; - -/** - * A wrapper for the two chat-events in Bukkit. - */ -public interface ChatEvent { - /** - * @return Whether this event is cancelled. - */ - boolean isCancelled(); - - /** - * @return The format. - */ - String getFormat(); - - /** - * Sets the format. - * @param s The new format. - */ - void setFormat(String s); - - /** - * @return The player. - */ - Player getPlayer(); -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVAsyncPlayerChatListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVAsyncPlayerChatListener.java deleted file mode 100644 index c62102538..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVAsyncPlayerChatListener.java +++ /dev/null @@ -1,35 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.listeners; - -import java.util.logging.Level; - -import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.AsyncPlayerChatEvent; - -import com.onarandombox.MultiverseCore.MultiverseCore; - -/** - * Multiverse's {@link org.bukkit.event.Listener} for players. - */ -public class MVAsyncPlayerChatListener extends MVChatListener { - public MVAsyncPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) { - super(plugin, playerListener); - Logging.fine("Created AsyncPlayerChatEvent listener."); - } - - /** - * This method is called when a player wants to chat. - * @param event The Event that was fired. - */ - @EventHandler - public void playerChat(AsyncPlayerChatEvent event) { - this.playerChat(new AsyncChatEvent(event)); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java index aaa05ab54..84fcb11f4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVChatListener.java @@ -5,12 +5,14 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; /** * Multiverse's {@link org.bukkit.event.Listener} for players. */ -public abstract class MVChatListener implements Listener { +public class MVChatListener implements Listener { private final MultiverseCore plugin; private final MVWorldManager worldManager; private final MVPlayerListener playerListener; @@ -22,10 +24,11 @@ public MVChatListener(MultiverseCore plugin, MVPlayerListener playerListener) { } /** - * This handles a {@link ChatEvent}. - * @param event The {@link ChatEvent}. + * This handles a {@link AsyncPlayerChatEvent}. + * @param event The {@link AsyncPlayerChatEvent}. */ - public void playerChat(ChatEvent event) { + @EventHandler + public void playerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) { return; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerChatListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerChatListener.java deleted file mode 100644 index fff535dac..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerChatListener.java +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.listeners; - -import java.util.logging.Level; - -import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerChatEvent; - -import com.onarandombox.MultiverseCore.MultiverseCore; - -/** - * Multiverse's {@link org.bukkit.event.Listener} for players. - */ -@SuppressWarnings("deprecation") // this exists only for downwards compatibility -public class MVPlayerChatListener extends MVChatListener { - public MVPlayerChatListener(MultiverseCore plugin, MVPlayerListener playerListener) { - super(plugin, playerListener); - Logging.fine("Registered PlayerChatEvent listener."); - } - - /** - * This method is called when a player wants to chat. - * @param event The Event that was fired. - */ - @EventHandler - public void playerChat(PlayerChatEvent event) { - this.playerChat(new NormalChatEvent(event)); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/NormalChatEvent.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/NormalChatEvent.java deleted file mode 100644 index a712c627e..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/NormalChatEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.onarandombox.MultiverseCore.listeners; - -import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerChatEvent; - -/** - * A wrapper for the {@link PlayerChatEvent}. - * @deprecated This is deprecated like the {@link PlayerChatEvent}. - */ -@Deprecated -public class NormalChatEvent implements ChatEvent { - private final PlayerChatEvent event; - - public NormalChatEvent(PlayerChatEvent event) { - this.event = event; - } - - @Override - public boolean isCancelled() { - return event.isCancelled(); - } - - @Override - public String getFormat() { - return event.getFormat(); - } - - @Override - public void setFormat(String s) { - event.setFormat(s); - } - - @Override - public Player getPlayer() { - return event.getPlayer(); - } -} diff --git a/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java index 3766e46ab..a431e8b75 100644 --- a/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java +++ b/src/test/java/com/onarandombox/MultiverseCore/TestWorldProperties.java @@ -7,10 +7,11 @@ package com.onarandombox.MultiverseCore; +import java.io.File; + import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.configuration.SpawnLocation; -import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener; import com.onarandombox.MultiverseCore.utils.MockWorldFactory; import com.onarandombox.MultiverseCore.utils.TestInstanceCreator; import org.bukkit.ChatColor; @@ -38,8 +39,6 @@ import org.junit.Before; import org.junit.Test; -import java.io.File; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -178,10 +177,10 @@ public void test() throws Exception { // call player chat event core.getMVConfig().setPrefixChat(true); - ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent); + core.getChatListener().playerChat(playerChatEvent); verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format"); core.getMVConfig().setPrefixChat(false); - ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent); + core.getChatListener().playerChat(playerChatEvent); verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!) // call player join events @@ -272,15 +271,15 @@ public void test() throws Exception { // call player chat event core.getMVConfig().setPrefixChat(true); - ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent); + core.getChatListener().playerChat(playerChatEvent); // never because it's hidden! verify(playerChatEvent, never()).setFormat( "[" + mvWorld.getColoredWorldString() + "]" + "format"); mvWorld.setHidden(false); - ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent); + core.getChatListener().playerChat(playerChatEvent); verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format"); core.getMVConfig().setPrefixChat(false); - ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent); + core.getChatListener().playerChat(playerChatEvent); verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!) mvWorld.setHidden(true); // reset hidden-state From 0166b8d139cf22fb479955827c459a1f9118b221 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:38:51 +0800 Subject: [PATCH 011/725] refactor!: Remove deprecated LocationManipulation class (#2528) --- .../utils/LocationManipulation.java | 285 ------------------ 1 file changed, 285 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java b/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java deleted file mode 100644 index b0bce924d..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/LocationManipulation.java +++ /dev/null @@ -1,285 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.utils; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.entity.Vehicle; -import org.bukkit.util.Vector; - -import java.text.DecimalFormat; -import java.util.Collections; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -/** - * Utility class to manipulate locations. - * - * @deprecated Use instead: {@link com.onarandombox.MultiverseCore.api.LocationManipulation} and {@link SimpleLocationManipulation}. - */ -@Deprecated -public class LocationManipulation { - private LocationManipulation() { } - - private static Map orientationInts = new HashMap(); - - static { - // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck - orientationInts.put("n", 180); - orientationInts.put("ne", 225); - orientationInts.put("e", 270); - orientationInts.put("se", 315); - orientationInts.put("s", 0); - orientationInts.put("sw", 45); - orientationInts.put("w", 90); - orientationInts.put("nw", 135); - - // "freeze" the map: - orientationInts = Collections.unmodifiableMap(orientationInts); - // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck - } - - /** - * Convert a Location into a Colon separated string to allow us to store it in text. - *

- * WORLD:X,Y,Z:yaw:pitch - *

- * The corresponding String2Loc function is {@link #stringToLocation} - * - * @param location The Location to save. - * @return The location as a string in this format: WORLD:x,y,z:yaw:pitch - */ - public static String locationToString(Location location) { - if (location == null) { - return ""; - } - // We set the locale to ENGLISH here so we always save with the format: - // world:1.2,5.4,3.6:1.8:21.3 - // Otherwise we blow up when parsing! - return String.format(Locale.ENGLISH, "%s:%.2f,%.2f,%.2f:%.2f:%.2f", location.getWorld().getName(), - location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); - } - - /** - * This method simply does some rounding, rather than forcing a call to the server to get the blockdata. - * - * @param l The location to round to the block location - * @return A rounded location. - */ - public static Location getBlockLocation(Location l) { - l.setX(l.getBlockX()); - l.setY(l.getBlockY()); - l.setZ(l.getBlockZ()); - return l; - } - - /** - * Returns a new location from a given string. The format is as follows: - *

- * WORLD:X,Y,Z:yaw:pitch - *

- * The corresponding Location2String function is {@link #stringToLocation} - * - * @param locationString The location represented as a string (WORLD:X,Y,Z:yaw:pitch) - * @return A new location defined by the string or null if the string was invalid. - */ - public static Location stringToLocation(String locationString) { - //format: - //world:x,y,z:pitch:yaw - if (locationString == null) { - return null; - } - - // Split the whole string, format is: - // {'world', 'x,y,z'[, 'pitch', 'yaw']} - String[] split = locationString.split(":"); - if (split.length < 2 || split.length > 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck - return null; - } - // Split the xyz string, format is: - // {'x', 'y', 'z'} - String[] xyzsplit = split[1].split(","); - if (xyzsplit.length != 3) { - return null; - } - - // Verify the world is valid - World w = Bukkit.getWorld(split[0]); - if (w == null) { - return null; - } - - try { - float pitch = 0; - float yaw = 0; - if (split.length >= 3) { - yaw = (float) Double.parseDouble(split[2]); - } - if (split.length == 4) { // SUPPRESS CHECKSTYLE: MagicNumberCheck - pitch = (float) Double.parseDouble(split[3]); - } - return new Location(w, Double.parseDouble(xyzsplit[0]), Double.parseDouble(xyzsplit[1]), Double.parseDouble(xyzsplit[2]), yaw, pitch); - } catch (NumberFormatException e) { - return null; - } - } - - /** - * Returns a colored string with the coords. - * - * @param l The {@link Location} - * @return The {@link String} - */ - public static String strCoords(Location l) { - String result = ""; - DecimalFormat df = new DecimalFormat(); - df.setMinimumFractionDigits(0); - df.setMaximumFractionDigits(2); - result += ChatColor.WHITE + "X: " + ChatColor.AQUA + df.format(l.getX()) + " "; - result += ChatColor.WHITE + "Y: " + ChatColor.AQUA + df.format(l.getY()) + " "; - result += ChatColor.WHITE + "Z: " + ChatColor.AQUA + df.format(l.getZ()) + " "; - result += ChatColor.WHITE + "P: " + ChatColor.GOLD + df.format(l.getPitch()) + " "; - result += ChatColor.WHITE + "Y: " + ChatColor.GOLD + df.format(l.getYaw()) + " "; - return result; - } - - /** - * Converts a location to a printable readable formatted string including pitch/yaw. - * - * @param l The {@link Location} - * @return The {@link String} - */ - public static String strCoordsRaw(Location l) { - if (l == null) { - return "null"; - } - String result = ""; - DecimalFormat df = new DecimalFormat(); - df.setMinimumFractionDigits(0); - df.setMaximumFractionDigits(2); - result += "X: " + df.format(l.getX()) + " "; - result += "Y: " + df.format(l.getY()) + " "; - result += "Z: " + df.format(l.getZ()) + " "; - result += "P: " + df.format(l.getPitch()) + " "; - result += "Y: " + df.format(l.getYaw()) + " "; - return result; - } - - /** - * Return the NESW Direction a Location is facing. - * - * @param location The {@link Location} - * @return The NESW Direction - */ - public static String getDirection(Location location) { - // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck - double r = (location.getYaw() % 360) + 180; - // Remember, these numbers are every 45 degrees with a 22.5 offset, to detect boundaries. - String dir; - if (r < 22.5) - dir = "n"; - else if (r < 67.5) - dir = "ne"; - else if (r < 112.5) - dir = "e"; - else if (r < 157.5) - dir = "se"; - else if (r < 202.5) - dir = "s"; - else if (r < 247.5) - dir = "sw"; - else if (r < 292.5) - dir = "w"; - else if (r < 337.5) - dir = "nw"; - else - dir = "n"; - // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck - - return dir; - } - - /** - * Returns the float yaw position for the given cardinal direction. - * - * @param orientation The cardinal direction - * @return The yaw - */ - public static float getYaw(String orientation) { - if (orientation == null) { - return 0; - } - if (orientationInts.containsKey(orientation.toLowerCase())) { - return orientationInts.get(orientation.toLowerCase()); - } - return 0; - } - - /** - * Returns a speed float from a given vector. - * - * @param v The {@link Vector} - * @return The speed - */ - public static float getSpeed(Vector v) { - return (float) Math.sqrt(v.getX() * v.getX() + v.getZ() * v.getZ()); - } - - // X, Y, Z - // -W/+E,0, -N/+S - - /** - * Returns a translated vector from the given direction. - * - * @param v The old {@link Vector} - * @param direction The new direction - * @return The translated {@link Vector} - */ - public static Vector getTranslatedVector(Vector v, String direction) { - if (direction == null) { - return v; - } - float speed = getSpeed(v); - float halfSpeed = (float) (speed / 2.0); - if (direction.equalsIgnoreCase("n")) { - return new Vector(0, 0, -1 * speed); - } else if (direction.equalsIgnoreCase("ne")) { - return new Vector(halfSpeed, 0, -1 * halfSpeed); - } else if (direction.equalsIgnoreCase("e")) { - return new Vector(speed, 0, 0); - } else if (direction.equalsIgnoreCase("se")) { - return new Vector(halfSpeed, 0, halfSpeed); - } else if (direction.equalsIgnoreCase("s")) { - return new Vector(0, 0, speed); - } else if (direction.equalsIgnoreCase("sw")) { - return new Vector(-1 * halfSpeed, 0, halfSpeed); - } else if (direction.equalsIgnoreCase("w")) { - return new Vector(-1 * speed, 0, 0); - } else if (direction.equalsIgnoreCase("nw")) { - return new Vector(-1 * halfSpeed, 0, -1 * halfSpeed); - } - return v; - } - - /** - * Returns the next Location that a {@link Vehicle} is traveling at. - * - * @param v The {@link Vehicle} - * @return The {@link Location} - */ - public static Location getNextBlock(Vehicle v) { - Vector vector = v.getVelocity(); - Location location = v.getLocation(); - int x = vector.getX() < 0 ? vector.getX() == 0 ? 0 : -1 : 1; - int z = vector.getZ() < 0 ? vector.getZ() == 0 ? 0 : -1 : 1; - return location.add(x, 0, z); - } -} From 17351e66c1cb53ccbd222b4fe0fb252a8bda1045 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:39:23 +0800 Subject: [PATCH 012/725] refactor!: Remove deprecated getStaticConfig (#2525) --- .../onarandombox/MultiverseCore/MultiverseCore.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index d665877a5..2fcd3dcfb 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -1213,17 +1213,6 @@ public MultiverseCoreConfig getMVConfig() { return config; } - /** - * This method is currently used by other plugins. - * It will be removed in 2.4 - * @return The Multiverse config. - * @deprecated This is deprecated. - */ - @Deprecated - public static MultiverseCoreConfiguration getStaticConfig() { - return MultiverseCoreConfiguration.getInstance(); - } - @Override public Buscript getScriptAPI() { return buscript; From 3ec22fc578ca9e8f35aebc951c896bf4aecac454 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:40:42 +0800 Subject: [PATCH 013/725] refactor!: Remove deprecated WorldManager methods (#2526) --- .../MultiverseCore/MultiverseCore.java | 2 +- .../MultiverseCore/api/MVWorldManager.java | 22 ------------------- .../MultiverseCore/utils/WorldManager.java | 20 ----------------- 3 files changed, 1 insertion(+), 43 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 2fcd3dcfb..7d082260f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -1123,7 +1123,7 @@ public Boolean deleteWorld(String name) { * @return True if success, false if fail. */ public Boolean cloneWorld(String oldName, String newName, String generator) { - return this.worldManager.cloneWorld(oldName, newName, generator); + return this.worldManager.cloneWorld(oldName, newName); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java index 599ce7cb9..3c835c8d9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVWorldManager.java @@ -59,18 +59,6 @@ boolean addWorld(String name, Environment env, String seedString, WorldType type boolean addWorld(String name, Environment env, String seedString, WorldType type, Boolean generateStructures, String generator, boolean useSpawnAdjust); - /** - * Make a copy of a world. - * - * @param oldName Name of world to be copied - * @param newName Name of world to be created - * @param generator The Custom generator plugin to use. Ignored. - * @return True if the world is copied successfully, false if not. - * @deprecated Use {@link #cloneWorld(String, String)} instead. - */ - @Deprecated - boolean cloneWorld(String oldName, String newName, String generator); - /** * Make a copy of a world. * @@ -234,19 +222,9 @@ boolean addWorld(String name, Environment env, String seedString, WorldType type */ void loadDefaultWorlds(); - /** - * Return the World Purger. - * - * @return A valid {@link PurgeWorlds}. - * @deprecated {@link PurgeWorlds} is deprecated! - */ - @Deprecated - PurgeWorlds getWorldPurger(); - /** * Gets the {@link WorldPurger}. *

- * TODO: Remove {@link #getWorldPurger()} and replace it with this method. * @return The {@link WorldPurger} this {@link MVWorldManager} is using. * @see WorldPurger * @see SimpleWorldPurger diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 0b2ab0701..d50c2a095 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -95,16 +95,6 @@ public boolean accept(File file, String s) { } } - /** - * {@inheritDoc} - * @deprecated Use {@link #cloneWorld(String, String)} instead. - */ - @Override - @Deprecated - public boolean cloneWorld(String oldName, String newName, String generator) { - return this.cloneWorld(oldName, newName); - } - /** * {@inheritDoc} */ @@ -784,16 +774,6 @@ private void ensureSecondNamespaceIsPrepared() { } } - /** - * {@inheritDoc} - * @deprecated This is deprecated! - */ - @Override - @Deprecated - public PurgeWorlds getWorldPurger() { - return new PurgeWorlds(plugin); - } - /** * {@inheritDoc} */ From 3377c1dbe508f6dc2c51ce56f67b53fb58b3f435 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 3 Feb 2023 22:45:55 +0800 Subject: [PATCH 014/725] refactor!: Remove deprecated logging (#2523) --- .../MultiverseCore/MultiverseCore.java | 80 ++++--------------- .../MultiverseCore/api/LoggablePlugin.java | 36 --------- .../MultiverseCore/api/MVPlugin.java | 2 +- .../MultiverseCore/api/MultiversePlugin.java | 27 ------- 4 files changed, 15 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/api/LoggablePlugin.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 7d082260f..a4e44b6ad 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -7,21 +7,6 @@ package com.onarandombox.MultiverseCore; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; - import buscript.Buscript; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MVWorld.NullLocation; @@ -120,6 +105,20 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPluginLoader; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + /** * The implementation of the Multiverse-{@link Core}. */ @@ -837,47 +836,6 @@ public boolean onCommand(CommandSender sender, Command command, String commandLa } } - /** - * {@inheritDoc} - * - * @deprecated This is now deprecated, nobody needs it any longer. - * All logging is now done with {@link Logging}. - */ - @Override - @Deprecated - public void log(Level level, String msg) { - Logging.log(level, msg); - } - - /** - * Logs a message at the specified level. - * - * @param level The Log-{@link Level}. - * @param msg The message to log. - * - * @deprecated Replaced by {@link Logging}. Please refrain from using this from a third party plugin as the - * messages will appear to originate from Multiverse-Core. - */ - @Deprecated - public static void staticLog(Level level, String msg) { - Logging.log(level, msg); - } - - /** - * Print messages to the Debug Log, if the servers in Debug Mode then we also want to print the messages to the - * standard Server Console. - * - * @param level The Log-{@link Level} - * @param msg The message - * - * @deprecated Replaced by {@link Logging}. Please refrain from using this from a third party plugin as the - * messages will appear to originate from Multiverse-Core. - */ - @Deprecated - public static void staticDebugLog(Level level, String msg) { - Logging.log(level, msg); - } - /** * {@inheritDoc} */ @@ -928,16 +886,6 @@ public CommandQueueManager getCommandQueueManager() { return commandQueueManager; } - /** - * Gets the log-tag. - * - * @return The log-tag - */ - // TODO this should be static! - public String getTag() { - return MultiverseCore.LOG_TAG; - } - /** * Shows a message that the given world is not a MultiverseWorld. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/LoggablePlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/LoggablePlugin.java deleted file mode 100644 index 56852e45c..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/api/LoggablePlugin.java +++ /dev/null @@ -1,36 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.api; - -import com.dumptruckman.minecraft.util.Logging; -import org.bukkit.Server; - -import java.util.logging.Level; - -/** - * A simple API to require plugins to have a log method. - * - * @deprecated Replaced by {@link Logging}. - * */ -@Deprecated -public interface LoggablePlugin { - /** - * Logs a message at the specified level. - * - * @param level The Log-{@link Level}. - * @param msg The message to log. - */ - void log(Level level, String msg); - - /** - * Gets the server instance that this plugin is attached to. - * - * @return A {@link Server} instance. - */ - Server getServer(); -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java index e70cd35dd..a9582edfa 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVPlugin.java @@ -13,7 +13,7 @@ /** * This interface is implemented by every official Multiverse-plugin. */ -public interface MVPlugin extends LoggablePlugin { +public interface MVPlugin { /** * Adds This plugin's version information to the buffer and returns the new string. * diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java index a6a064b8a..28bbc9190 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java @@ -115,33 +115,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs); } - @Override - public void log(Level level, String msg) { - int debugLevel = this.getCore().getMVConfig().getGlobalDebug(); - if ((level == Level.FINE && debugLevel >= 1) || (level == Level.FINER && debugLevel >= 2) - || (level == Level.FINEST && debugLevel >= 3)) { - debugLog.log(level, msg); - } else if (level != Level.FINE && level != Level.FINER && level != Level.FINEST) { - String message = new StringBuilder(getLogTag()).append(msg).toString(); - this.getServer().getLogger().log(level, message); - debugLog.log(level, message); - } - } - - private String getLogTag() { - if (logTag == null) - logTag = String.format("[%s]", this.getDescription().getName()); - return logTag; - } - - /** - * Sets the debug log-tag. - * @param tag The new tag. - */ - protected final void setDebugLogTag(String tag) { - this.debugLog.setTag(tag); - } - @Override public final String dumpVersionInfo(String buffer) { throw new UnsupportedOperationException("This is gone."); From fe8118854ee1a552caca75894f182992e2eac6b3 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Sat, 4 Feb 2023 16:49:11 +0800 Subject: [PATCH 015/725] refactor!: Remove deprecated debug log --- .../MultiverseCore/api/MultiversePlugin.java | 9 -- .../MultiverseCore/utils/DebugLog.java | 129 ------------------ 2 files changed, 138 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/utils/DebugLog.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java index 28bbc9190..90a9b33ff 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java @@ -5,14 +5,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.utils.DebugLog; import com.pneumaticraft.commandhandler.CommandHandler; /** @@ -20,11 +18,6 @@ */ public abstract class MultiversePlugin extends JavaPlugin implements MVPlugin { private MultiverseCore core; - /** - * Prefix for standard log entrys. - */ - protected String logTag; - private DebugLog debugLog; /** * {@inheritDoc} @@ -58,8 +51,6 @@ public final void onEnable() { } catch (IOException e) { e.printStackTrace(); } - debugLog = new DebugLog(this.getDescription().getName(), getDataFolder() + File.separator + "debug.log"); - debugLog.setTag(String.format("[%s-Debug]", this.getDescription().getName())); this.onPluginEnable(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/DebugLog.java b/src/main/java/com/onarandombox/MultiverseCore/utils/DebugLog.java deleted file mode 100644 index c83e7e089..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/DebugLog.java +++ /dev/null @@ -1,129 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.utils; - -import com.onarandombox.MultiverseCore.MultiverseCoreConfiguration; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.List; -import java.util.logging.FileHandler; -import java.util.logging.Formatter; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -/** - * The Multiverse debug-logger. - * @deprecated Deprecated in favor of new Logging lib. See {@link com.dumptruckman.minecraft.util.Logging}. - */ -@Deprecated -public class DebugLog extends Logger { - private FileHandler fh; - private Logger standardLog = null; - private String prefix = "[MVCore-Debug] "; - - /** - * Creates a new debug logger. - * - * @param logger The name of the logger. - * @param file The file to log to. - */ - public DebugLog(String logger, String file) { - super(logger, null); - try { - this.fh = new FileHandler(file, true); - this.setUseParentHandlers(false); - List toRemove = Arrays.asList(this.getHandlers()); - for (Handler handler : toRemove) { - this.removeHandler(handler); - } - this.addHandler(this.fh); - this.setLevel(Level.ALL); - this.fh.setFormatter(new LogFormatter()); - } catch (SecurityException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * Sets the log-tag. - * @param tag The new tag. - */ - public void setTag(String tag) { - this.prefix = tag + " "; - } - - /** - * Specifies the logger to use to send debug messages to as the debug logger itself only sends messages to a file. - * - * @param logger Logger to send debug messages to. - */ - public void setStandardLogger(Logger logger) { - this.standardLog = logger; - } - - /** - * Log a message at a certain level. - * - * @param level The log-{@link Level}. - * @param msg the message. - */ - @Override - public void log(final Level level, final String msg) { - if (MultiverseCoreConfiguration.isSet() && MultiverseCoreConfiguration.getInstance().getGlobalDebug() > 0) { - // only redirect to standardLog if it's lower than INFO so we don't log that twice! - if ((level.intValue() < Level.INFO.intValue()) && (standardLog != null)) { - standardLog.log(Level.INFO, prefix + msg); - } - - super.log(level, prefix + msg); - } - } - - /** - * Our log-{@link Formatter}. - */ - private class LogFormatter extends Formatter { - private final SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - @Override - public String format(LogRecord record) { - StringBuilder builder = new StringBuilder(); - Throwable ex = record.getThrown(); - - builder.append(this.date.format(record.getMillis())); - builder.append(" ["); - builder.append(record.getLevel().getLocalizedName().toUpperCase()); - builder.append("] "); - builder.append(record.getMessage()); - builder.append('\n'); - - if (ex != null) { - StringWriter writer = new StringWriter(); - ex.printStackTrace(new PrintWriter(writer)); - builder.append(writer); - } - - return builder.toString(); - } - } - - /** - * Closes this {@link DebugLog}. - */ - public void close() { - this.fh.close(); - } -} From 747cab75fde0e241ebf64ab2abd6dff002600bb3 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Mon, 6 Feb 2023 21:04:34 +0800 Subject: [PATCH 016/725] feat: Implement command flag system (#2827) * feat: Implement command flag system * docs: Add javadocs and annotation * chore: Implement suggested improvements * chore: Add shortcuts for flaggroup in MultiverseCommand * chore: Add check if flaggroup already registered --- .../MultiverseCore/MultiverseCore.java | 33 ++-- .../commands/CreateCommand.java | 108 +++++++++++ .../MultiverseCore/commands/DebugCommand.java | 3 +- .../commands/MultiverseCommand.java | 28 ++- .../commandtools/MVCommandCompletions.java | 15 ++ .../commandtools/MVCommandManager.java | 21 ++- .../commandtools/flags/CommandFlag.java | 93 ++++++++++ .../commandtools/flags/CommandFlagGroup.java | 129 +++++++++++++ .../flags/CommandFlagsManager.java | 93 ++++++++++ .../flags/CommandFlagsParser.java | 118 ++++++++++++ .../commandtools/flags/CommandValueFlag.java | 172 ++++++++++++++++++ .../flags/ParsedCommandFlags.java | 52 ++++++ 12 files changed, 842 insertions(+), 23 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagGroup.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsManager.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsParser.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/ParsedCommandFlags.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index a4e44b6ad..b32d3716e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -7,6 +7,20 @@ package com.onarandombox.MultiverseCore; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + import buscript.Buscript; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MVWorld.NullLocation; @@ -18,6 +32,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig; import com.onarandombox.MultiverseCore.api.MultiverseMessaging; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; +import com.onarandombox.MultiverseCore.commands.CreateCommand; import com.onarandombox.MultiverseCore.commands.DebugCommand; import com.onarandombox.MultiverseCore.commandsold.AnchorCommand; import com.onarandombox.MultiverseCore.commandsold.CheckCommand; @@ -25,7 +40,6 @@ import com.onarandombox.MultiverseCore.commandsold.ConfigCommand; import com.onarandombox.MultiverseCore.commandsold.ConfirmCommand; import com.onarandombox.MultiverseCore.commandsold.CoordCommand; -import com.onarandombox.MultiverseCore.commandsold.CreateCommand; import com.onarandombox.MultiverseCore.commandsold.DeleteCommand; import com.onarandombox.MultiverseCore.commandsold.EnvironmentCommand; import com.onarandombox.MultiverseCore.commandsold.GameruleCommand; @@ -105,20 +119,6 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPluginLoader; -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - /** * The implementation of the Multiverse-{@link Core}. */ @@ -743,7 +743,6 @@ private void registerCommands() { this.commandHandler.registerCommand(new VersionCommand(this)); this.commandHandler.registerCommand(new ListCommand(this)); this.commandHandler.registerCommand(new InfoCommand(this)); - this.commandHandler.registerCommand(new CreateCommand(this)); this.commandHandler.registerCommand(new CloneCommand(this)); this.commandHandler.registerCommand(new ImportCommand(this)); this.commandHandler.registerCommand(new ReloadCommand(this)); @@ -770,7 +769,6 @@ private void registerCommands() { this.commandHandler.registerCommand(new AnchorCommand(this)); // Misc Commands this.commandHandler.registerCommand(new EnvironmentCommand(this)); - // this.commandHandler.registerCommand(new DebugCommand(this)); this.commandHandler.registerCommand(new SilentCommand(this)); this.commandHandler.registerCommand(new GeneratorCommand(this)); this.commandHandler.registerCommand(new CheckCommand(this)); @@ -780,6 +778,7 @@ private void registerCommands() { //**NEW ACF COMMAND HANDLER** this.commandManager.registerCommand(new DebugCommand(this)); + this.commandManager.registerCommand(new CreateCommand(this)); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java new file mode 100644 index 000000000..a6b28fed1 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -0,0 +1,108 @@ +package com.onarandombox.MultiverseCore.commands; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; + +import co.aikar.commands.CommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Optional; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlag; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandValueFlag; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup; +import com.onarandombox.MultiverseCore.commandtools.flags.ParsedCommandFlags; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldType; +import org.bukkit.command.CommandException; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +@CommandAlias("mv") +public class CreateCommand extends MultiverseCommand { + + public CreateCommand(@NotNull MultiverseCore plugin) { + super(plugin); + + registerFlagGroup(CommandFlagGroup.builder("mvcreate") + .add(CommandValueFlag.builder("--seed", String.class) + .addAlias("-s") + .completion(() -> Collections.singleton(String.valueOf(new Random().nextLong()))) + .build()) + .add(CommandValueFlag.builder("--generator", String.class) + .addAlias("-g") + .completion(() -> Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()) + .filter(Plugin::isEnabled) + .filter(genplugin -> this.plugin.getUnsafeCallWrapper().wrap( + () -> genplugin.getDefaultWorldGenerator("world", ""), + genplugin.getName(), + "Get generator" + ) != null) + .map(genplugin -> genplugin.getDescription().getName()) + .collect(Collectors.toList())) + .build()) + .add(CommandValueFlag.builder("--world-type", WorldType.class) + .addAlias("-t") + .context((value) -> { + try { + return WorldType.valueOf(value.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new CommandException("Invalid world type: " + value); + } + }) + .completion(() -> { + List types = new ArrayList<>(); + for (WorldType type : WorldType.values()) { + types.add(type.name().toLowerCase()); + } + return types; + }) + .build()) + .add(CommandFlag.builder("--adjust-spawn") + .addAlias("-n") + .build()) + .add(CommandFlag.builder("--no-structures") + .addAlias("-a") + .build()) + .build()); + } + + @Subcommand("create") + @CommandPermission("multiverse.core.create") + @CommandCompletion("WORLDNAME @flags:groupName=mvcreate") + @Syntax(" -s [seed] -g [generator[:id]] -t [worldtype] [-n] -a [true|false]") + @Description("") //TODO + public void onCreateCommand(CommandIssuer issuer, + + @Syntax("") + @Description("") //TODO + String worldName, + + @Syntax("") + @Description("") //TODO + World.Environment environment, + + @Optional + @Syntax("[world-flags]") + @Description("") //TODO + String[] flags + ) { + ParsedCommandFlags parsedFlags = parseFlags(flags); + + issuer.sendMessage(worldName + " " + environment.toString()); + issuer.sendMessage("--seed: " + parsedFlags.hasFlag("--seed") + " " + String.valueOf(parsedFlags.flagValue("--seed", String.class))); + issuer.sendMessage("--generator: " + parsedFlags.hasFlag("--generator") + " " + String.valueOf(parsedFlags.flagValue("--generator", String.class))); + issuer.sendMessage("--world-type: " + parsedFlags.hasFlag("--world-type") + " " + String.valueOf(parsedFlags.flagValue("--world-type", WorldType.class))); + issuer.sendMessage("--adjust-spawn: " + parsedFlags.hasFlag("--adjust-spawn") + " " + String.valueOf(parsedFlags.flagValue("--adjust-spawn", String.class))); + issuer.sendMessage("--no-structures: " + parsedFlags.hasFlag("--no-structures") + " " + String.valueOf(parsedFlags.flagValue("--no-structures", String.class))); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java index e4cabe2a4..9e702267d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java @@ -16,7 +16,7 @@ @CommandAlias("mv") public class DebugCommand extends MultiverseCommand { - public DebugCommand(MultiverseCore plugin) { + public DebugCommand(@NotNull MultiverseCore plugin) { super(plugin); } @@ -27,7 +27,6 @@ public void onShowDebugCommand(@NotNull CommandIssuer issuer) { this.displayDebugMode(issuer); } - @Subcommand("debug") @CommandPermission("multiverse.core.debug") @Syntax("<{@@mv-core.debug_change_syntax}>") diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java index 42a65604e..f9385144d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/MultiverseCommand.java @@ -2,12 +2,38 @@ import co.aikar.commands.BaseCommand; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MVWorldManager; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagsManager; +import com.onarandombox.MultiverseCore.commandtools.flags.ParsedCommandFlags; +import org.jetbrains.annotations.NotNull; +/** + * A base command for Multiverse. + */ public class MultiverseCommand extends BaseCommand { protected final MultiverseCore plugin; + protected final MVWorldManager worldManager; + protected final CommandFlagsManager flagsManager; - protected MultiverseCommand(MultiverseCore plugin) { + private String flagGroupName; + + protected MultiverseCommand(@NotNull MultiverseCore plugin) { this.plugin = plugin; + this.worldManager = plugin.getMVWorldManager(); + this.flagsManager = plugin.getCommandManager().getFlagsManager(); + } + + protected void registerFlagGroup(@NotNull CommandFlagGroup flagGroup) { + if (flagGroupName != null) { + throw new IllegalStateException("Flag group already registered! (name: " + flagGroupName + ")"); + } + flagsManager.registerFlagGroup(flagGroup); + flagGroupName = flagGroup.getName(); + } + + protected @NotNull ParsedCommandFlags parseFlags(@NotNull String[] flags) { + return flagsManager.parse(flagGroupName, flags); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java index 7b5cbd9ff..72faa7ada 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java @@ -1,9 +1,24 @@ package com.onarandombox.MultiverseCore.commandtools; +import java.util.Collection; + +import co.aikar.commands.BukkitCommandCompletionContext; import co.aikar.commands.PaperCommandCompletions; +import org.jetbrains.annotations.NotNull; public class MVCommandCompletions extends PaperCommandCompletions { + protected final MVCommandManager commandManager; + public MVCommandCompletions(MVCommandManager mvCommandManager) { super(mvCommandManager); + this.commandManager = mvCommandManager; + + registerAsyncCompletion("flags", this::suggestFlags); + } + + @NotNull + private Collection suggestFlags(@NotNull BukkitCommandCompletionContext context) { + return this.commandManager.getFlagsManager().suggest( + context.getConfig("groupName", ""), context.getContextValue(String[].class)); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java index d84689f2c..0522c6c3a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java @@ -8,6 +8,8 @@ import co.aikar.commands.CommandContexts; import co.aikar.commands.PaperCommandManager; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagsManager; +import org.jetbrains.annotations.NotNull; /** * Main class to manage permissions. @@ -15,8 +17,9 @@ public class MVCommandManager extends PaperCommandManager { private final MultiverseCore plugin; + private CommandFlagsManager flagsManager; - public MVCommandManager(MultiverseCore plugin) { + public MVCommandManager(@NotNull MultiverseCore plugin) { super(plugin); this.plugin = plugin; @@ -26,13 +29,25 @@ public MVCommandManager(MultiverseCore plugin) { this.locales.loadLanguages(); } + /** + * Gets class responsible for flag handling. + * + * @return A not-null {@link CommandFlagsManager}. + */ + public synchronized @NotNull CommandFlagsManager getFlagsManager() { + if (this.flagsManager == null) { + this.flagsManager = new CommandFlagsManager(); + } + return flagsManager; + } + /** * Gets class responsible for parsing string args into objects. * * @return A not-null {@link CommandContexts}. */ @Override - public synchronized CommandContexts getCommandContexts() { + public synchronized @NotNull CommandContexts getCommandContexts() { if (this.contexts == null) { this.contexts = new MVCommandContexts(this); } @@ -45,7 +60,7 @@ public synchronized CommandContexts getCommandCon * @return A not-null {@link CommandCompletions}. */ @Override - public synchronized CommandCompletions getCommandCompletions() { + public synchronized @NotNull CommandCompletions getCommandCompletions() { if (this.completions == null) { this.completions = new MVCommandCompletions(this); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java new file mode 100644 index 000000000..6323244ef --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlag.java @@ -0,0 +1,93 @@ +package com.onarandombox.MultiverseCore.commandtools.flags; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.jetbrains.annotations.NotNull; + +/** + * Represents a flag. + */ +public class CommandFlag { + /** + * A builder for a flag. + * + * @param key The key for the new flag. + * @return The builder. + */ + public static @NotNull Builder builder(@NotNull String key){ + return new Builder<>(key); + } + + private final String key; + private final List aliases; + + /** + * Creates a new flag. + * + * @param builder The builder. + */ + protected CommandFlag(@NotNull Builder builder) { + key = builder.key; + aliases = builder.aliases; + } + + /** + * Get the key of this flag. + * + * @return The key of this flag. + */ + public @NotNull String getKey() { + return key; + } + + /** + * Get the aliases of this flag. + * + * @return The aliases of this flag. + */ + public @NotNull List getAliases() { + return aliases; + } + + /** + * A builder for a flag. + * + * @param The type of the builder. + */ + public static class Builder> { + private final String key; + private final List aliases; + + /** + * Create a new builder. + * + * @param key The key for the new flag. + */ + public Builder(@NotNull String key) { + this.key = key; + aliases = new ArrayList<>(); + } + + /** + * Add one or more alias to the flag. + * + * @param alias The alias to add. + * @return The builder. + */ + public @NotNull S addAlias(@NotNull String...alias){ + Collections.addAll(this.aliases, alias); + return (S) this; + } + + /** + * Build the flag. + * + * @return The flag. + */ + public @NotNull CommandFlag build(){ + return new CommandFlag(this); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagGroup.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagGroup.java new file mode 100644 index 000000000..a36d23d78 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagGroup.java @@ -0,0 +1,129 @@ +package com.onarandombox.MultiverseCore.commandtools.flags; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * A group of flags. + */ +public class CommandFlagGroup { + /** + * A builder for a flag group. + * + * @param name The name of the group. + * @return The builder. + */ + public static @NotNull Builder builder(@NotNull String name) { + return new Builder(name); + } + + private final String name; + private final List keys; + private final Map keysFlagMap; + + /** + * Creates a new flag group. + * + * @param builder The builder. + */ + protected CommandFlagGroup(@NotNull Builder builder) { + name = builder.name; + keys = builder.keys; + keysFlagMap = builder.keysFlagMap; + } + + /** + * Get the name of this group. + * + * @return The name of this group. + */ + public @NotNull String getName() { + return name; + } + + /** + * Check if this group contains a flag with the given key. Works with alias keys. + * + * @param key The key to check. + * @return True if the group contains a flag with the given key, false otherwise. + */ + public boolean hasKey(@Nullable String key) { + return keysFlagMap.containsKey(key); + } + + /** + * Get the remaining keys after the given flags have been removed. Works with alias keys. + * + * @param flags The flags to remove. + * @return The remaining keys. + */ + public @NotNull Set getRemainingKeys(@NotNull String[] flags) { + Set keysRemaining = new HashSet<>(this.keys); + for (String flag : flags) { + CommandFlag mvFlag = this.getFlagByKey(flag); + if (mvFlag != null) { + keysRemaining.remove(mvFlag.getKey()); + } + } + return keysRemaining; + } + + /** + * Get a flag by its key. Alias keys are supported as well. + * + * @param key The key of the flag. + * @return The flag if found, null otherwise. + */ + public @Nullable CommandFlag getFlagByKey(String key) { + return keysFlagMap.get(key); + } + + /** + * A builder for {@link CommandFlagGroup}. + */ + public static class Builder { + private final String name; + private final List keys; + private final Map keysFlagMap; + + /** + * Creates a new builder. + * + * @param name The name of the flag group. + */ + public Builder(@NotNull String name) { + this.name = name; + this.keys = new ArrayList<>(); + this.keysFlagMap = new HashMap<>(); + } + + /** + * Adds a flag to the group. + * + * @param flag The flag to add. + * @return The builder. + */ + public @NotNull Builder add(CommandFlag flag) { + keys.add(flag.getKey()); + keysFlagMap.put(flag.getKey(), flag); + flag.getAliases().forEach((alias) -> keysFlagMap.put(alias, flag)); + return this; + } + + /** + * Builds the flag group. + * + * @return The flag group. + */ + public @NotNull CommandFlagGroup build() { + return new CommandFlagGroup(this); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsManager.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsManager.java new file mode 100644 index 000000000..6c66e4623 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsManager.java @@ -0,0 +1,93 @@ +package com.onarandombox.MultiverseCore.commandtools.flags; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import co.aikar.commands.InvalidCommandArgument; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Manages all the flag groups and parsing. + */ +public class CommandFlagsManager { + private final Map flagGroupMap; + + /** + * Creates a new FlagsManager. + */ + public CommandFlagsManager() { + flagGroupMap = new HashMap<>(); + } + + /** + * Registers a flag group. + * + * @param flagGroup The target flag group to register. + */ + public void registerFlagGroup(@NotNull CommandFlagGroup flagGroup) { + flagGroupMap.put(flagGroup.getName(), flagGroup); + } + + /** + * Get a flag group by name. + * + * @param groupName The target flag group name. + * @return The flag group if found, null otherwise. + */ + public @Nullable CommandFlagGroup getFlagGroup(@Nullable String groupName) { + return this.flagGroupMap.get(groupName); + } + + /** + * Autocompletes suggestions for flags. + * + * @param groupName The target flag group name. + * @param flags The current flags so far. + * @return The list of suggestions. + */ + public @NotNull Collection suggest(@Nullable String groupName, @NotNull String[] flags) { + CommandFlagGroup flagGroup = this.getFlagGroup(groupName); + if (flagGroup == null) { + return Collections.emptyList(); + } + + Collection suggestions = new ArrayList<>(); + CommandFlag currentFlag = (flags.length <= 1) ? null : flagGroup.getFlagByKey(flags[flags.length - 2]); + + if (currentFlag instanceof CommandValueFlag) { + CommandValueFlag valueFlag = (CommandValueFlag) currentFlag; + if (valueFlag.getCompletion() != null) { + suggestions.addAll(valueFlag.getCompletion().get()); + } + if (valueFlag.isOptional()) { + suggestions.addAll(flagGroup.getRemainingKeys(flags)); + } + } else { + suggestions.addAll(flagGroup.getRemainingKeys(flags)); + } + + return suggestions; + } + + /** + * Parses the flags. + * + * @param groupName The target flag group name. + * @param flags The flags to parse. + * @return The parsed flags. + * + * @throws InvalidCommandArgument If the flags are invalid. + */ + public @NotNull ParsedCommandFlags parse(@Nullable String groupName, @NotNull String[] flags) { + CommandFlagGroup flagGroup = this.getFlagGroup(groupName); + if (flagGroup == null) { + return ParsedCommandFlags.EMPTY; + } + + return new CommandFlagsParser(this.getFlagGroup(groupName), flags).parse(); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsParser.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsParser.java new file mode 100644 index 000000000..4c5bde8c2 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandFlagsParser.java @@ -0,0 +1,118 @@ +package com.onarandombox.MultiverseCore.commandtools.flags; + +import co.aikar.commands.InvalidCommandArgument; + +/** + * Parses flags from a string array. Each parser should only be used once. + */ +public class CommandFlagsParser { + private final CommandFlagGroup flagGroup; + private final String[] flags; + + private ParsedCommandFlags parsedFlags; + private boolean nextArgMayBeKey; + private boolean nextArgMayBeValue; + private CommandFlag currentFlag; + + /** + * Creates a new CommandFlagsParser. + * + * @param flagGroup The flag group to parse flags for. + * @param flags The flags to parse. + */ + public CommandFlagsParser(CommandFlagGroup flagGroup, String[] flags) { + this.flagGroup = flagGroup; + this.flags = flags; + } + + /** + * Parses the flags. + * + * @return The parsed flags. + */ + public ParsedCommandFlags parse() { + parsedFlags = new ParsedCommandFlags(); + + // First argument is always a key + this.nextArgMayBeKey = true; + this.nextArgMayBeValue = false; + + for (String flag : flags) { + if (this.nextArgMayBeKey) { + if (parseKey(flag)) continue; + } + if (this.nextArgMayBeValue) { + if (parseValue(flag)) continue; + } + throw new InvalidCommandArgument(flag + " is not a valid flag."); + } + + if (!this.nextArgMayBeKey && this.nextArgMayBeValue) { + throw new InvalidCommandArgument(currentFlag.getKey() + " requires a value!"); + } + + return parsedFlags; + } + + /** + * Parses a key. + * + * @param flag The flag to parse. + * @return True if the flag was parsed as a key, false otherwise. + */ + private boolean parseKey(String flag) { + CommandFlag potentialFlag = flagGroup.getFlagByKey(flag); + if (potentialFlag == null) { + return false; + } + + this.currentFlag = potentialFlag; + + if (this.currentFlag instanceof CommandValueFlag) { + CommandValueFlag valueFlag = (CommandValueFlag) this.currentFlag; + + if (valueFlag.isOptional()) { + parsedFlags.addFlagResult(valueFlag.getKey(), valueFlag.getDefaultValue()); + this.nextArgMayBeKey = true; + this.nextArgMayBeValue = true; + return true; + } + + this.nextArgMayBeKey = false; + this.nextArgMayBeValue = true; + return true; + } + + parsedFlags.addFlagResult(this.currentFlag.getKey(), null); + this.nextArgMayBeKey = true; + this.nextArgMayBeValue = false; + + return true; + } + + /** + * Parses a value. + * + * @param flag The flag to parse. + * @return True if the flag was parsed as a value, false otherwise. + */ + private boolean parseValue(String flag) { + if (this.currentFlag == null) { + throw new InvalidCommandArgument("Some flag logic error occurred at " + flag + ""); + } + if (flagGroup.hasKey(flag)) { + throw new InvalidCommandArgument(currentFlag.getKey() + " requires a value!"); + } + + Object flagValue; + CommandValueFlag valueFlag = (CommandValueFlag) this.currentFlag; + flagValue = valueFlag.getContext() != null ? valueFlag.getContext().apply(flag) : flag; + parsedFlags.addFlagResult(valueFlag.getKey(), flagValue); + + // After a value, the next argument must be a key + this.nextArgMayBeKey = true; + this.nextArgMayBeValue = false; + this.currentFlag = null; + return true; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java new file mode 100644 index 000000000..bf1a70346 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/CommandValueFlag.java @@ -0,0 +1,172 @@ +package com.onarandombox.MultiverseCore.commandtools.flags; + +import java.util.Collection; +import java.util.function.Function; +import java.util.function.Supplier; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents a flag with a value. + * + * @param The type of the value. + */ +public class CommandValueFlag extends CommandFlag { + /** + * A builder for a flag. + * + * @param key The key for the new flag. + * @param type The type of the value. + * @return The builder. + */ + public static @NotNull Builder builder(@NotNull String key, @NotNull Class type) { + return new Builder<>(key, type); + } + + private final Class type; + private final boolean optional; + private final T defaultValue; + private final Function context; + private final Supplier> completion; + + /** + * Creates a new flag. + * + * @param builder The builder. + */ + protected CommandValueFlag(@NotNull Builder builder) { + super(builder); + type = builder.type; + optional = builder.optional; + defaultValue = builder.defaultValue; + context = builder.context; + completion = builder.completion; + } + + /** + * Get the type of the value. + * + * @return The type of the value. + */ + public @NotNull Class getType() { + return type; + } + + /** + * Check if it is optional for users to specify a value. + * + * @return True if the value is optional, false otherwise. + */ + public boolean isOptional() { + return optional; + } + + /** + * Get the default value. May be null. + * + * @return The default value. + */ + public @Nullable T getDefaultValue() { + return defaultValue; + } + + /** + * Get the context. May be null for {@link String} value type. + * + * @return The context. + */ + public @Nullable Function getContext() { + return context; + } + + /** + * Get the completion. May be null. + * + * @return The completion. + */ + public @Nullable Supplier> getCompletion() { + return completion; + } + + /** + * A builder for a flag. + * + * @param The type of the value. + * @param The type of the builder. + */ + public static class Builder> extends CommandFlag.Builder { + private final Class type; + private boolean optional = false; + private T defaultValue = null; + private Function context = null; + private Supplier> completion = null; + + /** + * Create a new builder. + * + * @param key The key for the new flag. + * @param type The type of the value. + */ + public Builder(@NotNull String key, @NotNull Class type) { + super(key); + this.type = type; + } + + /** + * Set the flag as optional for users to specify a value. + * + * @return The builder. + */ + public @NotNull S optional() { + this.optional = true; + return (S) this; + } + + /** + * Set the default value. Used if optional is true and user does not specify a value. + * + * @param defaultValue The default value. + * @return The builder. + */ + public @NotNull S defaultValue(@NotNull T defaultValue) { + this.defaultValue = defaultValue; + return (S) this; + } + + /** + * Set the context callback for parsing string into value type. + * + * @param context The context. + * @return The builder. + */ + public @NotNull S context(@NotNull Function context) { + this.context = context; + return (S) this; + } + + /** + * Set the completion callback for autocomplete. + * + * @param completion The completion. + * @return The builder. + */ + public @NotNull S completion(@NotNull Supplier> completion) { + this.completion = completion; + return (S) this; + } + + /** + * Build the flag. + * + * @return The flag. + */ + @Override + public @NotNull CommandFlag build() { + if (context == null && !String.class.equals(type)) { + throw new IllegalStateException("Context is required for none-string value flags"); + } + return new CommandValueFlag<>(this); + } + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/ParsedCommandFlags.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/ParsedCommandFlags.java new file mode 100644 index 000000000..469e917e3 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/flags/ParsedCommandFlags.java @@ -0,0 +1,52 @@ +package com.onarandombox.MultiverseCore.commandtools.flags; + +import java.util.HashMap; +import java.util.Map; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Object to contain the results of the flags present and its values. + */ +public class ParsedCommandFlags +{ + public static final ParsedCommandFlags EMPTY = new ParsedCommandFlags(); + + private final Map flagValues; + + public ParsedCommandFlags() { + flagValues = new HashMap<>(); + } + + /** + * Add a flag result to the parsed flags. + * + * @param key The key of the flag. + * @param value The value of the flag. + */ + void addFlagResult(@NotNull String key, @Nullable Object value) { + flagValues.put(key, value); + } + + /** + * Check if a flag is present. + * + * @param key The key of the flag. + * @return True if the flag is present, false otherwise. + */ + public boolean hasFlag(@Nullable String key) { + return this.flagValues.containsKey(key); + } + + /** + * Get the value of a flag. + * + * @param key The key of the flag. + * @return The value of the flag, null if flag does not exist or no value. + */ + public @Nullable T flagValue(@Nullable String key, @NotNull Class type) { + Object value = this.flagValues.get(key); + return (T) value; + } +} From a8590df9d4b13b125266c7f8c8899c170eb5e426 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Wed, 8 Feb 2023 12:43:59 +0800 Subject: [PATCH 017/725] feat: Implementation of new destination API (#2833) * feat: Basic implementation of new destination API * feat!: Move all destinations to new API * feat: Fully implement teleport and check command * chore: Improve autocomplete permission checking * chore: Fine tune tab completion * chore: Implement suggested changes * docs: Add javadocs to added api methods --- .../MultiverseCore/MultiverseCore.java | 41 ++- .../onarandombox/MultiverseCore/api/Core.java | 8 +- .../MultiverseCore/api/Destination.java | 56 ++++ .../api/DestinationInstance.java | 45 +++ .../MultiverseCore/api/MVDestination.java | 1 + .../MultiverseCore/api/SafeTTeleporter.java | 19 +- .../MultiverseCore/api/Teleporter.java | 16 +- .../MultiverseCore/commands/CheckCommand.java | 40 +++ .../commands/TeleportCommand.java | 47 ++++ .../commandsold/CheckCommand.java | 58 ---- .../commandsold/TeleportCommand.java | 198 ------------- .../commandtools/MVCommandCompletions.java | 32 ++- .../commandtools/MVCommandContexts.java | 73 ++++- .../commandtools/MVCommandManager.java | 4 +- .../destination/AnchorDestination.java | 148 ---------- .../destination/BedDestination.java | 141 ---------- .../destination/CannonDestination.java | 227 --------------- .../CustomTeleporterDestination.java | 29 -- .../destination/DestinationFactory.java | 177 ------------ .../destination/DestinationsProvider.java | 208 ++++++++++++++ .../destination/ExactDestination.java | 263 ------------------ .../destination/InvalidDestination.java | 107 ------- .../destination/ParsedDestination.java | 53 ++++ .../destination/PlayerDestination.java | 137 --------- .../destination/WorldDestination.java | 173 ------------ .../destination/core/AnchorDestination.java | 68 +++++ .../core/AnchorDestinationInstance.java | 56 ++++ .../destination/core/BedDestination.java | 67 +++++ .../core/BedDestinationInstance.java | 60 ++++ .../destination/core/CannonDestination.java | 103 +++++++ .../core/CannonDestinationInstance.java | 65 +++++ .../destination/core/ExactDestination.java | 106 +++++++ .../core/ExactDestinationInstance.java | 54 ++++ .../destination/core/PlayerDestination.java | 65 +++++ .../core/PlayerDestinationInstance.java | 54 ++++ .../destination/core/WorldDestination.java | 81 ++++++ .../core/WorldDestinationInstance.java | 66 +++++ .../MultiverseCore/event/MVTeleportEvent.java | 1 - .../MultiverseCore/utils/PlayerFinder.java | 30 +- .../utils/SimpleSafeTTeleporter.java | 70 ++--- 40 files changed, 1502 insertions(+), 1745 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/api/Destination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/api/DestinationInstance.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/InvalidDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/ParsedDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/PlayerDestination.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index b32d3716e..cfa0cdc70 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -34,8 +34,8 @@ import com.onarandombox.MultiverseCore.api.SafeTTeleporter; import com.onarandombox.MultiverseCore.commands.CreateCommand; import com.onarandombox.MultiverseCore.commands.DebugCommand; +import com.onarandombox.MultiverseCore.commands.TeleportCommand; import com.onarandombox.MultiverseCore.commandsold.AnchorCommand; -import com.onarandombox.MultiverseCore.commandsold.CheckCommand; import com.onarandombox.MultiverseCore.commandsold.CloneCommand; import com.onarandombox.MultiverseCore.commandsold.ConfigCommand; import com.onarandombox.MultiverseCore.commandsold.ConfirmCommand; @@ -63,19 +63,18 @@ import com.onarandombox.MultiverseCore.commandsold.SetSpawnCommand; import com.onarandombox.MultiverseCore.commandsold.SilentCommand; import com.onarandombox.MultiverseCore.commandsold.SpawnCommand; -import com.onarandombox.MultiverseCore.commandsold.TeleportCommand; import com.onarandombox.MultiverseCore.commandsold.UnloadCommand; import com.onarandombox.MultiverseCore.commandsold.VersionCommand; import com.onarandombox.MultiverseCore.commandsold.WhoCommand; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager; -import com.onarandombox.MultiverseCore.destination.AnchorDestination; -import com.onarandombox.MultiverseCore.destination.BedDestination; -import com.onarandombox.MultiverseCore.destination.CannonDestination; -import com.onarandombox.MultiverseCore.destination.DestinationFactory; -import com.onarandombox.MultiverseCore.destination.ExactDestination; -import com.onarandombox.MultiverseCore.destination.PlayerDestination; -import com.onarandombox.MultiverseCore.destination.WorldDestination; +import com.onarandombox.MultiverseCore.destination.core.AnchorDestination; +import com.onarandombox.MultiverseCore.destination.core.BedDestination; +import com.onarandombox.MultiverseCore.destination.core.CannonDestination; +import com.onarandombox.MultiverseCore.destination.core.ExactDestination; +import com.onarandombox.MultiverseCore.destination.core.PlayerDestination; +import com.onarandombox.MultiverseCore.destination.DestinationsProvider; +import com.onarandombox.MultiverseCore.destination.core.WorldDestination; import com.onarandombox.MultiverseCore.event.MVDebugModeEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent; import com.onarandombox.MultiverseCore.listeners.MVChatListener; @@ -227,7 +226,7 @@ public int getProtocolVersion() { private MVEconomist economist; private Buscript buscript; private int pluginCount; - private DestinationFactory destFactory; + private DestinationsProvider destinationsProvider; private MultiverseMessaging messaging; private BlockSafety blockSafety; private LocationManipulation locationManipulation; @@ -362,14 +361,13 @@ private void initializeBuscript() { } private void initializeDestinationFactory() { - this.destFactory = new DestinationFactory(this); - this.destFactory.registerDestinationType(WorldDestination.class, ""); - this.destFactory.registerDestinationType(WorldDestination.class, "w"); - this.destFactory.registerDestinationType(ExactDestination.class, "e"); - this.destFactory.registerDestinationType(PlayerDestination.class, "pl"); - this.destFactory.registerDestinationType(CannonDestination.class, "ca"); - this.destFactory.registerDestinationType(BedDestination.class, "b"); - this.destFactory.registerDestinationType(AnchorDestination.class, "a"); + this.destinationsProvider = new DestinationsProvider(this); + this.destinationsProvider.registerDestination(new AnchorDestination(this)); + this.destinationsProvider.registerDestination(new BedDestination()); + this.destinationsProvider.registerDestination(new CannonDestination(this)); + this.destinationsProvider.registerDestination(new ExactDestination(this)); + this.destinationsProvider.registerDestination(new PlayerDestination()); + this.destinationsProvider.registerDestination(new WorldDestination(this)); } /** @@ -748,7 +746,6 @@ private void registerCommands() { this.commandHandler.registerCommand(new ReloadCommand(this)); this.commandHandler.registerCommand(new SetSpawnCommand(this)); this.commandHandler.registerCommand(new CoordCommand(this)); - this.commandHandler.registerCommand(new TeleportCommand(this)); this.commandHandler.registerCommand(new WhoCommand(this)); this.commandHandler.registerCommand(new SpawnCommand(this)); // Dangerous Commands @@ -771,12 +768,12 @@ private void registerCommands() { this.commandHandler.registerCommand(new EnvironmentCommand(this)); this.commandHandler.registerCommand(new SilentCommand(this)); this.commandHandler.registerCommand(new GeneratorCommand(this)); - this.commandHandler.registerCommand(new CheckCommand(this)); this.commandHandler.registerCommand(new ScriptCommand(this)); this.commandHandler.registerCommand(new GameruleCommand(this)); this.commandHandler.registerCommand(new GamerulesCommand(this)); //**NEW ACF COMMAND HANDLER** + this.commandManager.registerCommand(new TeleportCommand(this)); this.commandManager.registerCommand(new DebugCommand(this)); this.commandManager.registerCommand(new CreateCommand(this)); } @@ -935,8 +932,8 @@ public void decrementPluginCount() { * {@inheritDoc} */ @Override - public DestinationFactory getDestFactory() { - return this.destFactory; + public DestinationsProvider getDestinationsProvider() { + return this.destinationsProvider; } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index d1d4e9e87..bb004c92b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -10,7 +10,7 @@ import buscript.Buscript; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager; -import com.onarandombox.MultiverseCore.destination.DestinationFactory; +import com.onarandombox.MultiverseCore.destination.DestinationsProvider; import com.onarandombox.MultiverseCore.utils.AnchorManager; import com.onarandombox.MultiverseCore.utils.MVEconomist; import com.onarandombox.MultiverseCore.utils.MVPermissions; @@ -106,12 +106,12 @@ public interface Core { CommandQueueManager getCommandQueueManager(); /** - * Gets the factory class responsible for loading many different destinations + * Gets the class responsible for loading many different destinations * on demand. * - * @return A valid {@link DestinationFactory}. + * @return A valid {@link DestinationsProvider}. */ - DestinationFactory getDestFactory(); + DestinationsProvider getDestinationsProvider(); /** * Gets the primary class responsible for managing Multiverse Worlds. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java b/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java new file mode 100644 index 000000000..7b15af66d --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Destination.java @@ -0,0 +1,56 @@ +package com.onarandombox.MultiverseCore.api; + +import java.util.Collection; + +import co.aikar.commands.BukkitCommandIssuer; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface Destination { + /** + * Returns the identifier or prefix that is required for this destination. + * + *

Portals have a prefix of "p" for example and OpenWarp (third party plugin) uses "ow". This is derived from a + * hash and cannot have duplicate values. Read that as your plugin cannot use 'p' because it's already used. + * Please check the wiki when adding a custom destination!

+ * + * @return The identifier or prefix that is required for this destination. + */ + @NotNull String getIdentifier(); + + /** + * Returns the destination instance for the given destination parameters. + * + * @param destinationParams The destination parameters. ex: p:MyPortal:nw + * @return The destination instance, or null if the destination parameters are invalid. + */ + @Nullable T getDestinationInstance(@Nullable String destinationParams); + + /** + * Returns a list of possible destinations for the given destination parameters. + * + * @param issuer The command issuer. + * @param destinationParams The destination parameters. ex: p:MyPortal:nw + * @return A list of possible destinations. + */ + @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams); + + /** + * Should the Multiverse SafeTeleporter be used? + * + *

If not, MV will blindly take people to the location specified.

+ * + * @return True if the SafeTeleporter will be used, false if not. + */ + boolean checkTeleportSafety(); + + /** + * Returns the teleporter to use for this destination. + * + *

By default, Multiverse will automatically use SafeTeleporter. If you want to use a different teleporter, you can + * override this method.

+ * + * @return The custom teleporter to use for this destination. Return null to use the default teleporter. + */ + @Nullable Teleporter getTeleporter(); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/DestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/api/DestinationInstance.java new file mode 100644 index 000000000..485f81058 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/api/DestinationInstance.java @@ -0,0 +1,45 @@ +package com.onarandombox.MultiverseCore.api; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface DestinationInstance { + /** + * Gets the exact location to teleport an entity to. + * + * @param teleportee The entity to teleport. + * @return The location to teleport to. + */ + @Nullable Location getLocation(@NotNull Entity teleportee); + + /** + * Gets the velocity to apply to an entity after teleporting. + * + * @param teleportee The entity to teleport. + * @return A vector representing the speed/direction the player should travel when arriving at the destination. + */ + @Nullable Vector getVelocity(@NotNull Entity teleportee); + + /** + * Gets the permission suffix to check for when teleporting to this destination. + * This is used for finer per world/player permissions, such as "multiverse.teleport.self.worldname". + * + *

For example, if the destination is "w:world", the permission suffix is "world".

+ * + * @return The permission suffix. + */ + @Nullable String getFinerPermissionSuffix(); + + /** + * Serialises the destination instance to a savable string. + * + *

This is used when plugins save destinations to configuration, + * and when the destination is displayed to the user.

+ * + * @return The serialised destination instance. + */ + @NotNull String serialise(); +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java index c4e64de8a..6cafabb43 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MVDestination.java @@ -16,6 +16,7 @@ * A destination API for Multiverse * Any plugin can add these to MV and when they are, any action that uses them (portals, MVTP, etc.) can use them! */ +@Deprecated public interface MVDestination { /** * Returns the identifier or prefix that is required for this destination. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java b/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java index c6e7e76bf..90740a0d7 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/SafeTTeleporter.java @@ -1,11 +1,12 @@ package com.onarandombox.MultiverseCore.api; +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.destination.ParsedDestination; +import com.onarandombox.MultiverseCore.enums.TeleportResult; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Entity; -import com.onarandombox.MultiverseCore.enums.TeleportResult; - /** * Used to safely teleport people. */ @@ -31,12 +32,12 @@ public interface SafeTTeleporter extends Teleporter { * Safely teleport the entity to the MVDestination. This will perform checks to see if the place is safe, and if * it's not, will adjust the final destination accordingly. * - * @param teleporter Person who performed the teleport command. - * @param teleportee Entity to teleport - * @param d Destination to teleport them to + * @param teleporter Person who performed the teleport command. + * @param teleportee Entity to teleport + * @param destination Destination to teleport them to * @return true for success, false for failure */ - TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d); + TeleportResult safelyTeleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination destination); /** * Safely teleport the entity to the Location. This may perform checks to @@ -55,11 +56,11 @@ TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, Locat /** * Returns a safe location for the entity to spawn at. * - * @param e The entity to spawn - * @param d The MVDestination to take the entity to. + * @param entity The entity to spawn + * @param destination The MVDestination to take the entity to. * @return A new location to spawn the entity at. */ - Location getSafeLocation(Entity e, MVDestination d); + Location getSafeLocation(Entity entity, DestinationInstance destination); /** * Finds a portal-block next to the specified {@link Location}. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java b/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java index aead219cd..9dea1323b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Teleporter.java @@ -1,10 +1,18 @@ package com.onarandombox.MultiverseCore.api; -import com.onarandombox.MultiverseCore.api.MVDestination; +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.destination.ParsedDestination; import com.onarandombox.MultiverseCore.enums.TeleportResult; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; +import org.bukkit.entity.Entity; public interface Teleporter { - TeleportResult teleport(CommandSender teleporter, Player teleportee, MVDestination destination); + /** + * Teleport the entity to the Multiverse Destination. + * + * @param teleporter Person who performed the teleport command. + * @param teleportee Entity to teleport + * @param destination Destination to teleport them to + * @return true for success, false for failure + */ + TeleportResult teleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination destination); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java new file mode 100644 index 000000000..347b1f837 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java @@ -0,0 +1,40 @@ +package com.onarandombox.MultiverseCore.commands; + +import co.aikar.commands.CommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.destination.ParsedDestination; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +@CommandAlias("mv") +public class CheckCommand extends MultiverseCommand { + protected CheckCommand(@NotNull MultiverseCore plugin) { + super(plugin); + } + + @Subcommand("check") + @CommandPermission("multiverse.core.check") + @CommandCompletion("@players @destinations|@mvworlds") + @Syntax(" ") + @Description("Checks if a player can teleport to a destination.") + public void onCheckCommand(CommandIssuer issuer, + + @Syntax("") + @Description("Player to check destination on.") + Player player, + + @Syntax("") + @Description("A destination location, e.g. a world name.") + ParsedDestination destination + ) { + issuer.sendMessage("Checking " + player + " to " + destination + "..."); + //TODO More detailed output on permissions required. + this.plugin.getDestinationsProvider().checkTeleportPermissions(issuer, player, destination); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java new file mode 100644 index 000000000..9629d6ea3 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/TeleportCommand.java @@ -0,0 +1,47 @@ +package com.onarandombox.MultiverseCore.commands; + +import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.CommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Flags; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.destination.ParsedDestination; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +@CommandAlias("mv") +public class TeleportCommand extends MultiverseCommand { + public TeleportCommand(MultiverseCore plugin) { + super(plugin); + } + + @Subcommand("teleport|tp") + @Syntax("[player] ") + @CommandCompletion("@players|@mvworlds:playeronly|@destinations:playeronly @mvworlds|@destinations") + @Description("Allows you to the teleport to a location on your server!") + public void onTeleportCommand(@NotNull CommandIssuer issuer, + + @Flags("resolve=issueraware") + @Syntax("[player]") + @Description("Target player to teleport.") + Player player, + + @Syntax("") + @Description("Location, can be a world name.") + ParsedDestination destination + ) { + issuer.sendMessage("Teleporting " + + (((BukkitCommandIssuer) issuer).getPlayer() == player ? "you" : player.getName()) + + " to " + destination + "..."); + this.plugin.getDestinationsProvider().playerTeleport((BukkitCommandIssuer) issuer, player, destination); + } + + @Override + public boolean hasPermission(CommandIssuer issuer) { + return this.plugin.getDestinationsProvider().hasAnyTeleportPermission(issuer); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java deleted file mode 100644 index 519dfa21a..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CheckCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; -import com.onarandombox.MultiverseCore.utils.MVPermissions; -import com.onarandombox.MultiverseCore.utils.PlayerFinder; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; -/** - * Checks to see if a player can go to a destination. - */ -public class CheckCommand extends MultiverseCommand { - - public CheckCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Help you validate your multiverse settings"); - this.setCommandUsage("/mv check " + ChatColor.GREEN + "{PLAYER} {DESTINATION}"); - this.setArgRange(2, 2); - this.addKey("mv check"); - this.addKey("mvcheck"); - this.addCommandExample("/mv check " + ChatColor.GREEN + "fernferret " + ChatColor.LIGHT_PURPLE + "w:MyWorld"); - this.addCommandExample("/mv check " + ChatColor.GREEN + "Rigby90 " + ChatColor.LIGHT_PURPLE + "p:MyPortal"); - this.addCommandExample("/mv check " + ChatColor.GREEN + "lithium3141 " + ChatColor.LIGHT_PURPLE + "ow:WarpName"); - this.setPermission("multiverse.core.debug", "Checks to see if a player can go to a destination. Prints debug if false.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player p = PlayerFinder.get(args.get(0), sender); - if (p == null) { - sender.sendMessage("Could not find player " + ChatColor.GREEN + args.get(0)); - sender.sendMessage("Are they online?"); - return; - } - MVDestination dest = this.plugin.getDestFactory().getDestination(args.get(1)); - if (dest instanceof InvalidDestination) { - sender.sendMessage(String.format("You asked if '%s' could go to %s%s%s,", - args.get(0), ChatColor.GREEN, args.get(0), ChatColor.WHITE)); - sender.sendMessage("but I couldn't find a Destination of that name? Did you type it correctly?"); - return; - } - - MVPermissions perms = this.plugin.getMVPerms(); - perms.tellMeWhyICantDoThis(sender, p, dest); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java deleted file mode 100644 index 15571fd48..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/TeleportCommand.java +++ /dev/null @@ -1,198 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.Teleporter; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; -import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination; -import com.onarandombox.MultiverseCore.destination.DestinationFactory; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; -import com.onarandombox.MultiverseCore.destination.WorldDestination; -import com.onarandombox.MultiverseCore.enums.TeleportResult; -import com.onarandombox.MultiverseCore.event.MVTeleportEvent; -import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.utils.PlayerFinder; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Used to teleport players. - */ -public class TeleportCommand extends MultiverseCommand { - private SafeTTeleporter playerTeleporter; - - public TeleportCommand(MultiverseCore plugin) { - super(plugin); - Permission menu = new Permission("multiverse.teleport.*", "Allows you to display the teleport menu.", PermissionDefault.OP); - - this.setName("Teleport"); - this.setCommandUsage("/mv tp " + ChatColor.GOLD + "[PLAYER]" + ChatColor.GREEN + " {DESTINATION}"); - this.setArgRange(1, 2); - this.addKey("mvtp"); - this.addKey("mv tp"); - this.playerTeleporter = this.plugin.getSafeTTeleporter(); - this.setPermission(menu); - } - - private static final int UNSAFE_TELEPORT_EXPIRE_DELAY = 15; - - @Override - public void runCommand(CommandSender sender, List args) { - CommandSender teleporter = sender; - Player teleportee = null; - - String destinationName; - - if (args.size() == 2) { - teleportee = PlayerFinder.get(args.get(0), sender); - if (teleportee == null) { - this.messaging.sendMessage(sender, String.format("Sorry, I couldn't find player: %s%s", - ChatColor.GOLD, args.get(0)), false); - return; - } - destinationName = args.get(1); - - } else { - destinationName = args.get(0); - if (!(sender instanceof Player)) { - this.messaging.sendMessage(sender, String.format("From the console, you must specify a player to teleport"), false); - return; - } - teleportee = (Player) sender; - } - - DestinationFactory df = this.plugin.getDestFactory(); - MVDestination d = df.getPlayerAwareDestination(teleportee, destinationName); - - MVTeleportEvent teleportEvent = new MVTeleportEvent(d, teleportee, teleporter, true); - this.plugin.getServer().getPluginManager().callEvent(teleportEvent); - if (teleportEvent.isCancelled()) { - Logging.fine("Someone else cancelled the MVTeleport Event!!!"); - return; - } - - if (d != null && d instanceof InvalidDestination) { - this.messaging.sendMessage(sender, String.format("Multiverse does not know how to take you to %s%s", - ChatColor.RED, destinationName), false); - return; - } - - if (!this.checkSendPermissions(teleporter, teleportee, d)) { - return; - } - - if (plugin.getMVConfig().getEnforceAccess() && teleporter != null && !this.plugin.getMVPerms().canEnterDestination(teleporter, d)) { - if (teleportee.equals(teleporter)) { - teleporter.sendMessage("Doesn't look like you're allowed to go " + ChatColor.RED + "there..."); - } else { - teleporter.sendMessage("Doesn't look like you're allowed to send " + ChatColor.GOLD - + teleportee.getName() + ChatColor.WHITE + " to " + ChatColor.RED + "there..."); - } - return; - } else if (teleporter != null && !this.plugin.getMVPerms().canTravelFromLocation(teleporter, d.getLocation(teleportee))) { - if (teleportee.equals(teleporter)) { - this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like you can get to %s%s %sfrom where you are...", - ChatColor.GREEN, d.toString(), ChatColor.WHITE), false); - } else { - this.messaging.sendMessage(teleporter, String.format("DOH! Doesn't look like %s%s %scan get to %sTHERE from where they are...", - ChatColor.GREEN, ((Player) teleporter).getWorld().getName(), ChatColor.WHITE, ChatColor.RED), false); - } - return; - } - - // Special check to verify if players are tryint to teleport to the same - // WORLDDestination as the world they're in, that they ALSO have multiverse.core.spawn.self - - if (d instanceof WorldDestination) { - World w = d.getLocation(teleportee).getWorld(); - if (teleportee.getWorld().equals(w)) { - if (teleporter.equals(teleportee)) { - if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.self", true)) { - this.messaging.sendMessages(teleporter, new String[]{ - String.format("Sorry you don't have permission to go to the world spawn!"), - String.format("%s (multiverse.core.spawn.self)", - ChatColor.RED) }, false); - return; - } - } else { - if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.core.spawn.other", true)) { - this.messaging.sendMessages(teleporter, new String[]{ - String.format("Sorry you don't have permission to send %s to the world spawn!", - teleportee.getDisplayName()), - String.format("%s (multiverse.core.spawn.other)", - ChatColor.RED) }, false); - return; - } - } - } - } - - if (d.getLocation(teleportee) == null) { - this.messaging.sendMessage(teleporter, "Sorry Boss, I tried everything, but just couldn't teleport ya there!", false); - return; - } - Teleporter teleportObject = (d instanceof CustomTeleporterDestination) ? - ((CustomTeleporterDestination)d).getTeleporter() : this.playerTeleporter; - TeleportResult result = teleportObject.teleport(teleporter, teleportee, d); - if (result == TeleportResult.FAIL_UNSAFE) { - Logging.fine("Could not teleport " + teleportee.getName() - + " to " + plugin.getLocationManipulation().strCoordsRaw(d.getLocation(teleportee))); - - String player = "you"; - if (!teleportee.equals(teleporter)) { - player = teleportee.getName(); - } - - this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand( - sender, - doUnsafeTeleport(teleporter, teleportee, d.getLocation(teleportee)), - String.format("%sMultiverse %sdid not teleport %s%s %sto %s%s %sbecause it was unsafe. Would you like to try anyway?", - ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, player, ChatColor.WHITE, ChatColor.DARK_AQUA, d.getName(), ChatColor.WHITE), - UNSAFE_TELEPORT_EXPIRE_DELAY - )); - } - // else: Player was teleported successfully (or the tp event was fired I should say) - } - - private Runnable doUnsafeTeleport(CommandSender teleporter, Player player, Location location) { - return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, player, location, false); - } - - private boolean checkSendPermissions(CommandSender teleporter, Player teleportee, MVDestination destination) { - if (teleporter.equals(teleportee)) { - if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.self." + destination.getIdentifier(), true)) { - this.messaging.sendMessages(teleporter, new String[]{ - String.format("%sYou don't have permission to teleport %syourself %sto a %s%s %sDestination", - ChatColor.WHITE, ChatColor.AQUA, ChatColor.WHITE, ChatColor.RED, destination.getType(), ChatColor.WHITE), - String.format("%s (multiverse.teleport.self.%s)", - ChatColor.RED, destination.getIdentifier()) }, false); - return false; - } - } else { - if (!this.plugin.getMVPerms().hasPermission(teleporter, "multiverse.teleport.other." + destination.getIdentifier(), true)) { - this.messaging.sendMessages(teleporter, new String[]{ - String.format("You don't have permission to teleport another player to a %s%s Destination.", - ChatColor.GREEN, destination.getType()), - String.format("%s(multiverse.teleport.other.%s)", - ChatColor.RED, destination.getIdentifier()) }, false); - return false; - } - } - return true; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java index 72faa7ada..8ce23113e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java @@ -1,24 +1,52 @@ package com.onarandombox.MultiverseCore.commandtools; import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; import co.aikar.commands.BukkitCommandCompletionContext; +import co.aikar.commands.BukkitCommandIssuer; import co.aikar.commands.PaperCommandCompletions; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; import org.jetbrains.annotations.NotNull; public class MVCommandCompletions extends PaperCommandCompletions { protected final MVCommandManager commandManager; + private final MultiverseCore plugin; - public MVCommandCompletions(MVCommandManager mvCommandManager) { + public MVCommandCompletions(MVCommandManager mvCommandManager, MultiverseCore plugin) { super(mvCommandManager); this.commandManager = mvCommandManager; + this.plugin = plugin; + registerAsyncCompletion("destinations", this::suggestDestinations); registerAsyncCompletion("flags", this::suggestFlags); + registerAsyncCompletion("mvworlds", this::suggestMVWorlds); + } + + private Collection suggestDestinations(BukkitCommandCompletionContext context) { + if (context.hasConfig("playeronly") && !context.getIssuer().isPlayer()) { + return Collections.emptyList(); + } + + return this.plugin.getDestinationsProvider() + .suggestDestinations((BukkitCommandIssuer)context.getIssuer(), context.getInput()); } - @NotNull private Collection suggestFlags(@NotNull BukkitCommandCompletionContext context) { return this.commandManager.getFlagsManager().suggest( context.getConfig("groupName", ""), context.getContextValue(String[].class)); } + + private Collection suggestMVWorlds(BukkitCommandCompletionContext context) { + if (context.hasConfig("playeronly") && !context.getIssuer().isPlayer()) { + return Collections.emptyList(); + } + + return this.plugin.getMVWorldManager().getMVWorlds() + .stream() + .map(MultiverseWorld::getName) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java index 0ed2ac902..c5560c5b9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandContexts.java @@ -1,9 +1,80 @@ package com.onarandombox.MultiverseCore.commandtools; +import co.aikar.commands.BukkitCommandExecutionContext; +import co.aikar.commands.InvalidCommandArgument; import co.aikar.commands.PaperCommandContexts; +import com.google.common.base.Strings; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.destination.ParsedDestination; +import com.onarandombox.MultiverseCore.utils.PlayerFinder; +import org.bukkit.entity.Player; public class MVCommandContexts extends PaperCommandContexts { - public MVCommandContexts(MVCommandManager mvCommandManager) { + private final MultiverseCore plugin; + + public MVCommandContexts(MVCommandManager mvCommandManager, MultiverseCore plugin) { super(mvCommandManager); + this.plugin = plugin; + + registerContext(ParsedDestination.class, this::parseDestination); + registerIssuerAwareContext(Player.class, this::parsePlayer); + } + + private ParsedDestination parseDestination(BukkitCommandExecutionContext context) { + String destination = context.popFirstArg(); + if (Strings.isNullOrEmpty(destination)) { + throw new InvalidCommandArgument("No destination specified."); + } + + ParsedDestination parsedDestination = plugin.getDestinationsProvider().parseDestination(destination); + if (parsedDestination == null) { + throw new InvalidCommandArgument("The destination " + destination + " is not valid."); + } + + return parsedDestination; + } + + private Player parsePlayer(BukkitCommandExecutionContext context) { + String resolve = context.getFlagValue("resolve", ""); + + // Get player based on sender only + if (resolve.equals("issueronly")) { + if (context.getIssuer().isPlayer()) { + return context.getIssuer().getPlayer(); + } + if (context.isOptional()) { + return null; + } + throw new InvalidCommandArgument("This command can only be used by a player."); + } + + String playerIdentifier = context.getFirstArg(); + Player player = PlayerFinder.get(playerIdentifier, context.getSender()); + + // Get player based on input, fallback to sender if input is not a player + if (resolve.equals("issueraware")) { + if (player != null) { + context.popFirstArg(); + return player; + } + if (context.getIssuer().isPlayer()) { + return context.getIssuer().getPlayer(); + } + if (context.isOptional()) { + return null; + } + throw new InvalidCommandArgument("Invalid player: " + playerIdentifier + + ". Either specify an online player or use this command as a player."); + } + + // Get player based on input only + if (player != null) { + context.popFirstArg(); + return player; + } + if (!context.isOptional()) { + return null; + } + throw new InvalidCommandArgument("Player " + playerIdentifier + " not found."); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java index 0522c6c3a..06db2a4aa 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandManager.java @@ -49,7 +49,7 @@ public MVCommandManager(@NotNull MultiverseCore plugin) { @Override public synchronized @NotNull CommandContexts getCommandContexts() { if (this.contexts == null) { - this.contexts = new MVCommandContexts(this); + this.contexts = new MVCommandContexts(this, plugin); } return this.contexts; } @@ -62,7 +62,7 @@ public MVCommandManager(@NotNull MultiverseCore plugin) { @Override public synchronized @NotNull CommandCompletions getCommandCompletions() { if (this.completions == null) { - this.completions = new MVCommandCompletions(this); + this.completions = new MVCommandCompletions(this, plugin); } return this.completions; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java deleted file mode 100644 index 0efea0173..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/AnchorDestination.java +++ /dev/null @@ -1,148 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import java.util.Arrays; -import java.util.List; - -/** - * An anchor-{@link MVDestination}. - */ -public class AnchorDestination implements MVDestination { - private boolean isValid; - private Location location; - private MultiverseCore plugin; - private String name; - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "a"; - } - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - if (!(plugin instanceof MultiverseCore)) { - return false; - } - this.plugin = (MultiverseCore) plugin; - List parsed = Arrays.asList(destination.split(":")); - // Need at least: a:name - if (!(parsed.size() == 2)) { - return false; - } - // If it's not an Anchor type - return parsed.get(0).equalsIgnoreCase("a"); - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity e) { - return this.location; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - if (!(plugin instanceof MultiverseCore)) { - return; - } - this.plugin = (MultiverseCore) plugin; - List parsed = Arrays.asList(destination.split(":")); - // Need at least: e:world:x,y,z - // OR e:world:x,y,z:pitch:yaw - // so basically 3 or 5 - if (!(parsed.size() == 2)) { - this.isValid = false; - return; - } - this.name = parsed.get(1); - this.location = this.plugin.getAnchorManager().getAnchorLocation(parsed.get(1)); - if (this.location == null) { - this.isValid = false; - return; - } - if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) { - this.isValid = false; - } - this.isValid = true; - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "Anchor"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return "Anchor: " + this.name; - } - - @Override - public String toString() { - if (isValid) { - return "a:" + this.name; - } - return "i:Invalid Destination"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - return "multiverse.access." + this.location.getWorld().getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - // This is an ANCHOR destination, don't safely teleport here. - return false; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java deleted file mode 100644 index 19b6ad0aa..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/BedDestination.java +++ /dev/null @@ -1,141 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -/** - * A bed-{@link MVDestination}. - */ -public class BedDestination implements MVDestination { - public static final String OWN_BED_STRING = "playerbed"; - private String playername = ""; - private boolean isValid; - private Location knownBedLoc; - private MultiverseCore plugin; - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "b"; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - String[] split = destination.split(":"); - boolean validFormat = split.length >= 1 && split.length <= 2 && split[0].equals(this.getIdentifier()); - - OfflinePlayer p = Bukkit.getOfflinePlayer(split[1]); - boolean validPlayer = p.getName() != null && !p.getName().equals(OWN_BED_STRING); - - if (validFormat && validPlayer) this.playername = p.getName(); - - this.isValid = destination.equals("b:" + OWN_BED_STRING) || (validFormat && validPlayer); - - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity entity) { - if (entity instanceof Player) { - if (this.playername.isEmpty()) - this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(((Player) entity).getBedSpawnLocation()); - else - this.knownBedLoc = this.plugin.getBlockSafety().getSafeBedSpawn(Bukkit.getOfflinePlayer(this.playername).getBedSpawnLocation()); - - if (this.knownBedLoc == null) { - ((Player) entity).sendMessage("The bed was " + ChatColor.RED + "invalid or blocked" + ChatColor.RESET + ". Sorry."); - } - return this.knownBedLoc; - } - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - return new Vector(); - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - this.plugin = (MultiverseCore) plugin; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "Bed"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return "Bed"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - if (knownBedLoc != null) { - return "multiverse.access." + knownBedLoc.getWorld().getName(); - } - return ""; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - // Bukkit should have already checked this. - return false; - } - - @Override - public String toString() { - return "b:" + (playername.isEmpty() ? OWN_BED_STRING : playername); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java deleted file mode 100644 index e26acec32..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/CannonDestination.java +++ /dev/null @@ -1,227 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import java.util.Arrays; -import java.util.List; - -/** - * A cannon-{@link MVDestination}. - */ -public class CannonDestination implements MVDestination { - private final String coordRegex = "(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*),(-?[\\d]+\\.?[\\d]*)"; - private boolean isValid; - private Location location; - private double speed; - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - double pitchRadians = Math.toRadians(location.getPitch()); - double yawRadians = Math.toRadians(location.getYaw()); - double x = Math.sin(yawRadians) * speed * -1; - double y = Math.sin(pitchRadians) * speed * -1; - double z = Math.cos(yawRadians) * speed; - // Account for the angle they were pointed, and take away velocity - x = Math.cos(pitchRadians) * x; - z = Math.cos(pitchRadians) * z; - return new Vector(x, y, z); - } - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "ca"; - } - - // NEED ca:world:x,y,z:pitch:yaw:speed - // so basically 6 - private static final int SPLIT_SIZE = 6; - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - if (!(plugin instanceof MultiverseCore)) { - return false; - } - List parsed = Arrays.asList(destination.split(":")); - if (parsed.size() != SPLIT_SIZE) { - return false; - } - // If it's not an Cannon type - if (!parsed.get(0).equalsIgnoreCase("ca")) { - return false; - } - - // If it's not a MV world - if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) { - return false; - } - // Verify X,Y,Z are numbers - if (!parsed.get(2).matches(coordRegex)) { - return false; - } - - try { - // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck - Float.parseFloat(parsed.get(3)); - Float.parseFloat(parsed.get(4)); - Float.parseFloat(parsed.get(5)); - // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck - } catch (NumberFormatException e) { - return false; - } - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity e) { - return this.location; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - if (!(plugin instanceof MultiverseCore)) { - return; - } - List parsed = Arrays.asList(destination.split(":")); - - if (parsed.size() != SPLIT_SIZE) { - this.isValid = false; - return; - } - if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) { - this.isValid = false; - return; - } - - if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) { - this.isValid = false; - return; - } - - this.location = new Location(((MultiverseCore) plugin).getMVWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0); - - if (!parsed.get(2).matches(this.coordRegex)) { - this.isValid = false; - return; - } - double[] coords = new double[3]; - String[] coordString = parsed.get(2).split(","); - for (int i = 0; i < 3; i++) { - try { - coords[i] = Double.parseDouble(coordString[i]); - } catch (NumberFormatException e) { - this.isValid = false; - return; - } - } - this.location.setX(coords[0]); - this.location.setY(coords[1]); - this.location.setZ(coords[2]); - - try { - // BEGIN CHECKSTYLE-SUPPRESSION: MagicNumberCheck - this.location.setPitch(Float.parseFloat(parsed.get(3))); - this.location.setYaw(Float.parseFloat(parsed.get(4))); - this.speed = Math.abs(Float.parseFloat(parsed.get(5))); - // END CHECKSTYLE-SUPPRESSION: MagicNumberCheck - } catch (NumberFormatException e) { - this.isValid = false; - return; - } - - this.isValid = true; - - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "Cannon!"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return "Cannon (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() + ":" - + this.location.getPitch() + ":" + this.location.getYaw() + ":" + this.speed + ")"; - - } - - /** - * Sets this {@link CannonDestination}. - * - * @param location The {@link Location}. - * @param speed The speed. - */ - public void setDestination(Location location, double speed) { - if (location != null) { - this.location = location; - this.speed = Math.abs(speed); - this.isValid = true; - } - this.isValid = false; - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - return "multiverse.access." + this.location.getWorld().getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - return false; - } - - @Override - public String toString() { - if (isValid) { - return "ca:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() - + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed; - } - return "i:Invalid Destination"; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java deleted file mode 100644 index 858c3e342..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/CustomTeleporterDestination.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.api.Teleporter; -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.util.Vector; - -public abstract class CustomTeleporterDestination implements MVDestination { - @Override - public final Location getLocation(final Entity entity) { - throw new UnsupportedOperationException(); - } - - @Override - public final Vector getVelocity() { - throw new UnsupportedOperationException(); - } - - @Override - public final boolean useSafeTeleporter() { - throw new UnsupportedOperationException(); - } - - @Override - public abstract String toString(); - - public abstract Teleporter getTeleporter(); -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java deleted file mode 100644 index 7f00248c9..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationFactory.java +++ /dev/null @@ -1,177 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.commandsold.TeleportCommand; -import com.onarandombox.MultiverseCore.utils.PermissionTools; -import com.onarandombox.MultiverseCore.utils.PlayerFinder; -import com.pneumaticraft.commandhandler.Command; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; - -/** - * A factory class that will create destinations from specific strings. - */ -public class DestinationFactory { - - private static final Pattern CANNON_PATTERN = Pattern.compile("(?i)cannon-[\\d]+(\\.[\\d]+)?"); - - private MultiverseCore plugin; - private Map> destList; - private Command teleportCommand; - - public DestinationFactory(MultiverseCore plugin) { - this.plugin = plugin; - this.destList = new HashMap>(); - List cmds = this.plugin.getCommandHandler().getAllCommands(); - for (Command c : cmds) { - if (c instanceof TeleportCommand) { - this.teleportCommand = c; - } - } - } - - /** - * Parse a destination that has relation to sender, such as a cannon or player destination. - * - * @param teleportee The player that is going to be teleported. - * @param destinationName The destination to parse. - * @return A non-null MVDestination - */ - @NotNull - public MVDestination getPlayerAwareDestination(@NotNull Player teleportee, - @NotNull String destinationName) { - - // Prioritise world, in the event that a world is named after a player online. - if (Bukkit.getWorld(destinationName) != null) { - return getDestination(destinationName); - } - - Player targetPlayer = PlayerFinder.get(destinationName, teleportee); - if (targetPlayer != null) { - return getDestination("pl:" + targetPlayer.getName()); - } - - if (CANNON_PATTERN.matcher(destinationName).matches()) { - return getDestination(parseCannonDest(teleportee, destinationName)); - } - - return getDestination(destinationName); - } - - /** - * Parses a cannon destination. - * - * @param teleportee The player that is going to be teleported. - * @param destinationName The destination to parse. - * @return A destination string. - */ - @NotNull - private String parseCannonDest(@NotNull Player teleportee, - @NotNull String destinationName) { - - String[] cannonSpeed = destinationName.split("-"); - try { - double speed = Double.parseDouble(cannonSpeed[1]); - destinationName = "ca:" + teleportee.getWorld().getName() + ":" + teleportee.getLocation().getX() - + "," + teleportee.getLocation().getY() + "," + teleportee.getLocation().getZ() + ":" - + teleportee.getLocation().getPitch() + ":" + teleportee.getLocation().getYaw() + ":" + speed; - } - catch (Exception e) { - destinationName = "i:invalid"; - } - - return destinationName; - } - - /** - * Gets a new destination from a string. - * Returns a new InvalidDestination if the string could not be parsed. - * - * @param destination The destination in string format. - * - * @return A non-null MVDestination - */ - public MVDestination getDestination(String destination) { - String idenChar = ""; - if (destination.split(":").length > 1) { - idenChar = destination.split(":")[0]; - } - - if (this.destList.containsKey(idenChar)) { - Class myClass = this.destList.get(idenChar); - try { - MVDestination mydest = myClass.newInstance(); - if (!mydest.isThisType(this.plugin, destination)) { - return new InvalidDestination(); - } - mydest.setDestination(this.plugin, destination); - return mydest; - } catch (InstantiationException e) { - } catch (IllegalAccessException e) { - } - } - return new InvalidDestination(); - } - - /** - * Registers a {@link MVDestination}. - * - * @param c The {@link Class} of the {@link MVDestination} to register. - * @param identifier The {@link String}-identifier. - * @return True if the class was successfully registered. - */ - public boolean registerDestinationType(Class c, String identifier) { - if (this.destList.containsKey(identifier)) { - return false; - } - this.destList.put(identifier, c); - // Special case for world defaults: - if (identifier.equals("")) { - identifier = "w"; - } - Permission self = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.self." + identifier); - Permission other = this.plugin.getServer().getPluginManager().getPermission("multiverse.teleport.other." + identifier); - PermissionTools pt = new PermissionTools(this.plugin); - if (self == null) { - self = new Permission("multiverse.teleport.self." + identifier, - "Permission to teleport yourself for the " + identifier + " destination.", PermissionDefault.OP); - this.plugin.getServer().getPluginManager().addPermission(self); - pt.addToParentPerms("multiverse.teleport.self." + identifier); - } - if (other == null) { - other = new Permission("multiverse.teleport.other." + identifier, - "Permission to teleport others for the " + identifier + " destination.", PermissionDefault.OP); - this.plugin.getServer().getPluginManager().addPermission(other); - pt.addToParentPerms("multiverse.teleport.other." + identifier); - } - this.teleportCommand.addAdditonalPermission(self); - this.teleportCommand.addAdditonalPermission(other); - return true; - } - - /** - * Gets all the {@link MVDestination} identifiers registered. - * - * @return A collection of destination identifiers. - */ - public Collection getRegisteredIdentifiers() { - return this.destList.keySet(); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java new file mode 100644 index 000000000..6e4d3b2b9 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/DestinationsProvider.java @@ -0,0 +1,208 @@ +package com.onarandombox.MultiverseCore.destination; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.CommandIssuer; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import com.onarandombox.MultiverseCore.api.Teleporter; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; +import org.bukkit.plugin.PluginManager; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Provides destinations for teleportation. + */ +public class DestinationsProvider { + private static final String SEPARATOR = ":"; + private static final String PERMISSION_PREFIX = "multiverse.teleport."; + + private final MultiverseCore plugin; + private final Map> destinationMap; + + /** + * Creates a new destinations provider. + * + * @param plugin The plugin. + */ + public DestinationsProvider(@NotNull MultiverseCore plugin) { + this.plugin = plugin; + this.destinationMap = new HashMap<>(); + } + + /** + * Adds a destination to the provider. + * + * @param destination The destination. + */ + public void registerDestination(@NotNull Destination destination) { + this.destinationMap.put(destination.getIdentifier(), destination); + this.registerDestinationPerms(destination); + } + + private void registerDestinationPerms(@NotNull Destination destination) { + PluginManager pluginManager = this.plugin.getServer().getPluginManager(); + pluginManager.addPermission(new Permission(PERMISSION_PREFIX + "self." + destination.getIdentifier())); + pluginManager.addPermission(new Permission(PERMISSION_PREFIX + "other." + destination.getIdentifier())); + } + + /** + * Suggest tab completions for a destination string. + * + * @param issuer The command issuer. + * @param deststring The current destination string. + * @return A collection of tab completions. + */ + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, + @Nullable String deststring + ) { + return destinationMap.values().stream() + .filter(destination -> issuer.hasPermission(PERMISSION_PREFIX + "self." + destination.getIdentifier()) + || issuer.hasPermission(PERMISSION_PREFIX + "other." + destination.getIdentifier())) + .map(destination -> destination.suggestDestinations(issuer, deststring).stream() + .map(s -> destination.getIdentifier() + SEPARATOR + s) + .collect(Collectors.toList())) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + /** + * Converts a destination string to a destination object. + * + * @param destinationString The destination string. + * @return The destination object, or null if invalid format. + */ + public ParsedDestination parseDestination(String destinationString) { + String[] items = destinationString.split(SEPARATOR, 2); + + String idString = items[0]; + String destinationParams; + Destination destination; + + if (items.length < 2) { + // Assume world destination + destination = this.getDestinationById("w"); + destinationParams = items[0]; + } else { + destination = this.getDestinationById(idString); + destinationParams = items[1]; + } + + if (destination == null) { + return null; + } + + DestinationInstance destinationInstance = destination.getDestinationInstance(destinationParams); + if (destinationInstance == null) { + return null; + } + + return new ParsedDestination<>(destination, destinationInstance); + } + + /** + * Gets a destination by its identifier. + * + * @param identifier The identifier. + * @return The destination, or null if not found. + */ + public @Nullable Destination getDestinationById(@Nullable String identifier) { + return this.destinationMap.get(identifier); + } + + /** + * Teleports the teleportee to the destination. + * + * @param teleporter The teleporter. + * @param teleportee The teleportee. + * @param destination The destination. + */ + public void playerTeleport(@NotNull BukkitCommandIssuer teleporter, + @NotNull Player teleportee, + @NotNull ParsedDestination destination + ) { + if (!checkTeleportPermissions(teleporter, teleportee, destination)) { + return; + } + teleport(teleporter, teleportee, destination); + } + + /** + * Teleports the teleportee to the destination. + * + * @param teleporter The teleporter. + * @param teleportee The teleportee. + * @param destination The destination. + */ + public void teleport(@NotNull BukkitCommandIssuer teleporter, + @NotNull Entity teleportee, + @NotNull ParsedDestination destination + ) { + Teleporter teleportHandler = destination.getDestination().getTeleporter(); + if (teleportHandler == null) { + teleportHandler = this.plugin.getSafeTTeleporter(); + } + teleportHandler.teleport(teleporter, teleportee, destination); + } + + /** + * Checks if the teleporter has permission to teleport the teleportee to the destination. + * + * @param teleporter The teleporter. + * @param teleportee The teleportee. + * @param destination The destination. + * @return True if the teleporter has permission, false otherwise. + */ + public boolean checkTeleportPermissions(CommandIssuer teleporter, Entity teleportee, ParsedDestination destination) { + //TODO Move permission checking to a separate class + String permission = PERMISSION_PREFIX + + (teleportee.equals(teleporter.getIssuer()) ? "self" : "other") + "." + + destination.getDestination().getIdentifier(); + if (!teleporter.hasPermission(permission)) { + teleporter.sendMessage("You don't have permission to teleport to this destination."); + return false; + } + + //TODO Config whether to use finer permission + String finerPermissionSuffix = destination.getDestinationInstance().getFinerPermissionSuffix(); + if (finerPermissionSuffix == null || finerPermissionSuffix.isEmpty()) { + return true; + } + + String finerPermission = permission + "." + finerPermissionSuffix; + if (!teleporter.hasPermission(finerPermission)) { + teleporter.sendMessage("You don't have permission to teleport to this destination."); + return false; + } + + return true; + } + + /** + * Checks if the issuer has permission to teleport to at least one destination. + * + * @param issuer The issuer. + * @return True if the issuer has permission, false otherwise. + */ + public boolean hasAnyTeleportPermission(CommandIssuer issuer) { + for (Destination destination : this.destinationMap.values()) { + String permission = PERMISSION_PREFIX + "self." + destination.getIdentifier(); + if (issuer.hasPermission(permission)) { + return true; + } + permission = PERMISSION_PREFIX + "other." + destination.getIdentifier(); + if (issuer.hasPermission(permission)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java deleted file mode 100644 index 081628933..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/ExactDestination.java +++ /dev/null @@ -1,263 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -import java.util.Arrays; -import java.util.List; - -/** - * An exact {@link MVDestination}. - */ -public class ExactDestination implements MVDestination { - private final String coordRegex = "(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~),(-?[\\d]+\\.?[\\d]*|~-?[\\d]+\\.?[\\d]*|~)"; - private boolean isValid; - private Location location; - private boolean relativeX, relativeY, relativeZ; - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "e"; - } - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - if (!(plugin instanceof MultiverseCore)) { - return false; - } - List parsed = Arrays.asList(destination.split(":")); - // Need at least: e:world:x,y,z - // OR e:world:x,y,z:pitch:yaw - // so basically 3 or 5 - if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck - return false; - } - // If it's not an Exact type - if (!parsed.get(0).equalsIgnoreCase("e")) { - return false; - } - - // If it's not a MV world - if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) { - return false; - } - - if (!parsed.get(2).matches(coordRegex)) { - return false; - } - // This is 1 now, because we've removed 2 - if (parsed.size() == 3) { - return true; - } - - try { - Float.parseFloat(parsed.get(3)); - Float.parseFloat(parsed.get(4)); // SUPPRESS CHECKSTYLE: MagicNumberCheck - } catch (NumberFormatException e) { - return false; - } - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity e) { - Location loc = this.location.clone(); - if (relativeX || relativeY || relativeZ) { - Location eLoc = e.getLocation(); - loc.add(relativeX ? eLoc.getX() : 0, relativeY ? eLoc.getY() : 0, relativeZ ? eLoc.getZ() : 0); - // Since the location is relative, it makes sense to use the entity's pitch and yaw unless those were - // specified in the destination. - if (loc.getPitch() == 0) { - loc.setPitch(eLoc.getPitch()); - } - if (loc.getYaw() == 0) { - loc.setYaw(eLoc.getYaw()); - } - } - return loc; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - if (!(plugin instanceof MultiverseCore)) { - return; - } - List parsed = Arrays.asList(destination.split(":")); - // Need at least: e:world:x,y,z - // OR e:world:x,y,z:pitch:yaw - // so basically 3 or 5 - if (!(parsed.size() == 3 || parsed.size() == 5)) { // SUPPRESS CHECKSTYLE: MagicNumberCheck - this.isValid = false; - return; - } - - if (!parsed.get(0).equalsIgnoreCase(this.getIdentifier())) { - this.isValid = false; - return; - } - - if (!((MultiverseCore) plugin).getMVWorldManager().isMVWorld(parsed.get(1))) { - this.isValid = false; - return; - } - this.location = new Location(((MultiverseCore) plugin).getMVWorldManager().getMVWorld(parsed.get(1)).getCBWorld(), 0, 0, 0); - - if (!parsed.get(2).matches(this.coordRegex)) { - this.isValid = false; - return; - } - double[] coords = new double[3]; - String[] coordString = parsed.get(2).split(","); - for (int i = 0; i < 3; i++) { - String[] relSplit = coordString[i].split("~"); - boolean relative = false; - if (relSplit.length == 0) { - // coord is "~" form - relative = true; - coords[i] = 0; - } else if (relSplit.length == 1) { - // coord is "123" form - try { - coords[i] = Double.parseDouble(relSplit[0]); - } catch (NumberFormatException e) { - this.isValid = false; - return; - } - } else { - // coord is "~123" form - relative = true; - try { - coords[i] = Double.parseDouble(relSplit[1]); - } catch (NumberFormatException e) { - this.isValid = false; - return; - } - } - if (relative) { - switch (i) { - case 0: - relativeX = true; - break; - case 1: - relativeY = true; - break; - case 2: - relativeZ = true; - break; - } - } - } - this.location.setX(coords[0]); - this.location.setY(coords[1]); - this.location.setZ(coords[2]); - - if (parsed.size() == 3) { - this.isValid = true; - return; - } - - try { - this.location.setPitch(Float.parseFloat(parsed.get(3))); - this.location.setYaw(Float.parseFloat(parsed.get(4))); // SUPPRESS CHECKSTYLE: MagicNumberCheck - } catch (NumberFormatException e) { - this.isValid = false; - return; - } - this.isValid = true; - - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "Exact"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return "Exact (" + this.location.getX() + ", " + this.location.getY() + ", " + this.location.getZ() - + ":" + location.getPitch() + ":" + location.getYaw() + ")"; - } - - /** - * Sets this {@link ExactDestination}. - * - * @param location The {@link Location}. - */ - public void setDestination(Location location) { - this.isValid = (this.location = location) != null; - } - - /** - * {@inheritDoc} - */ - @Override - public String toString() { - if (isValid) { - return "e:" + location.getWorld().getName() + ":" + location.getX() + "," + location.getY() - + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw(); - } - return "i:Invalid Destination"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - return "multiverse.access." + this.location.getWorld().getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - // This is an EXACT destination, don't safely teleport here. - return false; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/InvalidDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/InvalidDestination.java deleted file mode 100644 index 85e99b65d..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/InvalidDestination.java +++ /dev/null @@ -1,107 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -/** - * An invalid {@link MVDestination}. - */ -public class InvalidDestination implements MVDestination { - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "i"; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity e) { - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - // Nothing needed, it's invalid. - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return ChatColor.RED + "Invalid Destination"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return ChatColor.RED + "Invalid Destination"; - } - - @Override - public String toString() { - return "i:Invalid Destination"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - return false; - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/ParsedDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/ParsedDestination.java new file mode 100644 index 000000000..69c7b2d1b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/ParsedDestination.java @@ -0,0 +1,53 @@ +package com.onarandombox.MultiverseCore.destination; + +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.DestinationInstance; + +/** + * A parsed destination. + * + * @param The destination instance type. + */ +public class ParsedDestination { + private final Destination destination; + private final DestinationInstance destinationInstance; + + /** + * Creates a new parsed destination. + * + * @param destination The destination. + * @param destinationInstance The destination instance. + */ + public ParsedDestination(Destination destination, DestinationInstance destinationInstance) { + this.destination = destination; + this.destinationInstance = destinationInstance; + } + + /** + * Gets the destination. + * + * @return The destination. + */ + public Destination getDestination() { + return destination; + } + + /** + * Gets the destination instance. + * + * @return The destination instance. + */ + public DestinationInstance getDestinationInstance() { + return destinationInstance; + } + + /** + * Converts to saveable string representation of this destination. + * + * @return Serialized string. + */ + @Override + public String toString() { + return destination.getIdentifier() + ":" + destinationInstance.serialise(); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/PlayerDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/PlayerDestination.java deleted file mode 100644 index 0ca08f985..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/PlayerDestination.java +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.api.MVDestination; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -/** - * A player-{@link MVDestination}. - */ -public class PlayerDestination implements MVDestination { - private String player; - private boolean isValid; - private JavaPlugin plugin; - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "pl"; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - String[] items = destination.split(":"); - if (items.length != 2) { - return false; - } - if (!items[0].equalsIgnoreCase("pl")) { - return false; - } - return true; - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity e) { - Player p = plugin.getServer().getPlayerExact(this.player); - Player plLoc = null; - if (e instanceof Player) { - plLoc = (Player) e; - } else if (e.getPassenger() instanceof Player) { - plLoc = (Player) e.getPassenger(); - } - - if (p != null && plLoc != null) { - return p.getLocation(); - } - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - String[] items = destination.split(":"); - if (items.length != 2) { - this.isValid = false; - } - if (!items[0].equalsIgnoreCase("pl")) { - this.isValid = false; - } - this.isValid = true; - this.player = items[1]; - this.plugin = plugin; - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "Player"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return this.player; - } - - @Override - public String toString() { - return "pl:" + this.player; - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - return ""; - } - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - return true; - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java deleted file mode 100644 index 6cbc03510..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/destination/WorldDestination.java +++ /dev/null @@ -1,173 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.destination; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.Core; -import com.onarandombox.MultiverseCore.api.MVDestination; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import org.bukkit.Location; -import org.bukkit.entity.Entity; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; - -/** - * A world-{@link MVDestination}. - */ -public class WorldDestination implements MVDestination { - private boolean isValid; - private MultiverseWorld world; - private float yaw = -1; - private String direction = ""; - - /** - * {@inheritDoc} - */ - @Override - public String getIdentifier() { - return "w"; - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isThisType(JavaPlugin plugin, String destination) { - String[] items = destination.split(":"); - if (items.length > 3) { - return false; - } - if (items.length == 1 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) { - // This case is: world - return true; - } - if (items.length == 2 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) { - // This case is: world:n - return true; - } else if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[1])) { - // This case is: w:world - // and w:world:ne - return true; - } - return false; - } - - /** - * {@inheritDoc} - */ - @Override - public Location getLocation(Entity e) { - Location spawnLoc = getAcurateSpawnLocation(e, this.world); - if (this.yaw >= 0) { - // Only modify the yaw if its set. - spawnLoc.setYaw(this.yaw); - } - return spawnLoc; - } - - private static Location getAcurateSpawnLocation(Entity e, MultiverseWorld world) { - if (world != null) { - return world.getSpawnLocation(); - } else { - // add 0.5 to x and z to center people - // (spawn location is stored as int meaning that you would spawn in the corner of a block) - return e.getWorld().getSpawnLocation().add(.5, 0, .5); - } - } - - /** - * {@inheritDoc} - */ - @Override - public boolean isValid() { - return this.isValid; - } - - /** - * {@inheritDoc} - */ - @Override - public void setDestination(JavaPlugin plugin, String destination) { - // TODO Taking a JavaPlugin here is rather useless, if we keep casting it up to MultiverseCore. - // We should change that. - Core core = (Core) plugin; - String[] items = destination.split(":"); - if (items.length > 3) { - isValid = false; - return; - } - if (items.length == 1 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) { - isValid = true; - this.world = core.getMVWorldManager().getMVWorld(items[0]); - return; - } - if (items.length == 2 && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[0])) { - this.world = core.getMVWorldManager().getMVWorld(items[0]); - this.yaw = core.getLocationManipulation().getYaw(items[1]); - return; - } - if (items[0].equalsIgnoreCase("w") && ((MultiverseCore) plugin).getMVWorldManager().isMVWorld(items[1])) { - this.world = ((MultiverseCore) plugin).getMVWorldManager().getMVWorld(items[1]); - isValid = true; - if (items.length == 3) { - this.yaw = core.getLocationManipulation().getYaw(items[2]); - } - } - } - - /** - * {@inheritDoc} - */ - @Override - public String getType() { - return "World"; - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return this.world.getColoredWorldString(); - } - - @Override - public String toString() { - if (direction.length() > 0 && yaw >= 0) { - return this.world.getCBWorld().getName() + ":" + this.direction; - } - return this.world.getCBWorld().getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public String getRequiredPermission() { - // TODO: Potenitally replace spaces wiht tabs for friendlier yaml. - // this.world.getName().replace(" ","_"); - return "multiverse.access." + this.world.getName(); - } - - /** - * {@inheritDoc} - */ - @Override - public Vector getVelocity() { - return new Vector(0, 0, 0); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean useSafeTeleporter() { - return true; - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java new file mode 100644 index 000000000..87d30926b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestination.java @@ -0,0 +1,68 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import java.util.Collection; + +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.Teleporter; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class AnchorDestination implements Destination { + private final MultiverseCore plugin; + + /** + * Constructor. + * + * @param plugin The MultiverseCore plugin. + */ + public AnchorDestination(MultiverseCore plugin) { + this.plugin = plugin; + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String getIdentifier() { + return "a"; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable AnchorDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + Location anchorLocation = this.plugin.getAnchorManager().getAnchorLocation(destinationParams); + if (anchorLocation == null) { + return null; + } + return new AnchorDestinationInstance(destinationParams, anchorLocation); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) { + return this.plugin.getAnchorManager().getAnchors(issuer.getPlayer()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkTeleportSafety() { + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Teleporter getTeleporter() { + return null; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java new file mode 100644 index 000000000..f0cc0bbdb --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/AnchorDestinationInstance.java @@ -0,0 +1,56 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class AnchorDestinationInstance implements DestinationInstance { + private final String anchorName; + private final Location anchorLocation; + + /** + * Constructor. + * + * @param anchorName The name of the anchor. + * @param anchorLocation The location of the anchor. + */ + public AnchorDestinationInstance(@NotNull String anchorName, @NotNull Location anchorLocation) { + this.anchorName = anchorName; + this.anchorLocation = anchorLocation; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Location getLocation(@NotNull Entity teleportee) { + return anchorLocation; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Vector getVelocity(@NotNull Entity teleportee) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable String getFinerPermissionSuffix() { + return anchorName; + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String serialise() { + return anchorName; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java new file mode 100644 index 000000000..96eda7a6c --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestination.java @@ -0,0 +1,67 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.Teleporter; +import com.onarandombox.MultiverseCore.utils.PlayerFinder; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class BedDestination implements Destination { + public static final String OWN_BED_STRING = "playerbed"; + + public BedDestination() { + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String getIdentifier() { + return "b"; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable BedDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + Player player = PlayerFinder.get(destinationParams); + if (player == null && !destinationParams.equals(OWN_BED_STRING)) { + return null; + } + return new BedDestinationInstance(player); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) { + List collect = Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); + collect.add(OWN_BED_STRING); + return collect; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkTeleportSafety() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Teleporter getTeleporter() { + return null; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java new file mode 100644 index 000000000..8e7c0edb6 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/BedDestinationInstance.java @@ -0,0 +1,60 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class BedDestinationInstance implements DestinationInstance { + private final Player player; + + /** + * Constructor. + * + * @param player The player whose bed to use. + */ + public BedDestinationInstance(Player player) { + this.player = player; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Location getLocation(@NotNull Entity teleportee) { + if (player != null) { + return player.getBedSpawnLocation(); + } + if (teleportee instanceof Player) { + return ((Player) teleportee).getBedSpawnLocation(); + } + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Vector getVelocity(@NotNull Entity teleportee) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable String getFinerPermissionSuffix() { + return player != null ? player.getName() : BedDestination.OWN_BED_STRING; + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String serialise() { + return player != null ? player.getName() : BedDestination.OWN_BED_STRING; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java new file mode 100644 index 000000000..cb2ae27dd --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestination.java @@ -0,0 +1,103 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import java.util.Collection; +import java.util.Collections; + +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.api.Teleporter; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class CannonDestination implements Destination { + private final MultiverseCore plugin; + + /** + * Constructor. + * + * @param plugin The MultiverseCore plugin. + */ + public CannonDestination(MultiverseCore plugin) { + this.plugin = plugin; + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String getIdentifier() { + return "ca"; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable CannonDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + String[] params = destinationParams.split(":"); + if (params.length != 5) { + return null; + } + + String worldName = params[0]; + String coordinates = params[1]; + String pitch = params[2]; + String yaw = params[3]; + String speed = params[4]; + + String[] coordinatesParams = coordinates.split(","); + if (coordinatesParams.length != 3) { + return null; + } + + MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(worldName); + if (world == null) { + return null; + } + + Location location; + double dSpeed; + try { + location = new Location( + world.getCBWorld(), + Double.parseDouble(coordinatesParams[0]), + Double.parseDouble(coordinatesParams[1]), + Double.parseDouble(coordinatesParams[2]), + Float.parseFloat(yaw), + Float.parseFloat(pitch) + ); + dSpeed = Double.parseDouble(speed); + } catch (NumberFormatException e) { + return null; + } + + return new CannonDestinationInstance(location, dSpeed); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) { + return Collections.singleton(""); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkTeleportSafety() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Teleporter getTeleporter() { + return null; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java new file mode 100644 index 000000000..8ceb8c805 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/CannonDestinationInstance.java @@ -0,0 +1,65 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class CannonDestinationInstance implements DestinationInstance { + private final Location location; + private final double speed; + + /** + * Constructor. + * + * @param location The location to teleport to. + * @param speed The speed to fire the player at. + */ + public CannonDestinationInstance(@NotNull Location location, double speed) { + this.location = location; + this.speed = speed; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Location getLocation(@NotNull Entity teleportee) { + return location; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Vector getVelocity(@NotNull Entity teleportee) { + double pitchRadians = Math.toRadians(location.getPitch()); + double yawRadians = Math.toRadians(location.getYaw()); + double x = Math.sin(yawRadians) * speed * -1; + double y = Math.sin(pitchRadians) * speed * -1; + double z = Math.cos(yawRadians) * speed; + // Account for the angle they were pointed, and take away velocity + x = Math.cos(pitchRadians) * x; + z = Math.cos(pitchRadians) * z; + return new Vector(x, y, z); + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable String getFinerPermissionSuffix() { + return location.getWorld().getName(); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String serialise() { + return location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw() + ":" + this.speed; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java new file mode 100644 index 000000000..39776eac5 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestination.java @@ -0,0 +1,106 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import java.util.Collection; +import java.util.Collections; + +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.api.Teleporter; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ExactDestination implements Destination { + private final MultiverseCore plugin; + + /** + * Constructor. + * + * @param plugin The MultiverseCore plugin. + */ + public ExactDestination(MultiverseCore plugin) { + this.plugin = plugin; + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String getIdentifier() { + return "e"; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable ExactDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + String[] items = destinationParams.split(":"); + if (items.length < 2) { + return null; + } + + String worldName = items[0]; + String coordinates = items[1]; + String[] coordinatesParams = coordinates.split(","); + if (coordinatesParams.length != 3) { + return null; + } + + MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(worldName); + if (world == null) { + return null; + } + + Location location; + try { + location = new Location( + world.getCBWorld(), + Double.parseDouble(coordinatesParams[0]), + Double.parseDouble(coordinatesParams[1]), + Double.parseDouble(coordinatesParams[2]) + ); + } catch (NumberFormatException e) { + return null; + } + + if (items.length == 4) { + String pitch = items[2]; + String yaw = items[3]; + try { + location.setPitch(Float.parseFloat(pitch)); + location.setYaw(Float.parseFloat(yaw)); + } catch (NumberFormatException e) { + return null; + } + } + + return new ExactDestinationInstance(location); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) { + return Collections.singleton(""); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkTeleportSafety() { + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Teleporter getTeleporter() { + return null; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java new file mode 100644 index 000000000..e2235829b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/ExactDestinationInstance.java @@ -0,0 +1,54 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class ExactDestinationInstance implements DestinationInstance { + private final Location location; + + /** + * Constructor. + * + * @param location The location to teleport to. + */ + public ExactDestinationInstance(Location location) { + this.location = location; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Location getLocation(@NotNull Entity teleportee) { + return location; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Vector getVelocity(@NotNull Entity teleportee) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable String getFinerPermissionSuffix() { + return location.getWorld().getName(); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String serialise() { + return location.getWorld().getName() + ":" + location.getX() + "," + location.getY() + + "," + location.getZ() + ":" + location.getPitch() + ":" + location.getYaw(); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java new file mode 100644 index 000000000..b6ecf6e4b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestination.java @@ -0,0 +1,65 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import java.util.Collection; +import java.util.stream.Collectors; + +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.Teleporter; +import com.onarandombox.MultiverseCore.utils.PlayerFinder; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PlayerDestination implements Destination { + /** + * Creates a new instance of the PlayerDestination. + */ + public PlayerDestination() { + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String getIdentifier() { + return "pl"; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable PlayerDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + Player player = PlayerFinder.get(destinationParams); + if (player == null) { + return null; + } + return new PlayerDestinationInstance(player); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) { + return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkTeleportSafety() { + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Teleporter getTeleporter() { + return null; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java new file mode 100644 index 000000000..fc31082ff --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/PlayerDestinationInstance.java @@ -0,0 +1,54 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class PlayerDestinationInstance implements DestinationInstance { + private final Player player; + + /** + * Constructor. + * + * @param player The player whose location to go to. + */ + public PlayerDestinationInstance(Player player) { + this.player = player; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Location getLocation(@NotNull Entity teleportee) { + return player.getLocation(); + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Vector getVelocity(@NotNull Entity teleportee) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable String getFinerPermissionSuffix() { + return player.getName(); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String serialise() { + return player.getName(); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java new file mode 100644 index 000000000..d9c31b5b2 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestination.java @@ -0,0 +1,81 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import java.util.Collection; +import java.util.Collections; + +import co.aikar.commands.BukkitCommandIssuer; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.Destination; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.api.Teleporter; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class WorldDestination implements Destination { + + private final MultiverseCore plugin; + + /** + * Constructor. + * + * @param plugin The MultiverseCore plugin. + */ + public WorldDestination(MultiverseCore plugin) { + this.plugin = plugin; + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String getIdentifier() { + return "w"; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable WorldDestinationInstance getDestinationInstance(@Nullable String destinationParams) { + String[] items = destinationParams.split(":"); + if (items.length > 3) { + return null; + } + + String worldName = items[0]; + MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(worldName); + if (world == null) { + return null; + } + + String direction = (items.length == 2) ? items[1] : null; + float yaw = direction != null ? this.plugin.getLocationManipulation().getYaw(direction) : -1; + + return new WorldDestinationInstance(world, direction, yaw); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull Collection suggestDestinations(@NotNull BukkitCommandIssuer issuer, @Nullable String destinationParams) { + // Autocomplete of worlds is done by MVCommandCompletion without prefix + return Collections.emptyList(); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean checkTeleportSafety() { + return true; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Teleporter getTeleporter() { + return null; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java new file mode 100644 index 000000000..3f53da344 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/destination/core/WorldDestinationInstance.java @@ -0,0 +1,66 @@ +package com.onarandombox.MultiverseCore.destination.core; + +import com.onarandombox.MultiverseCore.api.DestinationInstance; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class WorldDestinationInstance implements DestinationInstance { + private final MultiverseWorld world; + private final String direction; + private final float yaw; + + /** + * Constructor. + * + * @param world The world to teleport to. + */ + public WorldDestinationInstance(@NotNull MultiverseWorld world, @Nullable String direction, float yaw) { + this.world = world; + this.direction = direction; + this.yaw = yaw; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Location getLocation(@NotNull Entity teleportee) { + Location worldLoc = world.getSpawnLocation(); + if (this.yaw >= 0) { + // Only modify the yaw if its set. + worldLoc.setYaw(this.yaw); + } + return worldLoc; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Vector getVelocity(@NotNull Entity teleportee) { + return null; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable String getFinerPermissionSuffix() { + return world.getName(); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull String serialise() { + if (this.direction != null) { + return this.world.getCBWorld().getName() + ":" + this.direction; + } + return this.world.getCBWorld().getName(); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java b/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java index fac53728b..75afb3ddc 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java +++ b/src/main/java/com/onarandombox/MultiverseCore/event/MVTeleportEvent.java @@ -9,7 +9,6 @@ import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; - import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/PlayerFinder.java b/src/main/java/com/onarandombox/MultiverseCore/utils/PlayerFinder.java index 318450084..62bbb7e6d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/PlayerFinder.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/PlayerFinder.java @@ -1,5 +1,11 @@ package com.onarandombox.MultiverseCore.utils; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + import com.dumptruckman.minecraft.util.Logging; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -7,12 +13,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - /** * Helper class to get {@link Player} from name, UUID or Selectors. */ @@ -21,6 +21,16 @@ public class PlayerFinder { private static final Pattern UUID_REGEX = Pattern.compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"); private static final Pattern COMMA_SPLIT = Pattern.compile(","); + /** + * Get a {@link Player} based on an identifier of name UUID or selector. + * + * @param playerIdentifier An identifier of name UUID or selector. + * @return The player if found, else null. + */ + public static Player get(@NotNull String playerIdentifier) { + return get(playerIdentifier, Bukkit.getConsoleSender()); + } + /** * Get a {@link Player} based on an identifier of name UUID or selector. * @@ -29,17 +39,21 @@ public class PlayerFinder { * @return The player if found, else null. */ @Nullable - public static Player get(@NotNull String playerIdentifier, - @NotNull CommandSender sender) { + public static Player get(@Nullable String playerIdentifier, @NotNull CommandSender sender) { + if (playerIdentifier == null) { + return null; + } Player targetPlayer = getByName(playerIdentifier); if (targetPlayer != null) { return targetPlayer; } + targetPlayer = getByUuid(playerIdentifier); if (targetPlayer != null) { return targetPlayer; } + return getBySelector(playerIdentifier, sender); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java b/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java index 93367ae51..0d0d54dfd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/SimpleSafeTTeleporter.java @@ -7,11 +7,12 @@ package com.onarandombox.MultiverseCore.utils; +import co.aikar.commands.BukkitCommandIssuer; import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVDestination; +import com.onarandombox.MultiverseCore.api.DestinationInstance; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; -import com.onarandombox.MultiverseCore.destination.InvalidDestination; +import com.onarandombox.MultiverseCore.destination.ParsedDestination; import com.onarandombox.MultiverseCore.enums.TeleportResult; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -189,11 +190,12 @@ private boolean checkAroundSpecificDiameter(Location checkLoc, int circle) { * {@inheritDoc} */ @Override - public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee, MVDestination d) { - if (d instanceof InvalidDestination) { + public TeleportResult safelyTeleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination destination) { + if (destination == null) { Logging.finer("Entity tried to teleport to an invalid destination"); return TeleportResult.FAIL_INVALID; } + Player teleporteePlayer = null; if (teleportee instanceof Player) { teleporteePlayer = ((Player) teleportee); @@ -204,26 +206,29 @@ public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee if (teleporteePlayer == null) { return TeleportResult.FAIL_INVALID; } - MultiverseCore.addPlayerToTeleportQueue(teleporter.getName(), teleporteePlayer.getName()); - Location safeLoc = d.getLocation(teleportee); - if (d.useSafeTeleporter()) { - safeLoc = this.getSafeLocation(teleportee, d); + MultiverseCore.addPlayerToTeleportQueue(teleporter.getIssuer().getName(), teleporteePlayer.getName()); + + Location safeLoc = destination.getDestinationInstance().getLocation(teleportee); + if (destination.getDestination().checkTeleportSafety()) { + safeLoc = this.getSafeLocation(teleportee, destination.getDestinationInstance()); } - if (safeLoc != null) { - if (teleportee.teleport(safeLoc)) { - Vector v = d.getVelocity(); - if (v != null && !DEFAULT_VECTOR.equals(v)) { - Bukkit.getScheduler().runTaskLater(this.plugin, () -> { - teleportee.setVelocity(d.getVelocity()); - }, 1); - } - return TeleportResult.SUCCESS; - } + if (safeLoc == null) { + return TeleportResult.FAIL_UNSAFE; + } + + if (!teleportee.teleport(safeLoc)) { return TeleportResult.FAIL_OTHER; } - return TeleportResult.FAIL_UNSAFE; + + Vector v = destination.getDestinationInstance().getVelocity(teleportee); + if (v != null && !DEFAULT_VECTOR.equals(v)) { + Bukkit.getScheduler().runTaskLater(this.plugin, () -> { + teleportee.setVelocity(v); + }, 1); + } + return TeleportResult.SUCCESS; } /** @@ -244,23 +249,20 @@ public TeleportResult safelyTeleport(CommandSender teleporter, Entity teleportee return TeleportResult.FAIL_UNSAFE; } - /** - * {@inheritDoc} - */ @Override - public Location getSafeLocation(Entity e, MVDestination d) { - Location l = d.getLocation(e); + public Location getSafeLocation(Entity entity, DestinationInstance destination) { + Location l = destination.getLocation(entity); if (plugin.getBlockSafety().playerCanSpawnHereSafely(l)) { Logging.fine("The first location you gave me was safe."); return l; } - if (e instanceof Minecart) { - Minecart m = (Minecart) e; + if (entity instanceof Minecart) { + Minecart m = (Minecart) entity; if (!plugin.getBlockSafety().canSpawnCartSafely(m)) { return null; } - } else if (e instanceof Vehicle) { - Vehicle v = (Vehicle) e; + } else if (entity instanceof Vehicle) { + Vehicle v = (Vehicle) entity; if (!plugin.getBlockSafety().canSpawnVehicleSafely(v)) { return null; } @@ -268,19 +270,19 @@ public Location getSafeLocation(Entity e, MVDestination d) { Location safeLocation = this.getSafeLocation(l); if (safeLocation != null) { // Add offset to account for a vehicle on dry land! - if (e instanceof Minecart && !plugin.getBlockSafety().isEntitiyOnTrack(safeLocation)) { + if (entity instanceof Minecart && !plugin.getBlockSafety().isEntitiyOnTrack(safeLocation)) { safeLocation.setY(safeLocation.getBlockY() + .5); Logging.finer("Player was inside a minecart. Offsetting Y location."); } Logging.finer("Had to look for a bit, but I found a safe place for ya!"); return safeLocation; } - if (e instanceof Player) { - Player p = (Player) e; + if (entity instanceof Player) { + Player p = (Player) entity; this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false); Logging.finer("No safe location found for " + p.getName()); - } else if (e.getPassenger() instanceof Player) { - Player p = (Player) e.getPassenger(); + } else if (entity.getPassenger() instanceof Player) { + Player p = (Player) entity.getPassenger(); this.plugin.getMessaging().sendMessage(p, "No safe locations found!", false); Logging.finer("No safe location found for " + p.getName()); } @@ -334,7 +336,7 @@ private static Location getCloserBlock(Location source, Location blockA, Locatio } @Override - public TeleportResult teleport(final CommandSender teleporter, final Player teleportee, final MVDestination destination) { + public TeleportResult teleport(BukkitCommandIssuer teleporter, Entity teleportee, ParsedDestination destination) { return this.safelyTeleport(teleporter, teleportee, destination); } } From 5dba9f156d31f46e845318301c23a0f346543ee0 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Wed, 8 Feb 2023 13:41:38 +0800 Subject: [PATCH 018/725] refactor!: Remove old command handler and commands --- pom.xml | 9 - .../MultiverseCore/MultiverseCore.java | 114 +------- .../onarandombox/MultiverseCore/api/Core.java | 9 - .../MultiverseCore/api/MultiversePlugin.java | 27 +- .../MultiverseCore/commands/CheckCommand.java | 2 +- .../commandsold/AnchorCommand.java | 162 ----------- .../commandsold/CloneCommand.java | 55 ---- .../commandsold/ConfigCommand.java | 72 ----- .../commandsold/ConfirmCommand.java | 39 --- .../commandsold/CoordCommand.java | 69 ----- .../commandsold/CreateCommand.java | 131 --------- .../commandsold/DebugCommand.java | 66 ----- .../commandsold/DeleteCommand.java | 59 ---- .../commandsold/EnvironmentCommand.java | 118 -------- .../commandsold/GameruleCommand.java | 116 -------- .../commandsold/GamerulesCommand.java | 111 ------- .../commandsold/GeneratorCommand.java | 60 ---- .../commandsold/HelpCommand.java | 98 ------- .../commandsold/ImportCommand.java | 137 --------- .../commandsold/InfoCommand.java | 274 ------------------ .../commandsold/ListCommand.java | 120 -------- .../commandsold/LoadCommand.java | 42 --- .../commandsold/ModifyAddCommand.java | 95 ------ .../commandsold/ModifyClearCommand.java | 92 ------ .../commandsold/ModifyCommand.java | 76 ----- .../commandsold/ModifyRemoveCommand.java | 97 ------- .../commandsold/ModifySetCommand.java | 125 -------- .../commandsold/MultiverseCommand.java | 40 --- .../commandsold/PaginatedCommand.java | 177 ----------- .../commandsold/PaginatedCoreCommand.java | 26 -- .../commandsold/PurgeCommand.java | 92 ------ .../commandsold/RegenCommand.java | 69 ----- .../commandsold/ReloadCommand.java | 58 ---- .../commandsold/RemoveCommand.java | 42 --- .../commandsold/ScriptCommand.java | 58 ---- .../commandsold/SetSpawnCommand.java | 148 ---------- .../commandsold/SilentCommand.java | 52 ---- .../commandsold/SleepCommand.java | 42 --- .../commandsold/SpawnCommand.java | 91 ------ .../commandsold/UnloadCommand.java | 42 --- .../commandsold/VersionCommand.java | 224 -------------- .../commandsold/WhoCommand.java | 118 -------- .../commandsold/package-info.java | 4 - .../MultiverseCore/utils/MVPermissions.java | 21 +- src/main/resources/plugin.yml | 180 ------------ 45 files changed, 11 insertions(+), 3848 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java diff --git a/pom.xml b/pom.xml index 2628624a5..8c348bae4 100644 --- a/pom.xml +++ b/pom.xml @@ -228,10 +228,6 @@ me.main__.util com.onarandombox.serializationconfig - - com.pneumaticraft.commandhandler - com.onarandombox.commandhandler - buscript com.onarandombox.buscript @@ -325,11 +321,6 @@ acf-paper 0.5.1-SNAPSHOT
- - com.pneumaticraft.commandhandler - CommandHandler - 11 - net.minidev diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index cfa0cdc70..2011699ae 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -13,8 +13,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -32,48 +30,18 @@ import com.onarandombox.MultiverseCore.api.MultiverseCoreConfig; import com.onarandombox.MultiverseCore.api.MultiverseMessaging; import com.onarandombox.MultiverseCore.api.SafeTTeleporter; +import com.onarandombox.MultiverseCore.commands.CheckCommand; import com.onarandombox.MultiverseCore.commands.CreateCommand; import com.onarandombox.MultiverseCore.commands.DebugCommand; import com.onarandombox.MultiverseCore.commands.TeleportCommand; -import com.onarandombox.MultiverseCore.commandsold.AnchorCommand; -import com.onarandombox.MultiverseCore.commandsold.CloneCommand; -import com.onarandombox.MultiverseCore.commandsold.ConfigCommand; -import com.onarandombox.MultiverseCore.commandsold.ConfirmCommand; -import com.onarandombox.MultiverseCore.commandsold.CoordCommand; -import com.onarandombox.MultiverseCore.commandsold.DeleteCommand; -import com.onarandombox.MultiverseCore.commandsold.EnvironmentCommand; -import com.onarandombox.MultiverseCore.commandsold.GameruleCommand; -import com.onarandombox.MultiverseCore.commandsold.GamerulesCommand; -import com.onarandombox.MultiverseCore.commandsold.GeneratorCommand; -import com.onarandombox.MultiverseCore.commandsold.HelpCommand; -import com.onarandombox.MultiverseCore.commandsold.ImportCommand; -import com.onarandombox.MultiverseCore.commandsold.InfoCommand; -import com.onarandombox.MultiverseCore.commandsold.ListCommand; -import com.onarandombox.MultiverseCore.commandsold.LoadCommand; -import com.onarandombox.MultiverseCore.commandsold.ModifyAddCommand; -import com.onarandombox.MultiverseCore.commandsold.ModifyClearCommand; -import com.onarandombox.MultiverseCore.commandsold.ModifyCommand; -import com.onarandombox.MultiverseCore.commandsold.ModifyRemoveCommand; -import com.onarandombox.MultiverseCore.commandsold.ModifySetCommand; -import com.onarandombox.MultiverseCore.commandsold.PurgeCommand; -import com.onarandombox.MultiverseCore.commandsold.RegenCommand; -import com.onarandombox.MultiverseCore.commandsold.ReloadCommand; -import com.onarandombox.MultiverseCore.commandsold.RemoveCommand; -import com.onarandombox.MultiverseCore.commandsold.ScriptCommand; -import com.onarandombox.MultiverseCore.commandsold.SetSpawnCommand; -import com.onarandombox.MultiverseCore.commandsold.SilentCommand; -import com.onarandombox.MultiverseCore.commandsold.SpawnCommand; -import com.onarandombox.MultiverseCore.commandsold.UnloadCommand; -import com.onarandombox.MultiverseCore.commandsold.VersionCommand; -import com.onarandombox.MultiverseCore.commandsold.WhoCommand; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.queue.CommandQueueManager; +import com.onarandombox.MultiverseCore.destination.DestinationsProvider; import com.onarandombox.MultiverseCore.destination.core.AnchorDestination; import com.onarandombox.MultiverseCore.destination.core.BedDestination; import com.onarandombox.MultiverseCore.destination.core.CannonDestination; import com.onarandombox.MultiverseCore.destination.core.ExactDestination; import com.onarandombox.MultiverseCore.destination.core.PlayerDestination; -import com.onarandombox.MultiverseCore.destination.DestinationsProvider; import com.onarandombox.MultiverseCore.destination.core.WorldDestination; import com.onarandombox.MultiverseCore.event.MVDebugModeEvent; import com.onarandombox.MultiverseCore.event.MVVersionEvent; @@ -98,14 +66,12 @@ import com.onarandombox.MultiverseCore.utils.VaultHandler; import com.onarandombox.MultiverseCore.utils.WorldManager; import com.onarandombox.MultiverseCore.utils.metrics.MetricsConfigurator; -import com.pneumaticraft.commandhandler.CommandHandler; import me.main__.util.SerializationConfig.NoSuchPropertyException; import me.main__.util.SerializationConfig.SerializationConfig; import org.bukkit.ChatColor; import org.bukkit.Difficulty; import org.bukkit.GameMode; import org.bukkit.Location; -import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.configuration.Configuration; import org.bukkit.configuration.ConfigurationSection; @@ -199,7 +165,6 @@ public int getProtocolVersion() { } // Setup our Map for our Commands using the CommandHandler. - private CommandHandler commandHandler; private MVCommandManager commandManager; private CommandQueueManager commandQueueManager; @@ -283,7 +248,6 @@ public void onEnable() { this.ph = new MVPermissions(this); // Setup the command manager - this.commandHandler = new CommandHandler(this, this.ph); this.commandManager = new MVCommandManager(this); this.commandQueueManager = new CommandQueueManager(this); // Call the Function to assign all the Commands to their Class. @@ -736,46 +700,10 @@ public MultiverseMessaging getMessaging() { * Register Multiverse-Core commands to Command Manager. */ private void registerCommands() { - // Intro Commands - this.commandHandler.registerCommand(new HelpCommand(this)); - this.commandHandler.registerCommand(new VersionCommand(this)); - this.commandHandler.registerCommand(new ListCommand(this)); - this.commandHandler.registerCommand(new InfoCommand(this)); - this.commandHandler.registerCommand(new CloneCommand(this)); - this.commandHandler.registerCommand(new ImportCommand(this)); - this.commandHandler.registerCommand(new ReloadCommand(this)); - this.commandHandler.registerCommand(new SetSpawnCommand(this)); - this.commandHandler.registerCommand(new CoordCommand(this)); - this.commandHandler.registerCommand(new WhoCommand(this)); - this.commandHandler.registerCommand(new SpawnCommand(this)); - // Dangerous Commands - this.commandHandler.registerCommand(new UnloadCommand(this)); - this.commandHandler.registerCommand(new LoadCommand(this)); - this.commandHandler.registerCommand(new RemoveCommand(this)); - this.commandHandler.registerCommand(new DeleteCommand(this)); - this.commandHandler.registerCommand(new RegenCommand(this)); - this.commandHandler.registerCommand(new ConfirmCommand(this)); - // Modification commands - this.commandHandler.registerCommand(new ModifyCommand(this)); - this.commandHandler.registerCommand(new PurgeCommand(this)); - this.commandHandler.registerCommand(new ModifyAddCommand(this)); - this.commandHandler.registerCommand(new ModifySetCommand(this)); - this.commandHandler.registerCommand(new ModifyRemoveCommand(this)); - this.commandHandler.registerCommand(new ModifyClearCommand(this)); - this.commandHandler.registerCommand(new ConfigCommand(this)); - this.commandHandler.registerCommand(new AnchorCommand(this)); - // Misc Commands - this.commandHandler.registerCommand(new EnvironmentCommand(this)); - this.commandHandler.registerCommand(new SilentCommand(this)); - this.commandHandler.registerCommand(new GeneratorCommand(this)); - this.commandHandler.registerCommand(new ScriptCommand(this)); - this.commandHandler.registerCommand(new GameruleCommand(this)); - this.commandHandler.registerCommand(new GamerulesCommand(this)); - - //**NEW ACF COMMAND HANDLER** - this.commandManager.registerCommand(new TeleportCommand(this)); - this.commandManager.registerCommand(new DebugCommand(this)); + this.commandManager.registerCommand(new CheckCommand(this)); this.commandManager.registerCommand(new CreateCommand(this)); + this.commandManager.registerCommand(new DebugCommand(this)); + this.commandManager.registerCommand(new TeleportCommand(this)); } /** @@ -808,30 +736,6 @@ public MVPermissions getMVPerms() { return this.ph; } - /** - * {@inheritDoc} - */ - @Override - public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) { - if (!this.isEnabled()) { - sender.sendMessage("This plugin is Disabled!"); - return true; - } - ArrayList allArgs = new ArrayList(Arrays.asList(args)); - allArgs.add(0, command.getName()); - try { - return this.commandHandler.locateAndRunCommand(sender, allArgs, getMVConfig().getDisplayPermErrors()); - } catch (Exception e) { - e.printStackTrace(); - sender.sendMessage(ChatColor.RED + "An internal error occurred when attempting to perform this command."); - if (sender.isOp()) - sender.sendMessage(ChatColor.RED + "Details were printed to the server console and logs, please add that to your bug report."); - else - sender.sendMessage(ChatColor.RED + "Try again and contact the server owner or an admin if this problem persists."); - return true; - } - } - /** * {@inheritDoc} */ @@ -857,14 +761,6 @@ public String getAuthors() { return authors.substring(2); } - /** - * {@inheritDoc} - */ - @Override - public CommandHandler getCommandHandler() { - return this.commandHandler; - } - /** * {@inheritDoc} */ diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index bb004c92b..511557498 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -19,7 +19,6 @@ import com.onarandombox.MultiverseCore.utils.SimpleLocationManipulation; import com.onarandombox.MultiverseCore.utils.SimpleSafeTTeleporter; import com.onarandombox.MultiverseCore.utils.VaultHandler; -import com.pneumaticraft.commandhandler.CommandHandler; import org.bukkit.entity.Player; /** @@ -80,14 +79,6 @@ public interface Core { */ MVPermissions getMVPerms(); - /** - * Multiverse uses {@link CommandHandler} to make adding and using commands - * a piece of cake. - * - * @return A non-null {@link CommandHandler}. - */ - CommandHandler getCommandHandler(); - /** * Multiverse uses {@link MVCommandManager} to make adding and using commands * a piece of cake. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java index 90a9b33ff..467e7e281 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiversePlugin.java @@ -2,16 +2,10 @@ import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.plugin.java.JavaPlugin; - import com.onarandombox.MultiverseCore.MultiverseCore; -import com.pneumaticraft.commandhandler.CommandHandler; +import org.bukkit.plugin.java.JavaPlugin; /** * Make things easier for MV-Plugins! @@ -87,25 +81,6 @@ protected String getAuthors() { */ protected abstract void onPluginEnable(); - /** - * You can register commands here. - * @param handler The CommandHandler. - */ - protected abstract void registerCommands(CommandHandler handler); - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (!this.isEnabled()) { - sender.sendMessage("This plugin is Disabled!"); - return true; - } - - ArrayList allArgs = new ArrayList(args.length + 1); - allArgs.add(command.getName()); - allArgs.addAll(Arrays.asList(args)); - return this.getCore().getCommandHandler().locateAndRunCommand(sender, allArgs); - } - @Override public final String dumpVersionInfo(String buffer) { throw new UnsupportedOperationException("This is gone."); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java index 347b1f837..ea58fb730 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java @@ -14,7 +14,7 @@ @CommandAlias("mv") public class CheckCommand extends MultiverseCommand { - protected CheckCommand(@NotNull MultiverseCore plugin) { + public CheckCommand(@NotNull MultiverseCore plugin) { super(plugin); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java deleted file mode 100644 index 5009c2702..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/AnchorCommand.java +++ /dev/null @@ -1,162 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; - -import java.util.ArrayList; -import java.util.List; - -/** - * Allows management of Anchor Destinations. - */ -public class AnchorCommand extends PaginatedCoreCommand { - - public AnchorCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Create, Delete and Manage Anchor Destinations."); - this.setCommandUsage("/mv anchor " + ChatColor.GREEN + "{name}" + ChatColor.GOLD + " [-d]"); - this.setArgRange(0, 2); - this.addKey("mv anchor"); - this.addKey("mv anchors"); - this.addKey("mvanchor"); - this.addKey("mvanchors"); - this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething"); - this.addCommandExample("/mv anchor " + ChatColor.GREEN + "otherthing"); - this.addCommandExample("/mv anchor " + ChatColor.GREEN + "awesomething " + ChatColor.RED + "-d"); - this.addCommandExample("/mv anchors "); - this.setPermission("multiverse.core.anchor.list", "Allows a player to list all anchors.", PermissionDefault.OP); - this.addAdditonalPermission(new Permission("multiverse.core.anchor.create", - "Allows a player to create anchors.", PermissionDefault.OP)); - this.addAdditonalPermission(new Permission("multiverse.core.anchor.delete", - "Allows a player to delete anchors.", PermissionDefault.OP)); - this.setItemsPerPage(8); // SUPPRESS CHECKSTYLE: MagicNumberCheck - } - - private List getFancyAnchorList(Player p) { - List anchorList = new ArrayList(); - ChatColor color = ChatColor.GREEN; - for (String anchor : this.plugin.getAnchorManager().getAnchors(p)) { - anchorList.add(color + anchor); - color = (color == ChatColor.GREEN) ? ChatColor.GOLD : ChatColor.GREEN; - } - return anchorList; - } - - private void showList(CommandSender sender, List args) { - if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.list", true)) { - sender.sendMessage(ChatColor.RED + "You don't have the permission to list anchors!"); - return; - } - - sender.sendMessage(ChatColor.LIGHT_PURPLE + "====[ Multiverse Anchor List ]===="); - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - - - FilterObject filterObject = this.getPageAndFilter(args); - - List availableAnchors = new ArrayList(this.getFancyAnchorList(p)); - if (filterObject.getFilter().length() > 0) { - availableAnchors = this.getFilteredItems(availableAnchors, filterObject.getFilter()); - if (availableAnchors.size() == 0) { - sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE - + "No anchors matched your filter: " + ChatColor.AQUA + filterObject.getFilter()); - return; - } - } else { - if (availableAnchors.size() == 0) { - sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE + "No anchors were defined."); - return; - } - } - - - if (!(sender instanceof Player)) { - for (String c : availableAnchors) { - sender.sendMessage(c); - } - return; - } - - int totalPages = (int) Math.ceil(availableAnchors.size() / (this.itemsPerPage + 0.0)); - - if (filterObject.getPage() > totalPages) { - filterObject.setPage(totalPages); - } else if (filterObject.getPage() < 1) { - filterObject.setPage(1); - } - - sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages); - - this.showPage(filterObject.getPage(), sender, availableAnchors); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (args.size() == 0) { - this.showList(sender, args); - return; - } - if (args.size() == 1 && (this.getPageAndFilter(args).getPage() != 1 || args.get(0).equals("1"))) { - this.showList(sender, args); - return; - } - if (args.size() == 2 && args.get(1).equalsIgnoreCase("-d")) { - if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.delete", true)) { - sender.sendMessage(ChatColor.RED + "You don't have the permission to delete anchors!"); - } else { - if (this.plugin.getAnchorManager().deleteAnchor(args.get(0))) { - sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.RED + "deleted!"); - } else { - sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "deleted!"); - } - } - return; - } - - if (!(sender instanceof Player)) { - sender.sendMessage("You must be a player to create Anchors."); - return; - } - - if (!this.plugin.getMVPerms().hasPermission(sender, "multiverse.core.anchor.create", true)) { - sender.sendMessage(ChatColor.RED + "You don't have the permission to create anchors!"); - } else { - Player player = (Player) sender; - if (this.plugin.getAnchorManager().saveAnchorLocation(args.get(0), player.getLocation())) { - sender.sendMessage("Anchor '" + args.get(0) + "' was successfully " + ChatColor.GREEN + "created!"); - } else { - sender.sendMessage("Anchor '" + args.get(0) + "' was " + ChatColor.RED + " NOT " + ChatColor.WHITE + "created!"); - } - } - } - - @Override - protected List getFilteredItems(List availableItems, String filter) { - List filtered = new ArrayList(); - for (String s : availableItems) { - if (s.matches("(?i).*" + filter + ".*")) { - filtered.add(s); - } - } - return filtered; - } - - @Override - protected String getItemText(String item) { - return item; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java deleted file mode 100644 index 7f2a2efe8..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CloneCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import java.util.List; - -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; - -/** - * Creates a clone of a world. - */ -public class CloneCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public CloneCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Clone World"); - this.setCommandUsage("/mv clone" + ChatColor.GREEN + " {TARGET} {NAME}" + ChatColor.GOLD + " -g [GENERATOR[:ID]]"); - this.setArgRange(2, 4); // SUPPRESS CHECKSTYLE: MagicNumberCheck - this.addKey("mvclone"); - this.addKey("mvcl"); - this.addKey("mv cl"); - this.addKey("mv clone"); - this.addCommandExample("/mv clone " + ChatColor.GOLD + "world" + ChatColor.GREEN + " world_backup"); - this.addCommandExample("/mv clone " + ChatColor.GOLD + "skyblock_pristine" + ChatColor.GREEN + " skyblock"); - this.setPermission("multiverse.core.clone", "Clones a world.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - String oldName = args.get(0); - if (!this.worldManager.hasUnloadedWorld(oldName, true)) { - // If no world was found, we can't clone. - sender.sendMessage("Sorry, Multiverse doesn't know about world " + oldName + ", so we can't clone it!"); - sender.sendMessage("Check the " + ChatColor.GREEN + "/mv list" + ChatColor.WHITE + " command to verify it is listed."); - return; - } - if (this.plugin.getMVWorldManager().cloneWorld(oldName, args.get(1))) { - sender.sendMessage(ChatColor.GREEN + "World cloned!"); - } else { - sender.sendMessage(ChatColor.RED + "World could NOT be cloned!"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java deleted file mode 100644 index e454dd959..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfigCommand.java +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; -import java.util.Map; - -/** - * Allows you to set Global MV Variables. - */ -public class ConfigCommand extends MultiverseCommand { - public ConfigCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Configuration"); - this.setCommandUsage("/mv config " + ChatColor.GREEN + "{PROPERTY} {VALUE}"); - this.setArgRange(1, 2); - this.addKey("mv config"); - this.addKey("mvconfig"); - this.addKey("mv conf"); - this.addKey("mvconf"); - this.addCommandExample("/mv config show"); - this.addCommandExample("/mv config " + ChatColor.GREEN + "debug" + ChatColor.AQUA + " 3"); - this.addCommandExample("/mv config " + ChatColor.GREEN + "enforceaccess" + ChatColor.AQUA + " false"); - this.setPermission("multiverse.core.config", "Allows you to set Global MV Variables.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (args.size() <= 1) { - StringBuilder builder = new StringBuilder(); - Map serializedConfig = this.plugin.getMVConfig().serialize(); - for (Map.Entry entry : serializedConfig.entrySet()) { - builder.append(ChatColor.GREEN); - builder.append(entry.getKey()); - builder.append(ChatColor.WHITE).append(" = ").append(ChatColor.GOLD); - builder.append(entry.getValue().toString()); - builder.append(ChatColor.WHITE).append(", "); - } - String message = builder.toString(); - message = message.substring(0, message.length() - 2); - sender.sendMessage(message); - return; - } - if (!this.plugin.getMVConfig().setConfigProperty(args.get(0).toLowerCase(), args.get(1))) { - sender.sendMessage(String.format("%sSetting '%s' to '%s' failed!", ChatColor.RED, args.get(0).toLowerCase(), args.get(1))); - return; - } - - // special rule - if (args.get(0).equalsIgnoreCase("firstspawnworld")) { - // Don't forget to set the world! - this.plugin.getMVWorldManager().setFirstSpawnWorld(args.get(1)); - } - - if (this.plugin.saveMVConfigs()) { - sender.sendMessage(ChatColor.GREEN + "SUCCESS!" + ChatColor.WHITE + " Values were updated successfully!"); - this.plugin.loadConfigs(); - } else { - sender.sendMessage(ChatColor.RED + "FAIL!" + ChatColor.WHITE + " Check your console for details!"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java deleted file mode 100644 index c216ca373..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ConfirmCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Confirms actions. - */ -public class ConfirmCommand extends MultiverseCommand { - - public ConfirmCommand(MultiverseCore plugin) { - super(plugin); - // Any command that is dangerous should require op - this.setName("Confirms a command that could destroy life, the universe and everything."); - this.setCommandUsage("/mv confirm"); - this.setArgRange(0, 0); - this.addKey("mvconfirm"); - this.addKey("mv confirm"); - this.addCommandExample("/mv confirm"); - this.setPermission("multiverse.core.confirm", "If you have not been prompted to use this, it will not do anything.", PermissionDefault.OP); - - } - - @Override - public void runCommand(CommandSender sender, List args) { - this.plugin.getCommandQueueManager().runQueuedCommand(sender); - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java deleted file mode 100644 index b7ce8553a..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CoordCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.text.DecimalFormat; -import java.util.List; - -/** - * Returns detailed information on the Players where abouts. - */ -public class CoordCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public CoordCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Coordinates"); - this.setCommandUsage("/mv coord"); - this.setArgRange(0, 0); - this.addKey("mv coord"); - this.addKey("mvcoord"); - this.addKey("mvco"); - this.addCommandExample("/mv coord"); - this.setPermission("multiverse.core.coord", "Returns detailed information on the Players where abouts.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // Check if the command was sent from a Player. - if (sender instanceof Player) { - Player p = (Player) sender; - World world = p.getWorld(); - - if (!this.worldManager.isMVWorld(world.getName())) { - this.plugin.showNotMVWorldMessage(sender, world.getName()); - return; - } - - MultiverseWorld mvworld = this.worldManager.getMVWorld(world.getName()); - - p.sendMessage(ChatColor.AQUA + "--- Location Information ---"); - p.sendMessage(ChatColor.AQUA + "World: " + ChatColor.WHITE + world.getName()); - p.sendMessage(ChatColor.AQUA + "Alias: " + mvworld.getColoredWorldString()); - p.sendMessage(ChatColor.AQUA + "World Scale: " + ChatColor.WHITE + mvworld.getScaling()); - DecimalFormat df = new DecimalFormat(); - df.setMinimumFractionDigits(0); - df.setMaximumFractionDigits(2); - p.sendMessage(ChatColor.AQUA + "Coordinates: " + ChatColor.WHITE + plugin.getLocationManipulation().strCoords(p.getLocation())); - p.sendMessage(ChatColor.AQUA + "Direction: " + ChatColor.WHITE + plugin.getLocationManipulation().getDirection(p.getLocation())); - p.sendMessage(ChatColor.AQUA + "Block: " + ChatColor.WHITE + world.getBlockAt(p.getLocation()).getType()); - } else { - sender.sendMessage("This command needs to be used from a Player."); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java deleted file mode 100644 index 750c9e625..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/CreateCommand.java +++ /dev/null @@ -1,131 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.pneumaticraft.commandhandler.CommandHandler; -import org.bukkit.ChatColor; -import org.bukkit.World.Environment; -import org.bukkit.WorldType; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Creates a new world and loads it. - */ -public class CreateCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public CreateCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Create World"); - this.setCommandUsage(String.format("/mv create %s{NAME} {ENV} %s-s [SEED] -g [GENERATOR[:ID]] -t [WORLDTYPE] [-n] -a [true|false]", - ChatColor.GREEN, ChatColor.GOLD)); - this.setArgRange(2, 11); // SUPPRESS CHECKSTYLE: MagicNumberCheck - this.addKey("mvcreate"); - this.addKey("mvc"); - this.addKey("mv create"); - this.setPermission("multiverse.core.create", "Creates a new world and loads it.", PermissionDefault.OP); - this.addCommandExample("/mv create " + ChatColor.GOLD + "world" + ChatColor.GREEN + " normal"); - this.addCommandExample("/mv create " + ChatColor.GOLD + "lavaland" + ChatColor.RED + " nether"); - this.addCommandExample("/mv create " + ChatColor.GOLD + "starwars" + ChatColor.AQUA + " end"); - this.addCommandExample("/mv create " + ChatColor.GOLD + "flatroom" + ChatColor.GREEN + " normal" + ChatColor.AQUA + " -t flat"); - this.addCommandExample("/mv create " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -s gargamel"); - this.addCommandExample("/mv create " + ChatColor.GOLD + "moonworld" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " -g BukkitFullOfMoon"); - this.worldManager = this.plugin.getMVWorldManager(); - } - - private String trimWorldName(String userInput) { - // Removes relative paths. - return userInput.replaceAll("^[./\\\\]+", ""); - } - - @Override - public void runCommand(CommandSender sender, List args) { - String worldName = trimWorldName(args.get(0)); - File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName); - String env = args.get(1); - String seed = CommandHandler.getFlag("-s", args); - String generator = CommandHandler.getFlag("-g", args); - boolean allowStructures = true; - String structureString = CommandHandler.getFlag("-a", args); - if (structureString != null) { - allowStructures = Boolean.parseBoolean(structureString); - } - String typeString = CommandHandler.getFlag("-t", args); - boolean useSpawnAdjust = true; - for (String s : args) { - if (s.equalsIgnoreCase("-n")) { - useSpawnAdjust = false; - } - } - - // Make sure the world name doesn't contain the words 'plugins' and '.dat' - if(worldName.contains("plugins")||worldName.contains(".dat")){ - sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'"); - return; - } - - if (this.worldManager.isMVWorld(worldName)) { - sender.sendMessage(ChatColor.RED + "Multiverse cannot create " + ChatColor.GOLD + ChatColor.UNDERLINE - + "another" + ChatColor.RESET + ChatColor.RED + " world named " + worldName); - return; - } - - if (worldFile.exists()) { - sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!"); - sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport"); - return; - } - - Environment environment = EnvironmentCommand.getEnvFromString(env); - if (environment == null) { - sender.sendMessage(ChatColor.RED + "That is not a valid environment."); - EnvironmentCommand.showEnvironments(sender); - return; - } - - // If they didn't specify a type, default to NORMAL - if (typeString == null) { - typeString = "NORMAL"; - } - WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString); - if (type == null) { - sender.sendMessage(ChatColor.RED + "That is not a valid World Type."); - EnvironmentCommand.showWorldTypes(sender); - return; - } - // Determine if the generator is valid. #918 - if (generator != null) { - List genarray = new ArrayList(Arrays.asList(generator.split(":"))); - if (genarray.size() < 2) { - // If there was only one arg specified, pad with another empty one. - genarray.add(""); - } - if (this.worldManager.getChunkGenerator(genarray.get(0), genarray.get(1), "test") == null) { - // We have an invalid generator. - sender.sendMessage("Invalid generator! '" + generator + "'. " + ChatColor.RED + "Aborting world creation."); - return; - } - } - Command.broadcastCommandMessage(sender, "Starting creation of world '" + worldName + "'..."); - - if (this.worldManager.addWorld(worldName, environment, seed, type, allowStructures, generator, useSpawnAdjust)) { - Command.broadcastCommandMessage(sender, "Complete!"); - } else { - Command.broadcastCommandMessage(sender, "FAILED."); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java deleted file mode 100644 index 81a7f74f4..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/DebugCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Enables debug-information. - */ -public class DebugCommand extends MultiverseCommand { - - public DebugCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Turn Debug on/off?"); - this.setCommandUsage("/mv debug" + ChatColor.GOLD + " [1|2|3|off|silent]"); - this.setArgRange(0, 1); - this.addKey("mv debug"); - this.addKey("mv d"); - this.addKey("mvdebug"); - this.addCommandExample("/mv debug " + ChatColor.GOLD + "2"); - this.setPermission("multiverse.core.debug", "Spams the console a bunch.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (args.size() == 1) { - if (args.get(0).equalsIgnoreCase("off")) { - plugin.getMVConfig().setGlobalDebug(0); - } else { - try { - int debugLevel = Integer.parseInt(args.get(0)); - if (debugLevel > 3 || debugLevel < 0) { - throw new NumberFormatException(); - } - plugin.getMVConfig().setGlobalDebug(debugLevel); - } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Error" + ChatColor.WHITE - + " setting debug level. Please use a number 0-3 " + ChatColor.AQUA + "(3 being many many messages!)"); - } - } - plugin.saveMVConfigs(); - } - this.displayDebugMode(sender); - } - - private void displayDebugMode(CommandSender sender) { - final int debugLevel = plugin.getMVConfig().getGlobalDebug(); - if (debugLevel == 0) { - sender.sendMessage("Multiverse Debug mode is " + ChatColor.RED + "OFF"); - } else { - sender.sendMessage("Multiverse Debug mode is " + ChatColor.GREEN + debugLevel); - Logging.fine("Multiverse Debug ENABLED"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java deleted file mode 100644 index 85157d161..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/DeleteCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -/** - * Deletes worlds. - */ -public class DeleteCommand extends MultiverseCommand { - - public DeleteCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Delete World"); - this.setCommandUsage("/mv delete" + ChatColor.GREEN + " {WORLD}"); - this.setArgRange(1, 1); - this.addKey("mvdelete"); - this.addKey("mv delete"); - this.addCommandExample("/mv delete " + ChatColor.GOLD + "MyWorld"); - this.setPermission("multiverse.core.delete", "Deletes a world on your server. " + ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - String worldName = args.get(0); - - this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand( - sender, - deleteRunnable(sender, worldName), - String.format("Are you sure you want to delete world '%s'? You cannot undo this action.", worldName) - )); - } - - private Runnable deleteRunnable(@NotNull CommandSender sender, - @NotNull String worldName) { - - return () -> { - sender.sendMessage(String.format("Deleting world '%s'...", worldName)); - if (this.plugin.getMVWorldManager().deleteWorld(worldName)) { - sender.sendMessage(String.format("%sWorld %s was deleted!", ChatColor.GREEN, worldName)); - return; - } - sender.sendMessage(String.format("%sThere was an issue deleting '%s'! Please check console for errors.", - ChatColor.RED, worldName)); - }; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java deleted file mode 100644 index 9fc85cd4e..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/EnvironmentCommand.java +++ /dev/null @@ -1,118 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.WorldType; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Lists valid known environments. - */ -public class EnvironmentCommand extends MultiverseCommand { - - public EnvironmentCommand(MultiverseCore plugin) { - super(plugin); - this.setName("List Environments"); - this.setCommandUsage("/mv env"); - this.setArgRange(0, 0); - this.addKey("mvenv"); - this.addKey("mv env"); - this.addKey("mv type"); - this.addKey("mv environment"); - this.addKey("mv environments"); - this.addCommandExample("/mv env"); - this.setPermission("multiverse.core.list.environments", "Lists valid known environments/world types.", PermissionDefault.OP); - } - - /** - * Shows all valid known environments to a {@link CommandSender}. - * - * @param sender The {@link CommandSender}. - */ - public static void showEnvironments(CommandSender sender) { - sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:"); - sender.sendMessage(ChatColor.GREEN + "NORMAL"); - sender.sendMessage(ChatColor.RED + "NETHER"); - sender.sendMessage(ChatColor.AQUA + "END"); - } - /** - * Shows all valid known world types to a {@link CommandSender}. - * - * @param sender The {@link CommandSender}. - */ - public static void showWorldTypes(CommandSender sender) { - sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:"); - sender.sendMessage(String.format("%sNORMAL%s, %sFLAT, %sLARGEBIOMES %sor %sVERSION_1_1", - ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.RED, ChatColor.WHITE, ChatColor.GOLD)); - } - - @Override - public void runCommand(CommandSender sender, List args) { - EnvironmentCommand.showEnvironments(sender); - EnvironmentCommand.showWorldTypes(sender); - } - - /** - * Converts a {@link String} into a {@link WorldType}. - * - * @param type The WorldType as a {@link String} - * @return The WorldType as a {@link WorldType} - */ - public static WorldType getWorldTypeFromString(String type) { - // Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way - if (type.equalsIgnoreCase("normal")) { - type = "NORMAL"; - } else if (type.equalsIgnoreCase("flat")) { - type = "FLAT"; - } else if (type.equalsIgnoreCase("largebiomes")) { - type = "LARGE_BIOMES"; - } else if (type.equalsIgnoreCase("amplified")) { - type = "AMPLIFIED"; - } - try { - // Now that we've converted a potentially unfriendly value - // to a friendly one, get it from the ENUM! - return WorldType.valueOf(type); - } catch (IllegalArgumentException e) { - return null; - } - } - - /** - * Converts a {@link String} into an {@link org.bukkit.World.Environment}. - * - * @param env The environment as {@link String} - * @return The environment as {@link org.bukkit.World.Environment} - */ - public static World.Environment getEnvFromString(String env) { - env = env.toUpperCase(); - // Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way - if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER")) - env = "NETHER"; - - if (env.equalsIgnoreCase("END") || env.equalsIgnoreCase("THEEND") || env.equalsIgnoreCase("STARWARS")) - env = "THE_END"; - - if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD")) - env = "NORMAL"; - - try { - // Now that we've converted a potentially unfriendly value - // to a friendly one, get it from the ENUM! - return World.Environment.valueOf(env); - } catch (IllegalArgumentException e) { - return null; - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java deleted file mode 100644 index 053c9f236..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GameruleCommand.java +++ /dev/null @@ -1,116 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameRule; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Allows management of Anchor Destinations. - */ -public class GameruleCommand extends MultiverseCommand { - - public GameruleCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Set a Minecraft Game Rule for a World."); - this.setCommandUsage("/mv gamerule " + ChatColor.GREEN + "{RULE} {VALUE}" + ChatColor.GOLD + " [WORLD]"); - this.setArgRange(2, 3); - this.addKey("mv gamerule"); - this.addKey("mv rule"); - this.addKey("mvgamerule"); - this.addKey("mvrule"); - this.addCommandExample("/mv gamerule " + ChatColor.GREEN + "doMobLoot false"); - this.addCommandExample("/mvrule " + ChatColor.GREEN + "keepInventory true " + ChatColor.RED + "world_nether"); - this.setPermission("multiverse.core.gamerule.set", "Allows a player to set a gamerule.", PermissionDefault.OP); - } - - - @Override - public void runCommand(CommandSender sender, List args) { - // We NEED a world from the command line - final Player p; - if (sender instanceof Player) { - p = (Player) sender; - } else { - p = null; - } - - if (args.size() == 2 && p == null) { - sender.sendMessage("From the command line, WORLD is required."); - sender.sendMessage(this.getCommandDesc()); - sender.sendMessage(this.getCommandUsage()); - sender.sendMessage("Nothing changed."); - return; - } - - final GameRule gameRule = GameRule.getByName(args.get(0)); - final String value = args.get(1); - final World world; - if (args.size() == 2) { - world = p.getWorld(); - } else { - world = Bukkit.getWorld(args.get(2)); - if (world == null) { - sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(2) - + ChatColor.WHITE + " does not exist."); - return; - } - } - - if (gameRule == null) { - sender.sendMessage(ChatColor.RED + "Failure! " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE - + " is not a valid gamerule."); - } else { - if (gameRule.getType() == Boolean.class) { - boolean booleanValue; - if (value.equalsIgnoreCase("true")) { - booleanValue = true; - } else if (value.equalsIgnoreCase("false")) { - booleanValue = false; - } else { - sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to true or false."); - return; - } - - if (!world.setGameRule(gameRule, booleanValue)) { - sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "something went wrong."); - return; - } - } else if (gameRule.getType() == Integer.class) { - try { - if (!world.setGameRule(gameRule, Integer.parseInt(value))) { - throw new NumberFormatException(); - } - } catch (NumberFormatException e) { - sender.sendMessage(getErrorMessage(gameRule.getName(), value) + "it can only be set to a positive integer."); - return; - } - } else { - sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() - + ChatColor.WHITE + " isn't supported yet, please let us know about it."); - return; - } - - sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule.getName() - + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value + ChatColor.WHITE + "."); - } - } - - private String getErrorMessage(String gameRule, String value) { - return ChatColor.RED + "Failure!" + ChatColor.WHITE + " Gamerule " + ChatColor.AQUA + gameRule - + ChatColor.WHITE + " could not be set to " + ChatColor.RED + value + ChatColor.WHITE + ", "; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java deleted file mode 100644 index 4a8726df8..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GamerulesCommand.java +++ /dev/null @@ -1,111 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.filters.ContentFilter; -import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter; -import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter; -import com.onarandombox.MultiverseCore.display.handlers.InlineSendHandler; -import com.onarandombox.MultiverseCore.display.parsers.MapContentParser; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.GameRule; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Allows management of Anchor Destinations. - */ -public class GamerulesCommand extends MultiverseCommand { - - public GamerulesCommand(MultiverseCore plugin) { - super(plugin); - this.setName("List the Minecraft Game Rules for a World."); - this.setCommandUsage("/mv gamerules" + ChatColor.GOLD + " [WORLD] [FILTER]"); - this.setArgRange(0, 2); - this.addKey("mv gamerules"); - this.addKey("mv rules"); - this.addKey("mvgamerules"); - this.addKey("mvrules"); - this.addCommandExample("/mv gamerules"); - this.addCommandExample("/mvrules " + ChatColor.RED + "world_nether"); - this.setPermission("multiverse.core.gamerule.list", "Allows a player to list gamerules.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // We NEED a world from the command line - Player p; - World world; - ContentFilter filter = DefaultContentFilter.getInstance(); - - if (sender instanceof Player) { - p = (Player) sender; - } else { - p = null; - } - - if (args.size() == 0 && p == null) { - sender.sendMessage("From the command line, WORLD is required."); - sender.sendMessage(this.getCommandDesc()); - sender.sendMessage(this.getCommandUsage()); - sender.sendMessage("Nothing changed."); - return; - } - - // Not the best way, need to fix with ACF soon... - if (args.size() == 0) { - world = p.getWorld(); - } else if (args.size() == 1) { - world = Bukkit.getWorld(args.get(0)); - if (world == null) { - if (p == null) { - sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0) - + ChatColor.WHITE + " does not exist."); - return; - } - world = p.getWorld(); - filter = RegexContentFilter.fromString(args.get(0)); - } - } else { - world = Bukkit.getWorld(args.get(0)); - if (world == null) { - sender.sendMessage(ChatColor.RED + "Failure!" + ChatColor.WHITE + " World " + ChatColor.AQUA + args.get(0) - + ChatColor.WHITE + " does not exist."); - return; - } - filter = RegexContentFilter.fromString(args.get(1)); - } - - ContentDisplay.create() - .addContentParser(MapContentParser.forContent(getGameRuleMap(world)) - .withKeyColor(ChatColor.GREEN) - .withValueColor(ChatColor.YELLOW)) - .withSendHandler(InlineSendHandler.create() - .withHeader("====[ Gamerules for %s%s%s ]====", ChatColor.AQUA, world.getName(), ChatColor.WHITE) - .withFilter(filter)) - .send(sender); - } - - private Map getGameRuleMap(World world) { - Map gameRuleMap = new HashMap<>(); - for (GameRule rule : GameRule.values()) { - Object value = world.getGameRuleValue(rule); - gameRuleMap.put(rule.getName(), value); - } - return gameRuleMap; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java deleted file mode 100644 index 342d71a18..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/GeneratorCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.plugin.Plugin; - -import java.util.ArrayList; -import java.util.List; - -/** - * Returns a list of loaded generator plugins. - */ -public class GeneratorCommand extends MultiverseCommand { - - public GeneratorCommand(MultiverseCore plugin) { - super(plugin); - this.setName("World Information"); - this.setCommandUsage("/mv generators"); - this.setArgRange(0, 0); - this.addKey("mv generators"); - this.addKey("mvgenerators"); - this.addKey("mv gens"); - this.addKey("mvgens"); - this.addCommandExample("/mv generators"); - this.setPermission("multiverse.core.generator", "Returns a list of Loaded Generator Plugins.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Logging.info("PLEASE IGNORE the 'Plugin X does not contain any generators' message below!"); - Plugin[] plugins = this.plugin.getServer().getPluginManager().getPlugins(); - List generators = new ArrayList(); - for (Plugin p : plugins) { - if (p.isEnabled() && p.getDefaultWorldGenerator("world", "") != null) { - generators.add(p.getDescription().getName()); - } - } - sender.sendMessage(ChatColor.AQUA + "--- Loaded Generator Plugins ---"); - String loadedGens = ""; - boolean altColor = false; - for (String s : generators) { - loadedGens += (altColor ? ChatColor.YELLOW : ChatColor.WHITE) + s + " "; - altColor = !altColor; - } - if (loadedGens.length() == 0) { - loadedGens = ChatColor.RED + "No Generator Plugins found."; - } - sender.sendMessage(loadedGens); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java deleted file mode 100644 index 42cbf9788..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/HelpCommand.java +++ /dev/null @@ -1,98 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.pneumaticraft.commandhandler.Command; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.ArrayList; -import java.util.List; - -/** - * Displays a nice help menu. - */ -public class HelpCommand extends PaginatedCoreCommand { - - public HelpCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Get Help with Multiverse"); - this.setCommandUsage("/mv " + ChatColor.GOLD + "[FILTER] [PAGE #]"); - this.setArgRange(0, 2); - this.addKey("mv"); - this.addKey("mvh"); - this.addKey("mvhelp"); - this.addKey("mv help"); - this.addKey("mvsearch"); - this.addKey("mv search"); - this.addCommandExample("/mv help ?"); - this.setPermission("multiverse.help", "Displays a nice help menu.", PermissionDefault.TRUE); - this.setItemsPerPage(7); // SUPPRESS CHECKSTYLE: MagicNumberCheck - } - - @Override - protected List getFilteredItems(List availableItems, String filter) { - String expression = "(?i).*" + cleanFilter(filter) + ".*"; - List filtered = new ArrayList(); - - for (Command c : availableItems) { - if (stitchThisString(c.getKeyStrings()).matches(expression) - || c.getCommandName().matches(expression) - || c.getCommandDesc().matches(expression) - || c.getCommandUsage().matches(expression) - || c.getCommandExamples().stream().anyMatch(eg -> eg.matches(expression))) { - filtered.add(c); - } - } - return filtered; - } - - @Override - protected String getItemText(Command item) { - return ChatColor.AQUA + item.getCommandUsage(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - sender.sendMessage(ChatColor.AQUA + "====[ Multiverse Help ]===="); - - FilterObject filterObject = this.getPageAndFilter(args); - - List availableCommands = new ArrayList(this.plugin.getCommandHandler().getCommands(sender)); - if (filterObject.getFilter().length() > 0) { - availableCommands = this.getFilteredItems(availableCommands, filterObject.getFilter()); - if (availableCommands.size() == 0) { - sender.sendMessage(ChatColor.RED + "Sorry... " + ChatColor.WHITE - + "No commands matched your filter: " + ChatColor.AQUA + filterObject.getFilter()); - return; - } - } - - if (!(sender instanceof Player)) { - sender.sendMessage(ChatColor.AQUA + " Add a '" + ChatColor.DARK_PURPLE + "?" + ChatColor.AQUA + "' after a command to see more about it."); - for (Command c : availableCommands) { - sender.sendMessage(ChatColor.AQUA + c.getCommandUsage()); - } - return; - } - - int totalPages = (int) Math.ceil(availableCommands.size() / (this.itemsPerPage + 0.0)); - - if (filterObject.getPage() > totalPages) { - filterObject.setPage(totalPages); - } - - sender.sendMessage(ChatColor.AQUA + " Page " + filterObject.getPage() + " of " + totalPages); - sender.sendMessage(ChatColor.AQUA + " Add a '" + ChatColor.DARK_PURPLE + "?" + ChatColor.AQUA + "' after a command to see more about it."); - - this.showPage(filterObject.getPage(), sender, availableCommands); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java deleted file mode 100644 index 9d44dbcf9..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ImportCommand.java +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.utils.WorldNameChecker; -import com.pneumaticraft.commandhandler.CommandHandler; -import org.bukkit.ChatColor; -import org.bukkit.World.Environment; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.io.File; -import java.util.Collection; -import java.util.List; - -/** - * Imports a new world of the specified type. - */ -public class ImportCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public ImportCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Import World"); - this.setCommandUsage("/mv import" + ChatColor.GREEN + " {NAME} {ENV}" + ChatColor.GOLD + " -g [GENERATOR[:ID]] [-n]"); - this.setArgRange(1, 5); // SUPPRESS CHECKSTYLE: MagicNumberCheck - this.addKey("mvimport"); - this.addKey("mvim"); - this.addKey("mv import"); - this.addCommandExample("/mv import " + ChatColor.GOLD + "gargamel" + ChatColor.GREEN + " normal"); - this.addCommandExample("/mv import " + ChatColor.GOLD + "hell_world" + ChatColor.GREEN + " nether"); - this.addCommandExample("To import a world that uses a generator, you'll need the generator:"); - this.addCommandExample("/mv import " + ChatColor.GOLD + "CleanRoom" + ChatColor.GREEN + " normal" + ChatColor.DARK_AQUA + " CleanRoomGenerator"); - this.setPermission("multiverse.core.import", "Imports a new world of the specified type.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - private String getPotentialWorldStrings() { - final Collection potentialWorlds = this.worldManager.getPotentialWorlds(); - StringBuilder worldList = new StringBuilder(); - ChatColor currColor = ChatColor.WHITE; - - for (String world : potentialWorlds) { - worldList.append(currColor).append(world).append(' '); - currColor = currColor == ChatColor.WHITE ? ChatColor.YELLOW : ChatColor.WHITE; - } - - return worldList.toString(); - } - - private String trimWorldName(String userInput) { - // Removes relative paths. - return userInput.replaceAll("^[./\\\\]+", ""); - } - - @Override - public void runCommand(CommandSender sender, List args) { - String worldName = trimWorldName(args.get(0)); - - if (worldName.toLowerCase().equals("--list") || worldName.toLowerCase().equals("-l")) { - String worldList = this.getPotentialWorldStrings(); - if (worldList.length() > 2) { - sender.sendMessage(ChatColor.AQUA + "====[ These look like worlds ]===="); - sender.sendMessage(worldList); - } else { - sender.sendMessage(ChatColor.RED + "No potential worlds found. Sorry!"); - } - return; - } - // Since we made an exception for the list, we have to make sure they have at least 2 params: - // Note the exception is --list, which is covered above. - if (args.size() == 1 || worldName.length() < 1) { - this.showHelp(sender); - return; - } - - // Make sure the world name doesn't contain the words 'plugins' and '.dat' - if(worldName.contains("plugins")||worldName.contains(".dat")){ - sender.sendMessage(ChatColor.RED + "Multiverse cannot create a world that contains 'plugins' or '.dat'"); - return; - } - - // Make sure we don't already know about this world. - if (this.worldManager.isMVWorld(worldName)) { - sender.sendMessage(ChatColor.GREEN + "Multiverse" + ChatColor.WHITE - + " already knows about '" + ChatColor.AQUA + worldName + ChatColor.WHITE + "'!"); - return; - } - - File worldFile = new File(this.plugin.getServer().getWorldContainer(), worldName); - - String generator = CommandHandler.getFlag("-g", args); - boolean useSpawnAdjust = true; - for (String s : args) { - if (s.equalsIgnoreCase("-n")) { - useSpawnAdjust = false; - } - } - - String env = args.get(1); - Environment environment = EnvironmentCommand.getEnvFromString(env); - if (environment == null) { - sender.sendMessage(ChatColor.RED + "That is not a valid environment."); - EnvironmentCommand.showEnvironments(sender); - return; - } - - if (!worldFile.exists()) { - sender.sendMessage(ChatColor.RED + "FAILED."); - String worldList = this.getPotentialWorldStrings(); - sender.sendMessage("That world folder does not exist. These look like worlds to me:"); - sender.sendMessage(worldList); - } else if (!WorldNameChecker.isValidWorldFolder(worldFile)) { - sender.sendMessage(ChatColor.RED + "FAILED."); - sender.sendMessage(String.format("'%s' does not appear to be a world. It is lacking a .dat file.", - worldName)); - } else if (env == null) { - sender.sendMessage(ChatColor.RED + "FAILED."); - sender.sendMessage("That world environment did not exist."); - sender.sendMessage("For a list of available world types, type: " + ChatColor.AQUA + "/mvenv"); - } else { - Command.broadcastCommandMessage(sender, String.format("Starting import of world '%s'...", worldName)); - if (this.worldManager.addWorld(worldName, environment, null, null, null, generator, useSpawnAdjust)) - Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Complete!"); - else - Command.broadcastCommandMessage(sender, ChatColor.RED + "Failed!"); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java deleted file mode 100644 index 579f271db..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/InfoCommand.java +++ /dev/null @@ -1,274 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.FancyText; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.FancyColorScheme; -import com.onarandombox.MultiverseCore.utils.FancyHeader; -import com.onarandombox.MultiverseCore.utils.FancyMessage; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.ArrayList; -import java.util.List; - -// Will use when we can compile with JDK 6 -//import com.sun.xml.internal.ws.util.StringUtils; - -/** - * Returns detailed information about a world. - */ -public class InfoCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public InfoCommand(MultiverseCore plugin) { - super(plugin); - this.setName("World Information"); - this.setCommandUsage("/mv info" + ChatColor.GOLD + " [WORLD] [PAGE]"); - this.setArgRange(0, 2); - this.addKey("mvinfo"); - this.addKey("mvi"); - this.addKey("mv info"); - this.addCommandExample("/mv info " + ChatColor.GOLD + "1"); - this.addCommandExample("/mv info " + ChatColor.GOLD + "3"); - this.setPermission("multiverse.core.info", "Returns detailed information on the world.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // Check if the command was sent from a Player. - String worldName = ""; - int pageNum = 0; - - if (args.size() == 0) { - if (sender instanceof Player) { - Player p = (Player) sender; - worldName = p.getWorld().getName(); - } else { - sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!"); - return; - } - } else if (args.size() == 1) { - if (this.worldManager.isMVWorld(args.get(0))) { - // then we have a world! - worldName = args.get(0); - } else if (this.worldManager.getUnloadedWorlds().contains(args.get(0))) { - sender.sendMessage("That world exists, but it is unloaded!"); - sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, args.get(0))); - return; - } else { - if (sender instanceof Player) { - Player p = (Player) sender; - worldName = p.getWorld().getName(); - try { - pageNum = Integer.parseInt(args.get(0)) - 1; - } catch (NumberFormatException e) { - sender.sendMessage("That world does not exist."); - return; - } - } else { - sender.sendMessage("You must enter a" + ChatColor.LIGHT_PURPLE + " world" + ChatColor.WHITE + " from the console!"); - return; - } - } - } else if (args.size() == 2) { - worldName = args.get(0); - try { - pageNum = Integer.parseInt(args.get(1)) - 1; - } catch (NumberFormatException e) { - pageNum = 0; - } - } - - if (this.worldManager.isMVWorld(worldName)) { - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - showPage(pageNum, sender, this.buildEntireCommand(this.worldManager.getMVWorld(worldName), p)); - } else if (this.worldManager.getUnloadedWorlds().contains(worldName)) { - sender.sendMessage("That world exists, but it is unloaded!"); - sender.sendMessage(String.format("You can load it with: %s/mv load %s", ChatColor.AQUA, worldName)); - } else if (this.plugin.getServer().getWorld(worldName) != null) { - sender.sendMessage("That world exists, but Multiverse does not know about it!"); - sender.sendMessage("You can import it with" + ChatColor.AQUA + "/mv import " + ChatColor.GREEN + worldName + ChatColor.LIGHT_PURPLE + "{ENV}"); - sender.sendMessage("For available environments type " + ChatColor.GREEN + "/mv env"); - } - } - - private List> buildEntireCommand(MultiverseWorld world, Player p) { - List message = new ArrayList(); - List> worldInfo = new ArrayList>(); - // Page 1 - FancyColorScheme colors = new FancyColorScheme(ChatColor.AQUA, ChatColor.AQUA, ChatColor.GOLD, ChatColor.WHITE); - message.add(new FancyHeader("General Info", colors)); - message.add(new FancyMessage("World Name: ", world.getName(), colors)); - message.add(new FancyMessage("World UID: ", world.getCBWorld().getUID().toString(), colors)); - message.add(new FancyMessage("World Alias: ", world.getColoredWorldString(), colors)); - message.add(new FancyMessage("Game Mode: ", world.getGameMode().toString(), colors)); - message.add(new FancyMessage("Difficulty: ", world.getDifficulty().toString(), colors)); - - //message.add(new FancyMessage("Game Mode: ", StringUtils.capitalize(world.getGameMode().toString()), colors)); - Location spawn = world.getSpawnLocation(); - message.add(new FancyMessage("Spawn Location: ", plugin.getLocationManipulation().strCoords(spawn), colors)); - message.add(new FancyMessage("World Scale: ", String.valueOf(world.getScaling()), colors)); - message.add(new FancyMessage("World Seed: ", String.valueOf(world.getSeed()), colors)); - if (world.getPrice() > 0) { - message.add(new FancyMessage("Price to enter this world: ", - plugin.getEconomist().formatPrice(world.getPrice(), world.getCurrency()), - colors)); - } else if (world.getPrice() < 0) { - message.add(new FancyMessage("Reward for entering this world: ", - plugin.getEconomist().formatPrice(-world.getPrice(), world.getCurrency()), - colors)); - } else { - message.add(new FancyMessage("Price to enter this world: ", ChatColor.GREEN + "FREE!", colors)); - } - - if (world.getRespawnToWorld() != null) { - MultiverseWorld respawn = this.worldManager.getMVWorld(world.getRespawnToWorld()); - if (respawn != null) { - message.add(new FancyMessage("Players will respawn in: ", respawn.getColoredWorldString(), colors)); - } else { - message.add(new FancyMessage("Players will respawn in: ", ChatColor.RED + "!!INVALID!!", colors)); - } - - } - - worldInfo.add(message); - // Page 2 - message = new ArrayList(); - message.add(new FancyHeader("More World Settings", colors)); - message.add(new FancyMessage("World Type: ", world.getWorldType().toString(), colors)); - message.add(new FancyMessage("Generator: ", world.getGenerator(), colors)); - message.add(new FancyMessage("Structures: ", world.getCBWorld().canGenerateStructures() + "", colors)); - message.add(new FancyMessage("Weather: ", world.isWeatherEnabled() + "", colors)); - message.add(new FancyMessage("Players will get hungry: ", world.getHunger() + "", colors)); - message.add(new FancyMessage("Keep spawn in memory: ", world.isKeepingSpawnInMemory() + "", colors)); - message.add(new FancyHeader("PVP Settings", colors)); - message.add(new FancyMessage("Multiverse Setting: ", world.isPVPEnabled() + "", colors)); - message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getPVP() + "", colors)); - worldInfo.add(message); - // Page 3 - message = new ArrayList(); - message.add(new FancyHeader("Monster Settings", colors)); - message.add(new FancyMessage("Multiverse Setting: ", world.canMonstersSpawn() + "", colors)); - message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowMonsters() + "", colors)); - if (world.getMonsterList().size() > 0) { - if (world.canMonstersSpawn()) { - message.add(new FancyMessage("Monsters that" + ChatColor.RED + " CAN NOT " - + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getMonsterList()), colors)); - } else { - message.add(new FancyMessage("Monsters that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getMonsterList()), colors)); - } - } else { - message.add(new FancyMessage("Monsters that CAN spawn: ", world.canMonstersSpawn() ? "ALL" : "NONE", colors)); - } - worldInfo.add(message); - - // Page 4 - message = new ArrayList(); - message.add(new FancyHeader("Animal Settings", colors)); - message.add(new FancyMessage("Multiverse Setting: ", world.canAnimalsSpawn() + "", colors)); - message.add(new FancyMessage("Bukkit Setting: ", world.getCBWorld().getAllowAnimals() + "", colors)); - if (world.getAnimalList().size() > 0) { - if (world.canAnimalsSpawn()) { - message.add(new FancyMessage("Animals that" + ChatColor.RED + " CAN NOT " - + ChatColor.GREEN + "spawn: ", toCommaSeperated(world.getAnimalList()), colors)); - } else { - message.add(new FancyMessage("Animals that" + ChatColor.GREEN + " CAN SPAWN: ", toCommaSeperated(world.getAnimalList()), colors)); - } - } else { - message.add(new FancyMessage("Animals that CAN spawn: ", world.canAnimalsSpawn() ? "ALL" : "NONE", colors)); - } - worldInfo.add(message); - - return worldInfo; - } - - private static String toCommaSeperated(List list) { - if (list == null || list.size() == 0) { - return ""; - } - if (list.size() == 1) { - return list.get(0); - } - String result = list.get(0); - - for (int i = 1; i < list.size() - 1; i++) { - result += ", " + list.get(i); - } - result += " and " + list.get(list.size() - 1); - return result; - } - - /** - * Gets a "positive" or "negative" {@link ChatColor}. - * - * @param positive Whether this {@link ChatColor} should be "positive". - * @return The {@link ChatColor}. - */ - protected ChatColor getChatColor(boolean positive) { - return positive ? ChatColor.GREEN : ChatColor.RED; - } - - private static void showPage(int page, CommandSender sender, List> doc) { - page = page < 0 ? 0 : page; - page = page > doc.size() - 1 ? doc.size() - 1 : page; - boolean altColor = false; - boolean appendedPageNum = false; - if (sender instanceof Player) { - List list = doc.get(page); - for (FancyText fancyT : list) { - if (fancyT instanceof FancyMessage) { - FancyMessage text = (FancyMessage) fancyT; - text.setAltColor(altColor); - altColor = !altColor; - sender.sendMessage(text.getFancyText()); - } else if (fancyT instanceof FancyHeader) { - FancyHeader text = (FancyHeader) fancyT; - if (!appendedPageNum) { - text.appendText(ChatColor.DARK_PURPLE + " [ Page " + (page + 1) + " of " + doc.size() + " ]"); - appendedPageNum = true; - } - sender.sendMessage(text.getFancyText()); - altColor = false; - } - } - - } else { - for (List list : doc) { - for (FancyText fancyT : list) { - if (fancyT instanceof FancyMessage) { - FancyMessage text = (FancyMessage) fancyT; - text.setAltColor(altColor); - altColor = !altColor; - sender.sendMessage(text.getFancyText()); - } else { - FancyText text = fancyT; - if (appendedPageNum) { - sender.sendMessage(" "); - } else { - appendedPageNum = true; - } - sender.sendMessage(text.getFancyText()); - altColor = false; - } - } - } - } - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java deleted file mode 100644 index 9b6c1a73a..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ListCommand.java +++ /dev/null @@ -1,120 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.display.ContentDisplay; -import com.onarandombox.MultiverseCore.display.filters.ContentFilter; -import com.onarandombox.MultiverseCore.display.filters.DefaultContentFilter; -import com.onarandombox.MultiverseCore.display.filters.RegexContentFilter; -import com.onarandombox.MultiverseCore.display.handlers.PagedSendHandler; -import com.onarandombox.MultiverseCore.display.parsers.ContentParser; -import org.bukkit.ChatColor; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -/** - * Displays a listing of all worlds that a player can enter. - */ -public class ListCommand extends MultiverseCommand { - - public ListCommand(MultiverseCore plugin) { - super(plugin); - this.setName("World Listing"); - this.setCommandUsage("/mv list [filter] [page]"); - this.setArgRange(0, 2); - this.addKey("mvlist"); - this.addKey("mvl"); - this.addKey("mv list"); - this.setPermission("multiverse.core.list.worlds", "Displays a listing of all worlds that you can enter.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - ContentFilter filter = DefaultContentFilter.getInstance(); - int page = 1; - - // Either page or filter. - if (args.size() == 1) { - try { - page = Integer.parseInt(args.get(0)); - } catch (NumberFormatException ignore) { - filter = RegexContentFilter.fromString(args.get(0)); - } - } - - // Filter then page. - if (args.size() == 2) { - filter = RegexContentFilter.fromString(args.get(0)); - try { - page = Integer.parseInt(args.get(1)); - } catch (NumberFormatException ignore) { - sender.sendMessage(ChatColor.RED + args.get(1) + " is not valid number!"); - } - } - - ContentDisplay.create() - .addContentParser(new WorldListContentParser()) - .withSendHandler(PagedSendHandler.create() - .withHeader("%s====[ Multiverse World List ]====", ChatColor.GOLD) - .withFilter(filter) - .withTargetPage(page)) - .send(sender); - } - - private class WorldListContentParser implements ContentParser { - - @Override - public void parse(@NotNull CommandSender sender, @NotNull List content) { - Player player = (sender instanceof Player) ? (Player) sender : null; - - plugin.getMVWorldManager().getMVWorlds().stream() - .filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world)) - .filter(world -> canSeeWorld(player, world)) - .map(world -> hiddenText(world) + world.getColoredWorldString() + " - " + parseColouredEnvironment(world.getEnvironment())) - .forEach(content::add); - - plugin.getMVWorldManager().getUnloadedWorlds().stream() - .filter(world -> plugin.getMVPerms().hasPermission(sender, "multiverse.access." + world, true)) - .map(world -> ChatColor.GRAY + world + " - UNLOADED") - .forEach(content::add); - } - - private boolean canSeeWorld(Player player, MultiverseWorld world) { - return !world.isHidden() - || player == null - || plugin.getMVPerms().hasPermission(player, "multiverse.core.modify", true); - } - - private String hiddenText(MultiverseWorld world) { - return (world.isHidden()) ? String.format("%s[H] ", ChatColor.GRAY) : ""; - } - - private String parseColouredEnvironment(World.Environment env) { - ChatColor color = ChatColor.GOLD; - switch (env) { - case NETHER: - color = ChatColor.RED; - break; - case NORMAL: - color = ChatColor.GREEN; - break; - case THE_END: - color = ChatColor.AQUA; - break; - } - return color + env.toString(); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java deleted file mode 100644 index 2b60a8dad..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/LoadCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Loads a world into Multiverse. - */ -public class LoadCommand extends MultiverseCommand { - - public LoadCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Load World"); - this.setCommandUsage("/mv load" + ChatColor.GREEN + " {WORLD}"); - this.setArgRange(1, 1); - this.addKey("mvload"); - this.addKey("mv load"); - this.addCommandExample("/mv load " + ChatColor.GREEN + "MyUnloadedWorld"); - this.setPermission("multiverse.core.load", "Loads a world into Multiverse.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (this.plugin.getMVWorldManager().loadWorld(args.get(0))) { - Command.broadcastCommandMessage(sender, "Loaded world '" + args.get(0) + "'!"); - } else { - sender.sendMessage("Error trying to load world '" + args.get(0) + "'!"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java deleted file mode 100644 index 93229d325..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyAddCommand.java +++ /dev/null @@ -1,95 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.enums.Action; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -// This will contain all the properties that support the ADD/REMOVE -// Anything not in here will only support the SET action - -/** - * Used to modify various aspects of worlds. - */ -public class ModifyAddCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public ModifyAddCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Modify a World (Add a value)"); - this.setCommandUsage("/mv modify " + ChatColor.GREEN + "add {VALUE} {PROPERTY}" + ChatColor.GOLD + " [WORLD] "); - this.setArgRange(2, 3); - this.addKey("mvm add"); - this.addKey("mvmadd"); - this.addKey("mv modify add"); - this.addKey("mvmodify add"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "add " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist"); - this.setPermission("multiverse.core.modify.add", "Modify various aspects of worlds. See the help wiki for how to use this command properly. " - + "If you do not include a world, the current world will be used.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // We NEED a world from the command line - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - - if (args.size() == 2 && p == null) { - sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); - sender.sendMessage(this.getCommandDesc()); - sender.sendMessage(this.getCommandUsage()); - sender.sendMessage("Nothing changed."); - return; - } - - MultiverseWorld world; - String value = args.get(0); - String property = args.get(1); - - if (args.size() == 2) { - world = this.worldManager.getMVWorld(p.getWorld().getName()); - } else { - world = this.worldManager.getMVWorld(args.get(2)); - } - - if (world == null) { - sender.sendMessage("That world does not exist!"); - return; - } - - if (!ModifyCommand.validateAction(Action.Add, property)) { - sender.sendMessage("Sorry, you can't ADD to " + property); - sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/OMGwzx"); - return; - } - - // TODO fix this - if (world.addToVariable(property, value)) { - sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA - + value + ChatColor.WHITE + " was " + ChatColor.GREEN + "added to " + ChatColor.GREEN + property); - if (!plugin.saveWorldConfig()) { - sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!"); - } - } else { - sender.sendMessage(value + " could not be added to " + property); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java deleted file mode 100644 index 93e576635..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyClearCommand.java +++ /dev/null @@ -1,92 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.enums.Action; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Removes all values from a world-property. - */ -public class ModifyClearCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public ModifyClearCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Modify a World (Clear a property)"); - this.setCommandUsage("/mv modify" + ChatColor.GREEN + " clear {PROPERTY}" + ChatColor.GOLD + " [WORLD]"); - this.setArgRange(1, 2); - this.addKey("mvm clear"); - this.addKey("mvmclear"); - this.addKey("mv modify clear"); - this.addKey("mvmodify clear"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "animals"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "monsters"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "clear " + ChatColor.RED + "worldblacklist"); - this.setPermission("multiverse.core.modify.clear", - "Removes all values from a property. This will work on properties that contain lists.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // We NEED a world from the command line - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - if (args.size() == 1 && p == null) { - sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); - sender.sendMessage(this.getCommandDesc()); - sender.sendMessage(this.getCommandUsage()); - sender.sendMessage("Nothing changed."); - return; - } - - MultiverseWorld world; - String property = args.get(0); - - if (args.size() == 1) { - world = this.worldManager.getMVWorld(p.getWorld().getName()); - } else { - world = this.worldManager.getMVWorld(args.get(1)); - } - - if (world == null) { - sender.sendMessage("That world does not exist!"); - return; - } - - if (!ModifyCommand.validateAction(Action.Clear, property)) { - sender.sendMessage("Sorry, you can't use CLEAR with " + property); - sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/q1h01S"); - return; - } - // TODO fix this - if (world.clearList(property)) { - sender.sendMessage(property + " was cleared. It contains 0 values now."); - sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + property + ChatColor.WHITE + " was " - + ChatColor.GREEN + "CLEARED" + ChatColor.WHITE + ". It contains " + ChatColor.LIGHT_PURPLE + "0" + ChatColor.WHITE + " values now."); - if (!plugin.saveWorldConfig()) { - sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!"); - } - } else { - sender.sendMessage(ChatColor.RED + "Error: " + ChatColor.GOLD + property - + ChatColor.WHITE + " was " + ChatColor.GOLD + "NOT" + ChatColor.WHITE + " cleared."); - } - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java deleted file mode 100644 index c87a0761f..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.enums.Action; -import com.onarandombox.MultiverseCore.enums.AddProperties; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Used to modify various aspects of worlds. - */ -public class ModifyCommand extends MultiverseCommand { - - public ModifyCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Modify a World"); - this.setCommandUsage("/mv modify" + ChatColor.GREEN + " {set|add|remove|clear} ..."); - this.setArgRange(2, 3); - this.addKey("mvm"); - this.addKey("mvmodify"); - this.addKey("mv modify"); - Map children = new HashMap(); - children.put("multiverse.core.modify.add", true); - children.put("multiverse.core.modify.modify", true); - children.put("multiverse.core.modify.clear", true); - children.put("multiverse.core.modify.remove", true); - Permission modify = new Permission("multiverse.core.modify", - "Modify various aspects of worlds. It requires add/set/clear/remove. See the examples below", PermissionDefault.OP, children); - this.addCommandExample(ChatColor.AQUA + "/mv modify set ?"); - this.addCommandExample(ChatColor.GREEN + "/mv modify add ?"); - this.addCommandExample(ChatColor.BLUE + "/mv modify clear ?"); - this.addCommandExample(ChatColor.RED + "/mv modify remove ?"); - this.setPermission(modify); - } - - /** - * Validates the specified action. - * - * @param action The {@link Action}. - * @param property The property. - * @return Whether this action is valid. - */ - protected static boolean validateAction(Action action, String property) { - if (action != Action.Set) { - try { - AddProperties.valueOf(property); - return true; - } catch (IllegalArgumentException e) { - return false; - } - } - return false; - } - - @Override - public void runCommand(CommandSender sender, List args) { - // This is just a place holder. The real commands are in: - // ModifyAddCommand - // ModifyRemoveCommand - // ModifySetCommand - // ModifyClearCommand - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java deleted file mode 100644 index 51792d99f..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifyRemoveCommand.java +++ /dev/null @@ -1,97 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.enums.Action; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Removes values from a world-property. - */ -public class ModifyRemoveCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public ModifyRemoveCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Modify a World (Remove a value)"); - this.setCommandUsage("/mv modify" + ChatColor.GREEN + " remove {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"); - this.setArgRange(2, 3); - this.addKey("mvm remove"); - this.addKey("mvmremove"); - this.addKey("mv modify remove"); - this.addKey("mvmodify remove"); - this.addKey("mvm delete"); - this.addKey("mvmdelete"); - this.addKey("mv modify delete"); - this.addKey("mvmodify delete"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "sheep " + ChatColor.RED + "animals"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "creeper " + ChatColor.RED + "monsters"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "remove " + ChatColor.GREEN + "MyWorld " + ChatColor.RED + "worldblacklist"); - this.setPermission("multiverse.core.modify.remove", "Modify various aspects of worlds. See the help wiki for how to use this command properly. " - + "If you do not include a world, the current world will be used.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // We NEED a world from the command line - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - - if (args.size() == 2 && p == null) { - sender.sendMessage(ChatColor.RED + "From the console, WORLD is required."); - sender.sendMessage(this.getCommandDesc()); - sender.sendMessage(this.getCommandUsage()); - sender.sendMessage("Nothing changed."); - return; - } - - MultiverseWorld world; - String value = args.get(0); - String property = args.get(1); - - if (args.size() == 2) { - world = this.worldManager.getMVWorld(p.getWorld().getName()); - } else { - world = this.worldManager.getMVWorld(args.get(2)); - } - - if (world == null) { - sender.sendMessage("That world does not exist!"); - return; - } - - if (!ModifyCommand.validateAction(Action.Remove, property)) { - sender.sendMessage("Sorry, you can't REMOVE anything from" + property); - sender.sendMessage("Please visit our Github Wiki for more information: https://goo.gl/OMGwzx"); - return; - } - // TODO fix this - if (world.removeFromVariable(property, value)) { - sender.sendMessage(ChatColor.GREEN + "Success! " + ChatColor.AQUA + value + ChatColor.WHITE - + " was " + ChatColor.RED + "removed from " + ChatColor.GREEN + property); - if (!plugin.saveWorldConfig()) { - sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!"); - } - } else { - sender.sendMessage(ChatColor.RED + "There was an error removing " + ChatColor.GRAY - + value + ChatColor.WHITE + " from " + ChatColor.GOLD + property); - } - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java deleted file mode 100644 index 57a487682..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ModifySetCommand.java +++ /dev/null @@ -1,125 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.enums.EnglishChatColor; -import com.onarandombox.MultiverseCore.exceptions.PropertyDoesNotExistException; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Used to set world-properties. - */ -public class ModifySetCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public ModifySetCommand(MultiverseCore plugin) { - super(plugin); - this.worldManager = this.plugin.getMVWorldManager(); - this.setName("Modify a World (Set a value)"); - this.setCommandUsage("/mv modify" + ChatColor.GREEN + " set {PROPERTY} {VALUE}" + ChatColor.GOLD + " [WORLD]"); - this.setArgRange(1, 3); - this.addKey("mvm set"); - this.addKey("mvmset"); - this.addKey("mv modify set"); - this.addKey("mvmodify set"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "mode " + ChatColor.RED + "creative"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "animals " + ChatColor.RED + "false"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "monsters " + ChatColor.RED + "false"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "alias " + ChatColor.RED + "MyWorld"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "color " + ChatColor.RED + "green"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "curr " + ChatColor.RED + "3"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "price " + ChatColor.RED + "5"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "scale " + ChatColor.RED + "1.2"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "memory " + ChatColor.RED + "true"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "diff " + ChatColor.RED + "hard"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hunger " + ChatColor.RED + "false"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "hidden " + ChatColor.RED + "true"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "pvp " + ChatColor.RED + "false"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "heal " + ChatColor.RED + "true"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "adjustspawn " + ChatColor.RED + "false"); - this.addCommandExample("/mvm " + ChatColor.GOLD + "set " + ChatColor.GREEN + "spawn"); - this.setPermission("multiverse.core.modify.set", "Modify various aspects of worlds. See the help wiki for how to use this command properly. " - + "If you do not include a world, the current world will be used.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // Special case for spawn: - if (args.size() == 1) { - if (!(sender instanceof Player)) { - sender.sendMessage("You must be a player to set the" + ChatColor.GREEN + " spawn"); - return; - } - if (args.get(0).equalsIgnoreCase("spawn")) { - SetSpawnCommand c = new SetSpawnCommand(this.plugin); - c.setWorldSpawn(sender); - - } else { - sender.sendMessage("Spawn is the only param with no" + ChatColor.GREEN + " VALUE"); - sender.sendMessage("Type " + ChatColor.GREEN + "/mv modify ?" + ChatColor.WHITE + " For help."); - } - return; - } - // We NEED a world from the command line - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - - if (args.size() == 2 && p == null) { - sender.sendMessage("From the command line, WORLD is required."); - sender.sendMessage(this.getCommandDesc()); - sender.sendMessage(this.getCommandUsage()); - sender.sendMessage("Nothing changed."); - return; - } - - MultiverseWorld world; - String value = args.get(1); - String property = args.get(0); - - if (args.size() == 2) { - world = this.worldManager.getMVWorld(p.getWorld().getName()); - } else { - world = this.worldManager.getMVWorld(args.get(2)); - } - - if (world == null) { - sender.sendMessage("That world does not exist!"); - return; - } - - if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) && !EnglishChatColor.isValidAliasColor(value)) { - sender.sendMessage(value + " is not a valid color. Please pick one of the following:"); - sender.sendMessage(EnglishChatColor.getAllColors()); - return; - } - try { - if (world.setPropertyValue(property, value)) { - sender.sendMessage(ChatColor.GREEN + "Success!" + ChatColor.WHITE + " Property " + ChatColor.AQUA + property - + ChatColor.WHITE + " was set to " + ChatColor.GREEN + value); - if (!plugin.saveWorldConfig()) { - sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!"); - } - } else { - sender.sendMessage(ChatColor.RED + world.getPropertyHelp(property)); - } - } catch (PropertyDoesNotExistException e) { - sender.sendMessage(ChatColor.RED + "Sorry, You can't set: '" + ChatColor.GRAY + property + ChatColor.RED + "'"); - sender.sendMessage("Valid world-properties: " + world.getAllPropertyNames()); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java deleted file mode 100644 index ac0aa7ba2..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/MultiverseCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import java.util.List; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MultiverseMessaging; -import com.pneumaticraft.commandhandler.Command; -import org.bukkit.command.CommandSender; - -/** - * A generic Multiverse-command. - */ -public abstract class MultiverseCommand extends Command { - - /** - * The reference to the core. - */ - protected MultiverseCore plugin; - /** - * The reference to {@link MultiverseMessaging}. - */ - protected MultiverseMessaging messaging; - - public MultiverseCommand(MultiverseCore plugin) { - super(plugin); - this.plugin = plugin; - this.messaging = this.plugin.getMessaging(); - } - - @Override - public abstract void runCommand(CommandSender sender, List args); - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java deleted file mode 100644 index 3e603e87d..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCommand.java +++ /dev/null @@ -1,177 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.pneumaticraft.commandhandler.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * A generic paginated command. - * @param The type of items on the page. - */ -public abstract class PaginatedCommand extends Command { - private final Pattern REGEX_SPECIAL_CHARS = Pattern.compile("[.+*?\\[^\\]$(){}=!<>|:-\\\\]"); - private static final int DEFAULT_ITEMS_PER_PAGE = 9; - /** - * The number of items per page. - */ - protected int itemsPerPage = DEFAULT_ITEMS_PER_PAGE; - - public PaginatedCommand(JavaPlugin plugin) { - super(plugin); - } - - /** - * Set the number of items per page. - * - * @param items The new number of items per page. - */ - protected void setItemsPerPage(int items) { - itemsPerPage = items; - } - - /** - * Gets filtered items. - * - * @param availableItems All available items. - * @param filter The filter-{@link String}. - * @return A list of items that match the filter. - */ - protected abstract List getFilteredItems(List availableItems, String filter); - - /** - * Escape regex special characters from filter - * - * @param filter The filter-{@link String}. - * @return String with regex characters escaped - */ - protected String cleanFilter(String filter) { - return REGEX_SPECIAL_CHARS.matcher(filter).replaceAll("\\\\$0"); - } - - /** - * Constructs a single string from a list of strings. - * - * @param list The {@link List} of strings. - * @return A single {@link String}. - */ - protected String stitchThisString(List list) { - StringBuilder builder = new StringBuilder(); - for (String s : list) { - builder.append(s); - builder.append(' '); - } - return builder.toString(); - } - - /** - * Shows a page. - * - * @param page The number of the page to show. - * @param sender The {@link CommandSender} that wants to see the page. - * @param cmds The items that should be displayed on the page. - */ - protected void showPage(int page, CommandSender sender, List cmds) { - // Ensure the page is at least 1. - page = (page <= 0) ? 1 : page; - int start = (page - 1) * itemsPerPage; - int end = start + itemsPerPage; - - for (int i = start; i < end; i++) { - // For consistancy, print some extra lines if it's a player: - if (i < cmds.size()) { - sender.sendMessage(this.getItemText(cmds.get(i))); - } else if (sender instanceof Player) { - sender.sendMessage(" "); - } - } - } - - /** - * Converts an item into a string. - * - * @param item The item. - * @return A {@link String}. - */ - protected abstract String getItemText(T item); - - /** - * Constructs a {@link FilterObject} from a {@link List} of arguments. - * - * @param args The {@link List} of arguments. - * @return The {@link FilterObject}. - */ - protected FilterObject getPageAndFilter(List args) { - int page = 1; - - String filter = ""; - - if (args.size() == 0) { - filter = ""; - page = 1; - } else if (args.size() == 1) { - try { - page = Integer.parseInt(args.get(0)); - } catch (NumberFormatException ex) { - filter = args.get(0); - page = 1; - } - } else if (args.size() == 2) { - filter = args.get(0); - try { - page = Integer.parseInt(args.get(1)); - } catch (NumberFormatException ex) { - page = 1; - } - } - return new FilterObject(page, filter); - } - - /** - * "Key-Object" containing information about the page and the filter that were requested. - */ - protected class FilterObject { - private Integer page; - private String filter; - - public FilterObject(Integer page, String filter) { - this.page = page; - this.filter = filter; - } - - /** - * Gets the page. - * @return The page. - */ - public Integer getPage() { - return this.page; - } - - /** - * Sets the page. - * - * @param page The new page. - */ - public void setPage(int page) { - this.page = page; - } - - /** - * Gets the filter. - * @return The filter. - */ - public String getFilter() { - return this.filter; - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java deleted file mode 100644 index ebd407b7e..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/PaginatedCoreCommand.java +++ /dev/null @@ -1,26 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; - -/** - * A generic paginated Multiverse-command. - * @param The type of items on the page. - */ -public abstract class PaginatedCoreCommand extends PaginatedCommand { - /** - * The reference to the core. - */ - protected MultiverseCore plugin; - - public PaginatedCoreCommand(MultiverseCore plugin) { - super(plugin); - this.plugin = plugin; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java deleted file mode 100644 index 38f32ca69..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/PurgeCommand.java +++ /dev/null @@ -1,92 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.api.WorldPurger; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -/** - * Removes a type of mob from a world. - */ -public class PurgeCommand extends MultiverseCommand { - private MVWorldManager worldManager; - - public PurgeCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Purge World of Creatures"); - this.setCommandUsage("/mv purge" + ChatColor.GOLD + " [WORLD|all] " + ChatColor.GREEN + "{all|animals|monsters|MOBNAME}"); - this.setArgRange(1, 2); - this.addKey("mvpurge"); - this.addKey("mv purge"); - this.addCommandExample("/mv purge " + ChatColor.GREEN + "all"); - this.addCommandExample("/mv purge " + ChatColor.GOLD + "all " + ChatColor.GREEN + "all"); - this.addCommandExample("/mv purge " + ChatColor.GREEN + "monsters"); - this.addCommandExample("/mv purge " + ChatColor.GOLD + "all " + ChatColor.GREEN + "animals"); - this.addCommandExample("/mv purge " + ChatColor.GOLD + "MyWorld " + ChatColor.GREEN + "squid"); - this.addCommandExample("/mv purge " + ChatColor.GOLD + "MyWorld_nether " + ChatColor.GREEN + "ghast"); - this.setPermission("multiverse.core.purge", "Removed the specified type of mob from the specified world.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - if (args.size() == 1 && p == null) { - sender.sendMessage("This command requires a WORLD when being run from the console!"); - sender.sendMessage(this.getCommandUsage()); - return; - } - String worldName = null; - String deathName = null; - if (args.size() == 1) { - worldName = p.getWorld().getName(); - deathName = args.get(0); - } else { - worldName = args.get(0); - deathName = args.get(1); - } - - if (!worldName.equalsIgnoreCase("all") && !this.worldManager.isMVWorld(worldName)) { - this.plugin.showNotMVWorldMessage(sender, worldName); - sender.sendMessage("It cannot be purged."); - return; - } - - List worldsToRemoveEntitiesFrom = new ArrayList(); - // Handle all case any user who names a world "all" should know better... - if (worldName.equalsIgnoreCase("all")) { - worldsToRemoveEntitiesFrom.addAll(this.worldManager.getMVWorlds()); - } else { - worldsToRemoveEntitiesFrom.add(this.worldManager.getMVWorld(worldName)); - } - - WorldPurger purger = this.worldManager.getTheWorldPurger(); - ArrayList thingsToKill = new ArrayList(); - if (deathName.equalsIgnoreCase("all") || deathName.equalsIgnoreCase("animals") || deathName.equalsIgnoreCase("monsters")) { - thingsToKill.add(deathName.toUpperCase()); - } else { - Collections.addAll(thingsToKill, deathName.toUpperCase().split(",")); - } - for (MultiverseWorld w : worldsToRemoveEntitiesFrom) { - purger.purgeWorld(w, thingsToKill, false, false, sender); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java deleted file mode 100644 index 2d2498424..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/RegenCommand.java +++ /dev/null @@ -1,69 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; -import com.pneumaticraft.commandhandler.CommandHandler; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -/** - * Regenerates a world. - */ -public class RegenCommand extends MultiverseCommand { - - public RegenCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Regenerates a World"); - this.setCommandUsage("/mv regen" + ChatColor.GREEN + " {WORLD}" + ChatColor.GOLD + " [-s [SEED]] [--keep-gamerules]"); - this.setArgRange(1, 4); - this.addKey("mvregen"); - this.addKey("mv regen"); - this.addCommandExample("You can use the -s with no args to get a new seed:"); - this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s"); - this.addCommandExample("or specifiy a seed to get that one:"); - this.addCommandExample("/mv regen " + ChatColor.GREEN + "MyWorld" + ChatColor.GOLD + " -s" + ChatColor.AQUA + " gargamel"); - this.setPermission("multiverse.core.regen", "Regenerates a world on your server. The previous state will be lost " - + ChatColor.RED + "PERMANENTLY.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - String worldName = args.get(0); - boolean useseed = (!(args.size() == 1)); - boolean randomseed = (args.size() == 2 && args.get(1).equalsIgnoreCase("-s")); - String seed = (args.size() == 3) ? args.get(2) : ""; - boolean keepGamerules = CommandHandler.hasFlag("--keep-gamerules", args); - this.plugin.getCommandQueueManager().addToQueue(new QueuedCommand( - sender, - doWorldRegen(sender, worldName, useseed, randomseed, seed, keepGamerules), - String.format("Are you sure you want to regen '%s'? You cannot undo this action.", worldName) - )); - } - - private Runnable doWorldRegen(@NotNull CommandSender sender, - @NotNull String worldName, - boolean useSeed, - boolean randomSeed, - @NotNull String seed, - boolean keepGamerules) { - - return () -> { - if (this.plugin.getMVWorldManager().regenWorld(worldName, useSeed, randomSeed, seed, keepGamerules)) { - sender.sendMessage(ChatColor.GREEN + "World Regenerated!"); - return; - } - sender.sendMessage(ChatColor.RED + "World could NOT be regenerated!"); - }; - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java deleted file mode 100644 index 680de34a7..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ReloadCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.event.MVConfigReloadEvent; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.ArrayList; -import java.util.List; - -/** - * Reloads worlds.yml and config.yml. - */ -public class ReloadCommand extends MultiverseCommand { - - public ReloadCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Reload Configs"); - this.setCommandUsage("/mv reload"); - this.setArgRange(0, 0); - this.addKey("mvreload"); - this.addKey("mvr"); - this.addKey("mv reload"); - this.addCommandExample("/mv reload"); - this.setPermission("multiverse.core.reload", "Reloads worlds.yml and config.yml.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - sender.sendMessage(ChatColor.GOLD + "Reloading all Multiverse Plugin configs..."); - this.plugin.loadConfigs(); - this.plugin.getAnchorManager().loadAnchors(); - this.plugin.getMVWorldManager().loadWorlds(true); - - List configsLoaded = new ArrayList(); - configsLoaded.add("Multiverse-Core - config.yml"); - configsLoaded.add("Multiverse-Core - worlds.yml"); - configsLoaded.add("Multiverse-Core - anchors.yml"); - // Create the event - MVConfigReloadEvent configReload = new MVConfigReloadEvent(configsLoaded); - // Fire it off - this.plugin.getServer().getPluginManager().callEvent(configReload); - for (String s : configReload.getAllConfigsLoaded()) { - sender.sendMessage(s); - } - - sender.sendMessage(ChatColor.GREEN + "Reload Complete!"); - } - -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java deleted file mode 100644 index aa821b33b..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/RemoveCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Unloads a world and removes it from the config. - */ -public class RemoveCommand extends MultiverseCommand { - - public RemoveCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Remove World"); - this.setCommandUsage("/mv remove" + ChatColor.GREEN + " {WORLD}"); - this.setArgRange(1, 1); - this.addKey("mvremove"); - this.addKey("mv remove"); - this.addCommandExample("/mv remove " + ChatColor.GREEN + "MyWorld"); - this.setPermission("multiverse.core.remove", - "Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (this.plugin.getMVWorldManager().removeWorldFromConfig(args.get(0))) { - sender.sendMessage("World removed from config!"); - } else { - sender.sendMessage("Error trying to remove world from config!"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java deleted file mode 100644 index baec84fbd..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/ScriptCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.io.File; -import java.util.List; - -/** - * States who is in what world. - */ -public class ScriptCommand extends MultiverseCommand { - - public ScriptCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Runs a script."); - this.setCommandUsage("/mv script" + ChatColor.GOLD + " {script} [target]"); - this.setArgRange(1, 2); - this.addKey("mv script"); - this.addKey("mvscript"); - this.addCommandExample(String.format("/mv script %sscript.txt", ChatColor.GOLD)); - this.addCommandExample(String.format("/mv script %stest.txt %ssomeplayer", ChatColor.GOLD, ChatColor.GREEN)); - this.setPermission("multiverse.core.script", "Runs a script.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (plugin.getScriptAPI() == null) { - sender.sendMessage("Buscript failed to load while the server was starting. Scripts cannot be run."); - return; - } - File file = new File(plugin.getScriptAPI().getScriptFolder(), args.get(0)); - if (!file.exists()) { - sender.sendMessage("That script file does not exist in the Multiverse-Core scripts directory!"); - return; - } - Player player = null; - if (sender instanceof Player) { - player = (Player) sender; - } - String target = null; - if (args.size() == 2) { - target = args.get(1); - } - plugin.getScriptAPI().executeScript(file, target, player); - sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE)); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java deleted file mode 100644 index 5e9fa3c6e..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SetSpawnCommand.java +++ /dev/null @@ -1,148 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.BlockSafety; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; -import org.bukkit.Bukkit; - -/** - * Sets the spawn for a world. - */ -public class SetSpawnCommand extends MultiverseCommand { - public SetSpawnCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Set World Spawn"); - this.setCommandUsage("/mv setspawn"); - this.setArgRange(0, 6); - this.addKey("mvsetspawn"); - this.addKey("mvsets"); - this.addKey("mvss"); - this.addKey("mv set spawn"); - this.addKey("mv setspawn"); - this.addKey("mvset spawn"); - this.addCommandExample("/mv set spawn"); - this.setPermission("multiverse.core.spawn.set", "Sets the spawn for the current world.", PermissionDefault.OP); - } - - /** - * Dispatches the user's command depending on the number of parameters - * @param sender The player who executes the command, may be console as well. - * @param args Command line parameters - */ - @Override - public void runCommand(CommandSender sender, List args) { - if (args.isEmpty()) { - setWorldSpawn(sender); - } else if (args.size() == 4) { - setWorldSpawn(sender, args.get(0), args.get(1), args.get(2), args.get(3)); - } else if (args.size() == 6) { - setWorldSpawn(sender, args.get(0), args.get(1), args.get(2), args.get(3), args.get(4), args.get(5)); - } else { - sender.sendMessage("Use no arguments for your current location, or world/x/y/z, or world/x/y/z/yaw/pitch!"); - } - } - - /** - * Set the world spawn when no parameters are given - * @param sender The {@link CommandSender} who executes the command. - * Everything not a {@link Player}, e.g. console, gets rejected, as we can't get coordinates from there. - */ - protected void setWorldSpawn(CommandSender sender) { - if (sender instanceof Player) { - Player p = (Player) sender; - Location l = p.getLocation(); - World w = p.getWorld(); - setWorldSpawn(sender, w, l); - } else { - sender.sendMessage("You need to give coordinates to use this command from the console!"); - } - } - - /** - * Set the world spawn when 4 parameters are given - * @param sender The {@link CommandSender} who executes the command - * @param world The world to set the spawn in - * @param x X-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double) - * @param y Y-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double) - * @param z Z-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double) - */ - protected void setWorldSpawn(CommandSender sender, String world, String x, String y, String z) { - setWorldSpawn(sender, world, x, y, z, "0", "0"); - } - - /** - * Set the world spawn when 6 parameters are given - * @param sender The {@link CommandSender} who executes the command - * @param world The world to set the spawn in - * @param x X-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double) - * @param y Y-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double) - * @param z Z-coordinate to set the spawn to (as a {@link String} as it's from the command line, gets parsed into a double) - * @param yaw Yaw a newly spawned player should look at (as a {@link String} as it's from the command line, gets parsed into a float) - * @param pitch Pitch a newly spawned player should look at (as a {@link String} as it's from the command line, gets parsed into a float) - */ - protected void setWorldSpawn(CommandSender sender, String world, String x, String y, String z, String yaw, String pitch) { - double dx, dy, dz; - float fpitch, fyaw; - World bukkitWorld = Bukkit.getWorld(world); - if (bukkitWorld == null) { - sender.sendMessage("World " + world + " is unknown!"); - return; - } - try { - dx = Double.parseDouble(x); - dy = Double.parseDouble(y); - dz = Double.parseDouble(z); - fpitch = Float.parseFloat(pitch); - fyaw = Float.parseFloat(yaw); - } catch (NumberFormatException ex) { - sender.sendMessage("All coordinates must be numeric"); - return; - } - Location l = new Location(bukkitWorld, dx, dy, dz, fyaw, fpitch); - setWorldSpawn(sender, bukkitWorld, l); - } - - /** - * Does the actual spawn-setting-work. - * - * @param sender The {@link CommandSender} that's setting the spawn. - * @param w The {@link World} to set the spawn in - * @param l The {@link Location} to set the spawn to - */ - private void setWorldSpawn(CommandSender sender, World w, Location l) { - MultiverseWorld foundWorld = this.plugin.getMVWorldManager().getMVWorld(w.getName()); - if (foundWorld != null) { - foundWorld.setSpawnLocation(l); - BlockSafety bs = this.plugin.getBlockSafety(); - if (!bs.playerCanSpawnHereSafely(l) && foundWorld.getAdjustSpawn()) { - sender.sendMessage("It looks like that location would normally be unsafe. But I trust you."); - sender.sendMessage("I'm turning off the Safe-T-Teleporter for spawns to this world."); - sender.sendMessage("If you want this turned back on just do:"); - sender.sendMessage(ChatColor.AQUA + "/mvm set adjustspawn true " + foundWorld.getAlias()); - foundWorld.setAdjustSpawn(false); - } - sender.sendMessage("Spawn was set to: " + plugin.getLocationManipulation().strCoords(l)); - if (!plugin.saveWorldConfig()) { - sender.sendMessage(ChatColor.RED + "There was an issue saving worlds.yml! Your changes will only be temporary!"); - } - } else { - w.setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - sender.sendMessage("Multiverse does not know about this world, only X,Y and Z set. Please import it to set the spawn fully (Pitch/Yaws)."); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java deleted file mode 100644 index 455022968..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SilentCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Enables debug-information. - */ -public class SilentCommand extends MultiverseCommand { - - public SilentCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Turn silent mode on/off?"); - this.setCommandUsage("/mv silent" + ChatColor.GOLD + " [true|false|on|off]"); - this.setArgRange(0, 1); - this.addKey("mv silent"); - this.addKey("mvsilent"); - this.addCommandExample("/mv silent " + ChatColor.GOLD + "true"); - this.setPermission("multiverse.core.silent", "Reduces the amount of startup messages.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (args.size() == 1) { - if (args.get(0).equalsIgnoreCase("on")) { - args.set(0, "true"); - } - plugin.getMVConfig().setSilentStart(Boolean.valueOf(args.get(0))); - plugin.saveMVConfigs(); - } - this.displaySilentMode(sender); - } - - private void displaySilentMode(CommandSender sender) { - if (plugin.getMVConfig().getSilentStart()) { - sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.GREEN + "ON"); - } else { - sender.sendMessage("Multiverse Silent Start mode is " + ChatColor.RED + "OFF"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java deleted file mode 100644 index c258b8f09..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SleepCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Takes the player to the latest bed he's slept in. - */ -public class SleepCommand extends MultiverseCommand { - - public SleepCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Go to Sleep"); - this.setCommandUsage("/mv sleep"); - this.setArgRange(0, 0); - this.addKey("mv sleep"); - this.setPermission("multiverse.core.sleep", "Takes you the latest bed you've slept in (Currently BROKEN).", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player p = null; - if (sender instanceof Player) { - p = (Player) sender; - } - - if (p == null) { - return; - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java deleted file mode 100644 index ae6c97dd3..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/SpawnCommand.java +++ /dev/null @@ -1,91 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseCore.utils.PlayerFinder; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Teleports a player to the spawn. - */ -public class SpawnCommand extends MultiverseCommand { - - public SpawnCommand(MultiverseCore plugin) { - super(plugin); - Permission otherPerm = new Permission("multiverse.core.spawn.other", - "Teleports another player to the spawn of the world they are in.", PermissionDefault.OP); - this.setName("Spawn"); - this.setCommandUsage("/mv spawn" + ChatColor.GOLD + " [PLAYER]"); - this.setArgRange(0, 1); - this.addKey("mvspawn"); - this.addKey("mv spawn"); - this.addKey("mvs"); - this.setPermission("multiverse.core.spawn.self", "Teleports you to the Spawn Point of the world you are in.", PermissionDefault.OP); - this.addAdditonalPermission(otherPerm); - - } - - @Override - public void runCommand(CommandSender sender, List args) { - Player player = null; - if (sender instanceof Player) { - player = (Player) sender; - } - // If a persons name was passed in, you must be A. the console, or B have permissions - if (args.size() == 1) { - if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.other", true)) { - sender.sendMessage("You don't have permission to teleport another player to spawn. (multiverse.core.spawn.other)"); - return; - } - Player target = PlayerFinder.get(args.get(0), sender); - if (target != null) { - target.sendMessage("Teleporting to this world's spawn..."); - spawnAccurately(target); - - if (player != null) { - target.sendMessage("You were teleported by: " + ChatColor.YELLOW + player.getName()); - } else { - target.sendMessage("You were teleported by: " + ChatColor.LIGHT_PURPLE + "the console"); - } - } else { - sender.sendMessage(args.get(0) + " is not logged on right now!"); - } - } else { - if (player != null && !this.plugin.getMVPerms().hasPermission(player, "multiverse.core.spawn.self", true)) { - sender.sendMessage("You don't have permission to teleport yourself to spawn. (multiverse.core.spawn.self)"); - return; - } - if (player != null) { - player.sendMessage("Teleporting to this world's spawn..."); - spawnAccurately(player); - } else { - sender.sendMessage("From the console, you must provide a PLAYER."); - } - } - } - - private void spawnAccurately(Player player) { - MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld().getName()); - Location spawnLocation; - if (world != null) { - spawnLocation = world.getSpawnLocation(); - } else { - spawnLocation = player.getWorld().getSpawnLocation(); - } - this.plugin.getSafeTTeleporter().safelyTeleport(player, player, spawnLocation, false); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java deleted file mode 100644 index 04a35e177..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/UnloadCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.permissions.PermissionDefault; - -import java.util.List; - -/** - * Unloads worlds from Multiverse. - */ -public class UnloadCommand extends MultiverseCommand { - - public UnloadCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Unload World"); - this.setCommandUsage("/mv unload" + ChatColor.GREEN + " {WORLD}"); - this.setArgRange(1, 1); - this.addKey("mvunload"); - this.addKey("mv unload"); - this.setPermission("multiverse.core.unload", - "Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.", PermissionDefault.OP); - } - - @Override - public void runCommand(CommandSender sender, List args) { - if (this.plugin.getMVWorldManager().unloadWorld(args.get(0))) { - Command.broadcastCommandMessage(sender, "Unloaded world '" + args.get(0) + "'!"); - } else { - sender.sendMessage("Error trying to unload world '" + args.get(0) + "'!"); - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java deleted file mode 100644 index 941e4713d..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/VersionCommand.java +++ /dev/null @@ -1,224 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import java.io.File; -import java.util.List; -import java.util.Map; - -import com.dumptruckman.minecraft.util.Logging; -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.event.MVVersionEvent; -import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException; -import com.onarandombox.MultiverseCore.utils.webpaste.PasteService; -import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceFactory; -import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType; -import com.onarandombox.MultiverseCore.utils.webpaste.URLShortener; -import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerFactory; -import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerType; -import com.pneumaticraft.commandhandler.CommandHandler; -import org.apache.commons.lang.StringUtils; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.ConsoleCommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.scheduler.BukkitRunnable; - -/** - * Dumps version info to the console. - */ -public class VersionCommand extends MultiverseCommand { - private static final URLShortener SHORTENER = URLShortenerFactory.getService(URLShortenerType.BITLY); - - public VersionCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Multiverse Version"); - this.setCommandUsage("/mv version " + ChatColor.GOLD + "[-b|-h|-p] [--include-plugin-list]"); - this.setArgRange(0, 2); - this.addKey("mv version"); - this.addKey("mvver"); - this.addKey("mvv"); - this.addKey("mvversion"); - this.setPermission( - "multiverse.core.version", - "Dumps version info to the console, optionally to pastebin.com with -b, to hastebin.com using -h, or to paste.gg with -p.", - PermissionDefault.OP) - ; - } - - private String getLegacyString() { - return "[Multiverse-Core] Multiverse-Core Version: " + this.plugin.getDescription().getVersion() + '\n' - + "[Multiverse-Core] Bukkit Version: " + this.plugin.getServer().getVersion() + '\n' - + "[Multiverse-Core] Loaded Worlds: " + this.plugin.getMVWorldManager().getMVWorlds() + '\n' - + "[Multiverse-Core] Multiverse Plugins Loaded: " + this.plugin.getPluginCount() + '\n' - +"[Multiverse-Core] Economy being used: " + plugin.getEconomist().getEconomyName() + '\n' - + "[Multiverse-Core] Permissions Plugin: " + this.plugin.getMVPerms().getType() + '\n' - + "[Multiverse-Core] Dumping Config Values: (version " + this.plugin.getMVConfig().getVersion() + ")" + '\n' - + "[Multiverse-Core] enforceaccess: " + plugin.getMVConfig().getEnforceAccess() + '\n' - + "[Multiverse-Core] prefixchat: " + plugin.getMVConfig().getPrefixChat() + '\n' - + "[Multiverse-Core] prefixchatformat: " + plugin.getMVConfig().getPrefixChatFormat() + '\n' - + "[Multiverse-Core] teleportintercept: " + plugin.getMVConfig().getTeleportIntercept() + '\n' - + "[Multiverse-Core] firstspawnoverride: " + plugin.getMVConfig().getFirstSpawnOverride() + '\n' - + "[Multiverse-Core] displaypermerrors: " + plugin.getMVConfig().getDisplayPermErrors() + '\n' - + "[Multiverse-Core] enablebuscript: " + plugin.getMVConfig().getEnableBuscript() + '\n' - + "[Multiverse-Core] globaldebug: " + plugin.getMVConfig().getGlobalDebug() + '\n' - + "[Multiverse-Core] silentstart: " + plugin.getMVConfig().getSilentStart() + '\n' - + "[Multiverse-Core] messagecooldown: " + plugin.getMessaging().getCooldown() + '\n' - + "[Multiverse-Core] version: " + plugin.getMVConfig().getVersion() + '\n' - + "[Multiverse-Core] firstspawnworld: " + plugin.getMVConfig().getFirstSpawnWorld() + '\n' - + "[Multiverse-Core] teleportcooldown: " + plugin.getMVConfig().getTeleportCooldown() + '\n' - + "[Multiverse-Core] defaultportalsearch: " + plugin.getMVConfig().isUsingDefaultPortalSearch() + '\n' - + "[Multiverse-Core] portalsearchradius: " + plugin.getMVConfig().getPortalSearchRadius() + '\n' - + "[Multiverse-Core] autopurge: " + plugin.getMVConfig().isAutoPurgeEnabled() + '\n' - + "[Multiverse-Core] Special Code: FRN002" + '\n'; - } - - private String getMarkdownString() { - return "# Multiverse-Core" + '\n' - + "## Overview" + '\n' - + "| Name | Value |" + '\n' - + "| --- | --- |" + '\n' - + "| Multiverse-Core Version | `" + this.plugin.getDescription().getVersion() + "` |" + '\n' - + "| Bukkit Version | `" + this.plugin.getServer().getVersion() + "` |" + '\n' - + "| Loaded Worlds | `" + this.plugin.getMVWorldManager().getMVWorlds() + "` |" + '\n' - + "| Multiverse Plugins Loaded | `" + this.plugin.getPluginCount() + "` |" + '\n' - + "| Economy being used | `" + plugin.getEconomist().getEconomyName() + "` |" + '\n' - + "| Permissions Plugin | `" + this.plugin.getMVPerms().getType() + "` |" + '\n' - + "## Parsed Config" + '\n' - + "These are what Multiverse thought the in-memory values of the config were." + "\n\n" - + "| Config Key | Value |" + '\n' - + "| --- | --- |" + '\n' - + "| version | `" + this.plugin.getMVConfig().getVersion() + "` |" + '\n' - + "| messagecooldown | `" + plugin.getMessaging().getCooldown() + "` |" + '\n' - + "| teleportcooldown | `" + plugin.getMVConfig().getTeleportCooldown() + "` |" + '\n' - + "| worldnameprefix | `" + plugin.getMVConfig().getPrefixChat() + "` |" + '\n' - + "| worldnameprefixFormat | `" + plugin.getMVConfig().getPrefixChatFormat() + "` |" + '\n' - + "| enforceaccess | `" + plugin.getMVConfig().getEnforceAccess() + "` |" + '\n' - + "| displaypermerrors | `" + plugin.getMVConfig().getDisplayPermErrors() + "` |" + '\n' - + "| teleportintercept | `" + plugin.getMVConfig().getTeleportIntercept() + "` |" + '\n' - + "| firstspawnoverride | `" + plugin.getMVConfig().getFirstSpawnOverride() + "` |" + '\n' - + "| firstspawnworld | `" + plugin.getMVConfig().getFirstSpawnWorld() + "` |" + '\n' - + "| debug | `" + plugin.getMVConfig().getGlobalDebug() + "` |" + '\n'; - } - - private void addVersionInfoToEvent(MVVersionEvent event) { - // add the legacy version info - event.appendVersionInfo(this.getLegacyString()); - - // add the legacy file, but as markdown so it's readable - // TODO Readd this in 5.0.0 - // event.putDetailedVersionInfo("version.md", this.getMarkdownString()); - - // add config.yml - File configFile = new File(this.plugin.getDataFolder(), "config.yml"); - event.putDetailedVersionInfo("multiverse-core/config.yml", configFile); - - // add worlds.yml - File worldsFile = new File(this.plugin.getDataFolder(), "worlds.yml"); - event.putDetailedVersionInfo("multiverse-core/worlds.yml", worldsFile); - } - - @Override - public void runCommand(final CommandSender sender, final List args) { - // Check if the command was sent from a Player. - if (sender instanceof Player) { - sender.sendMessage("Version info dumped to console. Please check your server logs."); - } - - MVVersionEvent versionEvent = new MVVersionEvent(); - - this.addVersionInfoToEvent(versionEvent); - this.plugin.getServer().getPluginManager().callEvent(versionEvent); - - if (CommandHandler.hasFlag("--include-plugin-list", args)) { - versionEvent.appendVersionInfo('\n' + "Plugins: " + getPluginList()); - versionEvent.putDetailedVersionInfo("plugins.txt", "Plugins: " + getPluginList()); - } - - final String versionInfo = versionEvent.getVersionInfo(); - versionEvent.putDetailedVersionInfo("version.txt", versionInfo); - - final Map files = versionEvent.getDetailedVersionInfo(); - - // log to console - String[] lines = versionInfo.split("\\r?\\n"); - for (String line : lines) { - if (!line.isEmpty()) { - this.plugin.getServer().getLogger().info(line); - } - } - - BukkitRunnable logPoster = new BukkitRunnable() { - @Override - public void run() { - if (args.size() > 0) { - String pasteUrl; - if (CommandHandler.hasFlag("-b", args)) { - // private post to pastebin - pasteUrl = postToService(PasteServiceType.PASTEBIN, true, versionInfo, files); - } else if (CommandHandler.hasFlag("-g", args)) { - // private post to github - pasteUrl = postToService(PasteServiceType.GITHUB, true, versionInfo, files); - } else if (CommandHandler.hasFlag("-h", args)) { - // private post to hastebin - pasteUrl = postToService(PasteServiceType.HASTEBIN, true, versionInfo, files); - } else if (CommandHandler.hasFlag("-p", args)) { - // private post to paste.gg - pasteUrl = postToService(PasteServiceType.PASTEGG, true, versionInfo, files); - } else { - return; - } - - if (!(sender instanceof ConsoleCommandSender)) { - sender.sendMessage("Version info dumped here: " + ChatColor.GREEN + pasteUrl); - } - Logging.info("Version info dumped here: %s", pasteUrl); - } - } - }; - - // Run the log posting operation asynchronously, since we don't know how long it will take. - logPoster.runTaskAsynchronously(this.plugin); - } - - /** - * Send the current contents of this.pasteBinBuffer to a web service. - * - * @param type Service type to send paste data to. - * @param isPrivate Should the paste be marked as private. - * @param pasteData Legacy string only data to post to a service. - * @param pasteFiles Map of filenames/contents of debug info. - * @return URL of visible paste - */ - private static String postToService(PasteServiceType type, boolean isPrivate, String pasteData, Map pasteFiles) { - PasteService ps = PasteServiceFactory.getService(type, isPrivate); - - try { - String result; - if (ps.supportsMultiFile()) { - result = ps.postData(pasteFiles); - } else { - result = ps.postData(pasteData); - } - - if (SHORTENER != null) return SHORTENER.shorten(result); - return result; - } catch (PasteFailedException e) { - e.printStackTrace(); - return "Error posting to service."; - } catch (NullPointerException e) { - e.printStackTrace(); - return "That service isn't supported yet."; - } - } - - private String getPluginList() { - return StringUtils.join(plugin.getServer().getPluginManager().getPlugins(), ", "); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java deleted file mode 100644 index fa9ab935f..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/WhoCommand.java +++ /dev/null @@ -1,118 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.commandsold; - -import com.onarandombox.MultiverseCore.MultiverseCore; -import com.onarandombox.MultiverseCore.api.MVWorldManager; -import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.permissions.PermissionDefault; - -import java.util.Collection; -import java.util.HashSet; -import java.util.List; - -/** - * States who is in what world. - */ -public class WhoCommand extends MultiverseCommand { - - private MVWorldManager worldManager; - - public WhoCommand(MultiverseCore plugin) { - super(plugin); - this.setName("Who?"); - this.setCommandUsage("/mv who" + ChatColor.GOLD + " [WORLD|--all]"); - this.setArgRange(0, 1); - this.addKey("mv who"); - this.addKey("mvw"); - this.addKey("mvwho"); - this.addCommandExample("/mv who"); - this.addCommandExample(String.format("/mv who %s--all", ChatColor.GREEN)); - this.addCommandExample(String.format("/mv who %smyworld", ChatColor.GOLD)); - this.setPermission("multiverse.core.list.who", "States who is in what world.", PermissionDefault.OP); - this.worldManager = this.plugin.getMVWorldManager(); - } - - @Override - public void runCommand(CommandSender sender, List args) { - // If this command was sent from a Player then we need to check Permissions - Player p = null; - // By default, show all from the console - boolean showAll = true; - if (sender instanceof Player) { - p = (Player) sender; - showAll = false; - } - - final Collection onlinePlayers = plugin.getServer().getOnlinePlayers(); - final Collection visiblePlayers = new HashSet(onlinePlayers.size()); - for (final Object player : onlinePlayers) { - if (player instanceof Player && (p == null || p.canSee((Player) player))) { - visiblePlayers.add((Player) player); - } - } - - if (args.size() == 1) { - if (args.get(0).equalsIgnoreCase("--all") || args.get(0).equalsIgnoreCase("-a")) { - showAll = true; - } else { - // single world mode - MultiverseWorld world = this.worldManager.getMVWorld(args.get(0)); - if (world == null) { - sender.sendMessage(ChatColor.RED + "That world does not exist."); - return; - } - - if (!this.plugin.getMVPerms().canEnterWorld(p, world)) { - sender.sendMessage(ChatColor.RED + "You aren't allowed to access to this world!"); - return; - } - - sender.sendMessage(String.format("%s--- Players in %s%s ---", ChatColor.AQUA, - world.getColoredWorldString(), ChatColor.AQUA)); - sender.sendMessage(this.buildPlayerString(world, p, visiblePlayers)); - return; - } - } - - // multiworld mode - sender.sendMessage(ChatColor.AQUA + "--- Worlds and their players --- " - + visiblePlayers.size() + "/" + plugin.getServer().getMaxPlayers()); - boolean shownOne = false; - for (MultiverseWorld world : this.worldManager.getMVWorlds()) { - if (this.plugin.getMVPerms().canEnterWorld(p, world)) { // only show world if the player can access it - if (showAll || !world.getCBWorld().getPlayers().isEmpty()) { // either show all or show if the world is not empty - sender.sendMessage(String.format("%s%s - %s", world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, p, visiblePlayers))); - shownOne = true; - } - } - } - if (!shownOne) { - sender.sendMessage("No worlds found."); - } - return; - } - - private static String buildPlayerString(MultiverseWorld world, Player viewer, final Collection visiblePlayers) { - // Retrieve the players in this world - List players = world.getCBWorld().getPlayers(); - StringBuilder playerBuilder = new StringBuilder(); - for (Player player : players) { - // If the viewer is the console or the viewier is allowed to see the player, show them. - // Make sure we're also ONLY showing online players. - // Since we already checked visible players, we'll just make sure who we're about to show is in that. - if (visiblePlayers.contains(player)) - playerBuilder.append(player.getDisplayName()).append(", "); - } - String bString = playerBuilder.toString(); - return (bString.length() == 0) ? "No players found." : bString.substring(0, bString.length() - 2); - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java b/src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java deleted file mode 100644 index a7559b959..000000000 --- a/src/main/java/com/onarandombox/MultiverseCore/commandsold/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * This package contains all Commands. - */ -package com.onarandombox.MultiverseCore.commandsold; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java index 24ca86924..bc8a944d2 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPermissions.java @@ -7,12 +7,13 @@ package com.onarandombox.MultiverseCore.utils; +import java.util.List; + import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.pneumaticraft.commandhandler.PermissionsInterface; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -20,13 +21,10 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; -import java.util.List; -import java.util.logging.Level; - /** - * Multiverse's {@link PermissionsInterface}. + * Multiverse's permission checker */ -public class MVPermissions implements PermissionsInterface { +public class MVPermissions { private MultiverseCore plugin; private MVWorldManager worldMgr; @@ -234,7 +232,6 @@ public void tellMeWhyICantDoThis(CommandSender asker, CommandSender playerInQues * @param isOpRequired deprecated This is not used for anything anymore. * @return True if they have that permission or any parent. */ - @Override public boolean hasPermission(CommandSender sender, String node, boolean isOpRequired) { if (!(sender instanceof Player)) { return true; @@ -311,18 +308,9 @@ private static String pullOneLevelOff(String node) { return null; } - /** - * Gets the type of this {@link PermissionsInterface}. - * @return The type of this {@link PermissionsInterface}. - */ - public String getType() { - return "Bukkit Permissions (SuperPerms)"; - } - /** * {@inheritDoc} */ - @Override public boolean hasAnyPermission(CommandSender sender, List nodes, boolean isOpRequired) { for (String node : nodes) { if (this.hasPermission(sender, node, isOpRequired)) { @@ -335,7 +323,6 @@ public boolean hasAnyPermission(CommandSender sender, List nodes, boolea /** * {@inheritDoc} */ - @Override public boolean hasAllPermission(CommandSender sender, List nodes, boolean isOpRequired) { for (String node : nodes) { if (!this.hasPermission(sender, node, isOpRequired)) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d46f0fd7e..c53b394f8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,183 +5,3 @@ website: 'https://dev.bukkit.org/projects/multiverse-core' softdepend: ['Vault'] api-version: 1.13 version: maven-version-number -commands: - mv: - description: Generic Multiverse Command - usage: / - mvcreate: - description: World create command - aliases: [mvc] - usage: | - / - / creative normal -- Creates a world called 'creative' with a NORMAL environment. - / hellworld nether -- Creates a world called 'hellworld' with a NETHER environment. - mvimport: - description: World import command - aliases: [mvim] - usage: | - / [-g generator[:id]] [-n] - / creative normal -- Imports an existing world called 'creative' with a NORMAL environment. - / hellworld nether -- Imports an existing world called 'hellworld' with a NETHER environment. - mvremove: - description: Remove world from multiverse command - usage: | - / - mvdelete: - description: Delete world from server folders command - usage: | - / - mvunload: - description: World unload command - usage: | - / - mvmodify: - description: Modify the settings of an existing world - aliases: [mvm] - usage: | - / [world] - / set pvp false creative -- Turns off PVP in the 'creative' world. - mvmset: - description: Modify the settings of an existing world - usage: | - / [world] - / pvp false creative -- Turns off PVP in the 'creative' world. - mvmadd: - description: Modify the settings of an existing world - usage: | - / [world] - / sheep animals world_nether -- Add sheep to animal list for 'world_nether' world. - mvmremove: - description: Modify the settings of an existing world - aliases: [mvmdelete] - usage: | - / [world] - / sheep animals world_nether -- remove sheep from animal list for 'world_nether' world. - mvmclear: - description: Modify the settings of an existing world - usage: | - / [world] - / animals world_nether -- Empties animal list for 'world_nether' world. - mvtp: - description: Command to teleport between Worlds - usage: | - / [player] - Example: / creative - Teleports you to the relevant location in the 'creative' world. - mvlist: - description: Print list of loaded Worlds - aliases: [mvl] - usage: | - / [page] - Example: / NETHER - Shows all NETHER Worlds. - Example: / NORMAL - Shows all NORMAL Worlds. - mvsetspawn: - description: Set the spawn area for a particular world - aliases: [mvsets, mvss] - usage: / -- Sets the spawn area of the current world to your location. - mvspawn: - description: Teleport to the spawn area - aliases: [mvs] - usage: / [player] -- Teleports you to the spawn area of your current world. - mvcoord: - description: Display World, Coordinates, Direction & Compression for a world. - aliases: [mvco] - usage: | - / [world] - / -- Shows the relevant coordinates in your current world. - / creative -- Shows the relevant coordinates if you were in the 'creative' world. - mvwho: - description: Display online users per world. - aliases: [mvw] - usage: | - / [world|--all] - / -- Shows who is online in each world. - / creative -- Shows who is online in the 'creative' world. - mvreload: - description: Reload Configuration files. - aliases: [mvr] - usage: / - mvpurge: - description: Purge the targetted world of creatures. - usage: | - / [WORLD|all] [all|animals|monsters|MOBNAME] - / -- Purges the players world of all creatures. - / creative all -- Purges the creative world of all Creatures. - / creative creeper -- Purges the creative world of all CREEPERS. - mvconfirm: - description: Confirms sensitive decisions like deleting a world. - usage: | - / - mvinfo: - description: Gets world info. - aliases: [mvi] - usage: | - / [world] [page] - mvenv: - description: Tells the user all possible environment types. - usage: | - / - mvversion: - description: Prints out version info. - aliases: [mvv, mvver] - usage: | - / [-b|-h|-p] [--include-plugin-list] - mvhelp: - description: Displays the Multiverse Help. - aliases: [mvsearch, mvh] - usage: | - / [filter] [page #] - mvdebug: - description: Turns on debugging. - usage: | - / [1|2|3|off|silent] - mvgenerators: - description: Displays all found world generators. - aliases: [mvgens] - usage: | - / - mvload: - description: Loads a world into Multiverse. - usage: | - / - mvregen: - description: Regenerates a world Multiverse already knows about. - usage: | - / [-s seed] - mvscript: - description: Runs a script from the Multiverse scripts directory. - usage: | - /