예제 #1
0
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Time selection")) {
      return;
    }
    if (currentItem.getType() != Material.WATCH) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "2 AM")) {
      return;
    }

    plot.setTime(Time.AM2);
    e.setCancelled(true);
  }
예제 #2
0
  public static void openShopGui(UUID playerUUID) {
    Player player = Bukkit.getPlayer(playerUUID);

    if (player == null) {
      Splegg.getInstance()
          .getLogger()
          .info("Tried to open shop inventory for offline player: " + playerUUID.toString());
      return;
    }

    Inventory i = Bukkit.createInventory(null, 9, ChatColor.GOLD + "Splegg Shop");

    ItemStack diamond = Utils.getDiamondSplegg();

    ItemMeta diamondMeta = diamond.getItemMeta();

    // this won't work
    // diamondMeta.getLore().add("shopItem");
    List<String> lore = diamondMeta.getLore();
    lore.add("shopItem");
    diamondMeta.setLore(lore);
    diamond.setItemMeta(diamondMeta);

    i.setItem(5, diamond);
    i.setItem(4, Utils.getGoldSplegg());
    i.setItem(3, Utils.getStoneSplegg());

    player.getPlayer().openInventory(i);
  }
예제 #3
0
  public void fuelRemove(Player player, Material block, Material single, int cost) {

    Inventory fuelInventory = getFuelInventory(player);

    for (ItemStack item : fuelInventory.getContents())
      if (item != null) if (item.getAmount() <= 0) item.setType(Material.AIR);

    if (!blockStacks.split(fuelInventory, block, single, cost, (9 - cost))) {
      commonString.messageSend(
          RocketInit.getPlugin(),
          player,
          true,
          RocketLanguage.FuelOutage(single.toString().toLowerCase()));
      disableRocketBoots(player, true, true, true, true, true);
    }

    try {

      Material jacketType = player.getInventory().getChestplate().getType();
      FileConfiguration fuelConfig = getFuelConfig(player);

      fuelConfig.set(getFuelJacketConfigString(jacketType), fuelInventory.getContents());
      fuelConfig.save(getFuelFile(player));

    } catch (IOException e) {
      commonString.messageSend(
          RocketInit.getPlugin(), player, true, RocketLanguage.RB_JACKET_SAVE_ERROR);
      e.printStackTrace();
    }
  }
예제 #4
0
  /**
   * copies a map of Items to a chest
   *
   * @param toDrop the items to copy
   * @param chest
   * @return items copied
   */
  private LinkedList<ItemStack> copyInventoryToChest(
      HashMap<Integer, ItemStack> toDrop, Chest chest) {
    Inventory chestInv = chest.getInventory();

    Block doubleChestBlock = getDoubleChest(chest.getBlock());
    boolean isDoubleChest = !(doubleChestBlock == null);

    LinkedList<ItemStack> toRemove = new LinkedList<ItemStack>();

    if (chestInv == null) return toRemove;

    for (Integer key : toDrop.keySet()) {
      ItemStack item = toDrop.get(key);
      if (item == null) continue;
      if (chestInv.firstEmpty() == -1) {
        if (!isDoubleChest) break;
        isDoubleChest = false;

        chestInv = ((Chest) doubleChestBlock.getState()).getInventory();
        if (chestInv.firstEmpty() == -1) break;
      }
      chestInv.addItem(item);
      toRemove.add(item);
    }
    return toRemove;
  }
예제 #5
0
파일: Shop.java 프로젝트: Elicis/LoM
  public void createConsumePage() {
    Inventory inv = Bukkit.createInventory(null, 54, "Consume");
    // TODO: Add more Items

    inv.setItem(53, back);
    sites.add(inv);
  }
예제 #6
0
 public void removePearlFromContainer(PrisonPearl pp) {
   Inventory inv[] = new Inventory[2];
   if (HolderStateToInventory(pp, inv) != HolderStateToInventory_SUCCESS) {
     return;
   }
   Inventory real_inv = null;
   int pearlslot = -1;
   for (int inv_idx = 0; inv_idx <= 1 && pearlslot == -1; ++inv_idx) {
     if (inv[inv_idx] == null) {
       continue;
     }
     HashMap<Integer, ? extends ItemStack> inv_contents = inv[inv_idx].all(Material.ENDER_PEARL);
     for (int inv_slot : inv_contents.keySet()) {
       ItemStack slot_item = inv_contents.get(inv_slot);
       if (PrisonPearlPlugin.getPrisonPearlManager().isItemStackPrisonPearl(pp, slot_item)) {
         real_inv = inv[inv_idx];
         pearlslot = inv_slot;
         break;
       }
     }
   }
   if (real_inv == null || pearlslot == -1) {
     return;
   }
   real_inv.setItem(pearlslot, new ItemStack(Material.ENDER_PEARL));
 }
예제 #7
0
  @SuppressWarnings("unchecked")
  public static ShopInventory getShopInventory(String s) {
    try {
      JSONObject j = JSONLoader.get(s);

      assert j.get("items") instanceof Map;
      Map<Integer, Map<String, Object>> items = (Map) j.get("items");

      assert j.get("actions") instanceof Map;
      Map<Integer, String> actions = (Map) j.get("actions");

      assert j.get("name") instanceof String;
      String title = (String) j.get("name");

      Inventory e = Bukkit.createInventory(null, INVENTORY_SIZE, title);
      for (int i = 0; i < INVENTORY_SIZE; i++) {
        if (items.get(i) == null) continue;

        e.setItem(i, ItemStack.deserialize(items.get(i)));
      }

      return new ShopInventory(title, e, actions);
    } catch (InventoryParseException | IOException | ParseException e) {
      e.printStackTrace();
      return null;
    }
  }
예제 #8
0
 /**
  * Shuffle the contents of the inventory, moving all items to random slots. 12
  *
  * @param inventory inventory to shuffle.
  */
 public static void shuffleContents(Inventory inventory) {
   ItemStack[] contents = inventory.getContents();
   ArrayUtils.shuffleArray(contents);
   for (int i = 0; i < contents.length; i++) {
     inventory.setItem(i, contents[i]);
   }
 }
예제 #9
0
  @Override
  public void setInventory(Inventory inventory, TEntityStatus status) {
    Trader trader = tNpcManager.instance().getTraderRelation(player);

    // debug info
    dB.info("Setting inventory, status: ", status.name().toLowerCase());

    // clear the inventory
    inventory.clear();
    for (StockItem item : this.stock.get(status.asStock())) {
      if (item.getSlot() < 0) item.setSlot(inventory.firstEmpty());

      // set the lore
      List<String> lore = item.getDescription(status);
      lore = Limit.loreRequest(player.getName(), item, lore, status);
      lore.addAll(
          new ShopSession(trader, player).getDescription(status.asStock(), item, item.getAmount()));

      ItemStack itemStack = item.getItem(false, lore);

      // set the item
      inventory.setItem(item.getSlot(), NBTUtils.markItem(itemStack));
    }
    setUi(inventory, null, status);
  }
예제 #10
0
  @Override
  public void setAmountsInventory(Inventory inventory, TEntityStatus status, StockItem item) {
    Trader trader = tNpcManager.instance().getTraderRelation(player);

    // debug info
    dB.info("Setting inventory, status: ", TEntityStatus.SELL_AMOUNTS.name().toLowerCase());

    // clear the inventory
    inventory.clear();
    for (Integer amount : item.getAmounts()) {
      // set new amount
      List<String> lore = item.getDescription(status);
      lore = Limit.loreRequest(player.getName(), item, lore, status);
      lore.addAll(new ShopSession(trader, player).getDescription("sell", item, amount));

      ItemStack itemStack = item.getItem(false, lore);
      itemStack.setAmount(amount);

      // set the lore
      ItemMeta meta = itemStack.getItemMeta();

      meta.setLore(lore);

      itemStack.setItemMeta(meta);

      // set the item
      inventory.setItem(inventory.firstEmpty(), NBTUtils.markItem(itemStack));
    }
    setUi(inventory, null, TEntityStatus.SELL_AMOUNTS);
  }
예제 #11
0
 public boolean upgradePearl(Inventory inv, PrisonPearl pp) {
   final String prisoner = pp.getImprisonedName();
   ItemStack is = new ItemStack(Material.ENDER_PEARL, 1, pp.getID());
   int pearlslot = inv.first(is);
   if (pearlslot < 0) {
     // If the pearl has been converted, first won't return it here
     // as the metadata doesn't match.
     return false;
   }
   ItemStack existing_is = inv.getItem(pearlslot);
   if (existing_is != null) {
     ItemMeta existing_meta = existing_is.getItemMeta();
     if (existing_meta != null) {
       String existing_name = existing_meta.getDisplayName();
       if (existing_name != null && existing_name.compareTo(prisoner) == 0) {
         return true;
       }
     }
   }
   ItemMeta im = is.getItemMeta();
   // Rename pearl to that of imprisoned player
   im.setDisplayName(prisoner);
   List<String> lore = new ArrayList<String>();
   lore.add(prisoner + " is held within this pearl");
   // Given enchantment effect
   // Durability used because it doesn't affect pearl behaviour
   im.addEnchant(Enchantment.DURABILITY, 1, true);
   im.setLore(lore);
   is.setItemMeta(im);
   is.removeEnchantment(Enchantment.DURABILITY);
   inv.clear(pearlslot);
   inv.setItem(pearlslot, is);
   return true;
 }
예제 #12
0
  private int findSpace(
      ItemStack item, Map<Integer, StackWithAmount> lookaside, boolean findEmpty) {
    // 1.9.4 and later extend living entity slots beyond 36, but some of these are read-only.
    // We could use .getStorageContents(), but this breaks 1.8.8 compatibility
    int length = (inventory.getHolder() instanceof HumanEntity) ? 36 : inventory.getSize();
    ItemStack[] stacks = Arrays.copyOfRange(inventory.getContents(), 0, length);

    if (item == null) {
      return -1;
    }

    for (int i = 0; i < stacks.length; i++) {
      boolean contains = lookaside.containsKey(i);
      if (findEmpty && !contains) {
        return i;
      } else if (!findEmpty && contains) {
        StackWithAmount compareWith = lookaside.get(i);
        if (compareWith != null) {
          ItemStack compareWithStack = compareWith.getStack();
          if (compareWith.getAmount() < compareWithStack.getMaxStackSize()
              && compareWithStack.isSimilar(item)) {
            return i;
          }
        }
      }
    }

    return -1;
  }
예제 #13
0
  /**
   * Creates a Selection Interface. The control interface is fixed at the bottom.
   *
   * <p>parent is the Parent object to open. If No Parent is found (parent == null), the Interface
   * is closed.
   *
   * @param player to show
   * @param parent that it is linked to
   * @param controlInventoryName name of the control inventory
   * @param selectionInventoryName name of the selection inventory
   */
  public BasicSelectionInterface(
      Player player,
      BasicSelectionInterface parent,
      String controlInventoryName,
      String selectionInventoryName,
      JavaPlugin plugin) {
    this.player = player;
    this.parent = parent;
    this.plugin = plugin;

    if (selectionInventoryName.length() > 32)
      selectionInventoryName = selectionInventoryName.substring(0, 32);
    if (controlInventoryName.length() > 32)
      controlInventoryName = controlInventoryName.substring(0, 32);

    selectionInventory = Bukkit.createInventory(player, 3 * 9, selectionInventoryName);
    controlInventory = Bukkit.createInventory(player, 4 * 9, controlInventoryName);

    BACK_OBJECT = generateBackItem();
    ACCEPT_OBJECT = generateAcceptItem();

    controlInventory.setItem(0, ACCEPT_OBJECT);
    controlInventory.setItem(8, BACK_OBJECT);

    Bukkit.getPluginManager().registerEvents(this, plugin);
    openInterfaces.add(this);
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent event) {
    Player p = event.getPlayer();
    if (event.getAction().equals(Action.RIGHT_CLICK_AIR)) {
      if (p.getItemInHand().getType() == Material.EYE_OF_ENDER) {

        for (Player other : Bukkit.getServer().getOnlinePlayers()) {
          other.hidePlayer(p);
          p.hidePlayer(other);

          Inventory inventory = p.getInventory();
          inventory.setItem(8, new ItemStack(Material.ENDER_PEARL, 1));
        }

      } else if (p.getItemInHand().getType() == Material.ENDER_PEARL) {
        for (Player other : Bukkit.getServer().getOnlinePlayers()) {
          other.showPlayer(p);
          p.showPlayer(other);
          Inventory inventory = p.getInventory();
          inventory.setItem(8, new ItemStack(Material.EYE_OF_ENDER, 1));
        }
      } else if (p.getItemInHand().getType() == Material.GOLD_AXE) {
        p.launchProjectile(EnderPearl.class);
      }
    } else {

    }
  }
예제 #15
0
  public static boolean removeItem(Inventory inv, Material mat, int data, int qty) {
    int remd = 0;

    HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    for (int i = 0; i < inv.getSize(); i++) {
      ItemStack s = inv.getItem(i);

      if (s != null) {
        if (remd < qty) {
          if ((s.getType().equals(mat)) && ((data == -1) || (data == s.getData().getData()))) {
            int take = Math.min(s.getAmount(), qty - remd);
            map.put(Integer.valueOf(i), Integer.valueOf(take));
            remd += take;

            if (take == s.getAmount()) {
              inv.setItem(i, null);
            } else {
              s.setAmount(s.getAmount() - take);
            }
          }
        }
      }
    }
    if (remd != qty) {
      return false;
    }
    return true;
  }
예제 #16
0
 /** Creates a Bukkit Inventory for a Menu class */
 Inventory generateFreshMenu(Menu menu, Class clazz) {
   MenuInventory menuInv = (MenuInventory) clazz.getAnnotation(MenuInventory.class);
   Inventory inv = Bukkit.createInventory(null, menuInv.slots(), menuInv.name());
   for (int i = 0; i < inv.getSize(); i++)
     inv.setItem(i, ItemUtils.annotationToItemStack(menuInv.filler()));
   for (Method m : loadedMenus.get(clazz)) {
     MenuItem menuItem = m.getAnnotation(MenuItem.class);
     ItemStack item = ItemUtils.annotationToItemStack(menuItem.item());
     inv.setItem(menuItem.slot(), item);
   }
   if (clazz.isAnnotationPresent(IgnoreSlots.class)) {
     IgnoreSlots ignoreSlots = (IgnoreSlots) clazz.getAnnotation(IgnoreSlots.class);
     if (ignoreSlots.slots().length == ignoreSlots.items().length)
       for (int i = 0; i < ignoreSlots.slots().length; i++)
         inv.setItem(
             ignoreSlots.slots()[i], ItemUtils.annotationToItemStack(ignoreSlots.items()[i]));
   }
   for (Method m : loadedPreprocessors.get(clazz)) {
     try {
       m.invoke(menu, inv);
     } catch (IllegalAccessException e) {
       System.out.println("All @PreProcessor methods must be static!");
       e.printStackTrace();
     } catch (InvocationTargetException e) {
       System.out.println("All @PreProcessor methods must take 1 Inventory as a parameter!");
       e.printStackTrace();
     }
   }
   return inv;
 }
  public static void openGomibako(CommandSender sender) {
    if (!(sender instanceof Player)) {
      Msg.warning(sender, "ゴミ箱コマンドはゲーム内からのみ実行できます");
    }

    Player player = (Player) sender;

    if (!(player.hasPermission(Permissions.getGomibakoPermisson()))) {
      Msg.noPermissionMessage(sender, Permissions.getGomibakoPermisson());
      return;
    }

    ItemStack item0 = new ItemStack(Material.BOOK);
    ItemMeta itemmeta0 = item0.getItemMeta();
    itemmeta0.setDisplayName(ChatColor.GOLD + "ゴミ箱の使い方");
    itemmeta0.setLore(
        Arrays.asList(ChatColor.WHITE + "ゴミ箱に不要なアイテムを収納し、", ChatColor.WHITE + "画面を閉じると処分が完了します。"));
    item0.setItemMeta(itemmeta0);

    ItemStack item1 = new ItemStack(Material.BED);
    ItemMeta itemmeta1 = item1.getItemMeta();
    itemmeta1.setDisplayName(ChatColor.GOLD + "画面を閉じる");
    itemmeta1.setLore(Arrays.asList(ChatColor.GRAY + "定食サーバオリジナルプラグイン!"));
    item1.setItemMeta(itemmeta1);

    Inventory inv = Bukkit.createInventory(player, 36, " ゴミ箱 ");
    inv.setItem(0, item0);
    inv.setItem(1, item1);
    player.openInventory(inv);
  }
예제 #18
0
파일: Shop.java 프로젝트: Elicis/LoM
  public void createMagicResistPage() {
    Inventory inv = Bukkit.createInventory(null, 54, "Magicresistance");
    // Null Magic Mantle
    ShopItem nullmagicmantle =
        new ShopItem(
            "Null Magic Mantle",
            Material.LEATHER_CHESTPLATE,
            ShopItemType.MAGICRESISTANCE,
            20,
            400);
    LeatherArmorMeta meta2 = (LeatherArmorMeta) nullmagicmantle.getItemMeta();
    meta2.setColor(Color.ORANGE);
    nullmagicmantle.setItemMeta(meta2);
    inv.addItem(nullmagicmantle);
    proxy.addItem(3, nullmagicmantle);
    // Negatron Cloak
    ShopItem negatroncloak =
        new ShopItem(
            "Negatron Cloak", Material.LEATHER_CHESTPLATE, ShopItemType.MAGICRESISTANCE, 40, 720);
    LeatherArmorMeta meta = (LeatherArmorMeta) negatroncloak.getItemMeta();
    meta.setColor(Color.WHITE);
    negatroncloak.setItemMeta(meta);
    inv.addItem(negatroncloak);
    proxy.addItem(3, negatroncloak);
    // TODO: Add more Items

    inv.setItem(53, back);
    sites.add(inv);
  }
예제 #19
0
  private Inventory getFuelInventory(Player player) {

    if (isValidFuelJacket(player.getInventory().getChestplate())) {

      FileConfiguration fuelConfig = getFuelConfig(player);
      Material jacket = player.getInventory().getChestplate().getType();

      int jacketSize = getFuelJacketSize(jacket);
      String jacketType = getFuelJacketConfigString(jacket);

      if (fuelConfig.get(jacketType) != null) {

        Inventory fuelInventory;
        ArrayList<ItemStack> itemStack = new ArrayList<>();

        itemStack.addAll(
            fuelConfig
                .getList(jacketType)
                .stream()
                .map(fuelCurrentItem -> (ItemStack) fuelCurrentItem)
                .collect(Collectors.toList()));

        fuelInventory =
            Bukkit.createInventory(
                player,
                jacketSize,
                "" + ChatColor.DARK_RED + ChatColor.BOLD + "Rocket Boot Fuel Jacket");
        fuelInventory.setContents(itemStack.toArray(new ItemStack[itemStack.size()]));

        return fuelInventory;
      }
    }

    return null;
  }
예제 #20
0
  @SuppressWarnings("deprecation")
  private void onLobbyInventoryClick(InventoryClickEvent ice, Player player, Game game) {
    Inventory inv = ice.getInventory();
    ItemStack clickedStack = ice.getCurrentItem();

    if (!inv.getTitle().equals(Main._l("lobby.chooseteam"))) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack == null) {
      ice.setCancelled(true);
      return;
    }

    if (clickedStack.getType() != Material.WOOL) {
      return;
    }

    ice.setCancelled(true);
    Team team = game.getTeamByDyeColor(DyeColor.getByData(clickedStack.getData().getData()));
    if (team == null) {
      return;
    }

    game.playerJoinTeam(player, team);
    player.closeInventory();
  }
 @Override
 protected void saveEditor(Inventory inventory, Player player) {
   for (int i = 0; i < 8; i++) {
     ItemStack item = inventory.getItem(i);
     if (item != null && item.getType() != Material.AIR) {
       ItemStack cost1 = null, cost2 = null;
       ItemStack item1 = inventory.getItem(i + 9);
       ItemStack item2 = inventory.getItem(i + 18);
       if (item1 != null && item1.getType() != Material.AIR) {
         cost1 = item1;
         if (item2 != null && item2.getType() != Material.AIR) {
           cost2 = item2;
         }
       } else if (item2 != null && item2.getType() != Material.AIR) {
         cost1 = item2;
       }
       if (cost1 != null) {
         Cost cost = new Cost();
         cost.amount = item.getAmount();
         cost.item1 = cost1;
         cost.item2 = cost2;
         ItemStack saleItem = item.clone();
         saleItem.setAmount(1);
         ((TradingPlayerShopkeeper) shopkeeper).costs.put(saleItem, cost);
       } else {
         ItemStack saleItem = item.clone();
         saleItem.setAmount(1);
         ((TradingPlayerShopkeeper) shopkeeper).costs.remove(saleItem);
       }
     }
   }
   ((TradingPlayerShopkeeper) shopkeeper).clickedItem = null;
 }
예제 #22
0
파일: NMSCore.java 프로젝트: RHE24/MaxClans
  @Override
  public Inventory getInventory(byte[] bytes, String name, int size) {
    // Fetch the String and convert it back to a byte[], then decompress it into a NBTTagCompound.
    net.minecraft.server.v1_5_R3.NBTTagCompound c =
        net.minecraft.server.v1_5_R3.NBTCompressedStreamTools.a(bytes);
    // The tag compound contained a list called "inventory"
    net.minecraft.server.v1_5_R3.NBTTagList list = c.getList("inventory");

    Inventory inv = Bukkit.createInventory(null, size, name);

    // Reconstruct the items from their NBT tags
    for (int i = 0; i < list.size(); i++) {
      // Fetch the next nbt item in the list
      net.minecraft.server.v1_5_R3.NBTTagCompound item =
          (net.minecraft.server.v1_5_R3.NBTTagCompound) list.get(i);
      // The item has a tag "index", where it is stored in the chest
      int index = item.getInt("index");
      // Create an itemstack from the nbt tag
      net.minecraft.server.v1_5_R3.ItemStack is =
          net.minecraft.server.v1_5_R3.ItemStack.createStack(item);
      // Convert that itemstack into a craftbukkit itemstack
      // org.bukkit.craftbukkit.v1_4_6.inventory.CraftItemStack cis = new
      // org.bukkit.craftbukkit.v1_4_6.inventory.CraftItemStack(is);
      ItemStack cis = org.bukkit.craftbukkit.v1_5_R3.inventory.CraftItemStack.asBukkitCopy(is);
      // Put the itemstack in the inventory.
      inv.setItem(index, cis);
    }
    return inv;
  }
예제 #23
0
  public static void drop(Player p) {
    Location loc = new Location(Bukkit.getWorld("world"), 0, 0, 0);
    Random rand = new Random();
    loc.setX(rand.nextInt(8000));
    loc.setY(100);
    loc.setZ(rand.nextInt(8000));
    loc.setY(Bukkit.getWorld("world").getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY());
    loc.getBlock().setType(Material.CHEST);
    Block bb = loc.getBlock();
    bb.setType(Material.CHEST);
    Chest chest = (Chest) bb.getState();

    Inventory inv = chest.getInventory();

    for (ItemStack stack : items) {
      inv.addItem(stack);
    }

    Bukkit.broadcastMessage(
        ChatColor.RED + "A tornado has appeared in the world, and left valuble supplies!");
    Bukkit.broadcastMessage(
        ChatColor.translateAlternateColorCodes(
            '&',
            "&7Coords: X: &c"
                + loc.getBlockX()
                + "&7 Y:&c "
                + loc.getBlockY()
                + "&7 Z: &c"
                + loc.getBlockZ()));
  }
예제 #24
0
  /**
   * Shows the skill tree for the player. If the player has multiple trees, this will show the list
   * of skill trees they can view.
   *
   * @param player player to show the skill tree for
   * @return true if able to show the player, false otherwise
   */
  public boolean showSkills(Player player) {
    // Cannot show an invalid player, and cannot show no skills
    if (player == null || classes.size() == 0 || skills.size() == 0) {
      return false;
    }

    // Show skill tree of only class
    if (classes.size() == 1) {
      PlayerClass playerClass = classes.get(classes.keySet().toArray(new String[1])[0]);
      if (playerClass.getData().getSkills().size() == 0) {
        return false;
      }

      player.openInventory(
          ((InventoryTree) playerClass.getData().getSkillTree()).getInventory(this));
      return true;
    }

    // Show list of classes that have skill trees
    else {
      Inventory inv =
          InventoryManager.createInventory(
              TreeListener.CLASS_LIST_KEY, (classes.size() + 8) / 9, player.getName());
      for (PlayerClass c : classes.values()) {
        inv.addItem(c.getData().getIcon());
      }
      player.openInventory(inv);
      return true;
    }
  }
예제 #25
0
 public InventorySlotType getActiveInventorySlotType(int clicked) {
   if (clicked == -999) {
     return InventorySlotType.OUTSIDE;
   }
   Inventory active = getActiveInventory();
   int size = active.getSize();
   if (this.player.activeContainer instanceof ContainerChest) {
     return InventorySlotType.CONTAINER;
   } else if (this.player.activeContainer instanceof ContainerPlayer) {
     if (clicked == 0) return InventorySlotType.RESULT;
     if (clicked < 5) return InventorySlotType.CRAFTING;
     if (clicked == 5) return InventorySlotType.HELMET;
     if (clicked == 6) return InventorySlotType.ARMOR;
     if (clicked == 7) return InventorySlotType.LEGGINGS;
     if (clicked == 8) return InventorySlotType.BOOTS;
     if (clicked < size) return InventorySlotType.CONTAINER;
     return InventorySlotType.QUICKBAR;
   } else if (this.player.activeContainer instanceof ContainerFurnace) {
     if (clicked == 0) return InventorySlotType.SMELTING;
     if (clicked == 1) return InventorySlotType.FUEL;
     return InventorySlotType.RESULT;
   } else if (this.player.activeContainer instanceof ContainerDispenser) {
     return InventorySlotType.CONTAINER;
   } else if (this.player.activeContainer instanceof ContainerWorkbench) {
     if (clicked == 0) return InventorySlotType.RESULT;
     else if (clicked < size) return InventorySlotType.CRAFTING;
     return InventorySlotType.CONTAINER;
   }
   if (clicked >= size + 27) return InventorySlotType.QUICKBAR;
   if (clicked >= size) return InventorySlotType.PACK;
   return InventorySlotType.CONTAINER;
 }
예제 #26
0
  @Override
  public SpellResult start(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Player player = mage.getPlayer();
    if (player == null) {
      return SpellResult.PLAYER_REQUIRED;
    }

    List<Player> allPlayers = null;
    players.clear();

    if (allowCrossWorld) {
      allPlayers = new ArrayList<>(controller.getPlugin().getServer().getOnlinePlayers());
    } else {
      allPlayers = context.getLocation().getWorld().getPlayers();
    }

    Collections.sort(
        allPlayers,
        new Comparator<Player>() {
          @Override
          public int compare(Player p1, Player p2) {
            return p1.getDisplayName().compareTo(p2.getDisplayName());
          }
        });

    int index = 0;
    for (Player targetPlayer : allPlayers) {
      if (!context.getTargetsCaster() && targetPlayer == player) continue;
      if (targetPlayer.hasPotionEffect(PotionEffectType.INVISIBILITY)) continue;
      if (!context.canTarget(targetPlayer)) continue;
      players.put(index++, new WeakReference<>(targetPlayer));
    }
    if (players.size() == 0) return SpellResult.NO_TARGET;

    String inventoryTitle = context.getMessage("title", "Select Player");
    int invSize = ((players.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (Map.Entry<Integer, WeakReference<Player>> entry : players.entrySet()) {
      Player targetPlayer = entry.getValue().get();
      if (targetPlayer == null) continue;

      String name = targetPlayer.getName();
      String displayName = targetPlayer.getDisplayName();
      ItemStack playerItem = InventoryUtils.getPlayerSkull(targetPlayer, displayName);
      if (!name.equals(displayName)) {
        ItemMeta meta = playerItem.getItemMeta();
        List<String> lore = new ArrayList<>();
        lore.add(name);
        meta.setLore(lore);
        playerItem.setItemMeta(meta);
      }
      displayInventory.setItem(entry.getKey(), playerItem);
    }
    active = true;
    mage.activateGUI(this, displayInventory);

    return SpellResult.NO_ACTION;
  }
예제 #27
0
  @SuppressWarnings("deprecation")
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Options menu")) {
      return;
    }
    if (currentItem.getType() != Material.HARD_CLAY) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Floor block")) {
      return;
    }

    for (Block block : plot.getFloor().getAllBlocks()) {
      block.setType(e.getCursor().getType());
      block.setData(e.getCursor().getData().getData());
    }

    e.setCancelled(true);
  }
  public static String InventoryToString(Inventory invInventory) {
    String serialization = invInventory.getSize() + ";";
    for (int i = 0; i < invInventory.getSize(); i++) {
      ItemStack is = invInventory.getItem(i);
      if (is != null) {
        String serializedItemStack = new String();

        String isType = String.valueOf(is.getType().getId());
        serializedItemStack += "t@" + isType;

        if (is.getDurability() != 0) {
          String isDurability = String.valueOf(is.getDurability());
          serializedItemStack += ":d@" + isDurability;
        }

        if (is.getAmount() != 1) {
          String isAmount = String.valueOf(is.getAmount());
          serializedItemStack += ":a@" + isAmount;
        }

        Map<Enchantment, Integer> isEnch = is.getEnchantments();
        if (isEnch.size() > 0) {
          for (Entry<Enchantment, Integer> ench : isEnch.entrySet()) {
            serializedItemStack += ":e@" + ench.getKey().getId() + "@" + ench.getValue();
          }
        }

        serialization += i + "#" + serializedItemStack + ";";
      }
    }
    return serialization;
  }
예제 #29
0
  @EventHandler
  public void onInventoryClick(InventoryClickEvent e) {
    Player player = (Player) e.getWhoClicked();
    Inventory inventory = e.getInventory();
    ItemStack currentItem = e.getCurrentItem();

    if (ArenaManager.getInstance().getArena(player) == null) {
      return;
    }

    Plot plot = ArenaManager.getInstance().getArena(player).getPlot(player);

    if (!inventory.getName().equals(ChatColor.GREEN + "Particles")) {
      return;
    }
    if (currentItem.getType() != Material.LAVA_BUCKET) {
      return;
    }
    if (!currentItem.hasItemMeta()) {
      return;
    }
    if (!currentItem.getItemMeta().getDisplayName().equals(ChatColor.GREEN + "Lava drip")) {
      return;
    }

    plot.addParticle(new Particle(player.getLocation(), ParticleType.LAVA_DRIP));
    e.setCancelled(true);
  }
 private boolean chestHasBlankBooks() {
   Block chest = this.getChest();
   if (Utils.isChest(chest.getType())) {
     Inventory inv = ((Chest) chest.getState()).getInventory();
     return inv.contains(Material.BOOK_AND_QUILL);
   }
   return false;
 }