Beispiel #1
0
 public boolean isShopInventory(Inventory inv) {
   boolean isShop = false;
   for (Inventory inv2 : sites) {
     if (inv2.getTitle().equalsIgnoreCase(inv.getTitle())) {
       isShop = true;
     }
   }
   return isShop;
 }
 private boolean compare(Inventory inv, Inventory inv2) {
   if (inv == null || inv2 == null) {
     return false;
   }
   if (!inv.getTitle().equals(inv2.getTitle())) {
     return false;
   }
   if (inv.getMaxStackSize() != inv2.getMaxStackSize()) {
     return false;
   }
   if (!inv.getViewers().equals(inv2.getViewers())) {
     return false;
   }
   return true;
 }
  @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();
  }
 @EventHandler(ignoreCancelled = true)
 public void onPrefsMenuClick(InventoryClickEvent event) {
   Inventory inv = event.getInventory();
   String name = inv.getTitle();
   if (name.equals("§4TARDIS Key Prefs Menu")) {
     Player p = (Player) event.getWhoClicked();
     int slot = event.getRawSlot();
     if (slot >= 0 && slot < 27) {
       switch (slot) {
         case 0:
         case 1:
         case 2:
         case 3:
         case 4:
         case 5:
         case 6:
         case 7:
         case 8:
         case 10:
         case 12:
         case 14:
         case 16:
           event.setCancelled(true);
           // set display name of key in slot 18
           ItemStack key = inv.getItem(18);
           if (key == null || !key.getType().equals(Material.GOLD_NUGGET) || !key.hasItemMeta()) {
             return;
           }
           // get Display name of selected key
           ItemStack choice = inv.getItem(slot);
           ItemMeta choice_im = choice.getItemMeta();
           String choice_name = choice_im.getDisplayName();
           ItemMeta sonic_im = key.getItemMeta();
           sonic_im.setDisplayName(choice_name);
           key.setItemMeta(sonic_im);
           break;
         case 18:
           break;
         case 26:
           // close
           event.setCancelled(true);
           close(p);
           break;
         default:
           event.setCancelled(true);
           break;
       }
     } else {
       ClickType click = event.getClick();
       if (click.equals(ClickType.SHIFT_RIGHT) || click.equals(ClickType.SHIFT_LEFT)) {
         event.setCancelled(true);
       }
     }
   }
 }
 @EventHandler(ignoreCancelled = true)
 public void onKeyMenuDrag(InventoryDragEvent event) {
   Inventory inv = event.getInventory();
   String title = inv.getTitle();
   if (!title.equals("§4TARDIS Key Prefs Menu")) {
     return;
   }
   Set<Integer> slots = event.getRawSlots();
   for (Integer slot : slots) {
     if ((slot >= 0 && slot < 27)) {
       event.setCancelled(true);
     }
   }
 }
 @EventHandler(ignoreCancelled = true)
 public void onKeyMenuClose(InventoryCloseEvent event) {
   Inventory inv = event.getInventory();
   String title = inv.getTitle();
   if (!title.equals("§4TARDIS Key Prefs Menu")) {
     return;
   }
   ItemStack key = inv.getItem(18);
   if (key != null) {
     Player p = (Player) event.getPlayer();
     Location loc = p.getLocation();
     loc.getWorld().dropItemNaturally(loc, key);
     inv.setItem(18, new ItemStack(Material.AIR));
   }
 }
 @EventHandler(ignoreCancelled = true)
 public void onAdminMenuClick(InventoryClickEvent event) {
   Inventory inv = event.getInventory();
   String name = inv.getTitle();
   if (name.equals("§4Admin Menu")) {
     event.setCancelled(true);
     int slot = event.getRawSlot();
     if (slot < 54) {
       String option = getDisplay(inv, slot);
       if (slot == 53 && option.equals("Player Preferences")) {
         final Player p = (Player) event.getWhoClicked();
         // close this gui and load the Player Prefs Menu
         plugin
             .getServer()
             .getScheduler()
             .scheduleSyncDelayedTask(
                 plugin,
                 new Runnable() {
                   @Override
                   public void run() {
                     Inventory ppm =
                         plugin.getServer().createInventory(p, 18, "§4Player Prefs Menu");
                     ppm.setContents(
                         new TARDISPrefsMenuInventory(plugin, p.getUniqueId()).getMenu());
                     p.openInventory(ppm);
                   }
                 },
                 1L);
         return;
       }
       if (!option.isEmpty()) {
         boolean bool = plugin.getConfig().getBoolean(option);
         plugin.getConfig().set(option, !bool);
         String lore = (bool) ? "false" : "true";
         setLore(inv, slot, lore);
         plugin.saveConfig();
       }
     }
   }
 }
  public static Inventory clone(Inventory inventory, boolean playerSupport) {
    // Evade
    if (inventory == null) return null;

    // Create
    Inventory ret = null;
    if (inventory instanceof PlayerInventory && playerSupport) {
      ret = MixinInventory.get().createPlayerInventory();
    } else {
      InventoryHolder holder = inventory.getHolder();
      int size = inventory.getSize();
      if (inventory instanceof PlayerInventory) size = SIZE_PLAYER_STORAGE;
      String title = inventory.getTitle();
      ret = MixinInventory.get().createInventory(holder, size, title);
    }

    // Fill
    ItemStack[] all = getContentsAll(inventory);
    all = clone(all);
    setContentsAll(ret, all);

    // Return
    return ret;
  }
Beispiel #9
0
 public boolean isBankchest(Player p, Inventory inv) {
   String title = inv.getTitle();
   if (title.contains((CharSequence) p.getName())) {
     return true;
   } else return false;
 }
Beispiel #10
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void inventoryMenu(final InventoryClickEvent event) {

    // -------Armor wear handling--------
    if (event.getSlotType() == SlotType.ARMOR && event.getClick() != ClickType.DOUBLE_CLICK) {
      CEventHandler.handleArmor(
          (Player) event.getWhoClicked(), event.getCurrentItem(), true, event);
      CEventHandler.handleArmor((Player) event.getWhoClicked(), event.getCursor(), false, event);
      if (event.getCursor() == null)
        CEventHandler.handleArmor(
            (Player) event.getWhoClicked(), event.getCurrentItem(), false, event);

    } else if (event.getClick() == ClickType.SHIFT_LEFT) {
      ItemStack current = event.getCurrentItem();
      String typeS = current.getType().toString();
      PlayerInventory inv = event.getWhoClicked().getInventory();
      if ((typeS.endsWith("HELMET") && inv.getHelmet() == null)
          || (typeS.endsWith("CHESTPLATE") && inv.getChestplate() == null)
          || (typeS.endsWith("LEGGINGS") && inv.getLeggings() == null)
          || (typeS.endsWith("BOOTS") && inv.getBoots() == null))
        CEventHandler.handleArmor(
            (Player) event.getWhoClicked(), event.getCurrentItem(), false, event);
    }
    // ---------------------------------

    if (event.getCurrentItem() == null
        || event.getCurrentItem().getType() == Material.AIR
        || event.getRawSlot() < -1) {
      return;
    }
    if (event.getView().getTopInventory().getTitle().startsWith("CE")) {
      Inventory topInv = event.getView().getTopInventory();
      final Player p = (Player) event.getWhoClicked();
      ItemStack clickedItem = event.getCurrentItem();
      event.setResult(Result.ALLOW);

      event.setCancelled(true);

      // This is the back-button, located in the very last spot of each inventory
      if ((event.getRawSlot() == topInv.getSize() - 1)
          && event.getCurrentItem().getType() != Material.AIR) {
        p.closeInventory();
        p.openInventory(Tools.getPreviousInventory(topInv.getTitle()));
        return;
      }

      if (event.getRawSlot() < topInv.getSize()) {

        // Opens the clicked Enchantments inventory and loads the permissions if needed
        if (topInv.getTitle().equals(Tools.prefix + "Enchantments")) {
          p.closeInventory();
          p.openInventory(Tools.getEnchantmentMenu(p, clickedItem.getItemMeta().getDisplayName()));
          return;
        }

        // Opens the item inventory and loads the permissions if needed
        if (topInv.getTitle().equals(Tools.prefix + "Main Menu") && event.getRawSlot() == 4) {
          p.closeInventory();
          p.openInventory(Tools.getItemMenu(p));
          return;
        }

        // These are the specific menus, clicking one of them will lead to the enchanting menu,
        // which needs to be 'notified' of the enchantment to give and it's cost
        if (topInv.getTitle().equals(Tools.prefix + "Global")
            || topInv.getTitle().equals(Tools.prefix + "Bow")
            || topInv.getTitle().equals(Tools.prefix + "Armor")
            || topInv.getTitle().equals(Tools.prefix + "Helmet")
            || topInv.getTitle().equals(Tools.prefix + "Boots")
            || topInv.getTitle().equals(Tools.prefix + "Tool"))
          if (p.isOp()
              || Tools.checkPermission(
                  Tools.getEnchantmentByDisplayname(clickedItem.getItemMeta().getDisplayName()),
                  p)) {
            Inventory enchantingMenu = Main.CEEnchantingMenu;
            enchantingMenu.setItem(0, clickedItem);
            p.closeInventory();
            p.openInventory(enchantingMenu);
            return;
          } else {
            p.sendMessage(
                ChatColor.RED + "[CE] You do not have permission to buy this Enchantment.");
            return;
          }

        // This opens the Item Creation Menu
        if (topInv.getTitle().equals(Tools.prefix + "Items"))
          if (p.isOp()
              || Tools.checkPermission(
                  Tools.getItemByDisplayname(clickedItem.getItemMeta().getDisplayName()), p)) {

            Inventory approveMenu = Main.CEApproveMenu;
            approveMenu.setItem(0, clickedItem);
            p.closeInventory();
            p.openInventory(approveMenu);
            return;
          } else {
            p.sendMessage(ChatColor.RED + "[CE] You do not have permission to buy this Item.");
            return;
          }
      }

      if (topInv.getTitle().equals(Tools.prefix + "Enchanting")
          || topInv.getTitle().equals(Tools.prefix + "Item Creation")) {
        double cost = 0;
        ItemStack item = clickedItem;
        ItemMeta im = item.getItemMeta();
        String type = "";
        String successString = "";
        Boolean itemSet = false; // TODO: Solve this by adding item-types
        // Swimsuit swimsuit = (Swimsuit) Main.items.get(9);

        if (topInv.getTitle().equals(Tools.prefix + "Enchanting")) {
          if (event.getRawSlot() > topInv.getSize() && event.isLeftClick()) {
            CEnchantment ce =
                Tools.getEnchantmentByDisplayname(
                    topInv.getContents()[0].getItemMeta().getDisplayName());
            cost = ce.getCost();
            type = "enchantment " + ce.getDisplayName();
            if (!ce.getApplication().equals(Application.GLOBAL)
                && !Tools.isApplicationCorrect(ce.getApplication(), clickedItem.getType())) {
              String appS = ce.getApplication().toString().toLowerCase();
              p.sendMessage(
                  ChatColor.RED
                      + "[CE] This enchantment can only be applied to "
                      + ChatColor.GRAY
                      + (appS.endsWith("s") ? appS : appS + "s")
                      + ChatColor.RED
                      + ".");
              return;
            }
            List<String> lore = new ArrayList<String>();
            if (clickedItem.getItemMeta().hasLore()) {
              lore = clickedItem.getItemMeta().getLore();
              int number = 0;
              for (String s : lore) {
                CEnchantment c = Tools.getEnchantmentByDisplayname(s);
                if (c != null && c.originalName == ce.originalName) {
                  p.sendMessage(ChatColor.RED + "[CE] This item already has this enchantment!");
                  return;
                }
                if (c != null) number++;
              }
              if (Main.maxEnchants > 0 && number >= Main.maxEnchants) {
                p.sendMessage(
                    ChatColor.RED
                        + "[CE] This item has already reached the maximum of "
                        + ChatColor.GRAY
                        + Main.maxEnchants
                        + ChatColor.RED
                        + " enchantments.");
                return;
              }
            }

            lore.add(ce.getDisplayName());
            im.setLore(lore);
            item.setItemMeta(im);
          } else return;

        } else if (topInv.getTitle().equals(Tools.prefix + "Item Creation")) {
          item = topInv.getContents()[0];
          cost = Tools.getItemByDisplayname(item.getItemMeta().getDisplayName()).getCost();
          //					if(item.hasItemMeta() && item.getItemMeta().hasDisplayName() &&
          // item.getItemMeta().getDisplayName().equals(swimsuit.getDisplayName())) { //TODO: Always
          // keep the position of the Swimsuit updated
          //
          //
          //						itemSet = true;
          //
          //						int count = 0;
          //
          //						for(ItemStack i : event.getView().getBottomInventory())
          //							if(i == null || i.getType().equals(Material.AIR))
          //								count++;
          //
          //						if(count < 4) {
          //							p.sendMessage(ChatColor.RED + "[CE] Your Inventory is full!");
          //							return;
          //						}
          //
          //
          //					} else {

          if (event.getView().getBottomInventory().firstEmpty() < 0) {
            p.sendMessage(ChatColor.RED + "[CE] Your Inventory is full!");
            return;
          }

          //					}

          ItemMeta itemIm = item.getItemMeta();
          List<String> lore = itemIm.getLore();
          lore.remove(lore.size() - 1);
          itemIm.setLore(lore);
          item.setItemMeta(itemIm);
          type = "item " + itemIm.getDisplayName();
        }

        // TODO: Fix the cost for items
        //      rewrite the whole section to check which enchantment or item is selected

        successString =
            (ChatColor.GREEN + "[CE] You have created the " + type + ChatColor.GREEN + ".");

        if (!p.isOp() && cost != 0) {
          if (Main.econ.getBalance(p.getName()) >= cost) {
            EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
            if (ecr.transactionSuccess())
              successString =
                  (ChatColor.GREEN
                      + "[CE] Purchased "
                      + type
                      + ChatColor.GREEN
                      + " for "
                      + cost
                      + " "
                      + ((cost == 1)
                          ? Main.econ.currencyNameSingular()
                          : Main.econ.currencyNamePlural()));
            else {
              Bukkit.getConsoleSender()
                  .sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
              Bukkit.getConsoleSender().sendMessage(ChatColor.RED + ecr.errorMessage);
              p.closeInventory();
              return;
            }
          } else {
            p.sendMessage(ChatColor.RED + "[CE] You do not have enough money to buy this!");
            p.closeInventory();
            return;
          }
        }
        if (item != null) {
          if (!itemSet)
            if (type.startsWith("item") && event.getRawSlot() < topInv.getSize())
              p.setItemInHand(item);
            else p.getInventory().setItem(event.getSlot(), item);
          //					else {
          //						ItemStack cp = item.clone();
          //						ItemStack le = item.clone();
          //						ItemStack bo = item.clone();
          //
          //						String[] parts = swimsuit.parts;
          //
          //						cp.setType(Material.IRON_CHESTPLATE);
          //						le.setType(Material.IRON_LEGGINGS);
          //						bo.setType(Material.IRON_BOOTS);
          //
          //						im.setDisplayName(parts[1]);
          //						cp.setItemMeta(im);
          //						im.setDisplayName(parts[2]);
          //						le.setItemMeta(im);
          //						im.setDisplayName(parts[3]);
          //						bo.setItemMeta(im);
          //
          //						p.getInventory().addItem(item);
          //						p.getInventory().addItem(cp);
          //						p.getInventory().addItem(le);
          //						p.getInventory().addItem(bo);
          //
          //					}
        }
        p.closeInventory();
        p.sendMessage(successString);
        return;
      }

      if (event.getRawSlot() < topInv.getSize()) {

        p.closeInventory();
        try {
          p.openInventory(Tools.getNextInventory(clickedItem.getItemMeta().getDisplayName()));
        } catch (Exception e) {
          p.sendMessage(ChatColor.RED + "[CE] This feature is disabled.");
        }
      }
    }
  }