Skip to content

Commit

Permalink
drop command cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 17, 2021
1 parent 56a6951 commit 52543bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
Expand Up @@ -88,43 +88,41 @@ public void addCustomTabCompletions(String arg, Consumer<String> addOne) {

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

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

if (!scriptEntry.hasObject("action")
&& arg.matchesArgumentList(ItemTag.class)) {
scriptEntry.addObject("action", new ElementTag(Action.DROP_ITEM.toString()).setPrefix("action"));
scriptEntry.addObject("item", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
}
else if (!scriptEntry.hasObject("action")
&& arg.matches("experience", "exp", "xp")) {
scriptEntry.addObject("action", new ElementTag(Action.DROP_EXP.toString()).setPrefix("action"));
}
else if (!scriptEntry.hasObject("action")
&& arg.matchesArgumentType(EntityTag.class)) {
// Entity arg
scriptEntry.addObject("action", new ElementTag(Action.DROP_ENTITY.toString()).setPrefix("action"));
scriptEntry.addObject("entity", arg.asType(EntityTag.class).setPrefix("entity"));
}
else if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class).setPrefix("location"));
}
else if (!scriptEntry.hasObject("speed")
&& arg.matchesPrefix("speed")
&& arg.matchesFloat()) {
scriptEntry.addObject("speed", arg.asElement());
}
else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(DurationTag.class)
&& arg.matchesPrefix("delay", "d")) {
scriptEntry.addObject("delay", arg.asType(DurationTag.class));
}
else if (!scriptEntry.hasObject("quantity")
&& arg.matchesInteger()) {
&& arg.matchesInteger()
&& arg.matchesPrefix("quantity", "q", "qty", "a", "amt", "amount")) {
if (arg.matchesPrefix("q", "qty")) {
Deprecations.qtyTags.warn(scriptEntry);
}
scriptEntry.addObject("quantity", arg.asElement().setPrefix("quantity"));
}
else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(DurationTag.class)
&& arg.matchesPrefix("delay", "d")) {
scriptEntry.addObject("delay", arg.asType(DurationTag.class));
else if (!scriptEntry.hasObject("action")
&& arg.matchesArgumentList(ItemTag.class)) {
scriptEntry.addObject("action", new ElementTag(Action.DROP_ITEM.toString()).setPrefix("action"));
scriptEntry.addObject("item", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
}
else if (!scriptEntry.hasObject("action")
&& arg.matchesArgumentType(EntityTag.class)) {
scriptEntry.addObject("action", new ElementTag(Action.DROP_ENTITY.toString()).setPrefix("action"));
scriptEntry.addObject("entity", arg.asType(EntityTag.class).setPrefix("entity"));
}
else if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class).setPrefix("location"));
}
else {
arg.reportUnhandled();
Expand All @@ -137,14 +135,13 @@ else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(DurationTag.
if (Utilities.getEntryPlayer(scriptEntry) != null && Utilities.getEntryPlayer(scriptEntry).isOnline()) {
scriptEntry.addObject("location", Utilities.getEntryPlayer(scriptEntry).getLocation().setPrefix("location"));
Debug.echoDebug(scriptEntry, "Did not specify a location, assuming Player's location.");

}
else {
throw new InvalidArgumentsException("Must specify a location!");
}
}
if (!scriptEntry.hasObject("quantity")) {
scriptEntry.addObject("quantity", new ElementTag("1").setPrefix("quantity"));
scriptEntry.addObject("quantity", new ElementTag("1"));
}
}

Expand Down Expand Up @@ -172,7 +169,6 @@ public void execute(ScriptEntry scriptEntry) {
((ExperienceOrb) orb.getBukkitEntity()).setExperience(quantity.asInt());
entityList.addObject(orb);
break;

case DROP_ITEM:
for (ItemTag item : items) {
if (item.getMaterial().getMaterial() == Material.AIR) {
Expand Down Expand Up @@ -215,6 +211,5 @@ public void execute(ScriptEntry scriptEntry) {
if (entityList.size() == 1) {
scriptEntry.addObject("dropped_entity", entityList.getObject(0));
}

}
}
Expand Up @@ -53,14 +53,11 @@ public void timeEvent() {
if (hour >= 24) {
hour = hour - 24;
}

WorldTag currentWorld = new WorldTag(world);

if (!current_time.containsKey(currentWorld.identifySimple())
|| current_time.get(currentWorld.identifySimple()) != hour) {
current_time.put(currentWorld.identifySimple(), hour);
if (!current_time.containsKey(world.getName())
|| current_time.get(world.getName()) != hour) {
current_time.put(world.getName(), hour);
TimeChangeScriptEvent.instance.hour = hour;
TimeChangeScriptEvent.instance.world = currentWorld;
TimeChangeScriptEvent.instance.world = new WorldTag(world);
TimeChangeScriptEvent.instance.fire();
}
}
Expand Down

0 comments on commit 52543bb

Please sign in to comment.