Package org.bukkit

Examples of org.bukkit.Material


 
  // TODO expand this to enchanting
  public static ItemStack parse(String[] args, CommandSender...senders){
    CommandSender sender = (senders.length > 0 ? senders[0] : null);
   
    Material material;
    int amount = -1;
    short damage = 0;
   
    if (args.length == 0){
      return null;
    }
   
    if (args[0].contains(":")){
      String[] data = args[0].split(":");

      List<Material> materialMatches = ClosestMatches.material(data[0]);
      if (materialMatches.size() > 0){
        material = materialMatches.get(0);
      } else {
        if (sender != null){ LogHelper.showWarning("itemNotFound", sender); }
        return null;
      }
     
      if (data[1].matches(CommandsEX.intRegex)){
        damage = Short.valueOf(data[1]);
      } else {
        List<DyeColor> dyeMatches = ClosestMatches.dyeColor(data[1]);
        if ((material == Material.WOOL || material == Material.INK_SACK) && dyeMatches.size() > 0){
                    damage = dyeMatches.get(0).getDyeData();
                } else {
                    if (sender != null){ LogHelper.showWarning("itemIncorrectDamage", sender); }
                    return null;
                }
      }
    } else {
      List<Material> materialMatches = ClosestMatches.material(args[0]);
      if (materialMatches.size() > 0){
        material = materialMatches.get(0);
      } else {
        if (sender != null){ LogHelper.showWarning("itemNotFound", sender); }
        return null;
      }
    }
   
    if (args.length > 1){
      if (args[1].matches(CommandsEX.intRegex)){
        amount = Integer.valueOf(args[1]);
      } else {
        if (sender != null){ LogHelper.showWarning("itemIncorrectAmount", sender); }
        return null;
      }
    }
   
    if (args.length > 2){
      if (args[2].matches(CommandsEX.intRegex)){
        damage = Short.valueOf(args[2]);
      } else {
        List<DyeColor> dyeMatches = ClosestMatches.dyeColor(args[2]);
        if (dyeMatches.size() > 0){
          damage = dyeMatches.get(0).getDyeData();
        } else {
          if (sender != null){ LogHelper.showWarning("itemIncorrectAmount", sender); }
          return null;
        }
      }
    }
   
    if (amount == -1){
      amount = material.getMaxStackSize();
    }
   
    return new ItemStack(material, amount, damage);
  }
View Full Code Here


   
    ItemStack stack = ItemStackParser.parse(listArgs.toArray(new String[]{}), sender);
    if (stack == null){ return; }
    target.getInventory().addItem(stack);

    Material item = stack.getType();
    int amount = stack.getAmount();
    short damage = stack.getDurability();
   
    // Messages will be different if the player spawned the item for himself, or someone else
    if (sender != target){
      LogHelper.showInfo("itemYouGave#####[" + Nicknames.getNick(target.getName()) + " " + amount + " " + Utils.userFriendlyNames(item.name()) + (damage != 0 ? " (" + damage + ")": ""), sender, ChatColor.AQUA);
      LogHelper.showInfo("itemGiveSuccess#####[" + amount + " " + Utils.userFriendlyNames(item.name()) + (damage != 0 ? " (" + damage + ")": "") + " #####itemFrom#####[" + Nicknames.getNick(sender.getName()), target, ChatColor.AQUA);
    } else {
      LogHelper.showInfo("itemGiveSuccess#####[" + amount + " " + Utils.userFriendlyNames(item.name()) + (damage != 0 ? " (" + damage + ")": ""), sender, ChatColor.AQUA);
    }
  }
View Full Code Here

      // Get some variables
      Player player = (Player)sender;
      ItemStack itemInHand = player.getItemInHand();
      int itemdura = itemInHand.getDurability();
      Material material = Material.getMaterial(itemInHand.getTypeId());
     
      // Check if it can be repaired
      if (material.isBlock() || material.getMaxDurability() < 1) {
        LogHelper.showWarning("repairCannotRepair", sender);
        return true;
      }
     
      // Check if it can be repaired
View Full Code Here

                    LogHelper.showWarning("commandSignInvalid", player);
                    sign.getBlock().breakNaturally();
                } else {
                    String[] data = lines[1].split(":");
                    List<Material> matches = ClosestMatches.material(data[0]);
                    Material material = (matches.size() > 0 ? matches.get(0) : null);
                    if (material == null){
                        LogHelper.showWarning("itemNotFound", player);
                        sign.getBlock().breakNaturally();
                    } else {
                        if (data.length > 0){
                            if (data.length != 2){
                                LogHelper.showWarning("commandSignInvalid", player);
                                sign.getBlock().breakNaturally();
                            } else {
                                if (material == Material.WOOL || material == Material.INK_SACK){
                                    List<DyeColor> dyeMatches = ClosestMatches.dyeColor(data[1]);
                                    DyeColor dye = (dyeMatches.size() > 0 ? dyeMatches.get(0) : null);
                                    if (dye == null){
                                        LogHelper.showWarning("commandSignInvalid", player);
                                        sign.getBlock().breakNaturally();
                                        return;
                                    } else {
                                        e.setLine(1, WordUtils.capitalize(material.name().toLowerCase().replaceAll("_", ""))  + ":" + WordUtils.capitalize(dye.toString().toLowerCase().replaceAll("_", "")));
                                    }
                                } else {
                                    if (!data[1].matches(CommandsEX.intRegex)){
                                        LogHelper.showWarning("commandSignInvalid", player);
                                        sign.getBlock().breakNaturally();
                                        return;
                                    } else {
                                        e.setLine(1, WordUtils.capitalize(material.name().toLowerCase().replaceAll("_", "")));
                                    }
                                }
                            }
                        }
                       
View Full Code Here

      Player player = (Player)sender;
      ItemStack hand = player.getItemInHand();
      PlayerInventory inv = player.getInventory();
      ItemStack head = inv.getHelmet();
      int handAmount = hand.getAmount();
      Material handID = Material.getMaterial(hand.getTypeId());
      ItemStack forHead = new ItemStack(handID, 1);
     
      // Check that head is empty
      if(head != null) {
        LogHelper.showWarning("hatHeadFull", sender);
View Full Code Here

   */
  public static int getBlockId(String blockName)
  {
    try
    {
      Material material;
      if(isNumeric(blockName))
      {
        material = Material.getMaterial(Integer.parseInt(blockName));
      }
      else
      {
        material = Material.matchMaterial(blockName);
      }
     
      return material.getId();
     
    }
    catch(NumberFormatException nfe) { return -1; }
  }
View Full Code Here

    Team attackerTeam = this.getPlayerTeam(attacker.getName());
    Team defenderTeam = this.getPlayerTeam(defender.getName());
    if (this.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
      String attackerString = attackerTeam.getKind().getColor() + attacker.getName();
      String defenderString = defenderTeam.getKind().getColor() + defender.getName();
      Material killerWeapon = attacker.getItemInHand().getType();
      String weaponString = killerWeapon.toString();
      if (attacker.getItemInHand().hasItemMeta() && attacker.getItemInHand().getItemMeta().hasDisplayName()) {
        weaponString = attacker.getItemInHand().getItemMeta().getDisplayName() + ChatColor.WHITE;
      }
      if (killerWeapon == Material.AIR) {
        weaponString = War.war.getString("pvp.kill.weapon.hand");
View Full Code Here

    this.ownerTeam = null;
    int x = this.location.getBlockX();
    int y = this.location.getBlockY();
    int z = this.location.getBlockZ();
    final Material main = this.warzone.getWarzoneMaterials().getMainBlock().getType();
    final MaterialData mainData = this.warzone.getWarzoneMaterials().getMainBlock().getData();
    final Material light = this.warzone.getWarzoneMaterials().getLightBlock().getType();
    final MaterialData lightData = this.warzone.getWarzoneMaterials().getLightBlock().getData();

    // center
    BlockState current = this.warzone.getWorld().getBlockAt(x, y - 1, z).getState();
    current.setType(main);
View Full Code Here

    }
    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() == null || playerInv.getHelmet().getType() != Material.LEATHER_HELMET) {
View Full Code Here

                r = new RepairableAttachable(state);
            else
                r = new RepairableBlock(state);

            // Cakes and liquids should just get removed. If player-placed block, drop as item.
            Material mat = state.getType();
            if (mat == Material.CAKE_BLOCK || mat == Material.WATER || mat == Material.LAVA)
                arena.removeBlock(b);
            else if (arena.removeBlock(b))
                arena.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(state.getTypeId(), 1));
            else if (softRestore)
View Full Code Here

TOP

Related Classes of org.bukkit.Material

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