Пример #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
 @Override
 public void onPlayerJoin(PlayerJoinEvent event) {
   Player player = event.getPlayer();
   Hero hero = plugin.getHeroManager().getHero(player);
   hero.syncExperience();
   hero.syncHealth();
   hero.checkInventory();
   if (plugin.getConfigManager().getProperties().prefixClassName) {
     player.setDisplayName("[" + hero.getHeroClass().getName() + "]" + player.getName());
   }
 }
Пример #3
0
  @Override
  public void onPlayerTeleport(PlayerTeleportEvent event) {
    if (event.isCancelled()) return;

    Player player = event.getPlayer();
    if (event.getFrom().getWorld() != event.getTo().getWorld()) {
      final Hero hero = plugin.getHeroManager().getHero(player);
      HeroClass heroClass = hero.getHeroClass();

      List<Command> commands = plugin.getCommandHandler().getCommands();
      for (Command cmd : commands) {
        if (cmd instanceof OutsourcedSkill) {
          OutsourcedSkill skill = (OutsourcedSkill) cmd;
          if (heroClass.hasSkill(skill.getName())) {
            skill.tryLearningSkill(hero);
          }
        }
      }
      if (plugin
          .getConfigManager()
          .getProperties()
          .disabledWorlds
          .contains(event.getTo().getWorld().getName())) {
        plugin
            .getServer()
            .getScheduler()
            .scheduleSyncDelayedTask(
                plugin,
                new Runnable() {
                  @Override
                  public void run() {
                    hero.checkInventory();
                  }
                });
      }
    }
  }