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());
}
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!");
}
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();
}
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() + "])");
}
}
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);
}
Aggregations