@Command(aliases = "clear", usage = "[player]", desc = "Clears your inventory", min = 0, max = 1) @CommandPermissions("vanilla.command.clear") public void clear(CommandContext args, CommandSource source) throws CommandException { if (args.length() == 0) { if (!(source instanceof Player)) { throw new CommandException("You must be a player to clear your own inventory."); } PlayerInventory inv = ((Player) source).get(PlayerInventory.class); if (inv == null) { source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "You have no inventory!"); return; } inv.clear(); } if (args.length() == 1) { Player player = args.getPlayer(0, false); if (player == null) { source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player is not online!"); return; } PlayerInventory inv = player.get(PlayerInventory.class); if (inv == null) { source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player has no inventory!"); return; } player.sendMessage( plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Your inventory has been cleared."); if (source instanceof Player && source.equals(player)) { return; } } source.sendMessage(plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Inventory cleared."); }
@EventHandler public Message onWindowOpen(WindowOpenEvent event) { if (event.getWindow() instanceof DefaultWindow) { return null; // no message for the default Window } PlayerInventory inventory = event.getWindow().getPlayerInventory(); int size = event.getWindow().getSize() - (inventory.getMain().size() + inventory.getQuickbar().size()); return new WindowOpenMessage(event.getWindow(), size); }
@Override protected void worldChanged(World world) { WorldConfigurationNode node = VanillaConfiguration.WORLDS.get(world); maxY = node.MAX_Y.getInt() & (~Chunk.BLOCKS.MASK); minY = node.MIN_Y.getInt() & (~Chunk.BLOCKS.MASK); stepY = node.STEP_Y.getInt() & (~Chunk.BLOCKS.MASK); lowY = maxY - stepY; highY = minY + stepY; lastY = Integer.MAX_VALUE; final DatatableComponent data = world.getComponentHolder().getData(); final Human human = player.get(Human.class); GameMode gamemode = null; Difficulty difficulty = data.get(VanillaData.DIFFICULTY); Dimension dimension = data.get(VanillaData.DIMENSION); WorldType worldType = data.get(VanillaData.WORLD_TYPE); int entityId = player.getId(); if (first) { first = false; if (human != null && human.getAttachedCount() > 1) { gamemode = human.getGameMode(); } else { gamemode = data.get(VanillaData.GAMEMODE); if (human != null) { human.setGamemode(gamemode); } } Server server = (Server) session.getEngine(); PlayerLoginRequestMessage idMsg = new PlayerLoginRequestMessage( entityId, worldType.toString(), gamemode.getId(), (byte) dimension.getId(), difficulty.getId(), (byte) server.getMaxPlayers()); player.getSession().send(false, true, idMsg); player.getSession().setState(State.GAME); } else { if (human != null) { gamemode = human.getGameMode(); } player .getSession() .send( false, new PlayerRespawnMessage( 0, difficulty.getId(), gamemode.getId(), 256, worldType.toString())); player .getSession() .send( false, new PlayerRespawnMessage( 1, difficulty.getId(), gamemode.getId(), 256, worldType.toString())); player .getSession() .send( false, new PlayerRespawnMessage( dimension.getId(), difficulty.getId(), gamemode.getId(), 256, worldType.toString())); } if (human != null) { if (first) { human.setGamemode(gamemode, false); } human.updateAbilities(); } PlayerInventory inv = player.get(PlayerInventory.class); if (inv != null) { inv.updateAll(); } Point pos = world.getSpawnPoint().getPosition(); PlayerSpawnPositionMessage SPMsg = new PlayerSpawnPositionMessage( (int) pos.getX(), (int) pos.getY(), (int) pos.getZ(), getRepositionManager()); player.getSession().send(false, SPMsg); session.send( false, new PlayerHeldItemChangeMessage( session .getPlayer() .add(PlayerInventory.class) .getQuickbar() .getSelectedSlot() .getIndex())); VanillaSky.getSky(world).updatePlayer(player); }