Beispiel #1
0
 public static void removeTeamHead(final int color, Player p) {
   ItemStack item = getTeamHead(color);
   final PlayerInventory inv = p.getInventory();
   if (inv != null && inv.getHelmet() != null && inv.getHelmet().getType() == item.getType()) {
     inv.setHelmet(new ItemStack(Material.AIR));
   }
 }
  @Override
  public void armorCheck(Player player) {
    if (!player.hasPermission("supernatural.player.ignorearmor")) {
      PlayerInventory inv = player.getInventory();
      ItemStack helmet = inv.getHelmet();
      ItemStack chest = inv.getChestplate();
      ItemStack leggings = inv.getLeggings();
      ItemStack boots = inv.getBoots();

      if (helmet != null) {
        if (!SNConfigHandler.priestArmor.contains(helmet.getType())) {
          inv.setHelmet(null);
          dropItem(player, helmet);
        }
      }
      if (chest != null) {
        if (!SNConfigHandler.priestArmor.contains(chest.getType())) {
          inv.setChestplate(null);
          dropItem(player, chest);
        }
      }
      if (leggings != null) {
        if (!SNConfigHandler.priestArmor.contains(leggings.getType())) {
          inv.setLeggings(null);
          dropItem(player, leggings);
        }
      }
      if (boots != null) {
        if (!SNConfigHandler.priestArmor.contains(boots.getType())) {
          inv.setBoots(null);
          dropItem(player, boots);
        }
      }
    }
  }
 public static ItemStack getHelmet(Inventory inventory) {
   PlayerInventory playerInventory = asPlayerInventory(inventory);
   if (playerInventory == null) return null;
   ItemStack ret = playerInventory.getHelmet();
   ret = clean(ret);
   return ret;
 }
  public boolean addEnchantmentsToPlayerInventorySlot(
      String playerName, int slot, List<Object> enchantments) {
    try {
      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it;

      if (slot == inv.getHeldItemSlot()) it = inv.getHelmet();
      else if (slot == 102) it = inv.getChestplate();
      else if (slot == 101) it = inv.getLeggings();
      else if (slot == 100) it = inv.getBoots();
      else it = inv.getItem(slot);

      for (int i = 0; i < enchantments.size(); i++) {
        JSONObject o = (JSONObject) enchantments.get(i);
        it.addEnchantment(
            Enchantment.getById(Integer.valueOf(o.get("enchantment").toString())),
            Integer.valueOf(o.get("level").toString()));
      }

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
 @EventHandler
 public void onPlayerRespawnEvent(PlayerRespawnEvent event) {
   if (event.getPlayer().getName().equals("Esaych")) {
     PlayerInventory eInv = event.getPlayer().getInventory();
     if (eInv.getHelmet() != null) return;
     if (eInv.getChestplate() != null) return;
     if (eInv.getLeggings() != null) return;
     if (eInv.getBoots() != null) return;
     eInv.setHelmet(new ItemStack(Material.LEATHER_HELMET));
     eInv.setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
     eInv.setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
     eInv.setBoots(new ItemStack(Material.LEATHER_BOOTS));
     PlayerInventory inv = event.getPlayer().getInventory();
     colorize(inv.getHelmet(), 47, 0, 111);
     colorize(inv.getChestplate(), 47, 0, 111);
     colorize(inv.getLeggings(), 47, 0, 111);
     colorize(inv.getBoots(), 47, 0, 111);
   }
 }
Beispiel #6
0
  /**
   * Clones the first passed PlayerInventory object to the second one.
   *
   * @param source
   * @param target
   */
  private void clonePlayerInventory(PlayerInventory source, PlayerInventory target) {
    ItemStack[] contents = new ItemStack[source.getContents().length];
    System.arraycopy(source.getContents(), 0, contents, 0, contents.length);
    target.setContents(contents);

    target.setHelmet(cloneItemStack(source.getHelmet()));
    target.setChestplate(cloneItemStack(source.getChestplate()));
    target.setLeggings(cloneItemStack(source.getLeggings()));
    target.setBoots(cloneItemStack(source.getBoots()));
  }
  public static void setAllContents(Inventory from, Inventory to) {
    to.setContents(from.getContents());
    if (from instanceof PlayerInventory) {
      PlayerInventory pfrom = (PlayerInventory) from;
      if (to instanceof PlayerInventory) {
        PlayerInventory pto = (PlayerInventory) to;

        pto.setHelmet(pfrom.getHelmet());
        pto.setChestplate(pfrom.getChestplate());
        pto.setLeggings(pfrom.getLeggings());
        pto.setBoots(pfrom.getBoots());
      }
    }
  }
 public void saveInventory(OfflinePlayer op, String world, Inventory i) {
   if (!Config.separateInv) return;
   String group = this.getWorldGroup(this.plugin.getServer().getWorld(world));
   if (group == null) return;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(op);
   for (int slot = 0; slot < i.getSize(); slot++) {
     pcm.set("inventory." + group + ".slot." + slot, i.getItem(slot));
   }
   if (i instanceof PlayerInventory) {
     PlayerInventory pi = (PlayerInventory) i;
     pcm.set("inventory." + group + ".slot.helm", pi.getHelmet());
     pcm.set("inventory." + group + ".slot.chestplate", pi.getChestplate());
     pcm.set("inventory." + group + ".slot.leggings", pi.getLeggings());
     pcm.set("inventory." + group + ".slot.boots", pi.getBoots());
   }
   pcm.set("inventory." + group + ".size", i.getSize());
 }
  public static boolean isEmpty(Inventory inv) {
    if (inv == null) return true;

    for (ItemStack itemStack : inv.getContents()) {
      if (isSomething(itemStack)) return false;
    }

    if (inv instanceof PlayerInventory) {
      PlayerInventory pinv = (PlayerInventory) inv;

      if (isSomething(pinv.getHelmet())) return false;
      if (isSomething(pinv.getChestplate())) return false;
      if (isSomething(pinv.getLeggings())) return false;
      if (isSomething(pinv.getBoots())) return false;
    }

    return true;
  }
Beispiel #10
0
 @EventHandler
 public void onPlayerJoin(PlayerJoinEvent event) {
   //		ipRecorder.onPlayerJoinEvent(event);
   //		forumActivation.onPlayerJoinEvent(event);
   respectedAutoPromote.onPlayerJoinEvent(event);
   homes.onJoinEvent(event);
   hubPortals.onJoinEvent(event);
   /*
   This allowed the owner when joining the game to get full epic armor
   */
   if (event.getPlayer().getName().equals("Esaych")) {
     PlayerInventory inv = event.getPlayer().getInventory();
     colorize(inv.getHelmet(), 47, 0, 111);
     colorize(inv.getChestplate(), 47, 0, 111);
     colorize(inv.getLeggings(), 47, 0, 111);
     colorize(inv.getBoots(), 47, 0, 111);
   }
   if (staffVotes != null) {
     staffVotes.onPlayerJoinEvent(event);
   }
 }
 private void saveInventory(Player p, Inventory i, World w) {
   if (!Config.separateInv) return;
   String group = getWorldGroup(w);
   if (group == null) return;
   PlayerConfiguration pcm = PlayerConfigurationManager.getConfiguration(p);
   for (int slot = 0; slot < i.getSize(); slot++) {
     pcm.set("inventory." + group + ".slot." + slot, i.getItem(slot));
   }
   if (i instanceof PlayerInventory) {
     PlayerInventory pi = (PlayerInventory) i;
     pcm.set("inventory." + group + ".slot.helm", pi.getHelmet());
     pcm.set("inventory." + group + ".slot.chestplate", pi.getChestplate());
     pcm.set("inventory." + group + ".slot.leggings", pi.getLeggings());
     pcm.set("inventory." + group + ".slot.boots", pi.getBoots());
   }
   pcm.set("inventory." + group + ".size", i.getSize());
   if (Config.separateXP) {
     pcm.set("inventory." + group + ".xp", p.getExp());
     pcm.set("inventory." + group + ".xplevel", p.getLevel());
   }
 }
Beispiel #12
0
  public boolean addEnchantmentToPlayerInventorySlot(
      String playerName, int slot, int enchantmentID, int level) {
    try {
      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it;

      if (slot == 103) it = inv.getHelmet();
      else if (slot == 102) it = inv.getChestplate();
      else if (slot == 101) it = inv.getLeggings();
      else if (slot == 100) it = inv.getBoots();
      else it = inv.getItem(slot);

      it.addEnchantment(Enchantment.getById(enchantmentID), level);

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
Beispiel #13
0
  /**
   * Gets armour multiplier.
   *
   * @param sagaPlayer saga player
   * @return armour multiplier
   */
  private double getArmourMultiplier(SagaPlayer sagaPlayer) {

    double armour = 0;
    PlayerInventory inventory = sagaPlayer.getPlayer().getInventory();

    ItemStack helmet = inventory.getHelmet();
    ItemStack chestplate = inventory.getChestplate();
    ItemStack leggings = inventory.getLeggings();
    ItemStack boots = inventory.getBoots();

    if (helmet != null
        && (helmet.getType().equals(Material.DIAMOND_HELMET)
            || helmet.getType().equals(Material.IRON_HELMET))) {
      armour += 0.15;
    }

    if (chestplate != null
        && (chestplate.getType().equals(Material.DIAMOND_CHESTPLATE)
            || chestplate.getType().equals(Material.IRON_CHESTPLATE))) {
      armour += 0.4;
    }

    if (leggings != null
        && (leggings.getType().equals(Material.DIAMOND_LEGGINGS)
            || leggings.getType().equals(Material.IRON_LEGGINGS))) {
      armour += 0.3;
    }

    if (boots != null
        && (boots.getType().equals(Material.DIAMOND_BOOTS)
            || boots.getType().equals(Material.IRON_BOOTS))) {
      armour += 0.15;
    }

    return armour;
  }
Beispiel #14
0
  public boolean removeEnchantmentsFromPlayerInventorySlot(
      String playerName, int slot, List<Object> enchantments) {
    try {
      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();
      ItemStack it;

      if (slot == inv.getHeldItemSlot()) it = inv.getHelmet();
      else if (slot == 102) it = inv.getChestplate();
      else if (slot == 101) it = inv.getLeggings();
      else if (slot == 100) it = inv.getBoots();
      else it = inv.getItem(slot);

      for (Object o : enchantments) {
        it.removeEnchantment(Enchantment.getById(Integer.valueOf(o.toString())));
      }

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
Beispiel #15
0
  /** @see Runnable.run() */
  public void run() {
    if (!War.war.isLoaded()) {
      return;
    }
    for (Warzone zone : War.war.getWarzones()) {
      for (Team team : zone.getTeams()) {
        for (Player player : team.getPlayers()) {
          PlayerInventory playerInv = player.getInventory();
          Material teamBlockMaterial;
          if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.BLOCKHEADS)) {
            teamBlockMaterial = team.getKind().getMaterial();
            // 1) Replace missing block head
            if (playerInv.getHelmet().getType() != teamBlockMaterial) {
              playerInv.setHelmet(this.createBlockHead(team));
            }
            // 2) Get rid of extra blocks in inventory: only keep one
            HashMap<Integer, ? extends ItemStack> blocks = playerInv.all(teamBlockMaterial);
            if (blocks.size() > 1
                || (blocks.size() == 1
                    && blocks.get(blocks.keySet().iterator().next()).getAmount() > 1)) {
              int i = 0;
              int removed = 0;
              for (ItemStack item : playerInv.getContents()) {
                // remove only same colored wool
                if (item != null
                    && item.getType() == teamBlockMaterial
                    && item.getData().getData() == team.getKind().getData()) {
                  playerInv.clear(i);
                  removed++;
                }
                i++;
              }

              int firstEmpty = playerInv.firstEmpty();
              if (firstEmpty > 0) {
                playerInv.setItem(firstEmpty, this.createBlockHead(team));
              }

              if (removed > 1) {
                War.war.badMsg(
                    player, "All that " + team.getName() + " wool must have been heavy!");
              }
            }
          } else {
            // enfore helmet (good thing?)
            if (team.getKind() == TeamKind.GOLD) {
              teamBlockMaterial = Material.GOLD_HELMET;
            } else if (team.getKind() == TeamKind.DIAMOND) {
              teamBlockMaterial = Material.DIAMOND_HELMET;
            } else if (team.getKind() == TeamKind.IRON) {
              teamBlockMaterial = Material.IRON_HELMET;
            } else {
              teamBlockMaterial = Material.LEATHER_HELMET;
            }
            if (playerInv.getHelmet() != null
                && playerInv.getHelmet().getType() != teamBlockMaterial) {
              playerInv.setHelmet(new ItemStack(teamBlockMaterial));
            }
            HashMap<Integer, ? extends ItemStack> helmets = playerInv.all(teamBlockMaterial);
            if (helmets.size() > 1
                || (helmets.size() == 1
                    && helmets.get(helmets.keySet().iterator().next()).getAmount() > 1)) {
              playerInv.remove(teamBlockMaterial);
              playerInv.setItem(playerInv.firstEmpty(), new ItemStack(teamBlockMaterial));
              War.war.badMsg(player, "All those helmets must have been heavy!");
            }
          }

          // check for thieves without their treasure in their hands
          if (zone.isFlagThief(player.getName())) {
            Team victim = zone.getVictimTeamForFlagThief(player.getName());
            player.setItemInHand(null);
            player
                .getInventory()
                .addItem(
                    new ItemStack(
                        victim.getKind().getMaterial(),
                        2240,
                        victim.getKind().getData(),
                        victim.getKind().getData()));
          } else if (zone.isBombThief(player.getName())) {
            player.setItemInHand(null);
            player.getInventory().addItem(new ItemStack(Material.TNT, 2240));
          } else if (zone.isCakeThief(player.getName())) {
            player.setItemInHand(null);
            player.getInventory().addItem(new ItemStack(Material.CAKE_BLOCK, 2240));
          }
        }
      }
    }
  }
Beispiel #16
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void PlayerInteractEvent(PlayerInteractEvent e) {

    Player p = e.getPlayer();

    CEventHandler.handleEvent(p, e, interact);

    if (e.getAction().toString().startsWith("LEFT")) CEventHandler.handleEvent(p, e, interactL);
    else if (e.getAction().toString().startsWith("RIGHT")) {
      CEventHandler.handleEvent(p, e, interactR);

      // Check if the player has put armor on by rightclicking
      if (p.getItemInHand().getType() != Material.AIR) {
        ItemStack i = p.getItemInHand();
        String mat = i.getType().toString();
        PlayerInventory inv = p.getInventory();
        if ((mat.endsWith("BOOTS") && inv.getBoots() == null)
            || (mat.endsWith("LEGGINGS") && inv.getLeggings() == null)
            || (mat.endsWith("CHESTPLATE") && inv.getChestplate() == null)
            || (mat.endsWith("HELMET") && inv.getHelmet() == null))
          CEventHandler.handleArmor(p, e.getItem(), false, e);
      }
    }

    // Sign shop
    if (e.getClickedBlock() != null && e.getClickedBlock().getType().toString().contains("SIGN"))
      if (((Sign) e.getClickedBlock().getState()).getLine(0).equals("[CustomEnchant]")) {
        if (!Main.hasEconomy) {
          p.performCommand("ce menu");
        } else if (p.getItemInHand().getType() != Material.AIR) {
          Sign sign = ((Sign) e.getClickedBlock().getState());
          CEnchantment ce = Tools.getEnchantmentByDisplayname(sign.getLine(1));
          if (ce == null) Tools.getEnchantmentByOriginalname(sign.getLine(1));
          if (ce == null)
            for (CEnchantment ceT : Main.enchantments)
              if (Tools.checkForEnchantment(sign.getLine(1), ceT)) ce = ceT;
          if (ce == null) return;

          ItemStack inHand = p.getItemInHand();
          if (!Tools.isApplicable(inHand, ce)) {
            p.sendMessage(ChatColor.RED + "[CE] This enchantment can not be applied to this item.");
            return;
          }

          int cost = 0;
          try {
            cost = Integer.parseInt(sign.getLine(3).replaceAll("\\D+", ""));
          } catch (NumberFormatException ex) {
            return;
          }

          if (inHand.hasItemMeta() && inHand.getItemMeta().hasLore()) {
            List<String> lore = inHand.getItemMeta().getLore();
            for (int i = 0; i < lore.size(); i++)
              if (Tools.checkForEnchantment(lore.get(i), ce)) {
                int newLevel = Tools.getLevel(lore.get(i)) + 1;
                if (newLevel <= ce.getEnchantmentMaxLevel()) {
                  if (Main.econ.getBalance(p.getName()) >= cost) {
                    EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
                    if (ecr.transactionSuccess())
                      p.sendMessage(
                          ChatColor.GREEN
                              + "[CE] Upgraded enchantment "
                              + ce.getDisplayName()
                              + ChatColor.RESET
                              + ""
                              + ChatColor.GREEN
                              + " for "
                              + cost
                              + " "
                              + ((cost == 1)
                                  ? Main.econ.currencyNameSingular()
                                  : Main.econ.currencyNamePlural()));
                    else {
                      p.sendMessage(ChatColor.RED + "[CE] An economy error has occured:");
                      p.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;
                  }
                  lore.set(i, ce.getDisplayName() + " " + Tools.intToLevel(newLevel));
                  ItemMeta im = inHand.getItemMeta();
                  im.setLore(lore);
                  inHand.setItemMeta(im);
                  return;
                } else {
                  p.sendMessage(
                      ChatColor.RED
                          + "[CE] You already have the maximum level of this enchantment!");
                  return;
                }
              }
          }

          List<String> lore = new ArrayList<String>();
          ItemMeta im = inHand.getItemMeta();

          if (inHand.getItemMeta().hasLore()) lore = im.getLore();

          if (Main.econ.getBalance(p.getName()) >= cost) {
            EconomyResponse ecr = Main.econ.withdrawPlayer(p.getName(), cost);
            if (ecr.transactionSuccess())
              p.sendMessage(
                  ChatColor.GREEN
                      + "[CE] Bought enchantment "
                      + ce.getDisplayName()
                      + ChatColor.RESET
                      + ""
                      + 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;
          }

          lore.add(ce.getDisplayName() + " I");
          im.setLore(lore);
          inHand.setItemMeta(im);
          return;

        } else {
          p.sendMessage(ChatColor.RED + "[CE] You do not have an item in your hand.");
          return;
        }
      }
  }
Beispiel #17
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.");
        }
      }
    }
  }
Beispiel #18
0
  public static Object handle(Object obj) {
    if (obj instanceof World.Environment) {
      World.Environment e = (World.Environment) obj;
      if (e == World.Environment.NETHER) {
        return "nether";
      } else {
        return "normal";
      }
    } else if (obj instanceof File) {
      return ((File) obj).toString();
    } else if (obj instanceof Player) {
      Player p = (Player) obj;
      JSONObject o = new JSONObject();

      o.put("name", p.getName());
      o.put("op", p.isOp());
      o.put("health", p.getHealth());
      o.put("ip", p.getAddress().toString());
      o.put("itemInHand", p.getItemInHand());
      o.put("location", p.getLocation());
      o.put("inventory", p.getInventory());
      o.put("sneaking", p.isSneaking());
      o.put("inVehicle", p.isInsideVehicle());
      o.put("sleeping", p.isSleeping());
      o.put("world", p.getServer().getWorlds().indexOf(p.getWorld()));

      return o;
    } else if (obj instanceof Server) {
      Server s = (Server) obj;

      JSONObject o = new JSONObject();

      o.put("maxPlayers", s.getMaxPlayers());
      o.put("players", Arrays.asList(s.getOnlinePlayers()));
      o.put("port", s.getPort());
      o.put("name", s.getName());
      o.put("serverName", s.getServerName());
      o.put("version", s.getVersion());
      o.put("worlds", s.getWorlds());

      return o;
    } else if (obj instanceof World) {
      World w = (World) obj;

      JSONObject o = new JSONObject();

      o.put("environment", w.getEnvironment());
      o.put("fullTime", w.getFullTime());
      o.put("time", w.getTime());
      o.put("name", w.getName());
      o.put("isThundering", w.isThundering());
      o.put("hasStorm", w.hasStorm());

      return o;
    } else if (obj instanceof Plugin) {
      Plugin p = (Plugin) obj;
      PluginDescriptionFile d = p.getDescription();

      JSONObject o = new JSONObject();

      o.put("name", d.getName());
      o.put("description", d.getDescription());
      o.put("authors", d.getAuthors());
      o.put("version", d.getVersion());
      o.put("website", d.getWebsite());
      o.put("enabled", JSONAPI.instance.getServer().getPluginManager().isPluginEnabled(p));

      return o;
    } else if (obj instanceof ItemStack) {
      ItemStack i = (ItemStack) obj;

      JSONObject o = new JSONObject();

      o.put("type", i.getTypeId());
      o.put("durability", i.getDurability());
      o.put("amount", i.getAmount());

      return o;
    } else if (obj instanceof PlayerInventory) {
      PlayerInventory p = (PlayerInventory) obj;

      JSONObject o = new JSONObject();

      JSONObject armor = new JSONObject();
      armor.put("boots", p.getBoots());
      armor.put("chestplate", p.getChestplate());
      armor.put("helmet", p.getHelmet());
      armor.put("leggings", p.getLeggings());

      o.put("armor", armor);
      o.put("hand", p.getItemInHand());
      o.put("inventory", Arrays.asList(p.getContents()));

      return o;
    } else if (obj instanceof Location) {
      Location l = (Location) obj;

      JSONObject o = new JSONObject();

      o.put("x", l.getX());
      o.put("y", l.getY());
      o.put("z", l.getZ());
      o.put("pitch", l.getPitch());
      o.put("yaw", l.getYaw());

      return o;
    } else if (obj instanceof Plugin[]) {
      List<Plugin> l = Arrays.asList((Plugin[]) obj);

      Collections.sort(l, new PluginSorter());

      return l;
    } else if (obj instanceof Object[]) {
      int l = ((Object[]) obj).length;
      JSONArray a = new JSONArray();
      for (int i = 0; i < l; i++) {
        a.add(((Object[]) obj)[i]);
      }

      return a;
    }
    Logger.getLogger("JSONAPI").warning("Uncaugh object! Value:");
    Logger.getLogger("JSONAPI").warning(obj.toString());
    Logger.getLogger("JSONAPI").warning("Type:");
    Logger.getLogger("JSONAPI").warning(obj.getClass().getName());

    return new Object();
  }