use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class EnchantmentScriptContainer method runSubScript.
public void runSubScript(String pathName, Entity attacker, Entity victim, Entity primary, int level) {
validateThread();
List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(new EntityTag(primary)), pathName);
if (entries == null || entries.isEmpty()) {
return;
}
InstantQueue queue = new InstantQueue(getName());
queue.addEntries(entries);
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = new HashMap<>();
if (attacker != null) {
src.contexts.put("attacker", new EntityTag(attacker));
}
if (victim != null) {
src.contexts.put("victim", new EntityTag(victim));
}
src.contexts.put("level", new ElementTag(level));
queue.contextSource = src;
queue.start();
}
use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue 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.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptContainer method runCommandScript.
public ScriptQueue runCommandScript(PlayerTag player, NPCTag npc, Map<String, ObjectTag> context) {
ScriptQueue queue = new InstantQueue(getName());
queue.addEntries(getBaseEntries(new BukkitScriptEntryData(player, npc)));
if (context != null) {
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
queue.setContextSource(src);
}
queue.start();
return queue;
}
Aggregations