예제 #1
0
  @EventHandler
  private void onPlayerInteract(PlayerInteractEvent event) {

    Player player = (Player) event.getPlayer();
    String itemName = player.getItemInHand().getType().name();

    if (!ToyChestHook.toyExists(itemName)) return;

    List<Entity> targets = gatherTargets(player, itemName);

    int customDamage = ToyChestHook.getDamage(itemName);

    for (Entity target : targets) ((LivingEntity) target).damage(customDamage);
  }
예제 #2
0
  private List<Entity> gatherTargets(Player player, String itemName) {

    int customRange = (Integer) ToyChestHook.getCustomValue(itemName, "Range");
    int customWidth = (Integer) ToyChestHook.getCustomValue(itemName, "Width");
    int customHeight = (Integer) ToyChestHook.getCustomValue(itemName, "Height");

    if (customRange == 0) return null;

    if (customWidth == 0 && customHeight == 0) {

      List<Entity> targets = Utility.getTargetsInLine(player, customRange, 3);
      return targets;
    }

    List<Entity> targets =
        Utility.getTargetsInBox(player, customRange, customWidth, customHeight, 3);
    return targets;
  }
예제 #3
0
  @EventHandler
  private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

    if (event.getDamager() instanceof Player == false) return;

    Player player = (Player) event.getDamager();
    String itemName = player.getItemInHand().getType().name();

    if (!ToyChestHook.toyExists(itemName)) return;

    List<Entity> targets = gatherTargets(player, itemName);

    int customDamage = ToyChestHook.getDamage(itemName);

    if (targets == null) {

      event.setDamage(customDamage);
      return;
    }

    event.setCancelled(true);

    for (Entity target : targets) ((LivingEntity) target).damage(customDamage);
  }