Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Nov 7, 2021
1 parent c1887c4 commit dfd3d99
Showing 1 changed file with 8 additions and 14 deletions.
Expand Up @@ -31,6 +31,7 @@ public ExecuteCommand() {
setSyntax("execute [as_player/as_op/as_npc/as_server] [<Bukkit-command>] (silent)");
setRequiredArguments(2, 3);
isProcedural = false;
setBooleansHandled("silent");
}

// <--[command]
Expand Down Expand Up @@ -102,10 +103,6 @@ else if (arg.matches("asserver", "as_server")
&& !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", new ElementTag("AS_SERVER"));
}
else if (!scriptEntry.hasObject("silent")
&& arg.matches("silent")) {
scriptEntry.addObject("silent", new ElementTag("true"));
}
else if (!scriptEntry.hasObject("command")) {
scriptEntry.addObject("command", new ElementTag(arg.getRawValue()));
}
Expand All @@ -119,16 +116,15 @@ else if (!scriptEntry.hasObject("command")) {
if (!scriptEntry.hasObject("command")) {
throw new InvalidArgumentsException("Missing command text!");
}
scriptEntry.defaultObject("silent", new ElementTag("false"));
}

@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag cmd = scriptEntry.getElement("command");
ElementTag type = scriptEntry.getElement("type");
ElementTag silent = scriptEntry.getElement("silent");
boolean silent = scriptEntry.argAsBoolean("silent");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), type, cmd, silent);
Debug.report(scriptEntry, getName(), type, cmd, db("silent", silent));
}
String command = cmd.asString();
switch (Type.valueOf(type.asString())) {
Expand All @@ -137,15 +133,14 @@ public void execute(ScriptEntry scriptEntry) {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), "/" + command);
Bukkit.getPluginManager().callEvent(pcpe);
if (!pcpe.isCancelled()) {
boolean silentBool = silent.asBoolean();
Player player = Utilities.getEntryPlayer(scriptEntry).getPlayerEntity();
if (silentBool) {
if (silent) {
NetworkInterceptHelper.enable();
silencedPlayers.add(player.getUniqueId());
}
player.performCommand(pcpe.getMessage().startsWith("/") ?
pcpe.getMessage().substring(1) : pcpe.getMessage());
if (silentBool) {
if (silent) {
silencedPlayers.remove(player.getUniqueId());
}
}
Expand All @@ -170,14 +165,13 @@ public void execute(ScriptEntry scriptEntry) {
PlayerCommandPreprocessEvent pcpe = new PlayerCommandPreprocessEvent(player, "/" + command);
Bukkit.getPluginManager().callEvent(pcpe);
if (!pcpe.isCancelled()) {
boolean silentBool = silent.asBoolean();
if (silentBool) {
if (silent) {
NetworkInterceptHelper.enable();
silencedPlayers.add(player.getUniqueId());
}
player.performCommand(pcpe.getMessage().startsWith("/") ?
pcpe.getMessage().substring(1) : pcpe.getMessage());
if (silentBool) {
if (silent) {
silencedPlayers.remove(player.getUniqueId());
}
}
Expand Down Expand Up @@ -211,7 +205,7 @@ public void execute(ScriptEntry scriptEntry) {
break;
case AS_SERVER:
dcs.clearOutput();
dcs.silent = silent.asBoolean();
dcs.silent = silent;
ServerCommandEvent sce = new ServerCommandEvent(dcs, command);
Bukkit.getPluginManager().callEvent(sce);
Denizen.getInstance().getServer().dispatchCommand(dcs, sce.getCommand());
Expand Down

0 comments on commit dfd3d99

Please sign in to comment.