use of net.aufdemrand.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class Denizen method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
if (cmdName.equalsIgnoreCase("ex")) {
List<Object> entries = new ArrayList<Object>();
String entry = "";
for (String arg : args) {
entry = entry + arg + " ";
}
if (entry.length() < 2) {
sender.sendMessage("/ex <dCommand> (arguments)");
return true;
}
if (Settings.showExHelp()) {
if (dB.showDebug) {
sender.sendMessage(ChatColor.YELLOW + "Executing dCommand... check the console for debug output!");
} else {
sender.sendMessage(ChatColor.YELLOW + "Executing dCommand... to see debug, use /denizen debug");
}
}
entries.add(entry);
InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("EXCOMMAND"));
dNPC npc = null;
if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null) {
npc = new dNPC(Depends.citizens.getNPCSelector().getSelected(sender));
}
List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null, new BukkitScriptEntryData(sender instanceof Player ? new dPlayer((Player) sender) : null, npc));
queue.addEntries(scriptEntries);
queue.start();
return true;
}
String modifier = args.length > 0 ? args[0] : "";
if (!commandManager.hasCommand(cmd, modifier) && !modifier.isEmpty()) {
return suggestClosestModifier(sender, cmd.getName(), modifier);
}
Object[] methodArgs = { sender };
return commandManager.executeSafe(cmd, args, sender, methodArgs);
}
use of net.aufdemrand.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class InventoryScriptContainer method getInventoryFrom.
public dInventory getInventoryFrom(dPlayer player, dNPC npc) {
// TODO: Clean all this code!
dInventory inventory = null;
BukkitTagContext context = new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this));
try {
if (contains("INVENTORY")) {
if (InventoryType.valueOf(getString("INVENTORY").toUpperCase()) != null) {
inventory = new dInventory(InventoryType.valueOf(getString("INVENTORY").toUpperCase()));
if (contains("TITLE")) {
inventory.setTitle(TagManager.tag(getString("TITLE"), context));
}
inventory.setIdentifiers("script", getName());
} else {
dB.echoError("Invalid inventory type specified. Assuming \"CHEST\"");
}
}
int size = 0;
if (contains("SIZE")) {
if (inventory != null && !getInventoryType().name().equalsIgnoreCase("CHEST")) {
dB.echoError("You can only set the size of chest inventories!");
} else {
size = aH.getIntegerFrom(TagManager.tag(getString("SIZE"), context));
if (size == 0) {
dB.echoError("Inventory size can't be 0. Assuming default of inventory type...");
}
if (size % 9 != 0) {
size = (int) Math.ceil(size / 9) * 9;
dB.echoError("Inventory size must be a multiple of 9! Rounding up to " + size + "...");
}
if (size < 0) {
size = size * -1;
dB.echoError("Inventory size must be a positive number! Inverting to " + size + "...");
}
inventory = new dInventory(size, contains("TITLE") ? TagManager.tag(getString("TITLE"), context) : "Chest");
inventory.setIdentifiers("script", getName());
}
}
if (size == 0) {
size = getInventoryType().getDefaultSize();
}
boolean[] filledSlots = new boolean[size];
if (contains("SLOTS")) {
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("]")) {
dB.echoError("Inventory script \"" + getName() + "\" has an invalid slots line: [" + items + "]... Ignoring it");
continue;
}
String[] itemsInLine = items.substring(1, items.length() - 1).split("\\[?\\]?\\s+\\[", -1);
for (String item : itemsInLine) {
if (contains("DEFINITIONS." + item)) {
dItem def = dItem.valueOf(TagManager.tag(getString("DEFINITIONS." + item), context), player, npc);
if (def == null) {
dB.echoError("Invalid definition '" + item + "' in inventory script '" + getName() + "'" + "... Ignoring it and assuming \"AIR\"");
finalItems[itemsAdded] = new ItemStack(Material.AIR);
} else {
finalItems[itemsAdded] = def.getItemStack();
}
} else if (dItem.matches(item)) {
finalItems[itemsAdded] = dItem.valueOf(item, player, npc).getItemStack();
} else {
finalItems[itemsAdded] = new ItemStack(Material.AIR);
if (!item.isEmpty()) {
dB.echoError("Inventory script \"" + getName() + "\" has an invalid slot item: [" + item + "]... Ignoring it and assuming \"AIR\"");
}
}
filledSlots[itemsAdded] = !item.isEmpty();
itemsAdded++;
}
}
if (inventory == null) {
size = finalItems.length % 9 == 0 ? finalItems.length : Math.round(finalItems.length / 9) * 9;
inventory = new dInventory(size == 0 ? 9 : size, contains("TITLE") ? TagManager.tag(getString("TITLE"), context) : "Chest");
}
inventory.setContents(finalItems);
}
if (contains("PROCEDURAL ITEMS")) {
// TODO: Document this feature!
if (inventory == null) {
size = InventoryType.CHEST.getDefaultSize();
inventory = new dInventory(size, contains("TITLE") ? TagManager.tag(getString("TITLE"), context) : "Chest");
}
List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "PROCEDURAL ITEMS");
if (!entries.isEmpty()) {
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("INV_SCRIPT_ITEM_PROC"));
queue.addEntries(entries);
queue.setReqId(id);
if (contains("DEFINITIONS")) {
YamlConfiguration section = getConfigurationSection("DEFINITIONS");
for (StringHolder string : section.getKeys(false)) {
String definition = string.str;
queue.addDefinition(definition, section.getString(definition));
}
}
queue.start();
if (DetermineCommand.hasOutcome(id)) {
dList list = dList.valueOf(DetermineCommand.getOutcome(id).get(0));
if (list != null) {
int x = 0;
for (dItem item : list.filter(dItem.class)) {
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) {
dB.echoError("Woah! An exception has been called with this inventory script!");
dB.echoError(e);
inventory = null;
}
if (inventory != null) {
InventoryScriptHelper.tempInventoryScripts.put(inventory.getInventory(), getName());
}
return inventory;
}
Aggregations