Skip to content

Commit

Permalink
fix mixed up script type check in zap/assign
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 1, 2021
1 parent ae1ca9d commit c83f40c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Expand Up @@ -84,7 +84,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
}
else if (!scriptEntry.hasObject("script")
&& arg.matchesArgumentType(ScriptTag.class)
&& arg.asType(ScriptTag.class).getType().equals("interact")
&& arg.asType(ScriptTag.class).getContainer() instanceof InteractScriptContainer
&& !arg.matchesPrefix("step")) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
}
Expand Down
Expand Up @@ -179,7 +179,7 @@ else if (!scriptEntry.hasObject("slot")
else if (!scriptEntry.hasObject("items")
&& !scriptEntry.hasObject("type")
&& arg.matchesArgumentList(ItemTag.class)) {
scriptEntry.addObject("items", ListTag.valueOf(arg.getRawValue().replace("item:", ""), scriptEntry.getContext()).filter(ItemTag.class, scriptEntry));
scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
}
else if (!scriptEntry.hasObject("inventory")
&& arg.matchesPrefix("f", "from")
Expand Down Expand Up @@ -225,8 +225,8 @@ public void execute(ScriptEntry scriptEntry) {
ElementTag nbtKey = scriptEntry.getElement("nbt_key");
ListTag flagList = scriptEntry.getObjectTag("flag_name");
List<MaterialTag> materialList = scriptEntry.getObjectTag("material");
Type type = (Type) scriptEntry.getObject("type");
List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("items");
Type type = scriptEntry.getObjectTag("type");
List<ItemTag> items = scriptEntry.getObjectTag("items");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("Type", type.name())
+ quantity.debug()
Expand Down
@@ -1,6 +1,7 @@
package com.denizenscript.denizen.scripts.commands.npc;

import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.npc.traits.AssignmentTrait;
Expand Down Expand Up @@ -62,9 +63,7 @@ private enum Action {SET, REMOVE}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (arg.matchesEnum(Action.values())
&& !scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
Expand All @@ -73,7 +72,7 @@ else if (arg.matchesArgumentType(ScriptTag.class)
&& !scriptEntry.hasObject("script")) {
// Check the type of script.. it must be an assignment-type container
if (arg.asType(ScriptTag.class) != null
&& arg.asType(ScriptTag.class).getType().equalsIgnoreCase("assignment")) {
&& arg.asType(ScriptTag.class).getContainer() instanceof AssignmentScriptContainer) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
}
else {
Expand All @@ -88,8 +87,6 @@ else if (!scriptEntry.hasObject("npcs")
arg.reportUnhandled();
}
}


if (!scriptEntry.hasObject("npcs")) {
if (!Utilities.entryHasNPC(scriptEntry)) {
throw new InvalidArgumentsException("This command requires a linked NPC!");
Expand All @@ -102,7 +99,6 @@ else if (!scriptEntry.hasObject("npcs")
if (scriptEntry.getObject("action").equals(Action.SET) && !scriptEntry.hasObject("script")) {
throw new InvalidArgumentsException("Script specified was missing or invalid.");
}

}

@Override
Expand All @@ -111,14 +107,12 @@ public void execute(ScriptEntry scriptEntry) {
ScriptTag script = scriptEntry.getObjectTag("script");
Action action = (Action) scriptEntry.getObject("action");
List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
ArgumentHelper.debugObj("action", action)
+ (script != null ? script.debug() : "")
+ ArgumentHelper.debugList("npc", npcs));
}

for (NPCTag npc : npcs) {
if (action.equals(Action.SET)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).setAssignment(script.getName(), Utilities.getEntryPlayer(scriptEntry));
Expand Down

0 comments on commit c83f40c

Please sign in to comment.