Exemple #1
0
  @Override
  public CastResult cast(SpellContext context) {
    Player player = context.<Player>getPlayer();
    Block target = context.<Block>getTarget().get();
    BlockFace direction = getClickedFace(player);
    Block phased = null;

    switch (direction) {
      case NORTH:
        phased = target.getRelative(0, 0, -1);
        break;
      case SOUTH:
        phased = target.getRelative(0, 0, 1);
        break;
      case EAST:
        phased = target.getRelative(1, 0, 0);
        break;
      case WEST:
        phased = target.getRelative(-1, 0, 0);
        break;
      case UP:
        phased = target.getRelative(0, +3, 0);
        break;
      case DOWN:
        phased = target.getRelative(0, -2, 0);
        break;
      default:
        phased = target;
        break;
    }

    if (!BukkitTargetUtils.getTransparent().contains(phased.getType())) {
      player.sendMessage(ChatColor.RED + "You cannot phase through that block");
      return CastResult.FAILURE;
    } else if (BukkitTargetUtils.getTransparent()
        .contains(phased.getRelative(0, -1, 0).getType())) {
      Location loc = phased.getRelative(0, -1, 0).getLocation();
      loc.add(0.5, 0, 0.5);
      loc.setPitch(player.getLocation().getPitch());
      loc.setYaw(player.getLocation().getYaw());
      player.teleport(loc);
      return CastResult.SUCCESS;
    } else if (BukkitTargetUtils.getTransparent().contains(phased.getRelative(0, 1, 0).getType())) {
      Location loc = phased.getLocation();
      loc.add(0.5, 0, 0.5);
      loc.setPitch(player.getLocation().getPitch());
      loc.setYaw(player.getLocation().getYaw());
      player.teleport(loc);
      return CastResult.SUCCESS;
    } else {
      player.sendMessage(ChatColor.RED + "You cannot phase through that block");
      return CastResult.FAILURE;
    }
  }
Exemple #2
0
 @Override
 public CastResult cast(SpellContext context) {
   Player player = context.<Player>getPlayer();
   player.setHealth(player.getHealth() + context.getPower() * 2);
   return CastResult.SUCCESS;
 }