Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
tag system improvements
  • Loading branch information
mcmonkey4eva committed Jun 10, 2018
1 parent cc8f50a commit 8008dfc
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 100 deletions.
Expand Up @@ -102,7 +102,7 @@ public void execute(CommandQueue queue, CommandEntry entry) {
if (queue.shouldShowGood()) {
queue.outGood("Spawning " + (passed ? "succeeded" : "was blocked") + "!");
}
queue.commandStack.peek().setDefinition("spawn_success", new BooleanTag(passed));
queue.commandStack.peek().setDefinition("spawn_success", BooleanTag.getForBoolean(passed));
if (passed) {
queue.commandStack.peek().setDefinition("spawn_entity", new EntityTag(entity));
}
Expand Down
Expand Up @@ -117,10 +117,10 @@ public void onExplosionOccurs(ExplosionEvent.Detonate evt) {
Explosion exp = evt.getExplosion();
MapTag data = new MapTag();
data.getInternal().put("radius", new NumberTag(exp.getRadius()));
data.getInternal().put("fire", new BooleanTag(exp.canCauseFire()));
data.getInternal().put("break_blocks", new BooleanTag(exp.shouldBreakBlocks()));
data.getInternal().put("damage_entities", new BooleanTag(exp.shouldDamageEntities()));
data.getInternal().put("smoke", new BooleanTag(exp.shouldPlaySmoke()));
data.getInternal().put("fire", BooleanTag.getForBoolean(exp.canCauseFire()));
data.getInternal().put("break_blocks", BooleanTag.getForBoolean(exp.shouldBreakBlocks()));
data.getInternal().put("damage_entities", BooleanTag.getForBoolean(exp.shouldDamageEntities()));
data.getInternal().put("smoke", BooleanTag.getForBoolean(exp.shouldPlaySmoke()));
event.explosion_data = data;
event.cancelled = evt.isCancelled();
event.run();
Expand Down
Expand Up @@ -32,6 +32,6 @@ public AbstractTagObject handle(TagData data) {
}
}
data.error.run("No context present!");
return new NullTag();
return NullTag.NULL;
}
}
Expand Up @@ -35,7 +35,7 @@ public AbstractTagObject handle(TagData data) {
return ato.handle(data.shrink());
}
data.error.run("Tried to read connected player, but failed (improperly typed player).");
return new NullTag();
return NullTag.NULL;
}
else if (data.currentQueue.commandStack.peek().hasDefinition("context")) {
AbstractTagObject ato = data.currentQueue.commandStack.peek().getDefinition("context");
Expand All @@ -46,14 +46,14 @@ else if (data.currentQueue.commandStack.peek().hasDefinition("context")) {
return plt.handle(data.shrink());
}
data.error.run("Tried to read connected player, but failed (improperly typed context -> player).");
return new NullTag();
return NullTag.NULL;
}
}
data.error.run("Tried to read connected player, but failed (context isn't a map?!).");
return new NullTag();
return NullTag.NULL;
}
data.error.run("Tried to read connected player, but failed (no connected player).");
return new NullTag();
return NullTag.NULL;
}
if (!data.hasNextModifier()) {
data.error.run("Invalid player tag-base: expected a modifier! See documentation for this tag! (No local player ref found)");
Expand Down
Expand Up @@ -103,7 +103,7 @@ public String getName() {
// @ReturnType BooleanTag
// @Returns whether there is currently an enabled whitelist on the server.
// -->
handlers.put("has_whitelist", (dat, obj) -> new BooleanTag(Sponge.getServer().hasWhitelist()));
handlers.put("has_whitelist", (dat, obj) -> BooleanTag.getForBoolean(Sponge.getServer().hasWhitelist()));
// <--[tag]
// @Since 0.3.0
// @Name ServerBaseTag.online_mode
Expand All @@ -112,7 +112,7 @@ public String getName() {
// @ReturnType BooleanTag
// @Returns whether there the server is currently on online mode or not.
// -->
handlers.put("online_mode", (dat, obj) -> new BooleanTag(Sponge.getServer().getOnlineMode()));
handlers.put("online_mode", (dat, obj) -> BooleanTag.getForBoolean(Sponge.getServer().getOnlineMode()));
// <--[tag]
// @Since 0.3.0
// @Name ServerBaseTag.motd
Expand All @@ -139,7 +139,7 @@ public String getName() {
// @ReturnType BooleanTag
// @Returns whether the specified text is a valid block type, and can be read as a BlockTypeTag.
// -->
handlers.put("block_type_is_valid", (dat, obj) -> new BooleanTag(Sponge.getRegistry().getType(
handlers.put("block_type_is_valid", (dat, obj) -> BooleanTag.getForBoolean(Sponge.getRegistry().getType(
BlockType.class, dat.getNextModifier().toString()).isPresent()));
// <--[tag]
// @Since 0.3.0
Expand All @@ -155,7 +155,7 @@ public String getName() {
if (!dat.hasFallback()) {
dat.error.run("Empty list tag, cannot wrap a cuboid around nothing!");
}
return new NullTag();
return NullTag.NULL;
}
LocationTag one = LocationTag.getFor(dat.error, lt.getInternal().get(0));
CuboidTag ct = new CuboidTag(one.getInternal(), one.getInternal());
Expand All @@ -181,7 +181,7 @@ public String getName() {
handlers.put("has_flag", (dat, obj) -> {
String flagName = CoreUtilities.toLowerCase(dat.getNextModifier().toString());
MapTag flags = Denizen2Sponge.instance.serverFlagMap;
return new BooleanTag(Utilities.flagIsValidAndNotExpired(dat.error, flags, flagName));
return BooleanTag.getForBoolean(Utilities.flagIsValidAndNotExpired(dat.error, flags, flagName));
});
// <--[tag]
// @Since 0.3.0
Expand Down Expand Up @@ -227,14 +227,14 @@ public String getName() {
if (!dat.hasFallback()) {
dat.error.run("Invalid flag specified, not present on the server!");
}
return new NullTag();
return NullTag.NULL;
}
MapTag smap = MapTag.getFor(dat.error, flags.getInternal().get(flagName));
if (smap == null) {
if (!dat.hasFallback()) {
dat.error.run("Invalid flag specified, not present on the server!");
}
return new NullTag();
return NullTag.NULL;
}
return smap.getInternal().get("value");
});
Expand Down Expand Up @@ -285,11 +285,11 @@ public String getName() {
properties.getInternal().put("title", new FormattedTextTag(bar.getName()));
properties.getInternal().put("color", new TextTag(Utilities.getIdWithoutDefaultPrefix(bar.getColor().getId())));
properties.getInternal().put("overlay", new TextTag(bar.getOverlay().getId()));
properties.getInternal().put("visible", new BooleanTag(bar.isVisible()));
properties.getInternal().put("visible", BooleanTag.getForBoolean(bar.isVisible()));
properties.getInternal().put("percent", new NumberTag(bar.getPercent()));
properties.getInternal().put("create_fog", new BooleanTag(bar.shouldCreateFog()));
properties.getInternal().put("darken_sky", new BooleanTag(bar.shouldDarkenSky()));
properties.getInternal().put("play_music", new BooleanTag(bar.shouldPlayEndBossMusic()));
properties.getInternal().put("create_fog", BooleanTag.getForBoolean(bar.shouldCreateFog()));
properties.getInternal().put("darken_sky", BooleanTag.getForBoolean(bar.shouldDarkenSky()));
properties.getInternal().put("play_music", BooleanTag.getForBoolean(bar.shouldPlayEndBossMusic()));
return properties;
});
// <--[tag]
Expand All @@ -303,7 +303,7 @@ public String getName() {
handlers.put("advancement_exists", (dat, obj) -> {
String id = dat.getNextModifier().toString();
Advancement advancement = (Advancement) Utilities.getTypeWithDefaultPrefix(Advancement.class, id);
return new BooleanTag(advancement != null);
return BooleanTag.getForBoolean(advancement != null);
});
}

Expand Down
Expand Up @@ -99,7 +99,7 @@ public boolean contains(UtilLocation point) {
// @Returns whether the cuboid contains the specified location.
// @Example "0,1,2/4,5,6/world" .contains[1,2,3,world] returns "true".
// -->
handlers.put("contains", (dat, obj) -> new BooleanTag(((CuboidTag) obj).contains(
handlers.put("contains", (dat, obj) -> BooleanTag.getForBoolean(((CuboidTag) obj).contains(
LocationTag.getFor(dat.error, dat.getNextModifier()).getInternal())));
// <--[tag]
// @Since 0.3.0
Expand Down
Expand Up @@ -252,7 +252,7 @@ public String friendlyName() {
Key key = DataKeys.getKeyForName(keyName);
if (key == null) {
dat.error.run("Invalid key '" + keyName + "'!");
return new NullTag();
return NullTag.NULL;
}
return DataKeys.getValue(((EntityTag) obj).internal, key, dat.error);
});
Expand All @@ -275,7 +275,7 @@ public String friendlyName() {
else {
flags = new MapTag();
}
return new BooleanTag(Utilities.flagIsValidAndNotExpired(dat.error, flags, flagName));
return BooleanTag.getForBoolean(Utilities.flagIsValidAndNotExpired(dat.error, flags, flagName));
});
// <--[tag]
// @Since 0.3.0
Expand Down Expand Up @@ -337,14 +337,14 @@ public String friendlyName() {
if (!dat.hasFallback()) {
dat.error.run("Invalid flag specified, not present on this entity!");
}
return new NullTag();
return NullTag.NULL;
}
MapTag smap = MapTag.getFor(dat.error, flags.getInternal().get(flagName));
if (smap == null) {
if (!dat.hasFallback()) {
dat.error.run("Invalid flag specified, not present on this entity!");
}
return new NullTag();
return NullTag.NULL;
}
return smap.getInternal().get("value");
});
Expand Down Expand Up @@ -375,7 +375,7 @@ public String friendlyName() {
handlers.put("vehicle", (dat, obj) -> {
Optional<Entity> opt = ((EntityTag) obj).internal.getVehicle();
if (!opt.isPresent()) {
return new NullTag();
return NullTag.NULL;
}
return new EntityTag(opt.get());
});
Expand All @@ -396,7 +396,7 @@ public String friendlyName() {
// @ReturnType BooleanTag
// @Returns whether this entity is on the ground or not.
// -->
handlers.put("on_ground", (dat, obj) -> new BooleanTag(((EntityTag) obj).internal.isOnGround()));
handlers.put("on_ground", (dat, obj) -> BooleanTag.getForBoolean(((EntityTag) obj).internal.isOnGround()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.scale
Expand Down Expand Up @@ -504,7 +504,7 @@ public String friendlyName() {
// @ReturnType BooleanTag
// @Returns whether this falling block can drop as an item if it can't be placed when it lands. Falling block entities only.
// -->
handlers.put("can_drop_as_item", (dat, obj) -> new BooleanTag(((FallingBlock) ((EntityTag) obj).internal).canDropAsItem().get()));
handlers.put("can_drop_as_item", (dat, obj) -> BooleanTag.getForBoolean(((FallingBlock) ((EntityTag) obj).internal).canDropAsItem().get()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.can_place_as_block
Expand All @@ -513,7 +513,7 @@ public String friendlyName() {
// @ReturnType BooleanTag
// @Returns whether this falling block can place as a block when it lands. Falling block entities only.
// -->
handlers.put("can_place_as_block", (dat, obj) -> new BooleanTag(((FallingBlock) ((EntityTag) obj).internal).canPlaceAsBlock().get()));
handlers.put("can_place_as_block", (dat, obj) -> BooleanTag.getForBoolean(((FallingBlock) ((EntityTag) obj).internal).canPlaceAsBlock().get()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.can_hurt_entities
Expand All @@ -522,7 +522,7 @@ public String friendlyName() {
// @ReturnType BooleanTag
// @Returns whether this falling block can hurt entities if it lands on them. Falling block entities only.
// -->
handlers.put("can_hurt_entities", (dat, obj) -> new BooleanTag(((FallingBlock) ((EntityTag) obj).internal).canHurtEntities().get()));
handlers.put("can_hurt_entities", (dat, obj) -> BooleanTag.getForBoolean(((FallingBlock) ((EntityTag) obj).internal).canHurtEntities().get()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.fall_damage_per_block
Expand Down Expand Up @@ -597,7 +597,7 @@ else if (source instanceof Entity) {
if (!dat.hasFallback()) {
dat.error.run("The projectile source is unknown!");
}
return new NullTag();
return NullTag.NULL;
}
});
// <--[tag]
Expand Down Expand Up @@ -635,7 +635,7 @@ else if (source instanceof Entity) {
// @ReturnType BooleanTag
// @Returns whether the boat is able to move freely on land or not. Boat entities only.
// -->
handlers.put("can_move_on_land", (dat, obj) -> new BooleanTag(((Boat) ((EntityTag) obj).internal).canMoveOnLand()));
handlers.put("can_move_on_land", (dat, obj) -> BooleanTag.getForBoolean(((Boat) ((EntityTag) obj).internal).canMoveOnLand()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.in_water
Expand All @@ -644,7 +644,7 @@ else if (source instanceof Entity) {
// @ReturnType BooleanTag
// @Returns whether the boat is currently in water or not. Boat entities only.
// -->
handlers.put("in_water", (dat, obj) -> new BooleanTag(((Boat) ((EntityTag) obj).internal).isInWater()));
handlers.put("in_water", (dat, obj) -> BooleanTag.getForBoolean(((Boat) ((EntityTag) obj).internal).isInWater()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.art_name
Expand Down Expand Up @@ -680,7 +680,7 @@ else if (source instanceof Entity) {
if (!dat.hasFallback()) {
dat.error.run("This hitch has no leashed entity!");
}
return new NullTag();
return NullTag.NULL;
}
return new EntityTag(ent);
});
Expand Down Expand Up @@ -788,7 +788,7 @@ else if (ent instanceof Ageable) {
if (!dat.hasFallback()) {
dat.error.run("This entity doesn't have an age property!");
}
return new NullTag();
return NullTag.NULL;
}
});
// <--[tag]
Expand All @@ -799,7 +799,7 @@ else if (ent instanceof Ageable) {
// @ReturnType BooleanTag
// @Returns whether this entity is an adult or not.
// -->
handlers.put("is_adult", (dat, obj) -> new BooleanTag(((Ageable) ((EntityTag) obj).internal).adult().get()));
handlers.put("is_adult", (dat, obj) -> BooleanTag.getForBoolean(((Ageable) ((EntityTag) obj).internal).adult().get()));
// <--[tag]
// @Since 0.3.0
// @Name EntityTag.target_block[<NumberTag>]
Expand Down Expand Up @@ -905,7 +905,7 @@ else if (ent instanceof Ageable) {
// @Returns whether an explosive entity is primed.
// @Warning This tag always returns false in Sponge during last testing.
// -->
handlers.put("is_primed", (dat, obj) -> new BooleanTag(((FusedExplosive) ((EntityTag) obj).internal).isPrimed()));
handlers.put("is_primed", (dat, obj) -> BooleanTag.getForBoolean(((FusedExplosive) ((EntityTag) obj).internal).isPrimed()));
// <--[tag]
// @Since 0.4.0
// @Name EntityTag.has_ai
Expand All @@ -914,7 +914,7 @@ else if (ent instanceof Ageable) {
// @ReturnType BooleanTag
// @Returns whether an entity has ai enabled.
// -->
handlers.put("has_ai", (dat, obj) -> new BooleanTag(((Agent) ((EntityTag) obj).internal).aiEnabled().get()));
handlers.put("has_ai", (dat, obj) -> BooleanTag.getForBoolean(((Agent) ((EntityTag) obj).internal).aiEnabled().get()));
// <--[tag]
// @Since 0.4.0
// @Name EntityTag.ai_target
Expand All @@ -932,7 +932,7 @@ else if (ent instanceof Ageable) {
if (!dat.hasFallback()) {
dat.error.run("This entity doesn't have target!");
}
return new NullTag();
return NullTag.NULL;
}
});
}
Expand Down
Expand Up @@ -66,7 +66,7 @@ public Inventory getInternal() {
// @Returns whether the inventory contains the specified quantity or more of the specified item.
// @Example "block/0,1,2,world" .contains[diamond/3] might return "false".
// -->
handlers.put("contains", (dat, obj) -> new BooleanTag(((InventoryTag) obj).internal.contains(ItemTag.getFor(dat.error, dat.getNextModifier(), dat.currentQueue).getInternal())));
handlers.put("contains", (dat, obj) -> BooleanTag.getForBoolean(((InventoryTag) obj).internal.contains(ItemTag.getFor(dat.error, dat.getNextModifier(), dat.currentQueue).getInternal())));
// <--[tag]
// @Since 0.3.0
// @Name InventoryTag.contains_any[<ItemTag>]
Expand All @@ -76,7 +76,7 @@ public Inventory getInternal() {
// @Returns whether the inventory contains any quantity of the specified item.
// @Example "block/0,1,2,world" .contains_any[diamond] might return "true".
// -->
handlers.put("contains_any", (dat, obj) -> new BooleanTag(((InventoryTag) obj).internal.containsAny(ItemTag.getFor(dat.error, dat.getNextModifier(), dat.currentQueue).getInternal())));
handlers.put("contains_any", (dat, obj) -> BooleanTag.getForBoolean(((InventoryTag) obj).internal.containsAny(ItemTag.getFor(dat.error, dat.getNextModifier(), dat.currentQueue).getInternal())));
// <--[tag]
// @Since 0.4.0
// @Name InventoryTag.fuel
Expand All @@ -92,7 +92,7 @@ public Inventory getInternal() {
if (!dat.hasFallback()) {
dat.error.run("This inventory does not contain any fuel slots!");
}
return new NullTag();
return NullTag.NULL;
}
ItemStack item = inventory.peek().orElse(ItemStack.empty());
return new ItemTag(item);
Expand Down Expand Up @@ -132,7 +132,7 @@ public Inventory getInternal() {
if (!dat.hasFallback()) {
dat.error.run("This inventory does not contain any result slots!");
}
return new NullTag();
return NullTag.NULL;
}
ItemStack item = inventory.peek().orElse(ItemStack.empty());
return new ItemTag(item);
Expand Down Expand Up @@ -162,14 +162,14 @@ public Inventory getInternal() {
if (!dat.hasFallback()) {
dat.error.run("This inventory does not contain slots ordered by index!");
}
return new NullTag();
return NullTag.NULL;
}
int slot = (int) IntegerTag.getFor(dat.error, dat.getNextModifier()).getInternal();
if (slot < 1 || slot > inventory.capacity()) {
if (!dat.hasFallback()) {
dat.error.run("Invalid slot index specified!");
}
return new NullTag();
return NullTag.NULL;
}
ItemStack item = ((OrderedInventory) inventory).peek(new SlotIndex(slot - 1)).orElse(ItemStack.empty());
return new ItemTag(item);
Expand Down

0 comments on commit 8008dfc

Please sign in to comment.