コード例 #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
  /**
   * Gets the name of the item passed
   *
   * @param item the item to check, cannot be null
   * @param ignoreMeta if true, item meta will be ignored
   * @return the item name
   */
  public static String getName(ItemStack item, boolean ignoreMeta) {
    String def = item.getType().name();
    if (DumbAuction.getInstance().getConfig().getString("aliases." + item.getType().name())
        != null) {
      def = DumbAuction.getInstance().getConfig().getString("aliases." + item.getType().name());
    }

    DyeColor color = getDyeColor(item);
    if (color != null) {
      def = color.name() + "_" + def; // underscore is stripped later, capitals are also fixed
    }

    // ItemMeta always overrides everything else
    if (!ignoreMeta && item.hasItemMeta()) {
      ItemMeta meta = item.getItemMeta();
      if (meta.hasDisplayName()) {
        def = ChatColor.ITALIC + meta.getDisplayName();
      }
    }

    String[] parts = def.split("_");
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < parts.length; i++) {
      builder.append(parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1).toLowerCase());
      builder.append(" ");
    }
    return builder.toString().trim();
  }
コード例 #3
0
 private static String getTitleOfBook(ItemStack book) {
   if (book.getType() == Material.WRITTEN_BOOK && book.hasItemMeta()) {
     BookMeta meta = (BookMeta) book.getItemMeta();
     return meta.getTitle();
   }
   return null;
 }
コード例 #4
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);
  }
コード例 #5
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);
  }
コード例 #6
0
 public PrisonPearl getPearlbyItemStack(ItemStack stack) {
   if (!stack.hasItemMeta() || stack.getType() != Material.ENDER_PEARL) return null;
   if (!stack.getItemMeta().hasLore()) return null;
   List<String> lore = stack.getItemMeta().getLore();
   if (lore.size() != 3) return null;
   UUID uuid = UUID.fromString(lore.get(1).split(" ")[1]);
   return pearls_byimprisoned.get(uuid);
 }
コード例 #7
0
 @Override
 protected boolean isSpecialItem(ItemStack stack) {
   if (stack != null && stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) {
     String name = stack.getItemMeta().getDisplayName();
     if (name.contains(getSpecialItemName()) && KitUtils.isSoulbound(stack)) return true;
   }
   return false;
 }
コード例 #8
0
 public void addItem(ItemStack i, int loc, BSShop shop, BasicConnector c) {
   to_ping.add(c);
   if (!i.hasItemMeta()) {
     c.setOldData(null, null, i, shop, loc);
     return;
   }
   c.setOldData(i.getItemMeta().getLore(), i.getItemMeta().getDisplayName(), i, shop, loc);
 }
コード例 #9
0
 /**
  * Creates a new item stack derived from the specified stack
  *
  * @param stack the stack to copy
  * @throws IllegalArgumentException if the specified stack is null or returns an item meta not
  *     created by the item factory
  */
 public ItemStack(final ItemStack stack) throws IllegalArgumentException {
   Validate.notNull(stack, "Cannot copy null stack");
   this.type = stack.getTypeId();
   this.amount = stack.getAmount();
   this.durability = stack.getDurability();
   this.data = stack.getData();
   if (stack.hasItemMeta()) {
     setItemMeta0(stack.getItemMeta(), getType0());
   }
 }
コード例 #10
0
  public boolean isValidRocketSaddle(ItemStack saddle) {

    if (saddle != null && saddle.hasItemMeta()) {
      ItemMeta saddleMeta = saddle.getItemMeta();
      if (saddleMeta.hasDisplayName())
        if (saddleMeta.getDisplayName().equals(RocketLanguage.RB_SADDLE)) return true;
    }

    return false;
  }
コード例 #11
0
 @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);
       }
     }
   }
 }
コード例 #12
0
 @SuppressWarnings("deprecation")
 public void run() {
   for (Player p : c.getServer().getOnlinePlayers()) {
     for (ItemStack is : p.getInventory().getContents()) {
       if (is == null || is.getType() == Material.AIR || !is.hasItemMeta()) continue;
       if (!is.getItemMeta().hasLore()) continue;
       if (!c.hasCustomEnchant(is.getItemMeta().getLore())) continue;
       boolean b = false;
       for (String s : is.getItemMeta().getLore()) {
         if (!c.isCustomEnchant(s)) continue;
         if (s.startsWith(ChatColor.RESET + "Repair ")) b = true;
       }
       if (!b) continue;
       if (is.getDurability() > 0) is.setDurability((short) (is.getDurability() - 1));
     }
     boolean hasChestplateOn = false;
     for (ItemStack is : p.getInventory().getArmorContents()) {
       if (is == null || !is.getType().name().endsWith("CHESTPLATE") || !is.hasItemMeta())
         continue;
       if (!is.getItemMeta().hasLore()) continue;
       if (!c.hasCustomEnchant(is.getItemMeta().getLore())) continue;
       boolean b = false;
       for (String s : is.getItemMeta().getLore()) {
         if (!c.isCustomEnchant(s)) continue;
         if (s.startsWith(ChatColor.RESET + "Flying ")) b = true;
       }
       if (!b) continue;
       if (!hasChestplateOn) {
         if (!p.isFlying()) {
           p.sendMessage(ChatColor.GOLD + "Flying enabled!");
         }
         p.setAllowFlight(true);
         p.setFlying(true);
         hasChestplateOn = true;
       }
     }
     if (!hasChestplateOn && p.getGameMode() != GameMode.CREATIVE && p.isFlying()) {
       p.setFlying(false);
       p.setAllowFlight(false);
     }
   }
 }
コード例 #13
0
ファイル: EconAPI.java プロジェクト: Giinger/EconAddon
 public boolean isBanknote(ItemStack item) {
   if (item.getType() == Material.PAPER) {
     if (item.hasItemMeta()) {
       ItemMeta meta = item.getItemMeta();
       if (meta.getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Bank Note")) {
         return true;
       }
     }
   }
   return false;
 }
コード例 #14
0
  public boolean isValidFuelJacket(ItemStack jacket) {

    if (jacket.hasItemMeta()) {
      ItemMeta jacketMeta = jacket.getItemMeta();
      if (jacketMeta.hasDisplayName())
        if (jacketMeta.getDisplayName().equals(ChatColor.RED + "Rocket Boot Fuel Jacket"))
          return true;
    }

    return false;
  }
コード例 #15
0
 /**
  * Returns a user friendly String of the given ItemStack's name
  *
  * @param item The given ItemStack
  * @return The name of the item
  */
 public static String getItemName(ItemStack item) {
   // Return the Display name of the item if there is one
   if (item.hasItemMeta()) {
     String name = item.getItemMeta().getDisplayName();
     if (name != null && !name.isEmpty()) {
       return name;
     }
   }
   // A display name was not found so use a cleaned up version of the Material name
   return WordUtils.capitalizeFully(item.getType().toString().replace("_", " "));
 }
コード例 #16
0
 /**
  * Gets the lore of an ItemStack
  *
  * @param itemStack ItemStack to get the lore of
  * @return the lore of an ItemStack
  */
 public List<String> getLore(final ItemStack itemStack) {
   ItemStack ret = itemStack;
   ItemMeta itemMeta;
   if (ret.hasItemMeta()) {
     itemMeta = ret.getItemMeta();
   } else {
     itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
   }
   if (itemMeta.hasLore()) return itemMeta.getLore();
   return new ArrayList<String>();
 }
コード例 #17
0
 /**
  * Cancel players from dropping the hat in their inventory.
  *
  * @param event
  */
 @EventHandler
 public void cancelHatDropping(PlayerDropItemEvent event) {
   ItemStack item = event.getItemDrop().getItemStack().clone();
   if (item != null
       && item.hasItemMeta()
       && item.getItemMeta().hasDisplayName()
       && item.getItemMeta().getDisplayName().equals("§8§oHat")) {
     event.getItemDrop().remove();
     event.getPlayer().closeInventory();
     event.getPlayer().updateInventory();
   }
 }
コード例 #18
0
 /**
  * Sets the name of an ItemStack
  *
  * @param itemStack ItemStack to set name for
  * @param name Name to give to the ItemStack
  * @return named ItemStack
  */
 public ItemStack setName(final ItemStack itemStack, final String name) {
   ItemStack ret = itemStack;
   ItemMeta itemMeta;
   if (ret.hasItemMeta()) {
     itemMeta = ret.getItemMeta();
   } else {
     itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
   }
   itemMeta.setDisplayName(name);
   ret.setItemMeta(itemMeta);
   return ret;
 }
コード例 #19
0
 /**
  * Sets the lore of an ItemStack
  *
  * @param itemStack ItemStack to set lore for
  * @param lore Lore to give to the ItemStack
  * @return lored ItemStack
  */
 public ItemStack setLore(final ItemStack itemStack, final String... lore) {
   ItemStack ret = itemStack;
   ItemMeta itemMeta;
   if (ret.hasItemMeta()) {
     itemMeta = ret.getItemMeta();
   } else {
     itemMeta = Bukkit.getItemFactory().getItemMeta(ret.getType());
   }
   itemMeta.setLore(Arrays.asList(lore));
   ret.setItemMeta(itemMeta);
   return ret;
 }
コード例 #20
0
ファイル: CthItem.java プロジェクト: Akoot/Cthulhu-Bukkit
 public CthItem(Cthulhu plugin, ItemStack item, Player player) {
   this.plugin = plugin;
   this.player = player;
   this.user = new CthUser(plugin, player);
   this.item = item;
   this.meta = (item.hasItemMeta() ? item.getItemMeta() : null);
   if (meta != null) {
     this.lore = (this.meta.getLore() != null ? this.meta.getLore() : new ArrayList<String>());
   } else {
     this.lore = new ArrayList<String>();
   }
 }
コード例 #21
0
ファイル: EnderDoge.java プロジェクト: SmackFPS/LCHub
 public String disName(ItemStack i) {
   if (i == null) {
     return null;
   }
   if (!i.hasItemMeta()) {
     return null;
   }
   if (!i.getItemMeta().hasDisplayName()) {
     return null;
   }
   return i.getItemMeta().getDisplayName();
 }
コード例 #22
0
 @Override
 public boolean apply(ItemStack stack) {
   if (stack.hasItemMeta()) {
     ItemMeta meta = stack.getItemMeta();
     if (meta.hasLore()) {
       String lore = Joiner.on('\n').join(stack.getItemMeta().getLore());
       if (ignoreColors) {
         lore = ChatColor.stripColor(lore);
       }
       return pattern.matcher(lore).find();
     }
   }
   return false;
 }
コード例 #23
0
  public boolean isValidRocketBoots(ItemStack boots) {

    if (boots.hasItemMeta()) {
      ItemMeta bootMeta = boots.getItemMeta();

      if (bootMeta.hasDisplayName())
        if (bootMeta.getDisplayName().matches(RocketLanguage.RB_NAME))
          if (bootMeta.hasLore())
            if (bootMeta.getLore().get(0).matches(ChatColor.YELLOW + "Rocket Level I{0,3}V?X?"))
              return true;
    }

    return false;
  }
コード例 #24
0
  @Override
  public void writeData(SpoutOutputStream output) throws IOException {
    super.writeData(output);
    output.writeInt(stack.getTypeId());
    output.writeShort((short) stack.getAmount());
    output.writeShort(stack.getDurability());
    output.writeInt(depth);
    output.writeBoolean(renderAmount);

    if (stack.hasItemMeta() && stack.getItemMeta().hasDisplayName()) {
      output.writeBoolean(true);
      output.writeString(stack.getItemMeta().getDisplayName());
    } else {
      output.writeBoolean(false);
    }

    if (stack.hasItemMeta() && stack.getItemMeta().hasLore()) {
      output.writeBoolean(true);
      output.writeInt(stack.getItemMeta().getLore().size());
      for (String l : stack.getItemMeta().getLore()) {
        output.writeString(l);
      }
    } else {
      output.writeBoolean(false);
    }

    if (stack.hasItemMeta() && stack.getItemMeta().hasEnchants()) {
      output.writeBoolean(true);
      output.writeInt(stack.getItemMeta().getEnchants().size());
      for (Entry e : stack.getItemMeta().getEnchants().entrySet()) {
        output.writeInt(((Enchantment) e.getKey()).getId());
        output.writeInt((Integer) e.getValue());
      }
    } else {
      output.writeBoolean(false);
    }
  }
コード例 #25
0
 /**
  * This method is the same as equals, but does not consider stack size (amount).
  *
  * @param stack the item stack to compare to
  * @return true if the two stacks are equal, ignoring the amount
  */
 @Utility
 public boolean isSimilar(ItemStack stack) {
   if (stack == null) {
     return false;
   }
   if (stack == this) {
     return true;
   }
   return getTypeId() == stack.getTypeId()
       && getDurability() == stack.getDurability()
       && hasItemMeta() == stack.hasItemMeta()
       && (hasItemMeta()
           ? Bukkit.getItemFactory().equals(getItemMeta(), stack.getItemMeta())
           : true);
 }
コード例 #26
0
ファイル: Main.java プロジェクト: Lucidiax/Tutoriels
 @EventHandler
 public void onInventoryClick(InventoryClickEvent event) {
   Inventory inventory = event.getInventory();
   if (inventory.getName().equals(i.getName())) {
     event.setCancelled(true);
     Player player = (Player) event.getWhoClicked();
     ItemStack stack = event.getCurrentItem();
     if (stack == null || !stack.hasItemMeta()) return;
     if (stack.getItemMeta().getDisplayName().equals("Une pomme g閚iale !")) {
       player.closeInventory();
       player.sendMessage(
           "Bravo, tu viens de cliquer sur " + stack.getItemMeta().getDisplayName() + " !");
       player.addPotionEffect(PotionEffectType.FIRE_RESISTANCE.createEffect(Integer.MAX_VALUE, 2));
     }
   }
 }
コード例 #27
0
ファイル: RollsManager.java プロジェクト: ZammieWins/Wayward
 private double getEnchantmentBonus(ItemStack item, Stat stat) {
   double bonus = 0D;
   if (item.hasItemMeta()) {
     ItemMeta meta = item.getItemMeta();
     if (meta.hasEnchants()) {
       for (Enchantment enchantment : meta.getEnchants().keySet()) {
         bonus +=
             meta.getEnchants().get(enchantment)
                 * plugin
                     .getConfig()
                     .getDouble("rolls.enchants." + enchantment.getName() + "." + stat.toString());
       }
     }
   }
   return bonus;
 }
コード例 #28
0
  @EventHandler(ignoreCancelled = true)
  public void onInventoryDrag(InventoryDragEvent event) {
    Mage mage = controller.getMage(event.getWhoClicked());
    GUIAction activeGUI = mage == null ? null : mage.getActiveGUI();
    if (activeGUI != null) {
      activeGUI.dragged(event);
      return;
    }

    if (!enableItemHacks) return;

    // this is a huge hack! :\
    // I apologize for any weird behavior this causes.
    // Bukkit, unfortunately, will blow away NBT data for anything you drag
    // Which will nuke a wand or spell.
    // To make matters worse, Bukkit passes a copy of the item in the event, so we can't
    // even check for metadata and only cancel the event if it involves one of our special items.
    // The best I can do is look for metadata at all, since Bukkit will retain the name and lore.

    // I have now decided to copy over the CB default handler for this, and cancel the event.
    // The only change I have made is that *real* ItemStack copies are made, instead of shallow
    // Bukkit ones.
    ItemStack oldStack = event.getOldCursor();
    HumanEntity entity = event.getWhoClicked();
    if (oldStack != null && oldStack.hasItemMeta() && entity instanceof Player) {
      // Only do this if we're only dragging one item, since I don't
      // really know what happens or how you would drag more than one.
      Map<Integer, ItemStack> draggedSlots = event.getNewItems();
      if (draggedSlots.size() != 1) return;

      event.setCancelled(true);

      // Cancelling the event will put the item back on the cursor,
      // and skip updating the inventory.

      // So we will wait one tick and then fix this up using the original item.
      InventoryView view = event.getView();
      for (Integer dslot : draggedSlots.keySet()) {
        CompleteDragTask completeDrag = new CompleteDragTask((Player) entity, view, dslot);
        completeDrag.runTaskLater(controller.getPlugin(), 1);
      }
    }
  }
コード例 #29
0
  /**
   * Sends a display of item information to the specified command sender. This is used for sending
   * the current auction queue to a command sender and therefore the resulting text is a "short
   * hand" version.
   *
   * @param item the item to display, cannot be null
   * @param sender the command sender to send the display to, cannot be null
   * @param placement the number to prefix the message. If less than zero, nothing is appended
   */
  public static void showQuickInformation(ItemStack item, CommandSender sender, int placement) {
    if (item == null || sender == null) throw new IllegalArgumentException();

    StringBuilder builder = new StringBuilder();
    builder.append(getName(item)).append(" ");
    if (item.hasItemMeta() && item.getItemMeta().hasDisplayName()) {
      builder.append(ChatColor.ITALIC).append("(").append(getName(item, true)).append(") ");
    }
    builder.append(ChatColor.BLUE).append("x").append(item.getAmount());

    DumbAuction.getInstance()
        .sendMessage(
            sender,
            ChatColor.GREEN
                + (placement > 0 ? "#" + placement : placement == 0 ? "(current)" : "")
                + " "
                + ChatColor.AQUA
                + builder.toString().trim());
  }
コード例 #30
0
 public boolean compareItemStr(ItemStack item, String str) {
   String itemstr = str;
   String name = "";
   if (itemstr.contains("$")) {
     name = str.substring(0, itemstr.indexOf("$"));
     name = ChatColor.translateAlternateColorCodes('&', name.replace("_", " "));
     itemstr = str.substring(name.length() + 1);
   }
   if (itemstr.isEmpty()) return false;
   if (!name.isEmpty()) {
     String iname = item.hasItemMeta() ? item.getItemMeta().getDisplayName() : "";
     if (!name.equals(iname)) return false;
   }
   return compareItemStrIgnoreName(
       item.getTypeId(),
       item.getDurability(),
       item.getAmount(),
       itemstr); // ;compareItemStr(item, itemstr);
 }