Search in sources :

Example 61 with GlowPlayer

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());
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) GlowBeaconInventory(net.glowstone.inventory.GlowBeaconInventory)

Example 62 with GlowPlayer

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);
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 63 with GlowPlayer

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());
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) GlowAnvilInventory(net.glowstone.inventory.GlowAnvilInventory)

Example 64 with GlowPlayer

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);
}
Also used : GlowInventoryView(net.glowstone.inventory.GlowInventoryView) InventoryView(org.bukkit.inventory.InventoryView) InventoryCreativeEvent(org.bukkit.event.inventory.InventoryCreativeEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) GlowInventory(net.glowstone.inventory.GlowInventory) EventFactory(net.glowstone.EventFactory) ItemStack(org.bukkit.inventory.ItemStack) SlotType(org.bukkit.event.inventory.InventoryType.SlotType)

Example 65 with GlowPlayer

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);
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) QueryHandler(net.glowstone.net.query.QueryHandler) GlowPlayer(net.glowstone.entity.GlowPlayer) World(org.bukkit.World) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)69 ItemStack (org.bukkit.inventory.ItemStack)15 Vector (org.bukkit.util.Vector)10 EventFactory (net.glowstone.EventFactory)9 Location (org.bukkit.Location)9 Player (org.bukkit.entity.Player)9 GlowEntity (net.glowstone.entity.GlowEntity)8 Message (com.flowpowered.network.Message)7 ArrayList (java.util.ArrayList)7 GlowBlock (net.glowstone.block.GlowBlock)7 Material (org.bukkit.Material)6 World (org.bukkit.World)6 Entity (org.bukkit.entity.Entity)6 List (java.util.List)5 GlowWorld (net.glowstone.GlowWorld)5 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)5 BlockFace (org.bukkit.block.BlockFace)5 CommandTarget (net.glowstone.command.CommandTarget)4 AsyncableMessage (com.flowpowered.network.AsyncableMessage)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3