use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.
the class ReloreCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!requirePermission(sender, PermissionLevel.GM) || !requirePlayer(sender))
return true;
User user = user(sender);
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Specify a new name for the item! /relore <ItemLoreLine1|ItemLoreLine2|ItemLoreLine3...>");
sender.sendMessage(ChatColor.RED + "e.g. /relore The re-lored sword of awesomeness!|This sword is extra fancy.|Another line");
return true;
}
String[] reloreTo = ChatColor.translateAlternateColorCodes('&', StringUtil.concatArgs(args, 0)).split(Pattern.quote("|"));
Item heldItem = ItemLoader.fromBukkit(user.getPlayer().getInventory().getItemInMainHand());
if (heldItem == null) {
sender.sendMessage(ChatColor.RED + "You must hold the item you want to relore!");
return true;
}
heldItem.setCustom(true);
user.getPlayer().getInventory().setItemInMainHand(heldItem.relore(reloreTo));
sender.sendMessage(ChatColor.GREEN + "Relored your item successfully.");
return true;
}
use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.
the class ItemAddon method apply.
@Override
public void apply() {
storageManager.getAllStorageAccess(GameObjectType.ITEM_CLASS, new Document("addons", new Document("$in", List.of(getName())))).stream().map(storageAccess -> itemClassLoader.loadObject(storageAccess)).forEach(itemClass -> {
LOGGER.debug("Applying item add-on " + getName() + " to item class " + itemClass.getClassName());
itemClass.reloadAddons();
});
}
use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.
the class User method cleanupQuest.
/**
* Terminate the specified quest for the user.
*
* @param quest
* @param undoProgress If the user's progress (items, location, objective) should be wiped.
*
* @apiNote NPCs marked for removal on termination will be removed regardless of the value
* of <code>undoProgress</code>.
*/
public void cleanupQuest(Quest quest, boolean undoProgress) {
logQuestEvent(quest, LogLevel.DEBUG, "Cleaning up quest " + quest.getName() + " (undoProgress=" + undoProgress + ")");
for (NPC npc : temporaryNPCs.getOrDefault(quest, new ArrayList<>())) {
npc.remove();
}
List<Item> remove = new ArrayList<>();
for (Entry<Item, Integer> entry : questItems.column(quest).entrySet()) {
if (undoProgress) {
if (entry.getValue() > 0) {
Item item = itemLoader.registerNew(entry.getKey());
item.setQuantity(entry.getValue());
giveItem(item);
} else {
takeItem(entry.getKey(), -entry.getValue(), true, true, false);
}
}
remove.add(entry.getKey());
}
for (Item item : remove) {
questItems.remove(item, quest);
}
unstashItems(quest);
if (questRestoreLocations.containsKey(quest) && undoProgress) {
player.teleport(questRestoreLocations.get(quest));
}
temporaryNPCs.remove(quest);
questRestoreLocations.remove(quest);
}
use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.
the class User method unstashItems.
/**
* Restore all items of the specified type that were stashed for the specified quest.
*
* @param quest
* @param type The type to restore, or null to restore all.
*/
public void unstashItems(Quest quest, Material type) {
Document stash = getData().get("questStash", new Document());
List<UUID> stashed = stash.get(quest.getName(), new ArrayList<>());
itemLoader.loadObjects(Set.copyOf(stashed), items -> {
int restored = 0;
for (Item item : items.values()) {
if (type == null || item.getMaterial() == type) {
giveItem(item, true, false, true);
stashed.remove(item.getUUID());
restored++;
}
}
stash.append(quest.getName(), stashed);
storageAccess.set("questStash", stash);
if (restored > 0) {
player.sendMessage(ChatColor.GREEN + "" + restored + " items were returned to your inventory.");
}
});
}
use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.
the class User method loadInventory.
/*
* Inventory management
*/
/**
* @param cid
* @return whether an error occurred.
*/
public void loadInventory(UUID cid, Document inventory) {
LOGGER.verbose(cid, "Stored inventory data: " + inventory);
List<UUID> usedItems = new ArrayList<>();
Set<UUID> uuids = inventory.entrySet().stream().map(e -> (UUID) e.getValue()).collect(Collectors.toSet());
itemLoader.loadObjects(uuids, items -> {
rollingAsync(() -> {
int dups = 0;
int broken = 0;
Map<Integer, ItemStack> bukkitInventory = new HashMap<>();
for (Entry<String, Object> entry : (Iterable<Entry<String, Object>>) inventory.entrySet()) {
String[] labels = entry.getKey().split(DASH_PATTERN_QUOTED);
String part = labels[0];
int slot = Integer.valueOf(labels[1]);
UUID id = (UUID) entry.getValue();
if (usedItems.contains(id)) {
dups++;
LOGGER.warning(cid, "Duplicated item: " + id);
continue;
}
Item item = items.get(id);
if (item == null) {
broken++;
LOGGER.warning(cid, "Could not load item: " + id);
continue;
}
ItemStack itemStack = item.getItemStack();
if (part.equals("I")) {
bukkitInventory.put(slot, itemStack);
continue;
}
}
syncSetInventory(bukkitInventory);
boolean error = false;
if (broken > 0) {
if (player != null)
player.sendMessage(ChatColor.RED + "" + broken + " items in your saved inventory could not be loaded.");
error = true;
}
if (dups > 0) {
if (player != null)
player.sendMessage(ChatColor.RED + "" + dups + " duplicated items were found in your saved inventory.");
error = true;
}
if (error) {
if (player != null)
player.sendMessage(ChatColor.RED + "Use this error code in any communications with staff: " + StringUtil.toHdFont("Correlation ID: " + cid));
initErrorOccurred();
}
});
});
}
Aggregations