Skip to content

Commit

Permalink
clean up a few left over 'qty' names that still exist, clean some com…
Browse files Browse the repository at this point in the history
…mand code
  • Loading branch information
mcmonkey4eva committed Nov 12, 2020
1 parent 08f563a commit 96ff8a1
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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")) {
Expand All @@ -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<EntityTag> targets = (List<EntityTag>) 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) {
Expand All @@ -144,23 +144,23 @@ 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 {
Debug.echoError(scriptEntry.getResidingQueue(), "NPC doesn't have health trait!");
}
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand All @@ -96,21 +93,20 @@ 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")
&& arg.matchesPrefix("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")) {
Expand All @@ -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"));
Expand All @@ -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<ItemTag> items = (List<ItemTag>) 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;

Expand All @@ -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));
Expand All @@ -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<Mechanism> mechanisms = new ArrayList<>();
for (Mechanism mechanism : entity.getWaitingMechanisms()) {
mechanisms.add(new Mechanism(new ElementTag(mechanism.getName()), mechanism.getValue()));
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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") &&
Expand All @@ -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");
Expand All @@ -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() : "") +
Expand All @@ -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()) {
Expand Down Expand Up @@ -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());
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 96ff8a1

Please sign in to comment.