Skip to content

Commit

Permalink
Add pforce_respawn()
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Jan 28, 2024
1 parent 2db12fb commit d10e117
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,6 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity, MCOfflinePlaye
void setWorldBorder(MCWorldBorder border);

String getLocale();

void respawn();
}
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,9 @@ public MCScoreboard getScoreboard() {
public void setScoreboard(MCScoreboard board) {
p.setScoreboard(((BukkitMCScoreboard) board)._scoreboard());
}

@Override
public void respawn() {
p.spigot().respawn();
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends CREThrowable>[] 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;
}
}
}

0 comments on commit d10e117

Please sign in to comment.