mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-22 16:09:16 +00:00
Add NullablePlayerHandler
Add Teleport Command
This commit is contained in:
@@ -31,6 +31,7 @@ import com.volmit.iris.util.decree.DecreeExecutor;
|
|||||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||||
import com.volmit.iris.util.decree.annotations.Decree;
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
import com.volmit.iris.util.decree.annotations.Param;
|
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.C;
|
||||||
import com.volmit.iris.util.format.Form;
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
@@ -41,6 +42,8 @@ import com.volmit.iris.util.scheduling.jobs.QueueJob;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Chunk;
|
import org.bukkit.Chunk;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -127,6 +130,31 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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")
|
@Decree(description = "Print version information")
|
||||||
public void version() {
|
public void version() {
|
||||||
sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software");
|
sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software");
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user