Skip to content

Commit

Permalink
improve playeffect arg matching
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 23, 2020
1 parent ab19097 commit c623649
Showing 1 changed file with 2 additions and 18 deletions.
Expand Up @@ -89,17 +89,14 @@ public PlayEffectCommand() {

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

ParticleHelper particleHelper = NMSHandler.getParticleHelper();

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

if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentList(LocationTag.class)) {
&& arg.matchesArgumentList(LocationTag.class)
&& (arg.matchesPrefix("at") || !arg.hasPrefix())) {
if (arg.matchesPrefix("at")) {
scriptEntry.addObject("no_offset", new ElementTag(true));
}

scriptEntry.addObject("location", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
continue;
}
Expand All @@ -108,7 +105,6 @@ else if (!scriptEntry.hasObject("effect") &&
!scriptEntry.hasObject("iconcrack") &&
!scriptEntry.hasObject("blockcrack") &&
!scriptEntry.hasObject("blockdust")) {

if (particleHelper.hasParticle(arg.getValue())) {
scriptEntry.addObject("particleeffect", particleHelper.getParticle(arg.getValue()));
continue;
Expand Down Expand Up @@ -167,13 +163,11 @@ else if (NMSHandler.getParticleHelper().effectRemap.containsKey(arg.getValue().t
if (!scriptEntry.hasObject("radius")
&& arg.matchesFloat()
&& arg.matchesPrefix("visibility", "v", "radius", "r")) {

scriptEntry.addObject("radius", arg.asElement());
}
else if (!scriptEntry.hasObject("data")
&& arg.matchesFloat()
&& arg.matchesPrefix("data", "d")) {

scriptEntry.addObject("data", arg.asElement());
}
else if (!scriptEntry.hasObject("special_data")
Expand All @@ -183,52 +177,42 @@ else if (!scriptEntry.hasObject("special_data")
else if (!scriptEntry.hasObject("qty")
&& arg.matchesInteger()
&& arg.matchesPrefix("qty", "q", "quantity")) {

scriptEntry.addObject("qty", arg.asElement());
}
else if (!scriptEntry.hasObject("offset")
&& arg.matchesFloat()
&& arg.matchesPrefix("offset", "o")) {

double offset = arg.asElement().asDouble();
scriptEntry.addObject("offset", new LocationTag(null, offset, offset, offset));
}
else if (!scriptEntry.hasObject("offset")
&& arg.matchesArgumentType(LocationTag.class)
&& arg.matchesPrefix("offset", "o")) {

scriptEntry.addObject("offset", arg.asType(LocationTag.class));
}
else if (!scriptEntry.hasObject("targets")
&& arg.matchesArgumentList(PlayerTag.class)
&& arg.matchesPrefix("targets", "target", "t")) {

scriptEntry.addObject("targets", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
}
else {
arg.reportUnhandled();
}
}

// Use default values if necessary
scriptEntry.defaultObject("location",
Utilities.entryHasNPC(scriptEntry) && Utilities.getEntryNPC(scriptEntry).isSpawned() ? Arrays.asList(Utilities.getEntryNPC(scriptEntry).getLocation()) : null,
Utilities.entryHasPlayer(scriptEntry) && Utilities.getEntryPlayer(scriptEntry).isOnline() ? Arrays.asList(Utilities.getEntryPlayer(scriptEntry).getLocation()) : null);
scriptEntry.defaultObject("data", new ElementTag(0));
scriptEntry.defaultObject("radius", new ElementTag(15));
scriptEntry.defaultObject("qty", new ElementTag(1));
scriptEntry.defaultObject("offset", new LocationTag(null, 0.5, 0.5, 0.5));

// Check to make sure required arguments have been filled

if (!scriptEntry.hasObject("effect") &&
!scriptEntry.hasObject("particleeffect") &&
!scriptEntry.hasObject("iconcrack") &&
!scriptEntry.hasObject("blockcrack") &&
!scriptEntry.hasObject("blockdust")) {
throw new InvalidArgumentsException("Missing effect argument!");
}

if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Missing location argument!");
}
Expand Down

0 comments on commit c623649

Please sign in to comment.