From 96ff8a1a7b08cd49cabc0de4f0960e5796899292 Mon Sep 17 00:00:00 2001 From: Alex 'mcmonkey' Goodwin Date: Wed, 11 Nov 2020 23:55:41 -0800 Subject: [PATCH] clean up a few left over 'qty' names that still exist, clean some command code --- .../commands/entity/HealthCommand.java | 22 ++++---- .../scripts/commands/item/GiveCommand.java | 4 ++ .../scripts/commands/item/TakeCommand.java | 3 ++ .../scripts/commands/player/MoneyCommand.java | 13 +++-- .../scripts/commands/world/DropCommand.java | 54 +++++++------------ .../commands/world/PlayEffectCommand.java | 24 +++++---- 6 files changed, 59 insertions(+), 61 deletions(-) diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HealthCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HealthCommand.java index 5296b0fb3d..bbae8c097d 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HealthCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/entity/HealthCommand.java @@ -79,9 +79,9 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException } scriptEntry.addObject("target", Arrays.asList(Utilities.getEntryPlayer(scriptEntry).getDenizenEntity())); } - else if (!scriptEntry.hasObject("qty") + else if (!scriptEntry.hasObject("quantity") && arg.matchesFloat()) { - scriptEntry.addObject("qty", arg.asElement()); + scriptEntry.addObject("quantity", arg.asElement()); } else if (!scriptEntry.hasObject("target") && arg.matchesArgumentList(EntityTag.class)) { @@ -99,7 +99,7 @@ else if (!scriptEntry.hasObject("heal") arg.reportUnhandled(); } } - if (!scriptEntry.hasObject("qty") && !scriptEntry.hasObject("action")) { + if (!scriptEntry.hasObject("quantity") && !scriptEntry.hasObject("action")) { throw new InvalidArgumentsException("Must specify a quantity!"); } if (!scriptEntry.hasObject("target")) { @@ -113,17 +113,17 @@ else if (!scriptEntry.hasObject("heal") @Override public void execute(ScriptEntry scriptEntry) { - ElementTag qty = scriptEntry.getElement("qty"); + ElementTag quantity = scriptEntry.getElement("quantity"); ElementTag action = scriptEntry.getElement("action"); ElementTag heal = scriptEntry.getElement("heal"); List targets = (List) scriptEntry.getObject("target"); if (scriptEntry.dbCallShouldDebug()) { - Debug.report(scriptEntry, getName(), (qty != null ? qty.debug() : "") + + Debug.report(scriptEntry, getName(), (quantity != null ? quantity.debug() : "") + (action != null ? action.debug() : "") + heal.debug() + ArgumentHelper.debugObj("target", targets.toString())); } - if (qty == null && action == null) { + if (quantity == null && action == null) { Debug.echoError(scriptEntry.getResidingQueue(), "Null quantity!"); } if (action == null) { @@ -144,13 +144,13 @@ else if (target.getDenizenNPC().getCitizen().hasTrait(HealthTrait.class)) { target.getDenizenNPC().getCitizen().addTrait(HealthTrait.class); } } - if (qty != null) { + if (quantity != null) { if (target.isCitizensNPC()) { if (target.getDenizenNPC().getCitizen().hasTrait(HealthTrait.class)) { HealthTrait trait = target.getDenizenNPC().getCitizen().getOrAddTrait(HealthTrait.class); - trait.setMaxhealth(qty.asInt()); + trait.setMaxhealth(quantity.asInt()); if (heal.asBoolean()) { - trait.setHealth(qty.asDouble()); + trait.setHealth(quantity.asDouble()); } } else { @@ -158,9 +158,9 @@ else if (target.getDenizenNPC().getCitizen().hasTrait(HealthTrait.class)) { } } else if (target.isLivingEntity()) { - target.getLivingEntity().setMaxHealth(qty.asDouble()); + target.getLivingEntity().setMaxHealth(quantity.asDouble()); if (heal.asBoolean()) { - target.getLivingEntity().setHealth(qty.asDouble()); + target.getLivingEntity().setHealth(quantity.asDouble()); } } else { diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/GiveCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/GiveCommand.java index 390250b381..dfb19926a7 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/GiveCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/GiveCommand.java @@ -14,6 +14,7 @@ import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; +import com.denizenscript.denizencore.utilities.Deprecations; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -72,6 +73,9 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException if (!scriptEntry.hasObject("quantity") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesFloat()) { + if (arg.matchesPrefix("q", "qty")) { + Deprecations.qtyTags.warn(scriptEntry); + } scriptEntry.addObject("quantity", arg.asElement()); scriptEntry.addObject("set_quantity", new ElementTag(true)); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/TakeCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/TakeCommand.java index fb8f32159f..6be8f74e38 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/TakeCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/item/TakeCommand.java @@ -117,6 +117,9 @@ else if (!scriptEntry.hasObject("type") else if (!scriptEntry.hasObject("quantity") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesFloat()) { + if (arg.matchesPrefix("q", "qty")) { + Deprecations.qtyTags.warn(scriptEntry); + } scriptEntry.addObject("quantity", arg.asElement()); } else if (!scriptEntry.hasObject("items") diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/MoneyCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/MoneyCommand.java index c35cc97b8d..74e5254ddc 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/MoneyCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/player/MoneyCommand.java @@ -10,6 +10,7 @@ import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; +import com.denizenscript.denizencore.utilities.Deprecations; import com.denizenscript.denizencore.utilities.debugging.Debug; import net.milkbowl.vault.economy.Economy; @@ -73,14 +74,20 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException return; } for (Argument arg : scriptEntry.getProcessedArgs()) { - if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) { + if (!scriptEntry.hasObject("action") + && arg.matchesEnum(Action.values())) { scriptEntry.addObject("action", arg.asElement()); } - else if (!scriptEntry.hasObject("quantity") && arg.matchesPrefix("quantity", "qty", "q") + else if (!scriptEntry.hasObject("quantity") + && arg.matchesPrefix("quantity", "qty", "q") && arg.matchesFloat()) { + if (arg.matchesPrefix("q", "qty")) { + Deprecations.qtyTags.warn(scriptEntry); + } scriptEntry.addObject("quantity", arg.asElement()); } - else if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "from", "players", "player") && + else if (!scriptEntry.hasObject("players") + && arg.matchesPrefix("to", "from", "players", "player") && arg.matchesArgumentList(PlayerTag.class)) { scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry)); } diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/DropCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/DropCommand.java index 8e9640f9ed..515ecd3b80 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/DropCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/DropCommand.java @@ -12,6 +12,7 @@ import com.denizenscript.denizencore.objects.core.ListTag; import com.denizenscript.denizencore.scripts.ScriptEntry; import com.denizenscript.denizencore.scripts.commands.AbstractCommand; +import com.denizenscript.denizencore.utilities.Deprecations; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.ExperienceOrb; @@ -77,16 +78,12 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException for (Argument arg : scriptEntry.getProcessedArgs()) { if (!scriptEntry.hasObject("action") - && !arg.matchesPrefix("qty") && arg.matchesArgumentList(ItemTag.class)) { - // Item arg 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")) - // Experience arg - { + && arg.matches("experience", "exp", "xp")) { scriptEntry.addObject("action", new ElementTag(Action.DROP_EXP.toString()).setPrefix("action")); } else if (!scriptEntry.hasObject("action") @@ -96,9 +93,7 @@ else if (!scriptEntry.hasObject("action") scriptEntry.addObject("entity", arg.asType(EntityTag.class).setPrefix("entity")); } else if (!scriptEntry.hasObject("location") - && arg.matchesArgumentType(LocationTag.class)) - // Location arg - { + && arg.matchesArgumentType(LocationTag.class)) { scriptEntry.addObject("location", arg.asType(LocationTag.class).setPrefix("location")); } else if (!scriptEntry.hasObject("speed") @@ -106,11 +101,12 @@ else if (!scriptEntry.hasObject("speed") && arg.matchesFloat()) { scriptEntry.addObject("speed", arg.asElement()); } - else if (!scriptEntry.hasObject("qty") - && arg.matchesInteger()) - // Quantity arg - { - scriptEntry.addObject("qty", arg.asElement().setPrefix("qty")); + else if (!scriptEntry.hasObject("quantity") + && arg.matchesInteger()) { + 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")) { @@ -120,13 +116,9 @@ else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(DurationTag. arg.reportUnhandled(); } } - - // Make sure all required arguments are met - if (!scriptEntry.hasObject("action")) { throw new InvalidArgumentsException("Must specify something to drop!"); } - if (!scriptEntry.hasObject("location")) { if (Utilities.getEntryPlayer(scriptEntry) != null && Utilities.getEntryPlayer(scriptEntry).isOnline()) { scriptEntry.addObject("location", Utilities.getEntryPlayer(scriptEntry).getLocation().setPrefix("location")); @@ -137,40 +129,33 @@ else if (!scriptEntry.hasObject("delay") && arg.matchesArgumentType(DurationTag. throw new InvalidArgumentsException("Must specify a location!"); } } - - if (!scriptEntry.hasObject("qty")) { - scriptEntry.addObject("qty", new ElementTag("1").setPrefix("qty")); + if (!scriptEntry.hasObject("quantity")) { + scriptEntry.addObject("quantity", new ElementTag("1").setPrefix("quantity")); } - - // Okay! } @Override public void execute(ScriptEntry scriptEntry) { LocationTag location = scriptEntry.getObjectTag("location"); - ElementTag qty = scriptEntry.getElement("qty"); + ElementTag quantity = scriptEntry.getElement("quantity"); ElementTag action = scriptEntry.getElement("action"); ElementTag speed = scriptEntry.getElement("speed"); List items = (List) scriptEntry.getObject("item"); EntityTag entity = scriptEntry.getObjectTag("entity"); DurationTag delay = scriptEntry.getObjectTag("delay"); - if (scriptEntry.dbCallShouldDebug()) { Debug.report(scriptEntry, getName(), - action.debug() + location.debug() + qty.debug() + action.debug() + location.debug() + quantity.debug() + (items != null ? ArgumentHelper.debugList("items", items) : "") + (entity != null ? entity.debug() : "") + (speed != null ? speed.debug() : "") + (delay != null ? delay.debug() : "")); } - ListTag entityList = new ListTag(); - - // Do the drop switch (Action.valueOf(action.asString())) { case DROP_EXP: EntityTag orb = new EntityTag(location.getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB)); - ((ExperienceOrb) orb.getBukkitEntity()).setExperience(qty.asInt()); + ((ExperienceOrb) orb.getBukkitEntity()).setExperience(quantity.asInt()); entityList.addObject(orb); break; @@ -179,10 +164,10 @@ public void execute(ScriptEntry scriptEntry) { if (item.getMaterial().getMaterial() == Material.AIR) { continue; } - if (qty.asInt() > 1 && item.isUnique()) { + if (quantity.asInt() > 1 && item.isUnique()) { Debug.echoDebug(scriptEntry, "Cannot drop multiples of this item because it is Unique!"); } - for (int x = 0; x < qty.asInt(); x++) { + for (int x = 0; x < quantity.asInt(); x++) { EntityTag e = new EntityTag(location.getWorld().dropItem(location, item.getItemStack())); if (e.isValid()) { e.setVelocity(e.getVelocity().multiply(speed != null ? speed.asDouble() : 1d)); @@ -194,15 +179,14 @@ public void execute(ScriptEntry scriptEntry) { } } break; - case DROP_ENTITY: - if (qty.asInt() > 1 && entity.isUnique()) { + if (quantity.asInt() > 1 && entity.isUnique()) { Debug.echoDebug(scriptEntry, "Cannot drop multiples of this entity because it is Unique!"); entity.spawnAt(location); entityList.addObject(entity); break; } - for (int x = 0; x < qty.asInt(); x++) { + for (int x = 0; x < quantity.asInt(); x++) { ArrayList mechanisms = new ArrayList<>(); for (Mechanism mechanism : entity.getWaitingMechanisms()) { mechanisms.add(new Mechanism(new ElementTag(mechanism.getName()), mechanism.getValue())); @@ -213,8 +197,6 @@ public void execute(ScriptEntry scriptEntry) { } break; } - - // Add entities to context so that the specific entities dropped can be fetched. scriptEntry.addObject("dropped_entities", entityList); if (entityList.size() == 1) { scriptEntry.addObject("dropped_entity", entityList.getObject(0)); diff --git a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlayEffectCommand.java b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlayEffectCommand.java index 2b86cbdddf..2939f30112 100644 --- a/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlayEffectCommand.java +++ b/plugin/src/main/java/com/denizenscript/denizen/scripts/commands/world/PlayEffectCommand.java @@ -151,10 +151,13 @@ else if (!scriptEntry.hasObject("special_data") && arg.matchesPrefix("special_data")) { scriptEntry.addObject("special_data", arg.asElement()); } - else if (!scriptEntry.hasObject("qty") + else if (!scriptEntry.hasObject("quantity") && arg.matchesInteger() && arg.matchesPrefix("qty", "q", "quantity")) { - scriptEntry.addObject("qty", arg.asElement()); + if (arg.matchesPrefix("q", "qty")) { + Deprecations.qtyTags.warn(scriptEntry); + } + scriptEntry.addObject("quantity", arg.asElement()); } else if (!scriptEntry.hasObject("offset") && arg.matchesFloat() @@ -184,7 +187,7 @@ else if (!scriptEntry.hasObject("targets") scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false)); scriptEntry.defaultObject("data", new ElementTag(0)); scriptEntry.defaultObject("radius", new ElementTag(15)); - scriptEntry.defaultObject("qty", new ElementTag(1)); + scriptEntry.defaultObject("quantity", new ElementTag(1)); scriptEntry.defaultObject("offset", new LocationTag(null, 0.5, 0.5, 0.5)); if (!scriptEntry.hasObject("effect") && !scriptEntry.hasObject("particleeffect") && @@ -205,7 +208,7 @@ public void execute(ScriptEntry scriptEntry) { ItemTag iconcrack = scriptEntry.getObjectTag("iconcrack"); ElementTag radius = scriptEntry.getElement("radius"); ElementTag data = scriptEntry.getElement("data"); - ElementTag qty = scriptEntry.getElement("qty"); + ElementTag quantity = scriptEntry.getElement("quantity"); ElementTag no_offset = scriptEntry.getElement("no_offset"); boolean should_offset = no_offset == null || !no_offset.asBoolean(); LocationTag offset = scriptEntry.getObjectTag("offset"); @@ -219,7 +222,7 @@ public void execute(ScriptEntry scriptEntry) { (targets != null ? ArgumentHelper.debugObj("targets", targets.toString()) : "") + radius.debug() + data.debug() + - qty.debug() + + quantity.debug() + offset.debug() + (special_data != null ? special_data.debug() : "") + (velocity != null ? velocity.debug() : "") + @@ -232,7 +235,7 @@ public void execute(ScriptEntry scriptEntry) { } // Play the Bukkit effect the number of times specified if (effect != null) { - for (int n = 0; n < qty.asInt(); n++) { + for (int n = 0; n < quantity.asInt(); n++) { if (targets != null) { for (PlayerTag player : targets) { if (player.isValid() && player.isOnline()) { @@ -296,14 +299,14 @@ else if (special_data != null) { Debug.echoError("Particles of type '" + particleEffect.getName() + "' cannot take special_data as input."); } Random random = CoreUtilities.getRandom(); - int quantity = qty.asInt(); + int quantityInt = quantity.asInt(); for (Player player : players) { if (velocity == null) { - particleEffect.playFor(player, location, quantity, offset.toVector(), data.asDouble(), dataObject); + particleEffect.playFor(player, location, quantityInt, offset.toVector(), data.asDouble(), dataObject); } else { Vector velocityVector = velocity.toVector(); - for (int i = 0; i < quantity; i++) { + for (int i = 0; i < quantityInt; i++) { LocationTag singleLocation = location.clone().add((random.nextDouble() - 0.5) * offset.getX(), (random.nextDouble() - 0.5) * offset.getY(), (random.nextDouble() - 0.5) * offset.getZ()); @@ -330,12 +333,11 @@ else if (special_data != null) { } } } - if (iconcrack != null) { ItemStack itemStack = iconcrack.getItemStack(); Particle particle = NMSHandler.getParticleHelper().getParticle("ITEM_CRACK"); for (Player player : players) { - particle.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat(), itemStack); + particle.playFor(player, location, quantity.asInt(), offset.toVector(), data.asFloat(), itemStack); } } }