use of com.denizenscript.denizen.scripts.containers.core.BookScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class ItemTag method valueOf.
@Fetchable("i")
public static ItemTag valueOf(String string, TagContext context) {
if (string == null || string.equals("")) {
return null;
}
ItemTag stack = null;
if (ObjectFetcher.isObjectWithProperties(string)) {
return ObjectFetcher.getObjectFromWithProperties(ItemTag.class, string, context);
}
if (string.startsWith("i@")) {
string = string.substring("i@".length());
}
string = CoreUtilities.toLowerCase(string);
try {
if (ScriptRegistry.containsScript(string, ItemScriptContainer.class)) {
ItemScriptContainer isc = ScriptRegistry.getScriptContainerAs(string, ItemScriptContainer.class);
// TODO: If a script does not contain tags, get the clean reference here.
stack = isc.getItemFrom(context);
if (stack == null && (context == null || context.showErrors())) {
Debug.echoError("Item script '" + isc.getName() + "' returned a null item.");
}
} else if (ScriptRegistry.containsScript(string, BookScriptContainer.class)) {
BookScriptContainer book = ScriptRegistry.getScriptContainerAs(string, BookScriptContainer.class);
stack = book.getBookFrom(context);
if (stack == null && (context == null || context.showErrors())) {
Debug.echoError("Book script '" + book.getName() + "' returned a null item.");
}
}
if (stack != null) {
return stack;
}
} catch (Exception ex) {
if (Debug.verbose) {
Debug.echoError(ex);
}
}
try {
MaterialTag mat = MaterialTag.valueOf(string.toUpperCase(), context);
if (mat != null) {
stack = new ItemTag(mat.getMaterial());
}
if (stack != null) {
return stack;
}
} catch (Exception ex) {
if (!string.equalsIgnoreCase("none") && (context == null || context.showErrors())) {
Debug.log("Does not match a valid item ID or material: " + string);
}
if (Debug.verbose) {
Debug.echoError(ex);
}
}
if (context == null || context.showErrors()) {
Debug.log("valueOf ItemTag returning null: " + string);
}
return null;
}
use of com.denizenscript.denizen.scripts.containers.core.BookScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class ScribeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Deprecations.scribeCommand.warn(scriptEntry);
// Retrieve objects from ScriptEntry
BookAction action = (BookAction) scriptEntry.getObject("action");
ItemTag book = scriptEntry.getObjectTag("item");
ScriptTag script = scriptEntry.getObjectTag("script");
LocationTag location = scriptEntry.getObjectTag("location");
BookScriptContainer bookScript = (BookScriptContainer) script.getContainer();
book = bookScript.writeBookTo(book, scriptEntry.getContext());
// Post-write action? Can be NONE.
switch(action) {
case DROP:
dropBook(location, book.getItemStack());
break;
case GIVE:
giveBook(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), book.getItemStack());
// Update player's inventory
Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().updateInventory();
break;
case EQUIP:
equipBook(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), book.getItemStack());
// Update player's inventory
Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().updateInventory();
break;
case NONE:
break;
}
}
Aggregations