Search in sources :

Example 26 with Item

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;
}
Also used : Item(mc.dragons.core.gameobject.item.Item) User(mc.dragons.core.gameobject.user.User)

Example 27 with Item

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();
    });
}
Also used : Document(org.bson.Document) DragonsLogger(mc.dragons.core.logging.DragonsLogger) List(java.util.List) GameObjectType(mc.dragons.core.gameobject.GameObjectType) Map(java.util.Map) StorageManager(mc.dragons.core.storage.StorageManager) User(mc.dragons.core.gameobject.user.User) HashMap(java.util.HashMap) ChatColor(org.bukkit.ChatColor) Item(mc.dragons.core.gameobject.item.Item) ItemClassLoader(mc.dragons.core.gameobject.item.ItemClassLoader) Dragons(mc.dragons.core.Dragons) Document(org.bson.Document)

Example 28 with Item

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);
}
Also used : NPC(mc.dragons.core.gameobject.npc.NPC) Item(mc.dragons.core.gameobject.item.Item) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList)

Example 29 with Item

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.");
        }
    });
}
Also used : Item(mc.dragons.core.gameobject.item.Item) Document(org.bson.Document) UUID(java.util.UUID)

Example 30 with Item

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();
            }
        });
    });
}
Also used : Document(org.bson.Document) SystemProfile(mc.dragons.core.gameobject.user.permission.SystemProfile) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) MessageData(mc.dragons.core.gameobject.user.chat.MessageData) SystemProfileLoader(mc.dragons.core.gameobject.user.permission.SystemProfileLoader) PermissionUtil(mc.dragons.core.util.PermissionUtil) Date(java.util.Date) NametagUtil(mc.dragons.core.util.NametagUtil) Event(org.bukkit.event.Event) HashBasedTable(com.google.common.collect.HashBasedTable) Player(org.bukkit.entity.Player) Inventory(org.bukkit.inventory.Inventory) Scoreboard(org.bukkit.scoreboard.Scoreboard) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder) ItemLoader(mc.dragons.core.gameobject.item.ItemLoader) Location(org.bukkit.Location) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) Map(java.util.Map) StorageUtil(mc.dragons.core.storage.StorageUtil) ChangeLogEntry(mc.dragons.core.storage.loader.ChangeLogLoader.ChangeLogEntry) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) ItemClass(mc.dragons.core.gameobject.item.ItemClass) QuestPauseState(mc.dragons.core.gameobject.quest.Quest.QuestPauseState) QuestLoader(mc.dragons.core.gameobject.quest.QuestLoader) DragonsLogger(mc.dragons.core.logging.DragonsLogger) StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) FloorLoader(mc.dragons.core.gameobject.floor.FloorLoader) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UUID(java.util.UUID) Item(mc.dragons.core.gameobject.item.Item) ChatMessageType(net.md_5.bungee.api.ChatMessageType) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Collectors(java.util.stream.Collectors) SystemProfileFlags(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags) ItemStack(org.bukkit.inventory.ItemStack) Floor(mc.dragons.core.gameobject.floor.Floor) List(java.util.List) GameObject(mc.dragons.core.gameobject.GameObject) GUI(mc.dragons.core.gui.GUI) StorageManager(mc.dragons.core.storage.StorageManager) LagMeter(mc.dragons.core.tasks.LagMeter) BukkitUtil.sync(mc.dragons.core.util.BukkitUtil.sync) Entry(java.util.Map.Entry) HologramUtil(mc.dragons.core.util.HologramUtil) Pattern(java.util.regex.Pattern) PotionEffectType(org.bukkit.potion.PotionEffectType) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) BukkitUtil.rollingSync(mc.dragons.core.util.BukkitUtil.rollingSync) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) HashSet(java.util.HashSet) TextComponent(net.md_5.bungee.api.chat.TextComponent) Quest(mc.dragons.core.gameobject.quest.Quest) QuestStep(mc.dragons.core.gameobject.quest.QuestStep) GameMode(org.bukkit.GameMode) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) GameObjectType(mc.dragons.core.gameobject.GameObjectType) RegionLoader(mc.dragons.core.gameobject.region.RegionLoader) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) ChangeLogLoader(mc.dragons.core.storage.loader.ChangeLogLoader) Attribute(org.bukkit.attribute.Attribute) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) ChatMessageHandler(mc.dragons.core.gameobject.user.chat.ChatMessageHandler) Dragons(mc.dragons.core.Dragons) PotionEffect(org.bukkit.potion.PotionEffect) Consumer(java.util.function.Consumer) StorageAccess(mc.dragons.core.storage.StorageAccess) ArmorStand(org.bukkit.entity.ArmorStand) Region(mc.dragons.core.gameobject.region.Region) ChatColor(org.bukkit.ChatColor) MathUtil(mc.dragons.core.util.MathUtil) Table(com.google.common.collect.Table) LogLevel(mc.dragons.core.logging.LogLevel) NPC(mc.dragons.core.gameobject.npc.NPC) BukkitUtil.rollingAsync(mc.dragons.core.util.BukkitUtil.rollingAsync) PlayerEventListeners(mc.dragons.core.events.PlayerEventListeners) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Item(mc.dragons.core.gameobject.item.Item) GameObject(mc.dragons.core.gameobject.GameObject) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Item (mc.dragons.core.gameobject.item.Item)33 ItemStack (org.bukkit.inventory.ItemStack)19 User (mc.dragons.core.gameobject.user.User)15 Player (org.bukkit.entity.Player)11 EventHandler (org.bukkit.event.EventHandler)11 NPC (mc.dragons.core.gameobject.npc.NPC)9 Document (org.bson.Document)9 UUID (java.util.UUID)6 ArrayList (java.util.ArrayList)5 Entity (org.bukkit.entity.Entity)5 List (java.util.List)4 Dragons (mc.dragons.core.Dragons)4 GameObjectType (mc.dragons.core.gameobject.GameObjectType)4 ItemClass (mc.dragons.core.gameobject.item.ItemClass)4 ChatColor (org.bukkit.ChatColor)4 Location (org.bukkit.Location)4 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Floor (mc.dragons.core.gameobject.floor.Floor)3