use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class BeaconEffectHandler method handle.
@Override
public void handle(GlowSession session, BeaconEffectMessage message) {
GlowPlayer player = session.getPlayer();
// Verify that the current player is in a beacon
if (!(player.getOpenInventory().getTopInventory() instanceof GlowBeaconInventory)) {
return;
}
GlowBeaconInventory beacon = (GlowBeaconInventory) player.getOpenInventory().getTopInventory();
beacon.setActiveEffects(message.getPrimary(), message.getSecondary());
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class EditBookHandler method handle.
@Override
public void handle(GlowSession session, EditBookMessage message) {
GlowPlayer player = session.getPlayer();
ItemStack item = message.getBook();
if (!isWritableBook(item)) {
return;
}
BookMeta book = (BookMeta) item.getItemMeta();
// Ignore if book is empty
if (!book.hasPages()) {
return;
}
// If signing, the book should have a title.
if (message.isSigning() && !book.hasTitle()) {
return;
}
// Verify item in hand is also a book
ItemStack inHand = message.getHand() == 0 ? player.getInventory().getItemInMainHand() : player.getInventory().getItemInOffHand();
if (!isWritableBook(inHand)) {
return;
}
BookMeta bookInHand = (BookMeta) inHand.getItemMeta();
// Update meta of the book in hand
if (message.isSigning()) {
bookInHand.setAuthor(book.getAuthor());
bookInHand.setTitle(book.getTitle());
bookInHand.setPages(book.getPages());
inHand.setType(Material.WRITTEN_BOOK);
} else {
bookInHand.setPages(book.getPages());
}
// Update the book in inventory.
inHand.setItemMeta(bookInHand);
if (message.getHand() == 0) {
player.getInventory().setItemInMainHand(inHand);
} else {
player.getInventory().setItemInOffHand(inHand);
}
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class NameItemHandler method handle.
@Override
public void handle(GlowSession session, NameItemMessage message) {
GlowPlayer player = session.getPlayer();
// Verify that the current player is in an anvil
if (!(player.getOpenInventory().getTopInventory() instanceof GlowAnvilInventory)) {
return;
}
GlowAnvilInventory anvil = (GlowAnvilInventory) player.getOpenInventory().getTopInventory();
anvil.setRenameText(message.getName());
}
use of net.glowstone.entity.GlowPlayer 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 net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class QueryTest method testFullStats.
@Test
public void testFullStats() throws Exception {
World world = mock(World.class);
when(world.getName()).thenReturn("world");
GlowPlayer p1 = mock(GlowPlayer.class);
GlowPlayer p2 = mock(GlowPlayer.class);
when(p1.getName()).thenReturn("barneygale");
when(p2.getName()).thenReturn("Vivalahelvig");
PluginManager pluginManager = mock(PluginManager.class);
when(glowServer.getMotd()).thenReturn("A Minecraft Server");
Mockito.doReturn(Arrays.asList(p1, p2)).when(glowServer).getOnlinePlayers();
when(glowServer.getMaxPlayers()).thenReturn(20);
when(glowServer.getPort()).thenReturn(25565);
when(glowServer.getWorlds()).thenReturn(Arrays.asList(world));
when(glowServer.getIp()).thenReturn("");
when(glowServer.getVersion()).thenReturn("123");
when(glowServer.getBukkitVersion()).thenReturn("xyz");
when(glowServer.getPluginManager()).thenReturn(pluginManager);
when(pluginManager.getPlugins()).thenReturn(new Plugin[0]);
QueryHandler handler = new QueryHandler(server, queryPlugins);
when(random.nextInt()).thenReturn(9513307);
server.generateChallengeToken(address);
testChannelRead(handler, FULL_STATS_RECV, FULL_STATS_SEND);
}
Aggregations