-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
BungeeRunCommand.java
91 lines (85 loc) · 3.78 KB
/
BungeeRunCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.denizenscript.depenizen.bukkit.commands.bungee;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.depenizen.bukkit.bungee.BungeeBridge;
import com.denizenscript.depenizen.bukkit.bungee.packets.out.KeepAlivePacketOut;
import com.denizenscript.depenizen.bukkit.bungee.packets.out.RedirectPacketOut;
import com.denizenscript.depenizen.bukkit.bungee.packets.out.redirectable.RunScriptPacketOut;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.ElementTag;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.objects.ListTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import java.util.UUID;
public class BungeeRunCommand extends AbstractCommand {
// <--[command]
// @Name BungeeRun
// @Syntax bungeerun [<server>|...] [<script name>] (def:<definition>|...)
// @Group Depenizen
// @Plugin Depenizen, BungeeCord
// @Required 2
// @Short Runs a task script on another server.
//
// @Description
// This command runs a task on another server on the Bungee network. Works similarly to the 'run' command.
//
// @Tags
// None
//
// @Usage
// Use to run a simple task on another server.
// - bungeerun lobby my_script def:32
//
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : ArgumentHelper.interpretArguments(scriptEntry.aHArgs)) {
if (!scriptEntry.hasObject("def")
&& arg.matchesPrefix("def")) {
scriptEntry.addObject("def", arg.asElement());
}
else if (!scriptEntry.hasObject("servers")) {
scriptEntry.addObject("servers", arg.asType(ListTag.class));
}
else if (!scriptEntry.hasObject("script_name")) {
scriptEntry.addObject("script_name", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("script_name")) {
throw new InvalidArgumentsException("Must define a SCRIPT to be run.");
}
if (!scriptEntry.hasObject("servers")) {
throw new InvalidArgumentsException("Must define servers to run the script on.");
}
scriptEntry.defaultObject("def", new ElementTag(""));
}
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag def = scriptEntry.getElement("def");
ListTag servers = scriptEntry.getdObject("servers");
ElementTag scriptName = scriptEntry.getElement("script_name");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), def.debug() + servers.debug() + scriptName.debug());
}
if (!BungeeBridge.instance.connected) {
Debug.echoError("Cannot BungeeRun: bungee is not connected!");
return;
}
RunScriptPacketOut packetScript = new RunScriptPacketOut();
packetScript.playerUUID = Utilities.entryHasPlayer(scriptEntry) ?
Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer().getUniqueId()
: new UUID(0, 0);
packetScript.scriptName = scriptName.asString();
packetScript.defs = def.asString();
for (String server : servers) {
RedirectPacketOut packet = new RedirectPacketOut(server, packetScript);
BungeeBridge.instance.sendPacket(packet);
BungeeBridge.instance.sendPacket(new KeepAlivePacketOut());
}
}
}