예제 #1
0
  @Override
  public boolean execute(CommandSender sender, String identifier, String[] args) {
    if (!(sender instanceof Player)) return false;

    Player player = (Player) sender;
    Hero hero = plugin.getHeroManager().getHero(player);
    HeroClass heroClass = hero.getHeroClass();

    Set<Material> allTools = EnumSet.noneOf(Material.class);
    allTools.addAll(heroClass.getAllowedWeapons());
    if (hero.getSecondClass() != null) allTools.addAll(hero.getSecondClass().getAllowedWeapons());

    if (allTools.isEmpty()) {
      player.sendMessage("Your classes do not allow you to use any tools or weapons");
      return false;
    }

    String[] categories = {"Sword", "Spade", "Pickaxe", "Axe", "Hoe"};
    String[] categorizedTools = new String[categories.length];

    for (int i = 0; i < categories.length; i++) {
      categorizedTools[i] = "";
    }

    for (Material mat : allTools) {
      String tool = mat.name();
      for (int i = 0; i < categories.length; i++) {
        if (tool.endsWith(categories[i].toUpperCase())) {
          if (categorizedTools[i] == null) {
            categorizedTools[i] = "";
          }
          Integer damage = plugin.getDamageManager().getItemDamage(mat, player);
          if (damage == null) {
            damage = Util.getDefaultDamage(mat);
          }
          categorizedTools[i] +=
              MaterialUtil.getFriendlyName(tool).split(" ")[0] + "§8 " + damage + "§f, ";
          break;
        }
      }
    }

    for (int i = 0; i < categories.length; i++) {
      if (!categorizedTools[i].isEmpty()) {
        categorizedTools[i] = categorizedTools[i].substring(0, categorizedTools[i].length() - 2);
      }
    }

    sender.sendMessage("§c--------[ §fAllowed Tools§c ]--------");
    for (int i = 0; i < categories.length; i++) {
      player.sendMessage("  §a" + categories[i] + ": §f" + categorizedTools[i]);
    }

    return true;
  }
예제 #2
0
 private String parseHero(String format) {
   Plugin tmp = manager.getPlugin().getServer().getPluginManager().getPlugin("Heroes");
   if (tmp != null) {
     try {
       Heroes heroes = (Heroes) tmp;
       Player player = manager.getPlugin().getServer().getPlayer(getName());
       Hero hero = heroes.getHeroManager().getHero(player);
       String hero_name = hero.getHeroClass().getName();
       format = HEROES.matcher(format).replaceAll(hero_name);
     } catch (Exception e) {
       manager
           .getPlugin()
           .warn("An error occurred while parsing a Hero class: " + e.getLocalizedMessage());
     }
   }
   return format;
 }