Examples of PlayerInventory


Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

  @EventHandler
  public void onWindowOpen(WindowOpenEvent event) {
    if (event.getWindow() instanceof DefaultWindow) {
      return;
    }
    PlayerInventory inventory = event.getWindow().getPlayerInventory();
    int size = event.getWindow().getSize() - (inventory.getMain().size() + inventory.getQuickbar().size());
    event.getMessages().add(new WindowOpenMessage(event.getWindow(), size));
  }
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

    Player player = args.popPlayerOrMe("player", source);
    Material filter = VanillaArgumentTypes.popMaterial("filter", args);
    Integer data = args.popInteger("data");
    args.assertCompletelyParsed();

    PlayerInventory inv = player.get(PlayerInventory.class);
    if (inv == null) {
      throw new CommandException(player.getName() + " doesn't have a inventory!");
    } else {
      // Count the items and clear the inventory
      Inventory[] inventories = new Inventory[] {inv.getMain(), inv.getQuickbar(), inv.getArmor()};
      int cleared = 0;
      for (int k = 0; k < inventories.length; k++) {
        for (int i = 0; i < inventories[k].size(); i++) {
          if (inventories[k].get(i) != null && (filter == null || inventories[k].get(i).isMaterial(filter)) && (data == null || inventories[k].get(i).getData() == data)) {
            cleared += inventories[k].get(i).getAmount();
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

    Material material = VanillaArgumentTypes.popMaterial("material", args);
    int quantity = args.popInteger("quantity");
    int data = args.popInteger("data");
    args.assertCompletelyParsed();

    PlayerInventory inventory = player.get(PlayerInventory.class);
    if (inventory != null) {
      inventory.add(new ItemStack(material, data, quantity));
      source.sendMessage(plugin.getPrefix() + ChatStyle.GREEN + "Gave "
          + ChatStyle.WHITE + player.getName() + " " + quantity + ChatStyle.GREEN + " of " + ChatStyle.WHITE
          + material.getDisplayName());
    } else {
      throw new CommandException(player.getName() + " doesn't have a inventory!");
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

    args.assertCompletelyParsed();

    String name = command.getName();
    if (name.startsWith("quickbar_")) {
      Player player = (Player) source;
      PlayerInventory inventory = player.get(PlayerInventory.class);
      if (inventory != null) {
        QuickbarInventory quickbar = inventory.getQuickbar();
        HUD hud = player.get(HUD.class);
        int newSlot = quickbar.getSelectedSlot().getIndex();
        if (name.endsWith("left")) {
          newSlot++;
          if (newSlot > 8) {
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

  @Override
  public boolean onShiftClick(ItemStack stack, int slot, Inventory from) {
    if (getPlayer().getEngine().getPlatform() == Platform.CLIENT) {
      throw new IllegalStateException("Shift click handling is handled server side.");
    }
    final PlayerInventory inventory = getPlayerInventory();

    // From main inventory/quickbar to the dispenser
    if (from instanceof PlayerMainInventory || from instanceof PlayerQuickbar) {
      for (InventoryConverter conv : this.getInventoryConverters()) {
        Inventory inv = conv.getInventory();
        if (inv instanceof DropperInventory) {
          Grid grid = inv.grid(3);
          final int height = grid.getHeight();
          final int length = grid.getLength();
          for (int y = height - 1; y >= 0; y--) {
            int x1 = length * y;
            int x2 = x1 + length - 1;
            inv.add(x1, x2, stack);
            from.set(slot, stack);
            if (stack.isEmpty()) {
              return true;
            }
          }
        }
      }
    }

    // From chest to inventory/quickbar
    if (from instanceof DropperInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }

      // To main inventory (reversed)
      final Inventory main = inventory.getMain();
      final int height = 3;
      final int length = 9;
      for (int y = 0; y < height; y++) {
        int x1 = length * y;
        int x2 = x1 + length - 1;
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

  @Override
  public boolean onShiftClick(ItemStack stack, int slot, Inventory from) {
    if (getPlayer().getEngine().getPlatform() == Platform.CLIENT) {
      throw new IllegalStateException("Shift click handling is handled server side.");
    }
    final PlayerInventory inventory = getPlayerInventory();

    // From main inventory/quickbar to the dispenser
    if (from instanceof PlayerMainInventory || from instanceof QuickbarInventory) {
      for (InventoryConverter conv : this.getInventoryConverters()) {
        Inventory inv = conv.getInventory();
        if (inv instanceof DispenserInventory) {
          Grid grid = inv.grid(3);
          final int height = grid.getHeight();
          final int length = grid.getLength();
          for (int row = height - 1; row >= 0; row--) {
            int startSlot = length * row;
            int endSlot = startSlot + length - 1;
            inv.add(startSlot, endSlot, stack);
            from.set(slot, stack);
            if (stack.isEmpty()) {
              return true;
            }
          }
        }
      }
    }

    // From chest to inventory/quickbar
    if (from instanceof DispenserInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }

      // To main inventory (reversed)
      final Inventory main = inventory.getMain();
      for (int row = 0; row < PlayerMainInventory.HEIGHT; row++) {
        int startSlot = PlayerMainInventory.LENGTH * row;
        int endSlot = startSlot + PlayerMainInventory.LENGTH - 1;
        main.add(endSlot, startSlot, stack);
        from.set(slot, stack);
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

  @Override
  public boolean onShiftClick(ItemStack stack, int slot, Inventory from) {
    if (getPlayer().getEngine().getPlatform() == Platform.CLIENT) {
      throw new IllegalStateException("Shift click handling is handled server side.");
    }
    final PlayerInventory inventory = getPlayerInventory();

    // From main inventory/quickbar to the chest
    if (from instanceof PlayerMainInventory || from instanceof PlayerQuickbar) {
      for (InventoryConverter conv : this.getInventoryConverters()) {
        Inventory inv = conv.getInventory();
        if (inv instanceof ChestInventory) {
          Grid grid = inv.grid(ChestInventory.LENGTH);
          for (int row = grid.getHeight() - 1; row >= 0; row--) {
            int startSlot = ChestInventory.LENGTH * row;
            int endSlot = startSlot + ChestInventory.LENGTH - 1;
            inv.add(startSlot, endSlot, stack);
            from.set(slot, stack);
            if (stack.isEmpty()) {
              return true;
            }
          }
        }
      }
    }

    // From chest to inventory/quickbar
    if (from instanceof ChestInventory) {
      // To quickbar (reversed)
      final QuickbarInventory qbar = inventory.getQuickbar();
      qbar.add(qbar.size() - 1, 0, stack);
      from.set(slot, stack);
      if (stack.isEmpty()) {
        return true;
      }

      // To main inventory (reversed)
      final Inventory main = inventory.getMain();
      for (int row = 0; row < PlayerMainInventory.HEIGHT; row++) {
        int startSlot = PlayerMainInventory.LENGTH * row;
        int endSlot = startSlot + PlayerMainInventory.LENGTH - 1;
        main.add(endSlot, startSlot, stack);
        from.set(slot, stack);
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

        }
      }
    } else if (item.getMaterial() instanceof Armor) {
      for (Player player : block.getWorld().getNearbyPlayers(block.getPosition(), 2)) {
        if (player.getPhysics().getPosition().getBlock().equals(facingBlock)) {
          PlayerInventory inv = player.get(PlayerInventory.class);
          int armorSlot = ((Armor) item.getMaterial()).getEquipableSlot();
          if (inv.getArmor().get(armorSlot) != null) {
            return false;
          }
          boolean canSet = inv.getArmor().canSet(armorSlot, item);
          InventoryCanSetEvent event = player.getEngine().getEventManager().callEvent(new InventoryCanSetEvent(inv.getArmor(), new BlockCause(block), armorSlot, item, !canSet));
          if (event.isCancelled()) {
            return false;
          }
          inv.getArmor().set(armorSlot, item, true);
          slot.addAmount(-1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(Dye.BONE_MEAL)) {
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

   */
  public abstract int getEquipableSlot();

  @Override
  public void onInteract(Entity entity, Block block, Action type, BlockFace clickedface) {
    PlayerInventory inv = entity.get(PlayerInventory.class);
    if (inv != null) {
      switch (type) {
        case RIGHT_CLICK:
          if (inv.getArmor().get(getEquipableSlot()) == null) {
            inv.getArmor().set(getEquipableSlot(), inv.getHeldItem());
            inv.getQuickbar().getSelectedSlot().set(null);
          }
      }
    }
  }
View Full Code Here

Examples of org.spout.vanilla.component.entity.inventory.PlayerInventory

  /**
   * Sets the selected quickbar slot.
   */
  @Override
  public void update() {
    PlayerInventory inventory = hud.getOwner().get(PlayerInventory.class);
    if (inventory == null) {
      return;
    }
    QuickbarInventory quickbar = inventory.getQuickbar();
    if (quickbar == null) {
      return;
    }
    int slot = quickbar.getSelectedSlot().getIndex();

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.