use of net.aufdemrand.denizencore.objects.aH.Argument in project Denizen-For-Bukkit by DenizenScript.
the class dInventory method valueOf.
/**
* Gets a dInventory from a string format.
*
* @param string The inventory in string form. (in@player[playerName], in@scriptName, etc.)
* @return The dInventory value. If the string is incorrectly formatted or
* the specified inventory is invalid, this is null.
*/
public static dInventory valueOf(String string, dPlayer player, dNPC npc) {
if (string == null) {
return null;
}
///////
// Handle objects with properties through the object fetcher
Matcher m = ObjectFetcher.DESCRIBED_PATTERN.matcher(string);
if (m.matches()) {
return ObjectFetcher.getObjectFrom(dInventory.class, string, new BukkitTagContext(player, npc, false, null, false, null));
}
// Match in@scriptName for Inventory Scripts, as well as in@notableName
m = inventory_by_script.matcher(string);
if (m.matches()) {
if (ScriptRegistry.containsScript(m.group(2), InventoryScriptContainer.class)) {
return ScriptRegistry.getScriptContainerAs(m.group(2), InventoryScriptContainer.class).getInventoryFrom(player, npc);
}
if (NotableManager.isSaved(m.group(2)) && NotableManager.isType(m.group(2), dInventory.class)) {
return (dInventory) NotableManager.getSavedObject(m.group(2));
}
for (String idType : idTypes) {
if (m.group(2).equalsIgnoreCase(idType)) {
return new dInventory(m.group(2));
}
}
}
m = inventory_by_type.matcher(string);
if (m.matches()) {
// Set the type of the inventory holder
String type = CoreUtilities.toLowerCase(m.group(2));
// Set the name/id/location of the inventory holder
String holder = m.group(3);
if (type.equals("generic")) {
Argument arg = Argument.valueOf(holder);
if (arg.matchesEnum(InventoryType.values())) {
return new dInventory(InventoryType.valueOf(holder.toUpperCase()));
} else if (arg.matchesPrimitive(PrimitiveType.Integer)) {
return new dInventory(arg.asElement().asInt());
} else {
dB.echoError("That type of inventory does not exist!");
}
} else if (type.equals("npc")) {
if (dNPC.matches(holder)) {
return dNPC.valueOf(holder).getDenizenInventory();
}
} else if (type.equals("player")) {
if (dPlayer.matches(holder)) {
return dPlayer.valueOf(holder).getInventory();
}
} else if (type.equals("workbench")) {
if (dPlayer.matches(holder)) {
dInventory workbench = dPlayer.valueOf(holder).getWorkbench();
if (workbench != null) {
dB.echoError("Value of dInventory returning null (" + string + ")." + " Specified player does not have an open workbench.");
} else {
return workbench;
}
}
} else if (type.equals("enderchest")) {
if (dPlayer.matches(holder)) {
return dPlayer.valueOf(holder).getEnderChest();
}
} else if (type.equals("entity")) {
if (dEntity.matches(holder)) {
return dEntity.valueOf(holder).getInventory();
}
} else if (type.equals("location")) {
if (dLocation.matches(holder)) {
return dLocation.valueOf(holder).getInventory();
}
}
// If the dInventory is invalid, alert the user and return null
dB.echoError("Value of dInventory returning null. Invalid " + type + " specified: " + holder);
return null;
}
dB.echoError("Value of dInventory returning null. Invalid dInventory specified: " + string);
return null;
}
Aggregations