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

Commit

Permalink
itemtag.with_flags, with_quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 5, 2016
1 parent 906a203 commit 617d999
Showing 1 changed file with 37 additions and 1 deletion.
Expand Up @@ -9,6 +9,7 @@
import com.denizenscript.denizen2sponge.utilities.DataKeys;
import com.denizenscript.denizen2sponge.utilities.flags.FlagHelper;
import com.denizenscript.denizen2sponge.utilities.flags.FlagMap;
import com.denizenscript.denizen2sponge.utilities.flags.FlagMapDataImpl;
import org.spongepowered.api.data.key.Key;
import org.spongepowered.api.item.inventory.ItemStack;

Expand Down Expand Up @@ -69,11 +70,46 @@ public ItemStack getInternal() {
return DataKeys.getValue(((ItemTag) obj).internal, key, dat.error);
});
// <--[tag]
// @Name ItemTag.with_flags[<MapTag>]
// @Updated 2016/12/04
// @Group General Information
// @ReturnType ItemTag
// @Returns a copy of the item, with the specified flag adjustments.
// -->
handlers.put("with_flags", (dat, obj) -> {
MapTag flags;
ItemStack e = ((ItemTag) obj).internal;
Optional<FlagMap> fm = e.get(FlagHelper.FLAGMAP);
if (fm.isPresent()) {
flags = new MapTag(fm.get().flags.getInternal());
}
else {
flags = new MapTag();
}
MapTag toApply = MapTag.getFor(dat.error, dat.getNextModifier());
flags.getInternal().putAll(toApply.getInternal());
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
its.offer(new FlagMapDataImpl(new FlagMap(flags)));
return new ItemTag(its);
});
// <--[tag]
// @Name ItemTag.with_quantity[<IntegerTag>]
// @Updated 2016/12/04
// @Group General Information
// @ReturnType ItemTag
// @Returns a copy of the item, with the specified quantity.
// -->
handlers.put("with_quantity", (dat, obj) -> {
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
its.setQuantity((int)IntegerTag.getFor(dat.error, dat.getNextModifier()).getInternal());
return new ItemTag(its);
});
// <--[tag]
// @Name ItemTag.with[<MapTag>]
// @Updated 2016/11/24
// @Group General Information
// @ReturnType ItemTag
// @Returns a copy of the item, with the specified adjustments.
// @Returns a copy of the item, with the specified data adjustments.
// -->
handlers.put("with", (dat, obj) -> {
ItemStack its = ((ItemTag) obj).internal.createSnapshot().createStack();
Expand Down

0 comments on commit 617d999

Please sign in to comment.