Added executable commands on /ws get

This commit is contained in:
Butzlabben 2018-10-03 17:34:09 +02:00
parent 620d0e911a
commit 685a965629
5 changed files with 41 additions and 32 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>de.butzlabben.world</groupId> <groupId>de.butzlabben.world</groupId>
<artifactId>WorldSystem</artifactId> <artifactId>WorldSystem</artifactId>
<version>2.4.0</version> <version>2.4.0.1</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.number>-</project.build.number> <project.build.number>-</project.build.number>

View File

@ -9,6 +9,7 @@ import java.io.InputStreamReader;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -170,6 +171,13 @@ public class SettingsConfig {
borderSizes.put(s, cfg.getLong("worldborder.ranks." + s)); borderSizes.put(s, cfg.getLong("worldborder.ranks." + s));
} }
} }
/**
* @return the commands specified in settings.yml on /ws get
*/
public static List<String> getCommandsonGet() {
YamlConfiguration cfg = getConfig();
return cfg.getStringList("commands_on_get");
}
private SettingsConfig() { private SettingsConfig() {
} }

View File

@ -35,7 +35,7 @@ public class AsyncCreatorAdapter implements CreatorAdapter {
if (sw != null) if (sw != null)
sw.setCreating(false); sw.setCreating(false);
// Send the play the message // Send the message
r.run(); r.run();
} }
}); });

View File

@ -18,6 +18,7 @@ import de.butzlabben.world.WorldSystem;
import de.butzlabben.world.config.DependenceConfig; import de.butzlabben.world.config.DependenceConfig;
import de.butzlabben.world.config.MessageConfig; import de.butzlabben.world.config.MessageConfig;
import de.butzlabben.world.config.PluginConfig; import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.SettingsConfig;
import de.butzlabben.world.config.WorldConfig; import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.event.WorldCreateEvent; import de.butzlabben.world.event.WorldCreateEvent;
import de.butzlabben.world.event.WorldLoadEvent; 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 * This method is the online way to get a system world instance
* *
* @param worldname * @param worldname as in minecraft
* as in minecraft
* @return a systemworld instance if it is a systemworld or null if is not a * @return a systemworld instance if it is a systemworld or null if is not a
* systemworld * systemworld
* @exception NullPointerException * @exception NullPointerException worldname == null
* worldname == null
*/ */
public static SystemWorld getSystemWorld(String worldname) { public static SystemWorld getSystemWorld(String worldname) {
Preconditions.checkNotNull(worldname, "worldname must not be null"); Preconditions.checkNotNull(worldname, "worldname must not be null");
@ -61,9 +60,8 @@ public class SystemWorld {
} }
/** /**
* @param w * @param w a world in bukkit, no matter if systemworld or not Trys to unload a
* a world in bukkit, no matter if systemworld or not Trys to * systemworld later, with the given delay in the config
* unload a systemworld later, with the given delay in the config
*/ */
public static void tryUnloadLater(World w) { public static void tryUnloadLater(World w) {
if (w != null) if (w != null)
@ -84,10 +82,8 @@ public class SystemWorld {
/** /**
* Trys to force-unload this world * Trys to force-unload this world
* *
* @param w * @param w associated world
* associated world * @exception NullPointerException w == null
* @exception NullPointerException
* w == null
*/ */
public void directUnload(World w) { public void directUnload(World w) {
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
@ -126,10 +122,8 @@ public class SystemWorld {
/** /**
* Trys to unload this world later, with the given delay in the config * Trys to unload this world later, with the given delay in the config
* *
* @param w * @param w the associated world
* the associated world * @exception NullPointerException w == null
* @exception NullPointerException
* w == null
*/ */
public void unloadLater(World w) { public void unloadLater(World w) {
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
@ -181,12 +175,9 @@ public class SystemWorld {
/** /**
* Trys to load this world, and messages the player about the process * Trys to load this world, and messages the player about the process
* *
* @param p * @param p the player to teleport on the world
* the player to teleport on the world * @exception NullPointerException if p is null
* @exception NullPointerException * @exception IllegalArgumentException if player is not online
* if p is null
* @exception IllegalArgumentException
* if player is not online
*/ */
public void load(Player p) { public void load(Player p) {
if (!Bukkit.isPrimaryThread()) { if (!Bukkit.isPrimaryThread()) {
@ -211,6 +202,7 @@ public class SystemWorld {
unloading = false; unloading = false;
p.sendMessage(MessageConfig.getSettingUpWorld()); p.sendMessage(MessageConfig.getSettingUpWorld());
// Move World into Server dir // Move World into Server dir
String worlddir = PluginConfig.getWorlddir(); String worlddir = PluginConfig.getWorlddir();
File world = new File(worlddir + "/" + worldname); 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 * Trys to create a new systemworld with all entries etc. finally loads the
* world * world
* *
* @param p * @param p Player to create the world for
* Player to create the world for
* @return whether it succesfull or not * @return whether it succesfull or not
*/ */
public static boolean create(Player p) { public static boolean create(Player p) {
@ -329,8 +320,13 @@ public class SystemWorld {
sw.setCreating(true); sw.setCreating(true);
// For #16 // For #16
WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> { WorldSystem.getInstance().getAdapter().create(event.getWorldCreator(), sw, () -> {
if (p != null && p.isOnline()) if (p != null && p.isOnline()) {
p.sendMessage(MessageConfig.getWorldCreated()); 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; return true;
@ -362,12 +358,9 @@ public class SystemWorld {
/** /**
* Teleports the player to the world with the given settings in the config * Teleports the player to the world with the given settings in the config
* *
* @param p * @param p player to teleport
* player to teleport * @exception NullPointerException if player is null
* @exception NullPointerException * @exception IllegalArgumentException if player is not online
* if player is null
* @exception IllegalArgumentException
* if player is not online
*/ */
public void teleportToWorldSpawn(Player p) { public void teleportToWorldSpawn(Player p) {
Preconditions.checkNotNull(p, "player must not be null"); Preconditions.checkNotNull(p, "player must not be null");

View File

@ -20,6 +20,14 @@ worldborder:
y: 20 y: 20
z: 0 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 # All Gamerules in 1.12
# Not supported gamerules will be ignored # Not supported gamerules will be ignored
# #