From 685a9656296676c52a5b58b8950fe5399598f535 Mon Sep 17 00:00:00 2001 From: Butzlabben Date: Wed, 3 Oct 2018 17:34:09 +0200 Subject: [PATCH] Added executable commands on /ws get --- WorldSystem/pom.xml | 2 +- .../world/config/SettingsConfig.java | 8 +++ .../world/wrapper/AsyncCreatorAdapter.java | 2 +- .../butzlabben/world/wrapper/SystemWorld.java | 53 ++++++++----------- WorldSystem/src/main/resources/settings.yml | 8 +++ 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/WorldSystem/pom.xml b/WorldSystem/pom.xml index 0b787b5..62b8afb 100644 --- a/WorldSystem/pom.xml +++ b/WorldSystem/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.butzlabben.world WorldSystem - 2.4.0 + 2.4.0.1 UTF-8 - diff --git a/WorldSystem/src/main/java/de/butzlabben/world/config/SettingsConfig.java b/WorldSystem/src/main/java/de/butzlabben/world/config/SettingsConfig.java index 9ac113d..7648e89 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/config/SettingsConfig.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/config/SettingsConfig.java @@ -9,6 +9,7 @@ import java.io.InputStreamReader; import java.nio.charset.Charset; import java.nio.file.Files; import java.util.HashMap; +import java.util.List; import java.util.UUID; import org.bukkit.Bukkit; @@ -170,6 +171,13 @@ public class SettingsConfig { borderSizes.put(s, cfg.getLong("worldborder.ranks." + s)); } } + /** + * @return the commands specified in settings.yml on /ws get + */ + public static List getCommandsonGet() { + YamlConfiguration cfg = getConfig(); + return cfg.getStringList("commands_on_get"); + } private SettingsConfig() { } diff --git a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java index 2a5fff5..97b1c23 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/AsyncCreatorAdapter.java @@ -35,7 +35,7 @@ public class AsyncCreatorAdapter implements CreatorAdapter { if (sw != null) sw.setCreating(false); - // Send the play the message + // Send the message r.run(); } }); diff --git a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java index 729ce9c..516d745 100644 --- a/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java +++ b/WorldSystem/src/main/java/de/butzlabben/world/wrapper/SystemWorld.java @@ -18,6 +18,7 @@ import de.butzlabben.world.WorldSystem; import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.PluginConfig; +import de.butzlabben.world.config.SettingsConfig; import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.event.WorldCreateEvent; import de.butzlabben.world.event.WorldLoadEvent; @@ -41,12 +42,10 @@ public class SystemWorld { /** * This method is the online way to get a system world instance * - * @param worldname - * as in minecraft + * @param worldname as in minecraft * @return a systemworld instance if it is a systemworld or null if is not a * systemworld - * @exception NullPointerException - * worldname == null + * @exception NullPointerException worldname == null */ public static SystemWorld getSystemWorld(String worldname) { Preconditions.checkNotNull(worldname, "worldname must not be null"); @@ -61,9 +60,8 @@ public class SystemWorld { } /** - * @param w - * a world in bukkit, no matter if systemworld or not Trys to - * unload a systemworld later, with the given delay in the config + * @param w a world in bukkit, no matter if systemworld or not Trys to unload a + * systemworld later, with the given delay in the config */ public static void tryUnloadLater(World w) { if (w != null) @@ -84,10 +82,8 @@ public class SystemWorld { /** * Trys to force-unload this world * - * @param w - * associated world - * @exception NullPointerException - * w == null + * @param w associated world + * @exception NullPointerException w == null */ public void directUnload(World w) { if (!Bukkit.isPrimaryThread()) { @@ -126,10 +122,8 @@ public class SystemWorld { /** * Trys to unload this world later, with the given delay in the config * - * @param w - * the associated world - * @exception NullPointerException - * w == null + * @param w the associated world + * @exception NullPointerException w == null */ public void unloadLater(World w) { if (!Bukkit.isPrimaryThread()) { @@ -181,12 +175,9 @@ public class SystemWorld { /** * Trys to load this world, and messages the player about the process * - * @param p - * the player to teleport on the world - * @exception NullPointerException - * if p is null - * @exception IllegalArgumentException - * if player is not online + * @param p the player to teleport on the world + * @exception NullPointerException if p is null + * @exception IllegalArgumentException if player is not online */ public void load(Player p) { if (!Bukkit.isPrimaryThread()) { @@ -211,6 +202,7 @@ public class SystemWorld { unloading = false; p.sendMessage(MessageConfig.getSettingUpWorld()); + // Move World into Server dir String worlddir = PluginConfig.getWorlddir(); File world = new File(worlddir + "/" + worldname); @@ -263,8 +255,7 @@ public class SystemWorld { * Trys to create a new systemworld with all entries etc. finally loads the * world * - * @param p - * Player to create the world for + * @param p Player to create the world for * @return whether it succesfull or not */ public static boolean create(Player p) { @@ -329,8 +320,13 @@ public class SystemWorld { sw.setCreating(true); // For #16 WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { - if (p != null && p.isOnline()) + if (p != null && p.isOnline()) { p.sendMessage(MessageConfig.getWorldCreated()); + SettingsConfig.getCommandsonGet().stream() + .map(s -> s.replace("%player", p.getName()).replace("%world", sw.getName()).replace("%uuid", + p.getUniqueId().toString())) + .forEach(s -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), s)); + } }); } return true; @@ -362,12 +358,9 @@ public class SystemWorld { /** * Teleports the player to the world with the given settings in the config * - * @param p - * player to teleport - * @exception NullPointerException - * if player is null - * @exception IllegalArgumentException - * if player is not online + * @param p player to teleport + * @exception NullPointerException if player is null + * @exception IllegalArgumentException if player is not online */ public void teleportToWorldSpawn(Player p) { Preconditions.checkNotNull(p, "player must not be null"); diff --git a/WorldSystem/src/main/resources/settings.yml b/WorldSystem/src/main/resources/settings.yml index b03b781..cc08d1d 100644 --- a/WorldSystem/src/main/resources/settings.yml +++ b/WorldSystem/src/main/resources/settings.yml @@ -20,6 +20,14 @@ worldborder: y: 20 z: 0 + +# Commands that should be executed on /ws get when it is ready +# Placeholders: %player: Name of player, %world: Name of world, %uuid: UUID of player +commands_on_get: +#- tell %player You have got a world +#- tell %player You are now on %world + + # All Gamerules in 1.12 # Not supported gamerules will be ignored #