Use player world as preset when using rtp without parameters

This commit is contained in:
johnfriedrich 2022-05-22 14:48:52 +02:00 committed by Max Lee
parent b8d686d9d3
commit 18ad2b50c0
2 changed files with 16 additions and 2 deletions

View File

@ -41,7 +41,14 @@ public class RandomTeleportCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0) {
if (sender instanceof Player) {
runPreset("default", sender, (Player) sender, ((Player) sender).getLocation());
Player player = (Player) sender;
String preset = "default";
if (plugin.getConfig().getBoolean("use-player-world-as-preset", false)) {
String worldName = player.getWorld().getName().toLowerCase();
if (presetExistsInConfig(worldName))
preset = worldName;
}
runPreset(preset, sender, player, player.getLocation());
return true;
}
} else if (args.length == 1) {
@ -88,7 +95,7 @@ public class RandomTeleportCommand implements CommandExecutor {
);
} else if (sender != target && !sender.hasPermission("randomteleport.tpothers")) {
plugin.sendMessage(sender, "error.no-permission.tp-others", "perm", "randomteleport.tpothers");
} else if (plugin.getConfig().getString("presets." + preset) == null) {
} else if (!presetExistsInConfig(preset)) {
plugin.sendMessage(sender, "error.preset-doesnt-exist", "preset", preset);
} else {
if (sender == target) {
@ -109,6 +116,10 @@ public class RandomTeleportCommand implements CommandExecutor {
}
}
private boolean presetExistsInConfig(String preset) {
return plugin.getConfig().getString("presets." + preset) != null;
}
private static Location getLocation(CommandSender sender) {
if (sender instanceof Entity) {
return ((Entity) sender).getLocation();

View File

@ -4,6 +4,9 @@ lang: en
debug: true
# Delay in ticks between checking chunks when searching
# Should we search for a preset named like the world the player is in when using /rtp without parameters?
use-player-world-as-preset: false
# Blocks to teleport on in normal mode
safe-blocks:
- sand