Search in sources :

Example 11 with Item

use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.

the class User method autoSave.

@Override
public void autoSave() {
    super.autoSave();
    if (player == null) {
        return;
    }
    sendActionBar(ChatColor.GREEN + "Autosaving...");
    Document autoSaveData = new Document("lastSeen", System.currentTimeMillis()).append("maxHealth", player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()).append("health", player.getHealth()).append("gamemode", joined ? player.getGameMode().toString() : getSavedGameMode().toString()).append("inventory", getInventoryAsDocument());
    if (joined) {
        String key = PermissionUtil.verifyActivePermissionLevel(this, PermissionLevel.TESTER, false) ? "lastStaffLocation" : "lastLocation";
        Floor floor = FloorLoader.fromLocation(player.getLocation());
        if (!floor.isVolatile()) {
            autoSaveData.append(key, StorageUtil.locToDoc(player.getLocation()));
        }
    }
    for (ItemStack itemStack : player.getInventory().getContents()) {
        if (itemStack != null) {
            Item item = ItemLoader.fromBukkit(itemStack);
            if (item != null) {
                item.autoSave();
            }
        }
    }
    userHookRegistry.getHooks().forEach(h -> h.onAutoSave(this, autoSaveData));
    update(autoSaveData);
}
Also used : Floor(mc.dragons.core.gameobject.floor.Floor) Item(mc.dragons.core.gameobject.item.Item) Document(org.bson.Document) ItemStack(org.bukkit.inventory.ItemStack)

Example 12 with Item

use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.

the class User method stashItems.

/**
 * Temporarily remove all items of the specified type from the player's inventory.
 *
 * <p>They can be restored at any time with <code>unstashItems</code>, or will
 * automatically be restored at the end of the quest.
 *
 * @param quest
 * @param type
 */
public void stashItems(Quest quest, Material type) {
    List<UUID> stashed = new ArrayList<>();
    for (ItemStack itemStack : player.getInventory().getContents()) {
        if (itemStack == null)
            continue;
        if (itemStack.getType() != type)
            continue;
        Item item = ItemLoader.fromBukkit(itemStack);
        if (item == null)
            continue;
        stashed.add(item.getUUID());
    }
    player.getInventory().remove(type);
    Document stash = getData().get("questStash", new Document());
    stash.computeIfAbsent(quest.getName(), q -> new ArrayList<>());
    stash.getList(quest.getName(), UUID.class).addAll(stashed);
    storageAccess.set("questStash", stash);
    if (stashed.size() > 0) {
        player.sendMessage(ChatColor.RED + "" + stashed.size() + " " + (stashed.size() == 1 ? "item was" : "items were") + " temporarily removed from your inventory due to quest " + quest.getQuestName());
    }
}
Also used : Item(mc.dragons.core.gameobject.item.Item) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack) Document(org.bson.Document)

Example 13 with Item

use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.

the class User method getEffectiveWalkSpeed.

public double getEffectiveWalkSpeed() {
    if (isOverridingWalkSpeed) {
        return player.getWalkSpeed();
    }
    double speed = instance.getServerOptions().getDefaultWalkSpeed();
    for (ItemStack itemStack : player.getInventory().getArmorContents()) {
        if (itemStack != null) {
            Item item = ItemLoader.fromBukkit(itemStack);
            if (item != null) {
                speed += item.getSpeedBoost();
            }
        }
    }
    ItemStack held = player.getInventory().getItemInMainHand();
    Item item = ItemLoader.fromBukkit(held);
    if (item != null) {
        speed += item.getSpeedBoost();
    }
    return Math.min(1.0D, Math.max(0.05D, speed));
}
Also used : Item(mc.dragons.core.gameobject.item.Item) ItemStack(org.bukkit.inventory.ItemStack)

Example 14 with Item

use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.

the class BindSpellCommand method onCommand.

@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender) || !requirePermission(sender, PermissionLevel.GM))
        return true;
    Player player = player(sender);
    if (label.equalsIgnoreCase("testspellbinding")) {
        SpellUtil.updateAllSpellItems(registry, player);
        sender.sendMessage("Held item: " + SpellUtil.sameItem(player.getItemInHand(), ItemLoader.fromBukkit(player.getItemInHand()).getItemStack()));
        sender.sendMessage("Computed slot: " + SpellUtil.getSlotOfItemStack(player, player.getItemInHand()));
        return true;
    }
    ItemStack itemStack = player.getInventory().getItemInMainHand();
    if (itemStack == null) {
        sender.sendMessage(ChatColor.RED + "Item stack is null");
        return true;
    }
    Item item = ItemLoader.fromBukkit(itemStack);
    if (item == null) {
        sender.sendMessage(ChatColor.RED + "Item stack is not an RPG item");
        return true;
    }
    Spell spell = registry.getSpellByName(args[0]);
    if (spell == null) {
        sender.sendMessage(ChatColor.RED + "Invalid spell name");
        return true;
    }
    sender.sendMessage("Bind status before: " + spell.bindStatus(item));
    spell.bind(player, item);
    sender.sendMessage("Bind status after: " + spell.bindStatus(item));
    // since we updated the lore
    player.getInventory().setItemInMainHand(item.getItemStack());
    return true;
}
Also used : Item(mc.dragons.core.gameobject.item.Item) Player(org.bukkit.entity.Player) ItemStack(org.bukkit.inventory.ItemStack) Spell(mc.dragons.spells.spells.Spell)

Example 15 with Item

use of mc.dragons.core.gameobject.item.Item in project DragonsOnline by UniverseCraft.

the class SpellListeners method onInventoryClick.

@SuppressWarnings("deprecation")
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    User user = UserLoader.fromPlayer(player);
    if (e.getInventory().getType() == InventoryType.FURNACE) {
        // 0 = smelting
        // 1 = fuel
        // 2 = result
        CraftInventory cc = (CraftInventory) e.getInventory();
        int i = 0;
        for (ItemStack is : cc.getContents()) {
            user.debug(i + ": " + is);
            i++;
        }
    }
    if (e.getView().getTitle().equals(SpellConstants.ENCHANTER_MENU_TITLE)) {
        user.debug("Interacted with the Enchanter menu. SlotType=" + e.getSlotType());
        CraftInventoryCustom cc = (CraftInventoryCustom) e.getInventory();
        if (e.getSlotType() == SlotType.RESULT) {
            user.debug("RESULT");
            user.debug("curr=" + e.getCurrentItem());
            user.debug("curs=" + e.getCursor());
            Item current = ItemLoader.fromBukkit(e.getCurrentItem());
            if (current == null)
                return;
            user.debug("receiving the updated item");
            current.setItemStack(e.getCurrentItem().clone());
            e.setCurrentItem(new ItemStack(Material.AIR));
            e.setCursor(current.getItemStack());
            cc.setItem(0, new ItemStack(Material.AIR));
            cc.setItem(1, new ItemStack(Material.AIR));
            cc.setItem(2, new ItemStack(Material.AIR));
            e.setResult(Result.DENY);
            e.setCancelled(false);
            return;
        }
        ItemStack cursorCopy = e.getCursor().clone();
        Item item = ItemLoader.fromBukkit(e.getCursor());
        if (item == null)
            return;
        if (e.getSlotType() == SlotType.FUEL && item.getItemClass().getAddons().contains(Dragons.getInstance().getAddonRegistry().getAddonByName("SpellScroll"))) {
            user.debug("Using alternative fuel in furnace for enchanting");
            user.debug("curr=" + e.getCurrentItem() + ", cursor=" + e.getCursor());
            item.setItemStack(cursorCopy);
            if (e.getInventory().getType() == InventoryType.FURNACE) {
                int i = 0;
                for (ItemStack is : cc.getContents()) {
                    user.debug(i + ": " + is);
                    i++;
                }
                e.setCurrentItem(cursorCopy);
                e.setCursor(new ItemStack(Material.AIR));
                e.setCancelled(true);
            }
        }
        if (e.getSlotType() == SlotType.CRAFTING && item.getItemClass().getAddons().contains(Dragons.getInstance().getAddonRegistry().getAddonByName("SpellCast"))) {
            // No fuel
            if (cc.getItem(1) == null)
                return;
            String spellDisplayName = ChatColor.stripColor(cc.getItem(1).getItemMeta().getDisplayName().replace("Scroll", "").trim());
            user.debug("binding spell " + spellDisplayName);
            Spell spell = registry.getSpellByDisplayName(spellDisplayName);
            user.debug("spell=" + spell);
            if (spell.bindStatus(item) == BindStatus.CAPABLE) {
                double gold = user.getGold();
                if (gold < 100.0) {
                    player.sendMessage(ChatColor.RED + "Binding spells costs 100 Gold. (Need " + (100 - gold) + " more)");
                    player.getInventory().addItem(cc.getItem(1) == null ? new ItemStack(Material.AIR) : cc.getItem(1));
                    player.getInventory().addItem(e.getCursor());
                    e.setCursor(new ItemStack(Material.AIR));
                    e.setCurrentItem(new ItemStack(Material.AIR));
                    e.setCancelled(true);
                    player.closeInventory();
                    return;
                }
                user.takeGold(100.0);
                spell.bind(player, item);
                cc.setItem(0, new ItemStack(Material.AIR));
                cc.setItem(1, new ItemStack(Material.AIR));
                cc.setItem(2, item.getItemStack());
                e.setCursor(new ItemStack(Material.AIR));
                e.setResult(Result.ALLOW);
                e.setCancelled(true);
                user.debug("bound spell and updated inventory");
                player.sendMessage(ChatColor.DARK_PURPLE + "Bound spell " + ChatColor.LIGHT_PURPLE + spell.getSpellDisplayName() + ChatColor.DARK_PURPLE + " to " + ChatColor.LIGHT_PURPLE + item.getName());
            }
        }
        return;
    }
}
Also used : CraftInventoryCustom(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryCustom) CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory) Item(mc.dragons.core.gameobject.item.Item) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) ItemStack(org.bukkit.inventory.ItemStack) Spell(mc.dragons.spells.spells.Spell) EventHandler(org.bukkit.event.EventHandler)

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