Package com.tommytony.war

Examples of com.tommytony.war.Warzone


    if (!War.war.isLoaded()) {
      return;
    }
    Player player = event.getPlayer();
    Block block = event.getBlock();
    Warzone playerZone = Warzone.getZoneByLocation(player);
    if (player != null && block != null && playerZone != null && playerZone.getWarzoneConfig().getBoolean(WarzoneConfig.INSTABREAK)) {
      Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
      if (blockZone != null && blockZone == playerZone && block.getType() != Material.BEDROCK) {
        event.setInstaBreak(true);
      }
    }
  }
View Full Code Here


    }
  }

  @EventHandler
  public void onBlockBurn(final BlockBurnEvent event) {
    Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
    if (zone != null && zone.isImportantBlock(event.getBlock())) {
      event.setCancelled(true);
    }
  }
View Full Code Here

      event.setCancelled(true);
    }
  }

  private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
    Warzone warzone = Warzone.getZoneByLocation(player);
    Team team = Team.getTeamByPlayerName(player.getName());
    boolean isZoneMaker = War.war.isZoneMaker(player);

    if (warzone != null && team == null && !isZoneMaker) {
      // can't actually destroy blocks in a warzone if not part of a team
      War.war.badMsg(player, "build.denied.zone.outside");
      event.setCancelled(true);
      return;
    }
    // monument's center is destroyed
    if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
      Monument monument = warzone.getMonumentFromCenterBlock(block);
      if (monument.hasOwner()) {
        Team ownerTeam = monument.getOwnerTeam();
        if (War.war.isSpoutServer()) {
          for (Player p : team.getPlayers()) {
            SpoutPlayer sp = SpoutManager.getPlayer(p);
            if (sp.isSpoutCraftEnabled()) {
                      sp.sendNotification(
                          SpoutDisplayer.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
                          SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "freed by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"),
                          ownerTeam.getKind().getMaterial(),
                          ownerTeam.getKind().getData(),
                          10000);
            }
          }
        }
        warzone.broadcast("zone.monument.lose", ownerTeam.getName(), monument.getName());
        monument.uncapture();
      }
      event.setCancelled(false);
      return;
    }
    // changes in parts of important areas
    if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
      // breakage of spawn
      if (team != null && team.isSpawnLocation(block.getLocation())) {
        // let team members loot one block the spawn for monument captures
        if (player.getInventory().containsAtLeast(team.getKind().getBlockHead(), 1)) {
          War.war.badMsg(player, "build.denied.zone.multteam", team.getName());
          event.setCancelled(true);
          return;
        } else {
          event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
          return;
        }
      }
      // stealing of flag
      if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
        if (warzone.isFlagThief(player.getName())) {
          // detect audacious thieves
          War.war.badMsg(player, "zone.stealextra.flag");
        } else if (warzone.isBombThief(player.getName()) || warzone.isCakeThief(player.getName())) {
          War.war.badMsg(player, "zone.stealextra.other");
        } else {
          Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
          if (lostFlagTeam.getPlayers().size() != 0) {
            // player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
            ItemStack teamKindBlock = lostFlagTeam.getKind().getBlockHead();
            player.getInventory().clear();
            player.getInventory().addItem(teamKindBlock);
            warzone.addFlagThief(lostFlagTeam, player.getName());
            block.setType(Material.AIR);
            for (Team t : warzone.getTeams()) {
              t.teamcast("zone.steal.flag.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, lostFlagTeam.getName());
              if (t.getName().equals(lostFlagTeam.getName())) {
                if (War.war.isSpoutServer()) {
                  for (Player p : t.getPlayers()) {
                    SpoutPlayer sp = SpoutManager.getPlayer(p);
                    if (sp.isSpoutCraftEnabled()) {
                              sp.sendNotification(
                                  SpoutDisplayer.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " stole"),
                                  SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "your flag!"),
                                  lostFlagTeam.getKind().getMaterial(),
                                  lostFlagTeam.getKind().getData(),
                                  5000);
                    }
                  }
                }
                t.teamcast("zone.steal.flag.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE, team.getName());
              }
            }
            War.war.msg(player, "zone.steal.flag.notice", lostFlagTeam.getName());
          } else {
            War.war.msg(player, "zone.steal.flag.empty", lostFlagTeam.getName());
          }
        }
        event.setCancelled(true);
        return;
      } else if (team != null && warzone.isBombBlock(block)) {
        if (warzone.isBombThief(player.getName())) {
          // detect audacious thieves
          War.war.badMsg(player, "zone.stealextra.bomb");
        } else if (warzone.isFlagThief(player.getName()) || warzone.isCakeThief(player.getName())) {
          War.war.badMsg(player, "zone.stealextra.other");
        } else {
          Bomb bomb = warzone.getBombForBlock(block);
          // player just broke the bomb block: cancel to avoid drop, give player the block, set block to air
          ItemStack tntBlock = new ItemStack(Material.TNT);
          tntBlock.setDurability((short)8);
          player.getInventory().clear();
          player.getInventory().addItem(tntBlock);
          warzone.addBombThief(bomb, player.getName());
          block.setType(Material.AIR);
          for (Team t : warzone.getTeams()) {
            t.teamcast("zone.steal.bomb.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + bomb.getName() + ChatColor.WHITE);
            if (War.war.isSpoutServer()) {
              for (Player p : t.getPlayers()) {
                SpoutPlayer sp = SpoutManager.getPlayer(p);
                if (sp.isSpoutCraftEnabled()) {
                          sp.sendNotification(
                              SpoutDisplayer.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "),
                              SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.YELLOW + "!"),
                              Material.TNT,
                              (short)0,
                              5000);
                }
              }
            }
            t.teamcast("zone.steal.bomb.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
          }
          War.war.msg(player, "zone.steal.bomb.notice", bomb.getName());
        }
        event.setCancelled(true);
        return;
      } else if (team != null && warzone.isCakeBlock(block)) {
        if (warzone.isCakeThief(player.getName())) {
          // detect audacious thieves
          War.war.badMsg(player, "zone.stealextra.cake");
        } else if (warzone.isFlagThief(player.getName()) || warzone.isBombThief(player.getName())) {
          War.war.badMsg(player, "zone.stealextra.other");
        } else {
          Cake cake = warzone.getCakeForBlock(block);
          // player just broke the cake block: cancel to avoid drop, give player the block, set block to air
          ItemStack cakeBlock = new ItemStack(Material.CAKE);
          cakeBlock.setDurability((short)8);
          player.getInventory().clear();
          player.getInventory().addItem(cakeBlock);
          warzone.addCakeThief(cake, player.getName());
          block.setType(Material.AIR);
          for (Team t : warzone.getTeams()) {
            t.teamcast("zone.steal.cake.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + cake.getName() + ChatColor.WHITE);
            if (War.war.isSpoutServer()) {
              for (Player p : t.getPlayers()) {
                SpoutPlayer sp = SpoutManager.getPlayer(p);
                if (sp.isSpoutCraftEnabled()) {
                          sp.sendNotification(
                              SpoutDisplayer.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "),
                              SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "!"),
                              Material.CAKE,
                              (short)0,
                              5000);
                }
              }
            }
            t.teamcast("zone.steal.cake.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
          }
          War.war.msg(player, "zone.steal.cake.notice", cake.getName());
        }
        event.setCancelled(true);
        return;
      } else if (!warzone.isMonumentCenterBlock(block)) {
        War.war.badMsg(player, "build.denied.location");
        event.setCancelled(true);
        return;
      }
    }

    // protect warzone lobbies
    if (block != null) {
      for (Warzone zone : War.war.getWarzones()) {
        if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
          War.war.badMsg(player, "build.denied.location");
          event.setCancelled(true);
          return;
        }
      }
    }

    // protect the hub
    if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
      War.war.badMsg(player, "build.denied.location");
      event.setCancelled(true);
      return;
    }

    // buildInZonesOnly
    Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
    if (blockZone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
      if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
        War.war.badMsg(player, "build.denied.outside");
      }
      event.setCancelled(true);
      return;
    }

    // unbreakableZoneBlocks
    if (blockZone != null && blockZone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
      // if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
      War.war.badMsg(player, "build.denied.zone.break");
      event.setCancelled(true);
      return;
    }
View Full Code Here

    }
  }

  @EventHandler(priority = EventPriority.HIGHEST)
  public void onStructureGrowth(final StructureGrowEvent event) {
    Warzone zone = Warzone.getZoneByLocation(event.getLocation());
    if (zone != null) {
      for (BlockState state : event.getBlocks()) {
        if (!zone.getVolume().contains(state.getLocation())) {
          state.setType(Material.AIR);
        }
      }
    }
  }
View Full Code Here

    if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) {
      // only let adversaries (same warzone, different team) attack each other
      Player a = (Player) attacker;
      Player d = (Player) defender;
      Warzone attackerWarzone = Warzone.getZoneByPlayerName(a.getName());
      Team attackerTeam = Team.getTeamByPlayerName(a.getName());
      Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
      Team defenderTeam = Team.getTeamByPlayerName(d.getName());
     
      if ((attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone)
          || (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId())) {
       
        LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
        if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
          War.war.badMsg(a, "pvp.target.spawn");
          event.setCancelled(true);
          return;
        }
       
        LoadoutSelection attackerLoadoutState = attackerWarzone.getLoadoutSelections().get(a.getName());
        if (attackerLoadoutState != null && attackerLoadoutState.isStillInSpawn()) {
          War.war.badMsg(a, "pvp.self.spawn");
          event.setCancelled(true);
          return;
        }
       
        // Make sure none of them are locked in by respawn timer
        if (defenderWarzone.isRespawning(d)) {
          War.war.badMsg(a, "pvp.target.respawn");
          event.setCancelled(true);
          return;
        } else if (attackerWarzone.isRespawning(a)) {
          War.war.badMsg(a, "pvp.self.respawn");
          event.setCancelled(true);
          return;
        }
       
        if (!attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.PVPINZONE)) {
          // spleef-like, non-pvp, zone
          event.setCancelled(true);
          return;
        }

        // Detect death, prevent it and respawn the player
        if (event.getDamage() >= d.getHealth()) {
          if (defenderWarzone.getReallyDeadFighters().contains(d.getName())) {
            // don't re-kill a dead person       
            return;
          }
          WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, a, event.getCause());
          War.war.getServer().getPluginManager().callEvent(event1);
          if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
            // fast respawn, don't really die
            event.setCancelled(true);
          }
          if (d == a) {
            defenderWarzone.handleSuicide(d);
          } else {
            defenderWarzone.handleKill(a, d, event.getDamager());
          }
        } else if (defenderWarzone.isBombThief(d.getName()) && d.getLocation().distance(a.getLocation()) < 2) {
          // Close combat, close enough to detonate         
          Bomb bomb = defenderWarzone.getBombForThief(d.getName());
                   
          // Kill the bomber
          WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
          War.war.getServer().getPluginManager().callEvent(event1);
          defenderWarzone.handleDeath(d);
         
          if (defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
            // and respawn him and remove from deadmen (cause realdeath + handleDeath means no respawn and getting queued up for onPlayerRespawn)
            defenderWarzone.getReallyDeadFighters().remove(d.getName());
            defenderWarzone.respawnPlayer(defenderTeam, d);
          }
         
          // Blow up bomb
          if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) {
            defenderWarzone.getWorld().createExplosion(a.getLocation(), 2F);
          }

          // bring back tnt
          bomb.getVolume().resetBlocks();
          bomb.addBombBlocks();
         
          // Notify everyone
          for (Team t : defenderWarzone.getTeams()) {
            t.sendAchievement(attackerTeam.getKind().getColor() + a.getName() + ChatColor.YELLOW + " made ",
                defenderTeam.getKind().getColor() + d.getName() + ChatColor.YELLOW + " blow up!", new ItemStack(Material.TNT), 10000);
            t.teamcast("pvp.kill.bomb", attackerTeam.getKind().getColor() + a.getName() + ChatColor.WHITE,
                defenderTeam.getKind().getColor() + d.getName() + ChatColor.WHITE);
          }
        }
      } else if (attackerTeam != null && defenderTeam != null && attackerTeam == defenderTeam && attackerWarzone == defenderWarzone && attacker.getEntityId() != defender.getEntityId()) {
        // same team, but not same person
        if (attackerWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.FRIENDLYFIRE)) {
          War.war.badMsg(a, "pvp.ff.enabled"); // if ff is on, let the attack go through
        } else {
          War.war.badMsg(a, "pvp.ff.disabled");
          event.setCancelled(true); // ff is off
        }
      } else if (attackerTeam == null && defenderTeam == null && War.war.canPvpOutsideZones(a)) {
        // let normal PVP through is its not turned off or if you have perms
      } else if (attackerTeam == null && defenderTeam == null && !War.war.canPvpOutsideZones(a)) {
        if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) {
          War.war.badMsg(a, "pvp.outside.permission");
        }
       
        event.setCancelled(true); // global pvp is off
      } else {
        if (attackerTeam == null) {
          War.war.badMsg(a, "pvp.self.notplaying");
        } else if (defenderTeam == null) {
          War.war.badMsg(a, "pvp.target.notplaying");
        } else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) {
          // You just hit yourself, probably with a bouncing arrow
        } else if (attackerTeam == defenderTeam) {
          War.war.badMsg(a, "pvp.ff.disabled");
        } else if (attackerWarzone != defenderWarzone) {
          War.war.badMsg(a, "pvp.target.otherzone");
        }

        event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
      }
    } else if (defender instanceof Player) {
      // attacked by dispenser arrow most probably
      // Detect death, prevent it and respawn the player
      Player d = (Player) defender;
      Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
      if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
        LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
        if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
          event.setCancelled(true);
          return;
        }
        if (defenderWarzone.getReallyDeadFighters().contains(d.getName())) {
          // don't re-kill a dead person
          return;
        }
               
        WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(defenderWarzone, d, null, event.getCause());
        War.war.getServer().getPluginManager().callEvent(event1);
        if (!defenderWarzone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
          // fast respawn, don't really die
          event.setCancelled(true);
        }
        defenderWarzone.handleNaturalKill(d, event);
      }
    }
  }
View Full Code Here

      return;
    }
    Player player = (Player) entity;

    // prevent godmode
    Warzone zone = Warzone.getZoneByPlayerName(player.getName());
    if (zone != null) {
      event.setCancelled(false);
    }

    // pass pvp-damage
    if (event instanceof EntityDamageByEntityEvent) {     
      this.handlerAttackDefend((EntityDamageByEntityEvent) event);
    } else  {
      Team team = Team.getTeamByPlayerName(player.getName());
     
      if (zone != null && team != null) {
        LoadoutSelection playerLoadoutState = zone.getLoadoutSelections().get(player.getName());
        if (team.isSpawnLocation(player.getLocation())
            && playerLoadoutState != null && playerLoadoutState.isStillInSpawn()) {
          // don't let a player still in spawn get damaged
          event.setCancelled(true);
        } else if (event.getDamage() >= player.getHealth()) {
          if (zone.getReallyDeadFighters().contains(player.getName())) {
            // don't re-count the death points of an already dead person
            return;
          }
         
          // Detect death, prevent it and respawn the player
          WarPlayerDeathEvent event1 = new WarPlayerDeathEvent(zone, player, null, event.getCause());
          War.war.getServer().getPluginManager().callEvent(event1);
          if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
            // fast respawn, don't really die
            event.setCancelled(true);
          }
          zone.handleNaturalKill(player, event);
        }
      }
    }
  }
View Full Code Here

    if (!War.war.isLoaded()) {
      return;
    }

    Location location = event.getLocation();
    Warzone zone = Warzone.getZoneByLocation(location);
    if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.NOCREATURES)) {
      event.setCancelled(true);
    }
  }
View Full Code Here

    if (!(entity instanceof Player)) {
      return;
    }

    Player player = (Player) entity;
    Warzone zone = Warzone.getZoneByPlayerName(player.getName());
    if (zone != null) {
      Team team = Team.getTeamByPlayerName(player.getName());
      if ((event.getRegainReason() == RegainReason.EATING
          || event.getRegainReason() != RegainReason.SATIATED )
        && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)) {
View Full Code Here

    if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) {
      return;
    }
   
    Player player = (Player) event.getEntity();
    Warzone zone = Warzone.getZoneByPlayerName(player.getName());
    Team team = Team.getTeamByPlayerName(player.getName());
    if (zone != null && team.getTeamConfig().resolveBoolean(TeamConfig.NOHUNGER)){
      event.setCancelled(true);
    }
  }
View Full Code Here

  }
 
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onPlayerDeath(final PlayerDeathEvent event) {
    Player player = event.getEntity();
    Warzone zone = Warzone.getZoneByPlayerName(player.getName());
    if (zone != null) {
      event.getDrops().clear();
      if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
        // catch the odd death that gets away from us when usually intercepting and preventing deaths
        zone.handleDeath(player);
        Team team = Team.getTeamByPlayerName(player.getName());
        if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
          zone.broadcast("pvp.death.other", team.getKind().getColor() + player.getName());
        }
        War.war.getLogger().log(Level.WARNING, "We missed the death of player {0} - something went wrong.", player.getName());
      } else {
        event.setDeathMessage("");
      }
View Full Code Here

TOP

Related Classes of com.tommytony.war.Warzone

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.