Merge pull request #521 from CocoTheOwner/patchExecute

Patch execute command
This commit is contained in:
Dan 2021-08-10 07:21:19 -04:00 committed by GitHub
commit bebad4d361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,7 +30,7 @@ import com.volmit.iris.util.plugin.VolmitSender;
public class CommandIrisStudioExecute extends MortarCommand { public class CommandIrisStudioExecute extends MortarCommand {
public CommandIrisStudioExecute() { public CommandIrisStudioExecute() {
super("execute", "ex"); super("execute", "ex", "exec");
requiresPermission(Iris.perm.studio); requiresPermission(Iris.perm.studio);
setDescription("Execute a script"); setDescription("Execute a script");
setCategory("Studio"); setCategory("Studio");
@ -44,12 +44,15 @@ public class CommandIrisStudioExecute extends MortarCommand {
sender.sendMessage("Tab complete options only work for summons while in an Iris world."); sender.sendMessage("Tab complete options only work for summons while in an Iris world.");
} else if (args.length == 0) { } else if (args.length == 0) {
list.add(data.getScriptLoader().getPossibleKeys()); list.add(data.getScriptLoader().getPossibleKeys());
} else if (args.length == 1) { } else {
list.add(data.getScriptLoader().getPossibleKeys(args[0])); list.add(data.getScriptLoader().getPossibleKeys(args[0]));
} }
} else {
sender.sendMessage("You must be in an Iris world as a player to run scripts!");
} }
} }
@SuppressWarnings("null")
@Override @Override
public boolean handle(VolmitSender sender, String[] args) { public boolean handle(VolmitSender sender, String[] args) {
if (!IrisSettings.get().isStudio()) { if (!IrisSettings.get().isStudio()) {
@ -57,13 +60,24 @@ public class CommandIrisStudioExecute extends MortarCommand {
return true; return true;
} }
PlatformChunkGenerator a = IrisToolbelt.access(sender.player().getWorld()); if (!sender.isPlayer() || !IrisToolbelt.isIrisWorld(sender.player().getWorld())){
sender.sendMessage("To execute scripts you must be in an Iris world as a player");
if (a != null) { return true;
a.getEngine().getExecution().execute(args[0]);
Iris.info("Executed. See script output in console.");
} }
if (args.length == 0){
sender.sendMessage("You need to specify a script name (use auto-completions to see which are available)");
return true;
}
Iris.info("Executing script: " + args[0] + ". See script output in console.");
try {
IrisToolbelt.access(sender.player().getWorld()).getEngine().getExecution().execute(args[0]);
} catch (Throwable e){
Iris.reportError(e);
sender.sendMessage("Failed to execute script " + args[0] + "!");
}
return true; return true;
} }