Skip to content

Commit

Permalink
Warn on player/npc arg misuse
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 29, 2020
1 parent cd98484 commit 13f2253
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -38,7 +38,9 @@ public BossBarCommand() {
// Displays a boss bar at the top of the screen of the specified player(s). You can also update the
// values and remove the bar.
//
// Requires an ID. Progress must be between 0 and 1.
// Requires an ID.
//
// Progress must be between 0 and 1.
//
// Valid colors: BLUE, GREEN, PINK, PURPLE, RED, WHITE, YELLOW.
// Valid styles: SEGMENTED_10, SEGMENTED_12, SEGMENTED_20, SEGMENTED_6, SOLID.
Expand Down
Expand Up @@ -23,11 +23,14 @@
import com.denizenscript.denizencore.tags.TagManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.Debuggable;
import com.denizenscript.denizencore.utilities.debugging.StrongWarning;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.function.Consumer;

public class DenizenCoreImplementation implements DenizenImplementation {
Expand Down Expand Up @@ -188,10 +191,17 @@ public boolean needsHandleArgPrefix(String prefix) {
// If you need to use the original player/NPC in a tag on the same line, use the define command to track it.
// -->

public static StrongWarning invalidPlayerArg = new StrongWarning("The 'player:' arg should not be used in commands like define/flag/yaml/... just input the player directly instead.");
public static StrongWarning invalidNpcArg = new StrongWarning("The 'npc:' arg should not be used in commands like define/flag/yaml/... just input the npc directly instead.");
public static HashSet<String> invalidPlayerArgCommands = new HashSet<>(Arrays.asList("DEFINE", "FLAG", "YAML"));

@Override
public boolean handleCustomArgs(ScriptEntry scriptEntry, Argument arg, boolean if_ignore) {
// Fill player/off-line player
if (arg.matchesPrefix("player") && !if_ignore) {
if (invalidPlayerArgCommands.contains(scriptEntry.getCommandName())) {
invalidPlayerArg.warn(scriptEntry);
}
Debug.echoDebug(scriptEntry, "...replacing the linked player with " + arg.getValue());
String value = TagManager.tag(arg.getValue(), scriptEntry.getContext());
PlayerTag player = PlayerTag.valueOf(value);
Expand All @@ -204,6 +214,9 @@ public boolean handleCustomArgs(ScriptEntry scriptEntry, Argument arg, boolean i

// Fill NPC argument
else if (arg.matchesPrefix("npc") && !if_ignore) {
if (invalidPlayerArgCommands.contains(scriptEntry.getCommandName())) {
invalidNpcArg.warn(scriptEntry);
}
Debug.echoDebug(scriptEntry, "...replacing the linked NPC with " + arg.getValue());
String value = TagManager.tag(arg.getValue(), scriptEntry.getContext());
NPCTag npc = NPCTag.valueOf(value);
Expand Down

0 comments on commit 13f2253

Please sign in to comment.