use of org.bukkit.event.inventory.InventoryType.SlotType in project Glowstone by GlowstoneMC.
the class GlowInventory method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
sb.append(" for ").append(getHolder()).append(":\n");
for (GlowInventorySlot slot : slots) {
ItemStack item = slot.getItem();
SlotType type = slot.getType();
if (type != SlotType.CONTAINER || !InventoryUtil.isEmpty(item)) {
sb.append(item).append(" in ").append(slot.getType()).append('\n');
}
}
return sb.toString();
}
use of org.bukkit.event.inventory.InventoryType.SlotType in project Glowstone by GlowstoneMC.
the class CreativeItemHandler method handle.
@Override
public void handle(GlowSession session, CreativeItemMessage message) {
GlowPlayer player = session.getPlayer();
// CraftBukkit does use a inventory view with both inventories set to the player's inventory
// for the creative inventory as there is no second inventory (no crafting) visible for the
// client
InventoryView view = player.getOpenInventory();
// only if creative mode; only if default (player) inventory
if (player.getGameMode() != GameMode.CREATIVE || !GlowInventoryView.isDefault(player.getOpenInventory())) {
player.kickPlayer(GlowstoneMessages.Kick.CREATIVE_ITEM.get());
return;
}
ItemStack stack = ItemIds.sanitize(message.getItem());
// clicking outside drops the item
EventFactory eventFactory = EventFactory.getInstance();
if (message.getSlot() < 0) {
InventoryCreativeEvent event = eventFactory.callEvent(new InventoryCreativeEvent(view, SlotType.OUTSIDE, -999, stack));
if (event.isCancelled()) {
session.send(new SetWindowSlotMessage(-1, -1, stack));
} else {
player.drop(event.getCursor());
}
return;
}
int viewSlot = message.getSlot();
// this happens quiet often as the client tends to update the whole inventory at once
if (Objects.equals(stack, view.getItem(viewSlot))) {
return;
}
GlowInventory inv = player.getInventory();
int slot = view.convertSlot(viewSlot);
SlotType type = inv.getSlotType(slot);
InventoryCreativeEvent event = eventFactory.callEvent(new InventoryCreativeEvent(view, type, viewSlot, stack));
if (event.isCancelled()) {
// send original slot to player to prevent async inventories
player.sendItemChange(viewSlot, view.getItem(viewSlot));
// don't keep track of player's current item, just give them back what they tried to
// place
session.send(new SetWindowSlotMessage(-1, -1, stack));
return;
}
view.setItem(viewSlot, stack);
}
use of org.bukkit.event.inventory.InventoryType.SlotType in project MassiveCore by MassiveCraft.
the class InventoryUtil method isEquipping.
// -------------------------------------------- //
// EVENT INTERPRETATION > EQUIPPING
// -------------------------------------------- //
/**
* This method will return the ItemStack the player is trying to equip.
* If the click event would not result in equipping something null will be returned.
* Note that this algorithm is not perfect. It's an adequate guess.
*
* @param event The InventoryClickEvent to analyze.
* @return The ItemStack the player is trying to equip.
*/
public static ItemStack isEquipping(InventoryClickEvent event) {
boolean isShiftClick = event.isShiftClick();
InventoryType inventoryType = event.getInventory().getType();
SlotType slotType = event.getSlotType();
ItemStack cursor = event.getCursor();
ItemStack currentItem = event.getCurrentItem();
if (isShiftClick) {
if (inventoryType != InventoryType.CRAFTING)
return null;
if (slotType == SlotType.CRAFTING)
return null;
if (slotType == SlotType.ARMOR)
return null;
if (slotType == SlotType.RESULT)
return null;
if (currentItem.getType() == Material.AIR)
return null;
return currentItem;
} else {
if (slotType == SlotType.ARMOR) {
return cursor;
}
return null;
}
}
Aggregations