Search in sources :

Example 16 with Item

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

the class SpellUtil method sameItem.

public static boolean sameItem(ItemStack a, ItemStack b) {
    Item ia = ItemLoader.fromBukkit(a);
    Item ib = ItemLoader.fromBukkit(b);
    if (ia == null || ib == null)
        return false;
    return ia.getUUID().equals(ib.getUUID());
}
Also used : Item(mc.dragons.core.gameobject.item.Item)

Example 17 with Item

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

the class SpellCastAddon method onCombo.

@Override
public void onCombo(User user, String combo) {
    user.debug("Combo " + combo);
    ItemStack itemStack = user.getPlayer().getInventory().getItemInMainHand();
    Item item = ItemLoader.fromBukkit(itemStack);
    List<Spell> spells = registry.getSpellsByCombo(combo);
    for (Spell spell : spells) {
        if (spell.bindStatus(item) == BindStatus.BOUND) {
            user.sendActionBar(ChatColor.DARK_PURPLE + "Cast " + ChatColor.LIGHT_PURPLE + spell.getSpellDisplayName());
            spell.execute(user);
            return;
        }
    }
    user.sendActionBar(ChatColor.RED + "No spell with that combo is bound to this item!");
}
Also used : Item(mc.dragons.core.gameobject.item.Item) ItemStack(org.bukkit.inventory.ItemStack) Spell(mc.dragons.spells.spells.Spell)

Example 18 with Item

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

the class SpellUtil method updateAllSpellItems.

public static void updateAllSpellItems(SpellRegistry registry, Player player) {
    int i = -1;
    for (ItemStack itemStack : player.getInventory().getContents()) {
        i++;
        if (itemStack == null)
            continue;
        Item item = ItemLoader.fromBukkit(itemStack);
        if (item == null || !item.getItemClass().getAddons().stream().map(a -> a.getClass()).collect(Collectors.toList()).contains(SpellCastAddon.class))
            continue;
        updateItemData(registry, player, i, item);
    }
    player.updateInventory();
}
Also used : Item(mc.dragons.core.gameobject.item.Item) ItemStack(org.bukkit.inventory.ItemStack)

Example 19 with Item

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

the class InventoryEventListeners method onInventoryClick.

@SuppressWarnings("deprecation")
@EventHandler
public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    User user = UserLoader.fromPlayer(player);
    user.debug("Inventory click event. Action=" + e.getAction() + ", clickType=" + e.getClick() + ", slot=" + e.getSlot());
    if (user.hasOpenGUI()) {
        Inventory clickedInventory = e.getClickedInventory();
        if (clickedInventory == null) {
            return;
        }
        GUI gui = user.getCurrentGUI();
        user.debug("gui name=" + gui.getMenuName() + ", clicked name=" + e.getView().getTitle());
        if (e.getView().getTitle().equals(gui.getMenuName())) {
            gui.click(user, e.getSlot());
            e.setCancelled(true);
            user.debug("cancelling click event since it's a gui");
        }
        return;
    } else if (e.getAction() == InventoryAction.SWAP_WITH_CURSOR && e.getClick() == ClickType.LEFT) {
        user.debug("- Merge candidate");
        ItemStack mergeWith = player.getInventory().getItem(e.getSlot());
        ItemStack mergeFrom = e.getCursor();
        if (mergeWith == null || mergeFrom == null) {
            user.debug("- Cannot merge: one or more item stacks is null (with=" + mergeWith + ",from=" + mergeFrom + ")");
            return;
        }
        Item rpgMergeWith = ItemLoader.fromBukkit(mergeWith);
        Item rpgMergeFrom = ItemLoader.fromBukkit(mergeFrom);
        if (rpgMergeWith == null || rpgMergeFrom == null) {
            user.debug("- Cannot merge: one or more rpg items is null (with=" + rpgMergeWith + ",from=" + rpgMergeFrom + ")");
            return;
        }
        if (rpgMergeWith.getClassName().contentEquals(rpgMergeFrom.getClassName()) && !rpgMergeWith.isCustom() && !rpgMergeFrom.isCustom()) {
            int maxStackSize = rpgMergeWith.getMaxStackSize();
            user.debug("- Merge allowed");
            int quantity = rpgMergeWith.getItemStack().getAmount() + rpgMergeFrom.getItemStack().getAmount();
            if (quantity > maxStackSize) {
                rpgMergeFrom.setQuantity(quantity - maxStackSize);
                e.setCursor(rpgMergeFrom.getItemStack());
            } else {
                user.takeItem(rpgMergeFrom, rpgMergeFrom.getQuantity(), true, false, false);
                e.setCursor(null);
            }
            rpgMergeWith.setQuantity(Math.min(quantity, maxStackSize));
            e.setCurrentItem(rpgMergeWith.getItemStack());
            user.debug("- Merge complete (total quantity=" + quantity + ")");
        }
    } else if (e.getAction() == InventoryAction.PICKUP_HALF || e.getAction() == InventoryAction.PICKUP_SOME) {
        user.debug("- Split candidate");
        ItemStack splitFrom = e.getCurrentItem();
        Item rpgSplitFrom = ItemLoader.fromBukkit(splitFrom);
        user.debug("- from=" + rpgSplitFrom);
        if (rpgSplitFrom == null) {
            user.debug("- Cannot split: split from is null");
            return;
        }
        int quantity = splitFrom.getAmount();
        int fromQuantity = quantity / 2;
        int toQuantity = quantity / 2;
        if (quantity % 2 == 1) {
            fromQuantity++;
        }
        Item rpgSplitToCopy = itemLoader.registerNew(rpgSplitFrom);
        rpgSplitToCopy.setQuantity(toQuantity);
        rpgSplitToCopy.setItemStack(splitFrom.clone());
        rpgSplitFrom.setQuantity(fromQuantity);
        e.setCursor(rpgSplitToCopy.getItemStack());
        e.setCurrentItem(rpgSplitFrom.getItemStack());
        user.debug("- Split complete (fromQuantity=" + rpgSplitFrom.getQuantity() + "[" + splitFrom.getAmount() + "], toQuantity=" + rpgSplitToCopy.getQuantity() + "[" + rpgSplitToCopy.getItemStack().getAmount() + "])");
    }
}
Also used : Item(mc.dragons.core.gameobject.item.Item) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) GUI(mc.dragons.core.gui.GUI) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 20 with Item

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

the class PlayerEventListeners method onInteractEntity.

@EventHandler
public void onInteractEntity(PlayerInteractEntityEvent event) {
    LOGGER.debug("Interact entity event on " + event.getPlayer().getName() + " to " + StringUtil.entityToString(event.getRightClicked()));
    User user = UserLoader.fromPlayer(event.getPlayer());
    Entity rightClicked = event.getRightClicked();
    user.debug("Right-click");
    Long lastAccess = interacts.get(user, rightClicked);
    if (lastAccess == null)
        lastAccess = 0L;
    long now = System.currentTimeMillis();
    if (now - lastAccess <= 20L) {
        LOGGER.debug("-Duplicate interact event, ignoring");
        return;
    }
    interacts.put(user, rightClicked, now);
    NPC npc = NPCLoader.fromBukkit(rightClicked);
    List<Consumer<User>> handlers = getRightClickHandlers(rightClicked);
    if (handlers.size() > 0) {
        LOGGER.debug("-Executing associated handlers (" + handlers.size() + ")");
        handlers.forEach(r -> r.accept(user));
    }
    if (npc != null) {
        user.debug("- Clicked an NPC");
        Item item = ItemLoader.fromBukkit(user.getPlayer().getInventory().getItemInMainHand());
        if (item != null) {
            user.debug("- Holding an RPG item");
            item.getItemClass().handleRightClick(user);
            if (item.getItemClass().isGMLocked() && !PermissionUtil.verifyActivePermissionLevel(user, PermissionLevel.GM, false)) {
                user.debug("- GM Locked, cancelling");
                user.sendActionBar(ChatColor.DARK_RED + "- This item is GM locked! -");
                return;
            }
            if (item.getClassName().equals(ItemConstants.IMMORTAL_OVERRIDE_ITEM_CLASS)) {
                user.debug("- Destroy the NPC");
                npc.remove();
                user.getPlayer().sendMessage(ChatColor.GREEN + "Removed NPC successfully.");
                return;
            }
        }
        if (npc.getNPCType() == NPC.NPCType.QUEST && user.hasActiveDialogue() && System.currentTimeMillis() - user.getWhenBeganDialogue() > 1000L) {
            user.debug("Next dialogue");
            user.nextDialogue();
            return;
        }
        npc.getNPCClass().executeConditionals(NPCTrigger.CLICK, user, npc);
        npc.getNPCClass().getAddons().forEach(addon -> addon.onInteract(npc, user));
    }
    user.updateQuests(event);
}
Also used : NPC(mc.dragons.core.gameobject.npc.NPC) Entity(org.bukkit.entity.Entity) Item(mc.dragons.core.gameobject.item.Item) User(mc.dragons.core.gameobject.user.User) Consumer(java.util.function.Consumer) 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