From d10e11798fe38ffa6cc646e2ab6952a58d945f8f Mon Sep 17 00:00:00 2001 From: PseudoKnight Date: Sun, 28 Jan 2024 06:11:06 -0800 Subject: [PATCH] Add pforce_respawn() --- .../com/laytonsmith/abstraction/MCPlayer.java | 2 + .../bukkit/entities/BukkitMCPlayer.java | 5 ++ .../core/functions/PlayerManagement.java | 52 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/main/java/com/laytonsmith/abstraction/MCPlayer.java b/src/main/java/com/laytonsmith/abstraction/MCPlayer.java index 5695fd930..a117e6932 100644 --- a/src/main/java/com/laytonsmith/abstraction/MCPlayer.java +++ b/src/main/java/com/laytonsmith/abstraction/MCPlayer.java @@ -195,4 +195,6 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye void setWorldBorder(MCWorldBorder border); String getLocale(); + + void respawn(); } diff --git a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java index 30a0e5b20..49f616168 100644 --- a/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java +++ b/src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java @@ -759,4 +759,9 @@ public MCScoreboard getScoreboard() { public void setScoreboard(MCScoreboard board) { p.setScoreboard(((BukkitMCScoreboard) board)._scoreboard()); } + + @Override + public void respawn() { + p.spigot().respawn(); + } } diff --git a/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java b/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java index cbbb7c7f0..10e5ca48a 100644 --- a/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java +++ b/src/main/java/com/laytonsmith/core/functions/PlayerManagement.java @@ -6835,4 +6835,56 @@ public Boolean runAsync() { return false; } } + + @api + public static class pforce_respawn extends AbstractFunction { + + @Override + public String getName() { + return "pforce_respawn"; + } + + @Override + public String docs() { + return "void {[player]} Forces a player to respawn immediately if they're currently dead."; + } + + @Override + public Integer[] numArgs() { + return new Integer[]{0, 1}; + } + + @Override + public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { + MCPlayer p; + if(args.length == 0) { + p = env.getEnv(CommandHelperEnvironment.class).GetPlayer(); + Static.AssertPlayerNonNull(p, t); + } else { + p = Static.GetPlayer(args[0], t); + } + p.respawn(); + return CVoid.VOID; + } + + @Override + public Class[] thrown() { + return new Class[]{CREPlayerOfflineException.class, CRELengthException.class}; + } + + @Override + public Version since() { + return MSVersion.V3_3_5; + } + + @Override + public boolean isRestricted() { + return true; + } + + @Override + public Boolean runAsync() { + return false; + } + } }