use of org.bukkit.inventory.InventoryView in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldAllowInventoryOpen.
@Test
public void shouldAllowInventoryOpen() {
// given
HumanEntity player = mock(Player.class);
InventoryView transaction = mock(InventoryView.class);
given(transaction.getPlayer()).willReturn(player);
InventoryOpenEvent event = new InventoryOpenEvent(transaction);
given(event.getPlayer()).willReturn(player);
given(listenerService.shouldCancelEvent(player)).willReturn(false);
// when
listener.onPlayerInventoryOpen(event);
// then
assertThat(event.isCancelled(), equalTo(false));
verifyZeroInteractions(bukkitService);
}
use of org.bukkit.inventory.InventoryView in project AuthMeReloaded by AuthMe.
the class PlayerListenerTest method shouldCancelInventoryOpen.
@Test
public void shouldCancelInventoryOpen() {
// given
HumanEntity player = mock(Player.class);
InventoryView transaction = mock(InventoryView.class);
given(transaction.getPlayer()).willReturn(player);
InventoryOpenEvent event = new InventoryOpenEvent(transaction);
given(event.getPlayer()).willReturn(player);
given(listenerService.shouldCancelEvent(player)).willReturn(true);
// when
listener.onPlayerInventoryOpen(event);
// then
assertThat(event.isCancelled(), equalTo(true));
TestHelper.runSyncDelayedTaskWithDelay(bukkitService);
verify(player).closeInventory();
}
use of org.bukkit.inventory.InventoryView in project Glowstone by GlowstoneMC.
the class GlowHumanEntity method openInventory.
@Override
public InventoryView openInventory(Inventory inventory) {
InventoryView view = new GlowInventoryView(this, inventory);
openInventory(view);
return view;
}
use of org.bukkit.inventory.InventoryView in project Glowstone by GlowstoneMC.
the class CreativeItemHandler method handle.
@Override
public void handle(GlowSession session, CreativeItemMessage message) {
GlowPlayer player = session.getPlayer();
GlowInventory inv = player.getInventory();
// 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();
int viewSlot = message.getSlot();
int slot = view.convertSlot(viewSlot);
ItemStack stack = ItemIds.sanitize(message.getItem());
SlotType type = inv.getSlotType(slot);
// only if creative mode
if (player.getGameMode() != GameMode.CREATIVE) {
player.kickPlayer("Illegal creative mode item selection");
return;
}
// only if default (player) inventory
if (!GlowInventoryView.isDefault(player.getOpenInventory())) {
player.kickPlayer("Illegal creative mode item selection");
return;
}
// clicking outside drops the item
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;
}
// this happens quiet often as the client tends to update the whole inventory at once
if (Objects.equals(stack, view.getItem(viewSlot))) {
return;
}
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);
}
Aggregations