Beispiel #1
0
  @Override
  public void onPlayerPickupItem(PlayerPickupItemEvent event) {
    if (event.isCancelled()
        || plugin
            .getConfigManager()
            .getProperties()
            .disabledWorlds
            .contains(event.getPlayer().getWorld().getName())) return;

    final Hero hero = plugin.getHeroManager().getHero(event.getPlayer());
    if (hero.hasEffectType(EffectType.DISARM)
        && Util.isWeapon(event.getItem().getItemStack().getType())) {
      event.setCancelled(true);
      return;
    }

    plugin
        .getServer()
        .getScheduler()
        .scheduleSyncDelayedTask(
            plugin,
            new Runnable() {
              @Override
              public void run() {
                hero.checkInventory();
              }
            });

    if (!hero.hasParty()) return;
    HeroParty party = hero.getParty();
    if (!party.updateMapDisplay()
        && event.getItem().getItemStack().getType().toString().equalsIgnoreCase("MAP")) {
      party.setUpdateMapDisplay(true);
    }
  }
Beispiel #2
0
 @Override
 public void onItemHeldChange(PlayerItemHeldEvent event) {
   Player player = event.getPlayer();
   Hero hero = plugin.getHeroManager().getHero(player);
   if (hero.hasEffectType(EffectType.DISARM)) {
     Util.disarmCheck(hero, plugin);
   }
   hero.checkInventory();
 }
Beispiel #3
0
  @Override
  public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
    if (!plugin.getConfigManager().getProperties().bedHeal) return;

    // This player is no longer in bed so remove them from the bedHealer set
    Hero hero = plugin.getHeroManager().getHero(event.getPlayer());
    if (hero.hasEffect("BedHeal")) {
      hero.removeEffect(hero.getEffect("BedHeal"));
    }
  }
Beispiel #4
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;
  }
Beispiel #5
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());
   }
 }
Beispiel #6
0
  @Override
  public void onPlayerBedEnter(PlayerBedEnterEvent event) {
    Properties props = plugin.getConfigManager().getProperties();
    if (event.isCancelled()
        || !props.bedHeal
        || props.disabledWorlds.contains(event.getPlayer().getWorld().getName())) return;

    Hero hero = plugin.getHeroManager().getHero(event.getPlayer());
    long period = props.healInterval * 1000;
    double tickHealPercent = props.healPercent / 100.0;
    BedHealEffect bhEffect = new BedHealEffect(period, tickHealPercent);
    hero.addEffect(bhEffect);
  }
Beispiel #7
0
 @Override
 public void onPlayerQuit(PlayerQuitEvent event) {
   Player player = event.getPlayer();
   HeroManager heroManager = plugin.getHeroManager();
   Hero hero = heroManager.getHero(player);
   hero.clearEffects();
   heroManager.saveHero(hero);
   heroManager.removeHero(hero);
   for (Command command : plugin.getCommandHandler().getCommands()) {
     if (command.isInteractive()) {
       command.cancelInteraction(player);
     }
   }
 }
Beispiel #8
0
 @Override
 public SkillResult use(Hero hero, String[] args) {
   int duration = SkillConfigManager.getUseSetting(hero, this, Setting.DURATION, 30000, false);
   int period = SkillConfigManager.getUseSetting(hero, this, Setting.PERIOD, 200, false);
   hero.addEffect(new LightEffect(this, period, duration));
   return SkillResult.NORMAL;
 }
Beispiel #9
0
 @Override
 public void remove(Hero hero) {
   super.remove(hero);
   Player p = hero.getPlayer();
   broadcast(p.getLocation(), expireText, p.getDisplayName());
   if (lastLoc != null) {
     p.sendBlockChange(lastLoc, lastMat, lastData);
   }
 }
Beispiel #10
0
 @Override
 public void tick(Hero hero) {
   super.tick(hero);
   Player player = hero.getPlayer();
   double healAmount = hero.getMaxHealth() * tickHealPercent;
   hero.setHealth(hero.getHealth() + healAmount);
   hero.syncHealth();
   if (hero.isVerbose()) {
     player.sendMessage(Messaging.createFullHealthBar(hero.getHealth(), hero.getMaxHealth()));
   }
 }
Beispiel #11
0
  @Override
  public SkillResult use(Hero hero, LivingEntity target, String[] args) {
    Player player = hero.getPlayer();
    if (target.equals(player) || hero.getSummons().contains(target)) {
      return SkillResult.INVALID_TARGET;
    }

    long duration = SkillConfigManager.getUseSetting(hero, this, Setting.DURATION, 10000, false);
    long period = SkillConfigManager.getUseSetting(hero, this, Setting.PERIOD, 2000, true);
    int tickDamage = SkillConfigManager.getUseSetting(hero, this, "tick-damage", 1, false);
    BleedSkillEffect bEffect = new BleedSkillEffect(this, duration, period, tickDamage, player);

    if (target instanceof Player) {
      plugin.getHeroManager().getHero((Player) target).addEffect(bEffect);
    } else plugin.getEffectManager().addEntityEffect(target, bEffect);

    broadcastExecuteText(hero, target);
    return SkillResult.NORMAL;
  }
Beispiel #12
0
 @Override
 public void onPlayerRespawn(PlayerRespawnEvent event) {
   Player player = event.getPlayer();
   final Hero hero = plugin.getHeroManager().getHero(player);
   hero.setHealth(hero.getMaxHealth());
   hero.setMana(0);
   CraftPlayer craftPlayer = (CraftPlayer) player;
   EntityPlayer entityPlayer = craftPlayer.getHandle();
   entityPlayer.exp = 0;
   entityPlayer.expTotal = 0;
   entityPlayer.expLevel = 0;
   Bukkit.getScheduler()
       .scheduleSyncDelayedTask(
           plugin,
           new Runnable() {
             @Override
             public void run() {
               hero.syncExperience();
             }
           },
           20L);
 }
Beispiel #13
0
 @Override
 public void apply(Hero hero) {
   super.apply(hero);
   Player p = hero.getPlayer();
   broadcast(p.getLocation(), applyText, p.getDisplayName());
   Block thisBlock = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
   if (allowedBlocks.contains(thisBlock.getType())) {
     lastLoc = thisBlock.getLocation();
     lastMat = thisBlock.getType();
     lastData = thisBlock.getData();
     p.sendBlockChange(lastLoc, Material.GLOWSTONE, (byte) 0);
   }
 }
Beispiel #14
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();
                  }
                });
      }
    }
  }
Beispiel #15
0
 @Override
 public void tick(Hero hero) {
   super.tick(hero);
   Player p = hero.getPlayer();
   Block thisBlock = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
   if (thisBlock.getLocation().equals(lastLoc)) {
     return;
   } else if (allowedBlocks.contains(thisBlock.getType())) {
     if (lastLoc != null) {
       p.sendBlockChange(lastLoc, lastMat, lastData);
     }
     lastLoc = thisBlock.getLocation();
     lastMat = thisBlock.getType();
     lastData = thisBlock.getData();
     p.sendBlockChange(lastLoc, Material.GLOWSTONE, (byte) 0);
   } else if (lastLoc != null) {
     p.sendBlockChange(lastLoc, lastMat, lastData);
   }
 }
Beispiel #16
0
 @Override
 public void apply(Hero hero) {
   super.apply(hero);
   Player player = hero.getPlayer();
   broadcast(player.getLocation(), applyText, player.getDisplayName());
 }
Beispiel #17
0
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (event.useItemInHand() == Result.DENY) return;

    Hero hero = plugin.getHeroManager().getHero(player);
    if (hero.hasEffectType(EffectType.DISARM)) Util.disarmCheck(hero, plugin);

    if (!hero.canEquipItem(player.getInventory().getHeldItemSlot())) {
      event.setCancelled(true);
      Util.syncInventory(player, plugin);
      return;
    }

    // Remove effects dependant on non-interaction
    if (hero.hasEffect("Invisible")) {
      hero.removeEffect(hero.getEffect("Invisible"));
    }

    Block clickedBlock = event.getClickedBlock();
    if (clickedBlock != null) {
      switch (clickedBlock.getType()) {
        case DISPENSER:
        case BED:
        case FURNACE:
        case BURNING_FURNACE:
        case WOOD_DOOR:
        case LEVER:
        case IRON_DOOR:
        case JUKEBOX:
        case DIODE_BLOCK_OFF:
        case DIODE_BLOCK_ON:
        case CHEST:
        case LOCKED_CHEST:
        case TRAP_DOOR:
          hero.cancelDelayedSkill();
          return;
      }
    }

    if (player.getItemInHand() != null) {
      Material material = player.getItemInHand().getType();
      if (hero.hasBind(material)) {
        if (event.getAction() == Action.RIGHT_CLICK_AIR
            || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
          String[] args = hero.getBind(material);
          plugin.onCommand(player, null, "skill", args);
        } else {
          hero.cancelDelayedSkill();
        }
      } else {
        hero.cancelDelayedSkill();
      }
    }
  }
Beispiel #18
0
 @Override
 public void remove(Hero hero) {
   super.remove(hero);
   Player player = hero.getPlayer();
   broadcast(player.getLocation(), expireText, player.getDisplayName());
 }