Example #1
0
  public PlayerState(final Player player) {
    name = player.getName();
    debug.i("creating PlayerState of " + name, player);

    fireticks = player.getFireTicks();
    foodlevel = player.getFoodLevel();
    gamemode = player.getGameMode().getValue();
    health = player.getHealth();
    maxhealth = player.getMaxHealth();

    exhaustion = player.getExhaustion();
    experience = player.getExp();
    explevel = player.getLevel();
    saturation = player.getSaturation();

    potionEffects = player.getActivePotionEffects();

    flying = player.isFlying();

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    final Arena arena = aPlayer.getArena();

    if (arena.getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) {
      displayname = player.getDisplayName();
    }

    fullReset(arena, player);
    final int time = arena.getArenaConfig().getInt(CFG.GENERAL_TIME);
    if (time != -1) {
      player.setPlayerTime(time, false);
    }
  }
Example #2
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityRegainHealth(EntityRegainHealthEvent event) {

    if (event.isCancelled()) {
      return; // respect other plugins
    }

    Entity p1 = event.getEntity();

    if ((p1 == null) || (!(p1 instanceof Player))) return; // no player

    Arena arena = Arenas.getArenaByPlayer((Player) p1);
    if (arena == null) return;

    db.i("onEntityRegainHealth => fighing player");
    if (!arena.fightInProgress) {
      return;
    }

    Player player = (Player) p1;

    ArenaPlayer ap = ArenaPlayer.parsePlayer(player);
    ArenaTeam team = Teams.getTeam(arena, ap);

    if (team == null) {
      return;
    }

    PVPArena.instance.getAmm().onEntityRegainHealth(arena, event);
  }
Example #3
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamage(EntityDamageEvent event) {

    if (event.isCancelled()) {
      return;
    }

    Entity p2 = event.getEntity();

    db.i(
        "onEntityDamage: cause: " + event.getCause().name() + " : " + event.getEntity().toString());

    if ((p2 == null) || (!(p2 instanceof Player))) {
      return;
    }

    Arena arena = Arenas.getArenaByPlayer((Player) p2);
    if (arena == null) {
      // defender no arena player => out
      return;
    }

    Player defender = (Player) p2;

    ArenaPlayer apDefender = ArenaPlayer.parsePlayer(defender);

    if (arena.REALEND_ID != -1
        || (!apDefender.getStatus().equals(Status.EMPTY)
            && !apDefender.getStatus().equals(Status.FIGHT))) {
      event.setCancelled(true);
      return;
    }
  }
  public void reload() {
    regions = loader.reload();
    regions.add(new Cuboid());

    for (ArenaRegion mod : regions) {
      db.i("module ArenaRegion loaded: " + mod.getName() + " (version " + mod.version() + ")");
    }
  }
Example #5
0
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onEntityExplode(EntityExplodeEvent event) {
    db.i("explosion");

    Arena arena = Arenas.getArenaByRegionLocation(event.getLocation());
    if (arena == null) return; // no arena => out

    db.i("explosion inside an arena");
    if ((!(arena.cfg.getBoolean("protection.enabled", true)))
        || (!(arena.cfg.getBoolean("protection.blocktntdamage", true)))
        || (!(event.getEntity() instanceof TNTPrimed))) {
      PVPArena.instance.getAmm().onEntityExplode(arena, event);
      return;
    }

    event.setCancelled(true); // ELSE => cancel event
  }
Example #6
0
  /**
   * health setting method. Implemented for heroes to work right
   *
   * @param player the player to set
   * @param value the health value
   */
  protected static void playersetHealth(final Player player, final int value) {
    debug.i("setting health to " + value + "/20", player);
    if (Bukkit.getServer().getPluginManager().getPlugin("Heroes") == null) {
      player.setHealth(value);
    }
    final double current = player.getHealth();
    final double regain = value - current;

    final EntityRegainHealthEvent event =
        new EntityRegainHealthEvent(player, regain, RegainReason.CUSTOM);
    Bukkit.getPluginManager().callEvent(event);
  }
  /**
   * create an arena region manager instance
   *
   * @param plugin the plugin instance
   */
  public ArenaRegionManager(PVPArena plugin) {
    File path = new File(plugin.getDataFolder().toString() + "/regions");
    if (!path.exists()) {
      path.mkdir();
    }
    loader = new NCLoader<ArenaRegion>(plugin, path, new Object[] {});
    regions = loader.load();
    regions.add(new Cuboid());

    for (ArenaRegion mod : regions) {
      db.i("module ArenaRegion loaded: " + mod.getName() + " (version " + mod.version() + ")");
    }
  }
Example #8
0
 public void dump(final YamlConfiguration cfg) {
   debug.i("backing up PlayerState of " + name, name);
   cfg.set("state.fireticks", fireticks);
   cfg.set("state.foodlevel", foodlevel);
   cfg.set("state.gamemode", gamemode);
   cfg.set("state.health", health);
   cfg.set("state.maxhealth", maxhealth);
   cfg.set("state.exhaustion", exhaustion);
   cfg.set("state.experience", experience);
   cfg.set("state.explevel", explevel);
   cfg.set("state.saturation", saturation);
   cfg.set("state.displayname", displayname);
   cfg.set("state.flying", flying);
 }
  public ArenaRegion readRegionFromConfig(
      String regionName, YamlConfiguration config, Arena arena) {
    db.i("reading config region: " + arena.name + "=>" + regionName);
    String coords = config.getString("regions." + regionName);

    ArenaRegion.RegionShape shape = ArenaRegionManager.getShapeByCoords(coords);

    ArenaRegion region = PVPArena.instance.getArm().newRegion(regionName, shape);

    if (region != null) {
      region.arena = arena;
      region.set(Bukkit.getWorld(arena.getWorld()), coords);
    }
    return region;
  }
Example #10
0
  public void reset() {
    debug.i("clearing PlayerState of " + name, name);
    fireticks = 0;
    foodlevel = 0;
    gamemode = 0;
    health = 0;
    maxhealth = 20;

    exhaustion = 0;
    experience = 0;
    explevel = 0;
    saturation = 0;
    displayname = null;
    potionEffects = null;
    flying = false;
  }
Example #11
0
  public static PlayerState undump(final YamlConfiguration cfg, final String pName) {
    debug.i("restoring backed up PlayerState of " + pName, pName);
    final PlayerState pState = new PlayerState(Bukkit.getPlayer(pName));

    pState.fireticks = cfg.getInt("state.fireticks", 0);
    pState.foodlevel = cfg.getInt("state.foodlevel", 0);
    pState.gamemode = cfg.getInt("state.gamemode", 0);
    pState.health = cfg.getInt("state.health", 1);
    pState.maxhealth = cfg.getInt("state.maxhealth", 20);
    pState.exhaustion = (float) cfg.getDouble("state.exhaustion", 1);
    pState.experience = (float) cfg.getDouble("state.experience", 0);
    pState.explevel = cfg.getInt("state.explevel", 0);
    pState.saturation = (float) cfg.getDouble("state.saturation", 0);
    pState.displayname = cfg.getString("state.displayname", pName);

    return pState;
  }
Example #12
0
 /**
  * create an arena class sign instance
  *
  * @param loc the location the sign resides
  */
 public ArenaClassSign(Location loc) {
   location = loc;
   db.i("adding arena class sign: " + location.toString());
   this.clear();
 }
Example #13
0
  public void unload() {
    final Player player = Bukkit.getPlayerExact(name);

    if (player == null) {
      final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(name);
      PVPArena.instance.getAgm().disconnect(aPlayer.getArena(), aPlayer);
      return;
    }
    debug.i("restoring PlayerState of " + name, player);

    player.setFireTicks(fireticks);
    player.setFoodLevel(foodlevel);
    player.setGameMode(GameMode.getByValue(gamemode));

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    player.setFoodLevel(foodlevel);
    if (player.getMaxHealth() != maxhealth) {
      final double newHealth = player.getMaxHealth() * health / maxhealth;
      if (newHealth > player.getMaxHealth()) {
        player.setHealth(player.getMaxHealth());
      } else {
        player.setHealth(newHealth);
      }

    } else {
      player.setHealth(health);
    }
    player.setSaturation(saturation);
    player.setGameMode(GameMode.getByValue(gamemode));
    player.setLevel(explevel);
    player.setExp(experience);
    player.setExhaustion(exhaustion);
    player.setFallDistance(0);
    player.setVelocity(new Vector());
    if (aPlayer.getArena() != null
        && aPlayer.getArena().getArenaConfig().getBoolean(CFG.CHAT_COLORNICK)) {
      player.setDisplayName(displayname);
    }

    if (aPlayer.getArena() != null) {

      ArenaModuleManager.unload(aPlayer.getArena(), player);
      PVPArena.instance.getAgm().unload(aPlayer.getArena(), player);
    }

    removeEffects(player);
    player.addPotionEffects(potionEffects);

    aPlayer.setTelePass(false);
    player.setFireTicks(fireticks);

    if (aPlayer.getArena() != null) {
      player.setNoDamageTicks(
          aPlayer.getArena().getArenaConfig().getInt(CFG.TIME_TELEPORTPROTECT) * 20);
    }
    player.resetPlayerTime();
    if (flying && !player.getAllowFlight()) {
      player.setAllowFlight(true);
    }
    player.setFlying(flying);
  }
Example #14
0
  /**
   * parsing of damage: Entity vs Entity
   *
   * @param event the triggering event
   */
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {

    if (event.isCancelled()) {
      return;
    }

    Entity p1 = event.getDamager();
    Entity p2 = event.getEntity();

    db.i(
        "onEntityDamageByEntity: cause: "
            + event.getCause().name()
            + " : "
            + event.getDamager().toString()
            + " => "
            + event.getEntity().toString());

    if (p1 instanceof Projectile) {
      db.i("parsing projectile");
      p1 = ((Projectile) p1).getShooter();
      db.i("=> " + String.valueOf(p1));
    }

    if (event.getEntity() instanceof Wolf) {
      Wolf wolf = (Wolf) event.getEntity();
      if (wolf.getOwner() != null) {
        try {
          p1 = (Entity) wolf.getOwner();
        } catch (Exception e) {
          // wolf belongs to dead player or whatnot
        }
      }
    }

    if ((p1 != null && p2 != null) && p1 instanceof Player && p2 instanceof Player) {
      if (PVPArena.instance.getConfig().getBoolean("onlyPVPinArena")) {
        event.setCancelled(true); // cancel events for regular no PVP
        // servers
      }
    }

    if ((p2 == null) || (!(p2 instanceof Player))) {
      return;
    }

    Arena arena = Arenas.getArenaByPlayer((Player) p2);
    if (arena == null) {
      // defender no arena player => out
      return;
    }

    db.i("onEntityDamageByEntity: fighting player");

    if ((p1 == null) || (!(p1 instanceof Player))) {
      // attacker no player => out!
      return;
    }

    db.i("both entities are players");
    Player attacker = (Player) p1;
    Player defender = (Player) p2;

    if (attacker.equals(defender)) {
      // player attacking himself. ignore!
      return;
    }

    boolean defTeam = false;
    boolean attTeam = false;
    ArenaPlayer apDefender = ArenaPlayer.parsePlayer(defender);
    ArenaPlayer apAttacker = ArenaPlayer.parsePlayer(attacker);

    for (ArenaTeam team : arena.getTeams()) {
      defTeam = defTeam ? true : team.getTeamMembers().contains(apDefender);
      attTeam = attTeam ? true : team.getTeamMembers().contains(apAttacker);
    }

    if (!defTeam || !attTeam || arena.REALEND_ID != -1) {
      event.setCancelled(true);
      return;
    }

    db.i("both players part of the arena");

    if (PVPArena.instance.getConfig().getBoolean("onlyPVPinArena")) {
      event.setCancelled(false); // uncancel events for regular no PVP
      // servers
    }

    if ((!arena.cfg.getBoolean("game.teamKill", false))
        && (Teams.getTeam(arena, apAttacker)).equals(Teams.getTeam(arena, apDefender))) {
      // no team fights!
      db.i("team hit, cancel!");
      event.setCancelled(true);
      return;
    }

    if (!arena.fightInProgress) {
      // fight not started, cancel!
      event.setCancelled(true);
      return;
    }

    if (arena.cfg.getBoolean("game.weaponDamage")) {
      if (Inventories.receivesDamage(attacker.getItemInHand())) {
        attacker.getItemInHand().setDurability((short) 0);
      }
    }

    // TODO NOT LAGGING

    if (arena.cfg.getInt("protection.spawn") > 0) {
      if (Spawns.isNearSpawn(arena, defender, arena.cfg.getInt("protection.spawn"))) {
        // spawn protection!
        db.i("spawn protection! damage cancelled!");
        event.setCancelled(true);
        return;
      }
    }

    // here it comes, process the damage!

    db.i("processing damage!");

    PVPArena.instance.getAmm().onEntityDamageByEntity(arena, attacker, defender, event);

    Statistics.damage(arena, attacker, defender, event.getDamage());
  }