use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class CuboidTag method valueOf.
@Fetchable("cu")
public static CuboidTag valueOf(String string, TagContext context) {
if (string == null) {
return null;
}
if (CoreUtilities.toLowerCase(string).startsWith("cu@")) {
string = string.substring("cu@".length());
}
Notable noted = NoteManager.getSavedObject(string);
if (noted instanceof CuboidTag) {
return (CuboidTag) noted;
}
if (CoreUtilities.contains(string, '@')) {
if (CoreUtilities.contains(string, '|') && string.contains("l@")) {
Debug.echoError("Warning: likely improperly constructed CuboidTag '" + string + "' - use to_cuboid");
} else {
return null;
}
}
if (CoreUtilities.contains(string, '|')) {
ListTag positions = ListTag.valueOf(string, context);
if (positions.size() > 1 && LocationTag.matches(positions.get(0)) && LocationTag.matches(positions.get(1))) {
if (positions.size() % 2 != 0) {
if (context == null || context.showErrors()) {
Debug.echoError("valueOf CuboidTag returning null (Uneven number of locations): '" + string + "'.");
}
return null;
}
CuboidTag toReturn = new CuboidTag();
for (int i = 0; i < positions.size(); i += 2) {
LocationTag pos_1 = LocationTag.valueOf(positions.get(i), context);
LocationTag pos_2 = LocationTag.valueOf(positions.get(i + 1), context);
if (pos_1 == null || pos_2 == null) {
if (context == null || context.showErrors()) {
Debug.echoError("valueOf in CuboidTag returning null (null locations): '" + string + "'.");
}
return null;
}
if (pos_1.getWorldName() == null || pos_2.getWorldName() == null) {
if (context == null || context.showErrors()) {
Debug.echoError("valueOf in CuboidTag returning null (null worlds): '" + string + "'.");
}
return null;
}
toReturn.addPair(pos_1, pos_2);
}
if (toReturn.pairs.size() > 0) {
return toReturn;
}
}
} else if (CoreUtilities.contains(string, ',')) {
List<String> subStrs = CoreUtilities.split(string, ',');
if (subStrs.size() < 7 || (subStrs.size() - 1) % 6 != 0) {
if (context == null || context.showErrors()) {
Debug.echoError("valueOf CuboidTag returning null (Improper number of commas): '" + string + "'.");
}
return null;
}
CuboidTag toReturn = new CuboidTag();
String worldName = subStrs.get(0);
if (worldName.startsWith("w@")) {
worldName = worldName.substring("w@".length());
}
try {
for (int i = 0; i < subStrs.size() - 1; i += 6) {
LocationTag locationOne = new LocationTag(parseRoundDouble(subStrs.get(i + 1)), parseRoundDouble(subStrs.get(i + 2)), parseRoundDouble(subStrs.get(i + 3)), worldName);
LocationTag locationTwo = new LocationTag(parseRoundDouble(subStrs.get(i + 4)), parseRoundDouble(subStrs.get(i + 5)), parseRoundDouble(subStrs.get(i + 6)), worldName);
toReturn.addPair(locationOne, locationTwo);
}
} catch (NumberFormatException ex) {
if (context == null || context.showErrors()) {
Debug.echoError("valueOf CuboidTag returning null (Improper number value inputs): '" + ex.getMessage() + "'.");
}
return null;
}
if (toReturn.pairs.size() > 0) {
return toReturn;
}
}
if (context == null || context.showErrors()) {
Debug.echoError("Minor: valueOf CuboidTag returning null: " + string);
}
return null;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class CuboidTag method getBlocks.
@Override
public ListTag getBlocks(Predicate<Location> test) {
List<LocationTag> locs = getBlocks_internal(test);
ListTag list = new ListTag();
for (LocationTag loc : locs) {
list.addObject(loc);
}
return list;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class InventoryScriptContainer method getInventoryFrom.
public InventoryTag getInventoryFrom(TagContext context) {
InventoryTag inventory;
context = (context == null ? CoreUtilities.basicContext : context).clone();
ScriptTag thisScript = new ScriptTag(this);
context.script = thisScript;
context.debug = context.debug && shouldDebug();
try {
InventoryType type = InventoryType.CHEST;
if (contains("inventory", String.class)) {
try {
type = InventoryType.valueOf(getString("inventory").toUpperCase());
} catch (IllegalArgumentException ex) {
Debug.echoError(this, "Invalid inventory type specified. Assuming \"CHEST\" (" + ex.getMessage() + ")");
}
} else {
Debug.echoError(this, "Inventory script '" + getName() + "' does not specify an inventory type. Assuming \"CHEST\".");
}
if (type == InventoryType.PLAYER) {
Debug.echoError(this, "Inventory type 'player' is not valid for inventory scripts - defaulting to 'CHEST'.");
type = InventoryType.CHEST;
}
int size = 0;
if (contains("size", String.class)) {
if (type != InventoryType.CHEST) {
Debug.echoError(this, "You can only set the size of chest inventories!");
} else {
String sizeText = TagManager.tag(getString("size"), context);
if (!ArgumentHelper.matchesInteger(sizeText)) {
Debug.echoError(this, "Invalid (not-a-number) size value.");
} else {
size = Integer.parseInt(sizeText);
}
if (size == 0) {
Debug.echoError(this, "Inventory size can't be 0. Assuming default of inventory type...");
}
if (size % 9 != 0) {
size = (int) Math.ceil(size / 9.0) * 9;
Debug.echoError(this, "Inventory size must be a multiple of 9! Rounding up to " + size + "...");
}
if (size < 0) {
size = size * -1;
Debug.echoError(this, "Inventory size must be a positive number! Inverting to " + size + "...");
}
}
}
if (size == 0) {
if (contains("slots", List.class) && type == InventoryType.CHEST) {
size = getStringList("slots").size() * 9;
} else {
size = type.getDefaultSize();
}
}
String title = contains("title", String.class) ? TagManager.tag(getString("title"), context) : null;
if (type == InventoryType.CHEST) {
inventory = new InventoryTag(size, title != null ? title : "Chest");
} else {
if (title == null) {
inventory = new InventoryTag(type);
} else {
inventory = new InventoryTag(type, title);
}
}
inventory.idType = "script";
inventory.idHolder = thisScript;
boolean[] filledSlots = new boolean[size];
if (contains("slots", List.class)) {
ItemStack[] finalItems = new ItemStack[size];
int itemsAdded = 0;
for (String items : getStringList("slots")) {
items = TagManager.tag(items, context).trim();
if (items.isEmpty()) {
continue;
}
if (!items.startsWith("[") || !items.endsWith("]")) {
Debug.echoError(this, "Invalid slots line: [" + items + "]... Ignoring it");
continue;
}
String[] itemsInLine = items.substring(1, items.length() - 1).split("\\[?\\]?\\s+\\[", -1);
for (String item : itemsInLine) {
if (item.isEmpty()) {
finalItems[itemsAdded++] = new ItemStack(Material.AIR);
continue;
}
filledSlots[itemsAdded] = true;
if (contains("definitions." + item, String.class)) {
ItemTag def = ItemTag.valueOf(TagManager.tag(getString("definitions." + item), context), context);
if (def == null) {
Debug.echoError(this, "Invalid definition '" + item + "'... Ignoring it and assuming 'AIR'");
finalItems[itemsAdded] = new ItemStack(Material.AIR);
} else {
finalItems[itemsAdded] = def.getItemStack();
}
} else {
try {
ItemTag itemTag = ItemTag.valueOf(item, context);
if (itemTag == null) {
finalItems[itemsAdded] = new ItemStack(Material.AIR);
Debug.echoError(this, "Invalid slot item: [" + item + "]... ignoring it and assuming 'AIR'");
} else {
finalItems[itemsAdded] = itemTag.getItemStack();
}
} catch (Exception ex) {
Debug.echoError(this, "Invalid slot item: [" + item + "]...");
Debug.echoError(ex);
}
}
itemsAdded++;
}
}
inventory.setContents(finalItems);
}
if (containsScriptSection("procedural items")) {
List<ScriptEntry> entries = getEntries(context.getScriptEntryData(), "procedural items");
if (!entries.isEmpty()) {
InstantQueue queue = new InstantQueue("INV_SCRIPT_ITEM_PROC");
queue.addEntries(entries);
if (contains("definitions", Map.class)) {
YamlConfiguration section = getConfigurationSection("definitions");
for (StringHolder string : section.getKeys(false)) {
String definition = string.str;
queue.addDefinition(definition, section.getString(definition));
}
}
queue.procedural = true;
queue.start();
if (queue.determinations != null) {
ListTag list = ListTag.getListFor(queue.determinations.getObject(0), context);
if (list != null) {
int x = 0;
for (ItemTag item : list.filter(ItemTag.class, context, true)) {
while (x < filledSlots.length && filledSlots[x]) {
x++;
}
if (x >= filledSlots.length || filledSlots[x]) {
break;
}
inventory.setSlots(x, item.getItemStack());
filledSlots[x] = true;
}
}
}
}
}
} catch (Exception e) {
Debug.echoError(this, "Woah! An exception has been called while building this inventory script!");
Debug.echoError(e);
inventory = null;
}
if (inventory != null) {
InventoryTag.trackTemporaryInventory(inventory);
}
return inventory;
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class SignCommand method execute.
@Override
public void execute(final ScriptEntry scriptEntry) {
String direction = scriptEntry.hasObject("direction") ? ((ElementTag) scriptEntry.getObject("direction")).asString() : null;
ElementTag typeElement = scriptEntry.getElement("type");
ListTag text = scriptEntry.getObjectTag("text");
LocationTag location = scriptEntry.getObjectTag("location");
MaterialTag material = scriptEntry.getObjectTag("material");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), typeElement, location, db("direction", direction), material, text);
}
Type type = Type.valueOf(typeElement.asString().toUpperCase());
Block sign = location.getBlock();
if (type != Type.AUTOMATIC || !isAnySign(sign.getType())) {
if (type == Type.WALL_SIGN) {
BlockFace bf;
if (direction != null) {
bf = Utilities.chooseSignRotation(direction);
} else {
bf = Utilities.chooseSignRotation(sign);
}
setWallSign(sign, bf, material);
} else {
sign.setType(material == null ? Material.OAK_SIGN : material.getMaterial(), false);
if (direction != null) {
Utilities.setSignRotation(sign.getState(), direction);
}
}
} else if (!isAnySign(sign.getType())) {
if (sign.getRelative(BlockFace.DOWN).getType().isSolid()) {
sign.setType(material == null ? Material.OAK_SIGN : material.getMaterial(), false);
} else {
BlockFace bf = Utilities.chooseSignRotation(sign);
setWallSign(sign, bf, material);
}
}
BlockState signState = sign.getState();
Utilities.setSignLines((Sign) signState, text.toArray(new String[4]));
}
use of com.denizenscript.denizencore.objects.core.ListTag in project Denizen-For-Bukkit by DenizenScript.
the class PlayEffectCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
List<LocationTag> locations = (List<LocationTag>) scriptEntry.getObject("location");
List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
Effect effect = (Effect) scriptEntry.getObject("effect");
Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect");
ItemTag iconcrack = scriptEntry.getObjectTag("iconcrack");
ElementTag radius = scriptEntry.getElement("radius");
ElementTag data = scriptEntry.getElement("data");
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");
ElementTag special_data = scriptEntry.getElement("special_data");
LocationTag velocity = scriptEntry.getObjectTag("velocity");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), (effect != null ? db("effect", effect.name()) : particleEffect != null ? db("special effect", particleEffect.getName()) : iconcrack), db("locations", locations), db("targets", targets), radius, data, quantity, offset, special_data, velocity, (should_offset ? db("note", "Location will be offset 1 block-height upward (see documentation)") : ""));
}
for (LocationTag location : locations) {
if (should_offset) {
// Slightly increase the location's Y so effects don't seem to come out of the ground
location = new LocationTag(location.clone().add(0, 1, 0));
}
// Play the Bukkit effect the number of times specified
if (effect != null) {
for (int n = 0; n < quantity.asInt(); n++) {
if (targets != null) {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
// TODO: 1.13
player.getPlayerEntity().playEffect(location, effect, data.asInt());
}
}
} else {
location.getWorld().playEffect(location, effect, data.asInt(), radius.asInt());
}
}
} else // Play a ParticleEffect
if (particleEffect != null) {
List<Player> players = new ArrayList<>();
if (targets == null) {
float rad = radius.asFloat();
for (Player player : location.getWorld().getPlayers()) {
if (player.getLocation().distanceSquared(location) < rad * rad) {
players.add(player);
}
}
} else {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
players.add(player.getPlayerEntity());
}
}
}
Class clazz = particleEffect.neededData();
Object dataObject = null;
if (clazz != null) {
if (special_data == null) {
Debug.echoError("Missing required special data for particle: " + particleEffect.getName());
return;
} else if (clazz == org.bukkit.Particle.DustOptions.class) {
ListTag dataList = ListTag.valueOf(special_data.asString(), scriptEntry.getContext());
if (dataList.size() != 2) {
Debug.echoError("DustOptions special_data must have 2 list entries for particle: " + particleEffect.getName());
return;
} else {
float size = Float.parseFloat(dataList.get(0));
ColorTag color = ColorTag.valueOf(dataList.get(1), scriptEntry.context);
dataObject = new org.bukkit.Particle.DustOptions(color.getColor(), size);
}
} else if (clazz == BlockData.class) {
MaterialTag blockMaterial = MaterialTag.valueOf(special_data.asString(), scriptEntry.getContext());
dataObject = blockMaterial.getModernData();
} else if (clazz == ItemStack.class) {
ItemTag itemType = ItemTag.valueOf(special_data.asString(), scriptEntry.getContext());
dataObject = itemType.getItemStack();
} else // Intentionally list last due to requiring 1.17+
if (clazz == org.bukkit.Particle.DustTransition.class) {
ListTag dataList = ListTag.valueOf(special_data.asString(), scriptEntry.getContext());
if (dataList.size() != 3) {
Debug.echoError("DustTransition special_data must have 3 list entries for particle: " + particleEffect.getName());
return;
} else {
float size = Float.parseFloat(dataList.get(0));
ColorTag fromColor = ColorTag.valueOf(dataList.get(1), scriptEntry.context);
ColorTag toColor = ColorTag.valueOf(dataList.get(2), scriptEntry.context);
dataObject = new org.bukkit.Particle.DustTransition(fromColor.getColor(), toColor.getColor(), size);
}
} else {
Debug.echoError("Unknown particle data type: " + clazz.getCanonicalName() + " for particle: " + particleEffect.getName());
return;
}
} else if (special_data != null) {
Debug.echoError("Particles of type '" + particleEffect.getName() + "' cannot take special_data as input.");
return;
}
Random random = CoreUtilities.getRandom();
int quantityInt = quantity.asInt();
for (Player player : players) {
if (velocity == null) {
particleEffect.playFor(player, location, quantityInt, offset.toVector(), data.asDouble(), dataObject);
} else {
Vector velocityVector = velocity.toVector();
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());
particleEffect.playFor(player, singleLocation, 0, velocityVector, 1f, dataObject);
}
}
}
} else // Play an iconcrack (item break) effect
{
List<Player> players = new ArrayList<>();
if (targets == null) {
float rad = radius.asFloat();
for (Player player : location.getWorld().getPlayers()) {
if (player.getLocation().distanceSquared(location) < rad * rad) {
players.add(player);
}
}
} else {
for (PlayerTag player : targets) {
if (player.isValid() && player.isOnline()) {
players.add(player.getPlayerEntity());
}
}
}
if (iconcrack != null) {
ItemStack itemStack = iconcrack.getItemStack();
Particle particle = NMSHandler.getParticleHelper().getParticle("ITEM_CRACK");
for (Player player : players) {
particle.playFor(player, location, quantity.asInt(), offset.toVector(), data.asFloat(), itemStack);
}
}
}
}
}
Aggregations