/** * Converts a raw slot ID into its local slot ID into whichever of the two * inventories the slot points to. * <p> * If the raw slot refers to the upper inventory, it will be returned * unchanged and thus be suitable for getTopInventory().getItem(); if it * refers to the lower inventory, the output will differ from the input * and be suitable for getBottomInventory().getItem(). * * @param rawSlot The raw slot ID. * @return The converted slot ID. */ public final int convertSlot(int rawSlot) { int numInTop = getTopInventory().getSize(); if (rawSlot < numInTop) { return rawSlot; } int slot = rawSlot - numInTop; if (getPlayer().getGameMode() == GameMode.CREATIVE && getType() == InventoryType.PLAYER) { return slot; } if (getType() == InventoryType.CRAFTING) { if(slot < 4) return 39 - slot; else slot -= 4; } if (slot >= 27) slot -= 27; else slot += 9; return slot; }
/** * Consumes 1 copy of the given item, which must be held by the given player, unless that player * is in Creative mode. * * @param player the player holding the item * @param item the item to consume */ public static void consumeHeldItem(HumanEntity player, ItemStack item) { if (player.getGameMode() == GameMode.CREATIVE) { return; } if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { player.getInventory().clear(player.getInventory().getHeldItemSlot()); } } }
@Override public MCGameMode getGameMode() { return MCGameMode.valueOf(he.getGameMode().name()); }
/** * Converts a raw slot ID into its local slot ID into whichever of the two * inventories the slot points to. * <p> * If the raw slot refers to the upper inventory, it will be returned * unchanged and thus be suitable for getTopInventory().getItem(); if it * refers to the lower inventory, the output will differ from the input * and be suitable for getBottomInventory().getItem(). * * @param rawSlot The raw slot ID. * @return The converted slot ID. */ public final int convertSlot(int rawSlot) { int numInTop = getTopInventory().getSize(); if (rawSlot < numInTop) { return rawSlot; } int slot = rawSlot - numInTop; if (getPlayer().getGameMode() == GameMode.CREATIVE && getType() == InventoryType.PLAYER) { return slot; } if (getType() == InventoryType.CRAFTING) { if(slot < 4) return 39 - slot; else slot -= 4; } if (slot >= 27) slot -= 27; else slot += 9; return slot; }
@EventHandler public void onItemDrag(InventoryDragEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { return; } String playerID = PlayerConverter.getID((Player) event.getWhoClicked()); if (Journal.isJournal(playerID, event.getOldCursor()) || Utils.isQuestItem(event.getOldCursor())) { event.setCancelled(true); } }
return; if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) { return;
if(he.getGameMode().equals(GameMode.CREATIVE)) return; //Because Bukkit does strange stuff with the inventory in creative