From 8939a903bee0baf0591ca7de6938f6bc02a3dcf4 Mon Sep 17 00:00:00 2001 From: CrazyDev22 Date: Sun, 1 Oct 2023 16:50:50 +0200 Subject: [PATCH] Add NullablePlayerHandler Add Teleport Command --- .../iris/core/commands/CommandIris.java | 72 +++++++++++++++---- .../NullablePlayerHandler.java | 13 ++++ 2 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/volmit/iris/util/decree/specialhandlers/NullablePlayerHandler.java diff --git a/src/main/java/com/volmit/iris/core/commands/CommandIris.java b/src/main/java/com/volmit/iris/core/commands/CommandIris.java index 507e58365..3f9707355 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandIris.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandIris.java @@ -25,13 +25,13 @@ import com.volmit.iris.core.tools.IrisToolbelt; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.IrisDimension; import com.volmit.iris.engine.platform.PlatformChunkGenerator; -import com.volmit.iris.engine.safeguard.ServerBoot; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeContext; import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeOrigin; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; +import com.volmit.iris.util.decree.specialhandlers.NullablePlayerHandler; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.parallel.BurstExecutor; @@ -42,13 +42,14 @@ import com.volmit.iris.util.scheduling.jobs.QueueJob; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import java.io.File; +import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; -import static com.volmit.iris.engine.safeguard.ServerBoot.multiverse; - @Decree(name = "iris", aliases = {"ir", "irs"}, description = "Basic Command") public class CommandIris implements DecreeExecutor { private CommandStudio studio; @@ -56,7 +57,6 @@ public class CommandIris implements DecreeExecutor { private CommandSettings settings; private CommandObject object; private CommandJigsaw jigsaw; - private CommandWorldManager manager; private CommandWhat what; private CommandEdit edit; private CommandFind find; @@ -70,14 +70,6 @@ public class CommandIris implements DecreeExecutor { @Param(description = "The seed to generate the world with", defaultValue = "1337") long seed ) { - if (multiverse){ - sender().sendMessage(C.RED + "Your server has a incompatibility that may corrupt all worlds on the server if not handled properly."); - sender().sendMessage(C.RED + "its heavily advised for you to take action. see log for full detail"); - Iris.safeguard(C.RED + "----------------------------------------------------------------"); - Iris.safeguard(C.RED + "Command ran: /iris create"); - ServerBoot.incompatiblepluginset(); - Iris.safeguard(C.RED + "----------------------------------------------------------------"); - } if (name.equals("iris")) { sender().sendMessage(C.RED + "You cannot use the world name \"iris\" for creating worlds as Iris uses this directory for studio worlds."); sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?"); @@ -107,6 +99,62 @@ public class CommandIris implements DecreeExecutor { sender().sendMessage(C.GREEN + "Successfully created your world!"); } + @Decree(description = "Remove an Iris world", aliases = {"del", "rm"}, sync = true) + public void remove( + @Param(description = "The world to remove") + World world, + @Param(description = "Whether to also remove the folder (if set to false, just does not load the world)", defaultValue = "true") + boolean delete + ) { + if (!IrisToolbelt.isIrisWorld(world)) { + sender().sendMessage(C.RED + "This is not an Iris world. Iris worlds: " + String.join(", ", Bukkit.getServer().getWorlds().stream().filter(IrisToolbelt::isIrisWorld).map(World::getName).toList())); + return; + } + sender().sendMessage(C.GREEN + "Removing world: " + world.getName()); + try { + if (IrisToolbelt.removeWorld(world)) { + sender().sendMessage(C.GREEN + "Successfully removed " + world.getName() + " from bukkit.yml"); + } else { + sender().sendMessage(C.YELLOW + "Looks like the world was already removed from bukkit.yml"); + } + } catch (IOException e) { + sender().sendMessage(C.RED + "Failed to save bukkit.yml because of " + e.getMessage()); + e.printStackTrace(); + } + IrisToolbelt.evacuate(world, "Deleting world"); + Bukkit.unloadWorld(world, false); + if (delete && world.getWorldFolder().delete()) { + sender().sendMessage(C.GREEN + "Successfully removed world folder"); + } else { + sender().sendMessage(C.RED + "Failed to remove world folder"); + } + } + + @Decree(description = "Teleport to another world", aliases = {"tp"}, sync = true) + public void teleport( + @Param(description = "World to teleport to") + World world, + @Param(description = "Player to teleport", defaultValue = "---", customHandler = NullablePlayerHandler.class) + Player player + ) { + if (player == null && sender().isPlayer()) + player = sender().player(); + + final Player target = player; + if (target == null) { + sender().sendMessage(C.RED + "The specified player does not exist."); + return; + } + + new BukkitRunnable() { + @Override + public void run() { + target.teleport(world.getSpawnLocation()); + target.sendMessage(C.GREEN + "You have been teleported to " + world.getName() + "."); + } + }.runTask(Iris.instance); + } + @Decree(description = "Print version information") public void version() { sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software"); diff --git a/src/main/java/com/volmit/iris/util/decree/specialhandlers/NullablePlayerHandler.java b/src/main/java/com/volmit/iris/util/decree/specialhandlers/NullablePlayerHandler.java new file mode 100644 index 000000000..3c7567140 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/specialhandlers/NullablePlayerHandler.java @@ -0,0 +1,13 @@ +package com.volmit.iris.util.decree.specialhandlers; + +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; +import com.volmit.iris.util.decree.handlers.PlayerHandler; +import org.bukkit.entity.Player; + +public class NullablePlayerHandler extends PlayerHandler { + + @Override + public Player parse(String in, boolean force) throws DecreeParsingException { + return getPossibilities(in).stream().filter((i) -> toString(i).equalsIgnoreCase(in)).findFirst().orElse(null); + } +}