-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
DenizenCommand.java
117 lines (108 loc) · 4.65 KB
/
DenizenCommand.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package net.aufdemrand.denizen.utilities;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.scripts.containers.core.CommandScriptContainer;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.*;
public class DenizenCommand extends Command {
private CommandScriptContainer script;
public DenizenCommand(CommandScriptContainer script) {
super(script.getCommandName(), script.getDescription(), script.getUsage(), script.getAliases());
this.script = script;
}
public boolean canSeeHelp(CommandSender commandSender) {
if (!script.hasAllowedHelpProcedure()) return true;
Map<String, dObject> context = new HashMap<String, dObject>();
dPlayer player = null;
dNPC npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (Depends.citizens == null || !CitizensAPI.getNPCRegistry().isNPC(pl))
player = dPlayer.mirrorBukkitPlayer(pl);
context.put("server", Element.FALSE);
}
else {
context.put("server", Element.TRUE);
}
return script.runAllowedHelpProcedure(player, npc, context);
}
@Override
public boolean execute(CommandSender commandSender, String commandLabel, String[] arguments) {
Map<String, dObject> context = new HashMap<String, dObject>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(aH.buildArgs(raw_args));
context.put("args", new dList(args));
context.put("raw_args", new Element(raw_args));
dPlayer player = null;
dNPC npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(pl))
npc = dNPC.fromEntity(pl);
else
player = dPlayer.mirrorBukkitPlayer(pl);
context.put("server", Element.FALSE);
}
else {
context.put("server", Element.TRUE);
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null)
npc = dNPC.mirrorCitizensNPC(citizen);
}
script.runCommandScript(player, npc, context);
return true;
}
@Override
public boolean isRegistered() {
return true;
}
@Override
public List<String> tabComplete(CommandSender commandSender, String alias, String[] arguments) {
if (!script.hasTabCompleteProcedure()) return super.tabComplete(commandSender, alias, arguments);
Map<String, dObject> context = new HashMap<String, dObject>();
String raw_args = "";
if (arguments.length > 0) {
StringBuilder rawArgsBuilder = new StringBuilder();
for (String arg : arguments) {
rawArgsBuilder.append(arg).append(' ');
}
raw_args = rawArgsBuilder.substring(0, rawArgsBuilder.length() - 1);
}
List<String> args = Arrays.asList(aH.buildArgs(raw_args));
context.put("args", new dList(args));
context.put("raw_args", new Element(raw_args));
context.put("alias", new Element(alias));
dPlayer player = null;
dNPC npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (Depends.citizens != null && CitizensAPI.getNPCRegistry().isNPC(pl))
npc = dNPC.fromEntity(pl);
else
player = dPlayer.mirrorBukkitPlayer(pl);
context.put("server", Element.FALSE);
}
else {
context.put("server", Element.TRUE);
}
if (Depends.citizens != null && npc == null) {
NPC citizen = CitizensAPI.getDefaultNPCSelector().getSelected(commandSender);
if (citizen != null)
npc = dNPC.mirrorCitizensNPC(citizen);
}
return script.runTabCompleteProcedure(player, npc, context);
}
}