use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerPreparesEnchantScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String determineLow = CoreUtilities.toLowerCase(determinationObj.toString());
if (determineLow.startsWith("offers:")) {
ListTag offers = ListTag.valueOf(determineLow.substring("offers:".length()), getTagContext(path));
if (offers.size() != event.getOffers().length) {
Debug.echoError("Offer list size incorrect.");
return false;
}
for (int i = 0; i < offers.size(); i++) {
MapTag map = MapTag.getMapFor(offers.getObject(i), getTagContext(path));
event.getOffers()[i].setCost(map.getObject("cost").asElement().asInt());
ObjectTag enchantment = map.getObject("enchantment_type");
if (enchantment == null) {
enchantment = map.getObject("enchantment");
}
event.getOffers()[i].setEnchantment(enchantment.asType(EnchantmentTag.class, getTagContext(path)).enchantment);
event.getOffers()[i].setEnchantmentLevel(map.getObject("level").asElement().asInt());
}
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerPreparesEnchantScriptEvent method getContext.
@Override
public ObjectTag getContext(String name) {
switch(name) {
case "item":
return new ItemTag(event.getItem());
case "location":
return new LocationTag(event.getEnchantBlock().getLocation());
case "bonus":
return new ElementTag(event.getEnchantmentBonus());
case "offers":
ListTag output = new ListTag();
for (EnchantmentOffer offer : event.getOffers()) {
MapTag map = new MapTag();
map.putObject("cost", new ElementTag(offer.getCost()));
map.putObject("enchantment", new ElementTag(offer.getEnchantment().getKey().getKey()));
map.putObject("enchantment_type", new EnchantmentTag(offer.getEnchantment()));
map.putObject("level", new ElementTag(offer.getEnchantmentLevel()));
output.addObject(map);
}
return output;
}
return super.getContext(name);
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayerReceivesCommandsScriptEvent method getContext.
@Override
public ObjectTag getContext(String name) {
if (name.equals("commands")) {
ListTag list = new ListTag();
list.addAll(event.getCommands());
return list;
}
return super.getContext(name);
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class LootGenerateScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String determination = determinationObj.toString();
String determinationLower = CoreUtilities.toLowerCase(determination);
if (determinationLower.startsWith("loot:")) {
ListTag list = ListTag.valueOf(determination.substring("loot:".length()), getTagContext(path));
ArrayList<ItemStack> newLoot = new ArrayList<>(list.size());
for (ItemTag item : list.filter(ItemTag.class, getTagContext(path))) {
newLoot.add(item.getItemStack());
}
event.setLoot(newLoot);
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class AreaContainmentObject method getBlocksFlagged.
default ListTag getBlocksFlagged(String flagName, Attribute attribute) {
CuboidTag cuboid = getCuboidBoundary();
ListTag blocks = new ListTag();
for (CuboidTag.LocationPair pair : cuboid.pairs) {
ChunkTag minChunk = new ChunkTag(pair.low);
ChunkTag maxChunk = new ChunkTag(pair.high);
ChunkTag subChunk = new ChunkTag(pair.low);
for (int x = minChunk.getX(); x <= maxChunk.getX(); x++) {
subChunk.chunkX = x;
for (int z = minChunk.getZ(); z <= maxChunk.getZ(); z++) {
subChunk.chunkZ = z;
subChunk.cachedChunk = null;
if (subChunk.isLoadedSafe()) {
LocationFlagSearchHelper.getFlaggedLocations(subChunk.getChunkForTag(attribute), flagName, (loc) -> {
if (doesContainLocation(loc)) {
blocks.addObject(new LocationTag(loc));
}
});
}
}
}
}
return blocks;
}
Aggregations