This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
/
ExecuteCommand.java
74 lines (66 loc) · 2.59 KB
/
ExecuteCommand.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
package com.denizenscript.denizen2sponge.commands.server;
import com.denizenscript.denizen2core.commands.AbstractCommand;
import com.denizenscript.denizen2core.commands.CommandEntry;
import com.denizenscript.denizen2core.commands.CommandQueue;
import com.denizenscript.denizen2core.utilities.CoreUtilities;
import com.denizenscript.denizen2core.utilities.debugging.ColorSet;
import com.denizenscript.denizen2sponge.tags.objects.PlayerTag;
import org.spongepowered.api.Sponge;
public class ExecuteCommand extends AbstractCommand {
// <--[command]
// @Name execute
// @Arguments 'as_server'/'as_player' <command> [source]
// @Short executes a command as the specified command sender.
// @Updated 2016/09/22
// @Group World
// @Minimum 2
// @Maximum 3
// @Description
// Executes a command as the specified command sender.
// TODO: Explain more!
// @Example
// # This example stops the server.
// - execute as_server "stop"
// @Example
// # This example makes the specified player execute 'say hi'.
// - execute as_player "say hi" <player>
// -->
@Override
public String getName() {
return "execute";
}
@Override
public String getArguments() {
return "'as_server'/'as_player' <command> [source]";
}
@Override
public int getMinimumArguments() {
return 2;
}
@Override
public int getMaximumArguments() {
return 3;
}
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
String mode = CoreUtilities.toLowerCase(entry.getArgumentObject(queue, 0).toString());
String cmd = entry.getArgumentObject(queue, 1).toString();
if (mode.equals("as_server")) {
Sponge.getCommandManager().process(Sponge.getServer().getConsole(), cmd);
if (queue.shouldShowGood()) {
queue.outGood("Executed " + ColorSet.emphasis + cmd + ColorSet.good + " as the server!");
}
}
else if (mode.equals("as_player")) {
PlayerTag player = PlayerTag.getFor(queue.error, entry.getArgumentObject(queue, 2));
Sponge.getCommandManager().process(player.getInternal(), cmd);
if (queue.shouldShowGood()) {
queue.outGood("Executed " + ColorSet.emphasis + cmd + ColorSet.good + " as the player: "
+ ColorSet.emphasis + player.debug());
}
}
else {
queue.handleError(entry, "Invalid mode specified: '" + mode + "'!");
}
}
}