Package com.tommytony.war

Examples of com.tommytony.war.Warzone


    super(handler, sender, args);
  }

  @Override
  public boolean handle() {
    Warzone zone;
    if (this.args.length == 1) {
      zone = Warzone.getZoneByName(this.args[0]);
    } else if (this.args.length == 0) {
      if (!(this.getSender() instanceof Player)) {
        return false;
      }
      zone = Warzone.getZoneByLocation((Player) this.getSender());
      if (zone == null) {
        ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
        if (lobby == null) {
          return false;
        }
        zone = lobby.getZone();
      }
    } else {
      return false;
    }
   
    if (zone == null) {
      return false;
    } else if (!this.isSenderAuthorOfZone(zone)) {
      return true;
    }

    zone.clearThieves();
    for (Team team : zone.getTeams()) {
      team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams...");
      for (Iterator<Player> it = team.getPlayers().iterator(); it.hasNext();) {
        Player p = it.next();
        it.remove();
        team.removePlayer(p);
        if (!zone.getReallyDeadFighters().contains(p.getName())) {
          p.teleport(zone.getEndTeleport(LeaveCause.RESET));
        }
      }
      team.resetPoints();
      team.getPlayers().clear();
    }

    this.msg("Reloading warzone " + zone.getName() + ".");
   
    PartialZoneResetJob.setSenderToNotify(zone, this.getSender())
   
    zone.reinitialize();
   
    War.war.log(this.getSender().getName() + " reset warzone " + zone.getName(), Level.INFO);

    return true;
  }
View Full Code Here


    super(handler, sender, args, false);
  }

  @Override
  public boolean handle() {
    Warzone zone = null;
    Player player = null;
    CommandSender commandSender = this.getSender();
    boolean isFirstParamWarzone = false;
    boolean wantsToPrint = false;

    if (this.args.length == 0) {
      return false;
    } else {
      if (!this.args[0].contains(":")) {
        // warzone name maybe in first place
        Warzone zoneByName = Warzone.getZoneByName(this.args[0]);
        if (zoneByName != null) {
          zone = zoneByName;
          isFirstParamWarzone = true;
        } else if (this.args[0].equals("-p") || this.args[0].equals("print")) {
          wantsToPrint = true;
        }
      }
     
      if (this.getSender() instanceof Player) {
        player = (Player) commandSender;
        if (zone == null) {
          // zone not found, is he standing in it?
          Warzone zoneByLoc = Warzone.getZoneByLocation(player);
          ZoneLobby lobbyByLoc = ZoneLobby.getLobbyByLocation(player);
          if (zoneByLoc == null && lobbyByLoc != null) {
            zoneByLoc = lobbyByLoc.getZone();
          }
          if (zoneByLoc != null) {
View Full Code Here

    super(handler, sender, args);
  }

  @Override
  public boolean handle() {
    Warzone zone;

    if (this.args.length == 0) {
      return false;
    } else if (this.args.length == 2) {
      zone = Warzone.getZoneByName(this.args[0]);
      this.args[0] = this.args[1];
    } else if (this.args.length == 1) {
      if (!(this.getSender() instanceof Player)) {
        return false;
      }
      zone = Warzone.getZoneByLocation((Player) this.getSender());
      if (zone == null) {
        ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
        if (lobby == null) {
          return false;
        }
        zone = lobby.getZone();
      }
    } else {
      return false;
    }

    if (zone == null) {
      return false;
    } else if (!this.isSenderAuthorOfZone(zone)) {
      return true;
    }

    Team team = zone.getTeamByKind(TeamKind.teamKindFromString(this.args[0]));
    if (team != null) {
      if (team.getFlagVolume() != null) {
        team.getFlagVolume().resetBlocks();
      }
      for (Volume spawnVolume : team.getSpawnVolumes().values()) {
        spawnVolume.resetBlocks();
      }
      zone.getTeams().remove(team);
      if (zone.getLobby() != null) {
        zone.getLobby().setLocation(zone.getTeleport());
        zone.getLobby().initialize();
      }
      WarzoneYmlMapper.save(zone);
      this.msg("Team " + team.getName() + " removed.");
      War.war.log(this.getSender().getName() + " deleted team " + team.getName() + " in warzone " + zone.getName(), Level.INFO);
    } else {
      this.badMsg("No such team.");
    }

    return true;
View Full Code Here

    super(handler, sender, args);
  }

  @Override
  public boolean handle() {
    Warzone zone;
    if (this.args.length == 1) {
      zone = Warzone.getZoneByName(this.args[0]);
    } else if (this.args.length == 0) {
      if (!(this.getSender() instanceof Player)) {
        return false;
      }
      zone = Warzone.getZoneByLocation((Player) this.getSender());
      if (zone == null) {
        ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
        if (lobby == null) {
          return false;
        }
        zone = lobby.getZone();
      }
    } else {
      return false;
    }
    if (zone == null) {
      return false;
    }

    this.msg(zone.getTeamInformation());

    return true;
  }
View Full Code Here

    if (this.args.length != 0) {
      return false;
    }

    Player player = (Player) this.getSender();
    Warzone zone = Warzone.getZoneByPlayerName(player.getName());
    if (zone == null) {
      return false;
    }

    zone.handlePlayerLeave(player, zone.getEndTeleport(LeaveCause.COMMAND), true);
    return true;
  }
View Full Code Here

      return true;
    }

    Player player = (Player) this.getSender();

    Warzone zone;
    TeamKind kind;
    if (this.args.length == 2) {
      // zone by name
      zone = Warzone.getZoneByName(this.args[0]);
      kind = TeamKind.teamKindFromString(this.args[1]);
    } else if (this.args.length == 1) {
      zone = Warzone.getZoneByLocation((Player) this.getSender());
      if (zone == null) {
        ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender());
        if (lobby == null) {
          return false;
        }
        zone = lobby.getZone();
      }
      kind = TeamKind.teamKindFromString(this.args[0]);
    } else {
      return false;
    }
    if (zone == null) {
      return false;
    }
    if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
      this.badMsg("join.disabled");
    } else if (zone.isReinitializing()) {
      this.badMsg("join.disabled");
    } else if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
      this.badMsg("join.aarequired");
    } else if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.JOINMIDBATTLE) && zone.isEnoughPlayers()) {
      this.badMsg("join.progress");
    } else {
      Team team = zone.getTeamByKind(kind);
      if (kind == null || team == null) {
        this.badMsg("join.team404");
      } else if (!War.war.canPlayWar(player, team)) {
        this.badMsg("join.permission.single");
      } else if (team.isFull()) {
        this.badMsg("join.full.single", team.getName());
      } else {
        Team previousTeam = Team.getTeamByPlayerName(player.getName());
        if (previousTeam != null) {
          if (previousTeam == team) {
            this.badMsg("join.selfteam");
            return true;
          }
          previousTeam.removePlayer(player);
          previousTeam.resetSign();
        }
        zone.assign(player, team);
      }
    }
    return true;
  }
View Full Code Here

   
    // Convert from TXT to YML if needed
    if (warzoneTxtFile.exists() && !warzoneYmlFile.exists()) {
      // Since we're converting, WarTxtMapper didn't load the warzones.
      // We need to load the old-text-format-Warzone into memory.
      Warzone zoneToConvert = WarzoneTxtMapper.load(name, false);
      WarzoneYmlMapper.save(zoneToConvert);
      War.war.log("Converted warzone-" + name + ".txt to warzone-" + name + ".yml", Level.INFO);
    }
   
    if (!warzoneYmlFile.exists()) {
      War.war.log("File warzone-" + name + ".yml not found", Level.WARNING);
    } else {
      YamlConfiguration warzoneYmlConfig = YamlConfiguration.loadConfiguration(warzoneYmlFile);
      ConfigurationSection warzoneRootSection = warzoneYmlConfig.getConfigurationSection("set");
     
      // Bukkit config API forces all Yml nodes to lowercase, now, it seems, sigh...
      // We need to keep this original (non-lowercase) implementation because old warzone.yml
      // files are not lowercased yet if they haven't been saved since the API change.
      String zoneInfoPrefix = "warzone." + name + ".info.";
     
      // world of the warzone
      String worldStr = warzoneRootSection.getString(zoneInfoPrefix + "world");
      if (worldStr == null) {
        // Ah! Seems that the new (post 1.2.3-ish) Bukkit config API has lowercased our map name on the previous save.
        // Retry with lowercase warzone name.
        zoneInfoPrefix = "warzone." + name.toLowerCase() + ".info.";
        worldStr = warzoneRootSection.getString(zoneInfoPrefix + "world");
      }
      World world = War.war.getServer().getWorld(worldStr);
     
      // Create the zone
      Warzone warzone = new Warzone(world, name);

      // teleport
      int teleX = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.x");
      int teleY = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.y");
      int teleZ = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.z");
      int teleYaw = warzoneRootSection.getInt(zoneInfoPrefix + "teleport.yaw");
      warzone.setTeleport(new Location(world, teleX, teleY, teleZ, teleYaw, 0));
     
      // defaultLoadouts
      if (warzoneRootSection.contains("team.default.loadout")) {
        ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection("team.default.loadout");
        warzone.getDefaultInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));
      }

      // defaultReward
      if (warzoneRootSection.contains("team.default.reward")) {
        ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection("team.default.reward");
        HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
        LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
        warzone.getDefaultInventories().setReward(reward);
      }
     
      // Team default settings
      if (warzoneRootSection.contains("team.default.config")) {
        ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection("team.default.config");
        warzone.getTeamDefaultConfig().loadFrom(teamConfigSection);
      }
     
      // Warzone settings
      if (warzoneRootSection.contains("warzone." + warzone.getName() + ".config")) {
        ConfigurationSection warzoneConfigSection = warzoneRootSection.getConfigurationSection("warzone." + warzone.getName() + ".config");
        warzone.getWarzoneConfig().loadFrom(warzoneConfigSection);
      } else if (warzoneRootSection.contains("warzone." + warzone.getName().toLowerCase() + ".config")) {
        // Workaround for broken Bukkit backward-compatibility for non-lowercase Yml nodes
        ConfigurationSection warzoneConfigSection = warzoneRootSection.getConfigurationSection("warzone." + warzone.getName().toLowerCase() + ".config");
        warzone.getWarzoneConfig().loadFrom(warzoneConfigSection);
      }

      // authors
      if (warzoneRootSection.contains(zoneInfoPrefix + "authors")) {
        for(String authorStr : warzoneRootSection.getStringList(zoneInfoPrefix + "authors")) {
          if (!authorStr.equals("")) {
            warzone.addAuthor(authorStr);
          }
        }
      }

      // rallyPoint
      if (warzoneRootSection.contains(zoneInfoPrefix + "rallypoint")) {
        int rpX = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.x");
        int rpY = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.y");
        int rpZ = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.z");
        int rpYaw = warzoneRootSection.getInt(zoneInfoPrefix + "rallypoint.yaw");
        Location rallyPoint = new Location(world, rpX, rpY, rpZ, rpYaw, 0);
        warzone.setRallyPoint(rallyPoint);
      }

      // monuments
      if (warzoneRootSection.contains(zoneInfoPrefix + "monument")) {
        List<String> monunmentNames = warzoneRootSection.getStringList(zoneInfoPrefix + "monument.names");
        for (String monumentName : monunmentNames) {
          if (monumentName != null && !monumentName.equals("")) {
            String monumentPrefix = zoneInfoPrefix + "monument." + monumentName + ".";
            if (!warzoneRootSection.contains(monumentPrefix + "x")) {
              // try lowercase instead
              monumentPrefix = zoneInfoPrefix + "monument." + monumentName.toLowerCase() + ".";
            }
            int monumentX = warzoneRootSection.getInt(monumentPrefix + "x");
            int monumentY = warzoneRootSection.getInt(monumentPrefix + "y");
            int monumentZ = warzoneRootSection.getInt(monumentPrefix + "z");
            int monumentYaw = warzoneRootSection.getInt(monumentPrefix + "yaw");
            Monument monument = new Monument(monumentName, warzone, new Location(world, monumentX, monumentY, monumentZ, monumentYaw, 0));
            warzone.getMonuments().add(monument);
          }
        }
      }
     
      // bombs
      if (warzoneRootSection.contains(zoneInfoPrefix + "bomb")) {
        List<String> bombNames = warzoneRootSection.getStringList(zoneInfoPrefix + "bomb.names");
        for (String bombName : bombNames) {
          if (bombName != null && !bombName.equals("")) {
            String bombPrefix = zoneInfoPrefix + "bomb." + bombName + ".";
            if (!warzoneRootSection.contains(bombPrefix + "x")) {
              // try lowercase instead
              bombPrefix = zoneInfoPrefix + "bomb." + bombName.toLowerCase() + ".";
            }
            int bombX = warzoneRootSection.getInt(bombPrefix + "x");
            int bombY = warzoneRootSection.getInt(bombPrefix + "y");
            int bombZ = warzoneRootSection.getInt(bombPrefix + "z");
            int bombYaw = warzoneRootSection.getInt(bombPrefix + "yaw");
            Bomb bomb = new Bomb(bombName, warzone, new Location(world, bombX, bombY, bombZ, bombYaw, 0));
            warzone.getBombs().add(bomb);
          }
        }
      }
     
      // cakes
      if (warzoneRootSection.contains(zoneInfoPrefix + "cake")) {
        List<String> cakeNames = warzoneRootSection.getStringList(zoneInfoPrefix + "cake.names");
        for (String cakeName : cakeNames) {
          if (cakeName != null && !cakeName.equals("")) {
            String cakePrefix = zoneInfoPrefix + "cake." + cakeName + ".";
            if (!warzoneRootSection.contains(cakePrefix + "x")) {
              // try lowercase instead
              cakePrefix = zoneInfoPrefix + "cake." + cakeName + ".";
            }
            int cakeX = warzoneRootSection.getInt(cakePrefix + "x");
            int cakeY = warzoneRootSection.getInt(cakePrefix + "y");
            int cakeZ = warzoneRootSection.getInt(cakePrefix + "z");
            int cakeYaw = warzoneRootSection.getInt(cakePrefix + "yaw");
            Cake cake = new Cake(cakeName, warzone, new Location(world, cakeX, cakeY, cakeZ, cakeYaw, 0));
            warzone.getCakes().add(cake);
          }
        }
      }
     
      // teams (maybe no teams)
      if (warzoneRootSection.contains("team.names")) {
        List<String> teamsNames = warzoneRootSection.getStringList("team.names");
        for (String teamName : teamsNames) {
          // team info
          String teamInfoPrefix = "team." + teamName + ".info.";
          if (!warzoneRootSection.contains(teamInfoPrefix + "spawn.x")) {
            // try lowercase instead - supports custom team names
            teamInfoPrefix = "team." + teamName.toLowerCase() + ".info.";
          }
          List<Location> teamSpawns = new ArrayList<Location>();
          if (warzoneRootSection.contains(teamInfoPrefix + "spawn")) {
            int teamX = warzoneRootSection.getInt(teamInfoPrefix + "spawn.x");
            int teamY = warzoneRootSection.getInt(teamInfoPrefix + "spawn.y");
            int teamZ = warzoneRootSection.getInt(teamInfoPrefix + "spawn.z");
            int teamYaw = warzoneRootSection.getInt(teamInfoPrefix + "spawn.yaw");
            Location teamLocation = new Location(world, teamX, teamY, teamZ, teamYaw, 0);
            teamSpawns.add(teamLocation);
            File original = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + ".dat");
            File modified = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + teamSpawns.indexOf(teamLocation) + ".dat");
            File originalSql = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + ".sl3");
            File modifiedSql = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamName + teamSpawns.indexOf(teamLocation) + ".sl3");
            try {
              original.renameTo(modified);
            } catch (Exception ignored) {
            }
            try {
              originalSql.renameTo(modifiedSql);
            } catch (Exception ignored) {
            }
          }
          if (warzoneRootSection.contains(teamInfoPrefix + "spawns")) {
            for (Map<?, ?> map : warzoneRootSection.getMapList(teamInfoPrefix + "spawns")) {
              int teamX = (Integer) map.get("x");
              int teamY = (Integer) map.get("y");
              int teamZ = (Integer) map.get("z");
              int teamYaw = (Integer) map.get("yaw");
              Location teamLocation = new Location(world, teamX, teamY, teamZ, teamYaw, 0);
              teamSpawns.add(teamLocation);
            }
          }
 
          Team team = new Team(teamName, TeamKind.teamKindFromString(teamName), teamSpawns, warzone);
          warzone.getTeams().add(team);
         
          if (warzoneRootSection.contains(teamInfoPrefix + "flag")) {
            int flagX = warzoneRootSection.getInt(teamInfoPrefix + "flag.x");
            int flagY = warzoneRootSection.getInt(teamInfoPrefix + "flag.y");
            int flagZ = warzoneRootSection.getInt(teamInfoPrefix + "flag.z");
            int flagYaw = warzoneRootSection.getInt(teamInfoPrefix + "flag.yaw");
            Location flagLocation = new Location(world, flagX, flagY, flagZ, flagYaw, 0);
            team.setTeamFlag(flagLocation);
          }
         
          String teamConfigPrefix = "team." + teamName + ".config";
          if (warzoneRootSection.contains(teamConfigPrefix)) {
            // team specific config
            ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection(teamConfigPrefix);
            team.getTeamConfig().loadFrom(teamConfigSection);
          } else if (warzoneRootSection.contains(teamConfigPrefix.toLowerCase())) {
            // try lowercase instead
            ConfigurationSection teamConfigSection = warzoneRootSection.getConfigurationSection(teamConfigPrefix.toLowerCase());
            team.getTeamConfig().loadFrom(teamConfigSection);
          }
         
          // LIFEPOOL INITIALIZATION HERE
          team.setRemainingLives(team.getTeamConfig().resolveInt(TeamConfig.LIFEPOOL));
         
          String teamLoadoutPrefix = "team." + teamName + ".loadout";
          if (warzoneRootSection.contains(teamLoadoutPrefix)) {
            // team specific loadouts
            ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix);
            team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));
          } else if (warzoneRootSection.contains(teamLoadoutPrefix.toLowerCase())) {
            // try lowercase instead
            ConfigurationSection loadoutsSection = warzoneRootSection.getConfigurationSection(teamLoadoutPrefix.toLowerCase());
            team.getInventories().setLoadouts(LoadoutYmlMapper.fromConfigToLoadouts(loadoutsSection, new HashMap<String, HashMap<Integer, ItemStack>>()));
          }
         
          String teamRewardPrefix = "team." + teamName + ".reward";
          if (warzoneRootSection.contains(teamRewardPrefix)) {
            // team specific reward
            ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection(teamRewardPrefix);
            HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
            LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
            warzone.getDefaultInventories().setReward(reward);
          } else if (warzoneRootSection.contains(teamRewardPrefix.toLowerCase())) {
            // try lowercase instead
            ConfigurationSection rewardsSection = warzoneRootSection.getConfigurationSection(teamRewardPrefix.toLowerCase());
            HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
            LoadoutYmlMapper.fromConfigToLoadout(rewardsSection, reward, "default");
            warzone.getDefaultInventories().setReward(reward);
          }
        }
      }
      Connection connection = null;
      try {
        connection = ZoneVolumeMapper.getZoneConnection(warzone.getVolume(), warzone.getName(), warzone.getWorld());
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
      }
      // monument blocks
      for (Monument monument : warzone.getMonuments()) {
        try {
          monument.setVolume(warzone.loadStructure(monument.getName(), connection));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
        }
      }
     
      // bomb blocks
      for (Bomb bomb : warzone.getBombs()) {
        try {
          bomb.setVolume(warzone.loadStructure("bomb-" + bomb.getName(), connection));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
        }
      }
     
      // cake blocks
      for (Cake cake : warzone.getCakes()) {
        try {
          cake.setVolume(warzone.loadStructure("cake-" + cake.getName(), connection));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
        }
      }
     
      // team spawn blocks
      for (Team team : warzone.getTeams()) {
        for (Location teamSpawn : team.getTeamSpawns()) {
          try {
            team.setSpawnVolume(teamSpawn, warzone.loadStructure(team.getName() + team.getTeamSpawns().indexOf(teamSpawn), connection));
          } catch (SQLException e) {
            War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
          }
        }
        if (team.getTeamFlag() != null) {
          try {
            team.setFlagVolume(warzone.loadStructure(team.getName() + "flag", connection));
          } catch (SQLException e) {
            War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
          }
        }
      }

      // lobby
      String lobbyPrefix = zoneInfoPrefix + "lobby.";
     
      // lobby orientation
      String lobbyOrientation = warzoneRootSection.getString(lobbyPrefix + "orientation");
      BlockFace lobbyFace = null;
      if (lobbyOrientation.equals("south")) {
        lobbyFace = Direction.SOUTH();
      } else if (lobbyOrientation.equals("east")) {
        lobbyFace = Direction.EAST();
      } else if (lobbyOrientation.equals("north")) {
        lobbyFace = Direction.NORTH();
      } else if (lobbyOrientation.equals("west")) {
        lobbyFace = Direction.WEST();
      }
     
      // lobby materials
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.floor")) {
        warzone.getLobbyMaterials().setFloorBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.floor"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.floor");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setFloorBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.outline")) {
        warzone.getLobbyMaterials().setOutlineBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.outline"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.outline");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setOutlineBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.gate")) {
        warzone.getLobbyMaterials().setGateBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.gate"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.gate");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setGateBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(lobbyPrefix + "materials.light")) {
        warzone.getLobbyMaterials().setLightBlock(
            warzoneRootSection.getItemStack(lobbyPrefix + "materials.light"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(lobbyPrefix + "materials.light");
        if (floorMaterialSection != null) {
          warzone.getLobbyMaterials().setLightBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
     
      // lobby world
      String lobbyWorldName = warzoneRootSection.getString(lobbyPrefix + "world");
      World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName);
           
      // create the lobby
      Volume lobbyVolume = null;
      try {
        lobbyVolume = warzone.loadStructure("lobby", lobbyWorld, connection);
      } catch (SQLException e) {
        War.war.getLogger().log(Level.WARNING, "Failed to load warzone lobby", e);
      }
      ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
      warzone.setLobby(lobby);
     
      // warzone materials
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.main")) {
        warzone.getWarzoneMaterials().setMainBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.main"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.main");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setMainBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.stand")) {
        warzone.getWarzoneMaterials().setStandBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.stand"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.stand");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setStandBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      if (warzoneRootSection.isItemStack(zoneInfoPrefix + "materials.light")) {
        warzone.getWarzoneMaterials().setLightBlock(
            warzoneRootSection.getItemStack(zoneInfoPrefix + "materials.light"));
      } else {
        ConfigurationSection floorMaterialSection = warzoneRootSection
            .getConfigurationSection(zoneInfoPrefix + "materials.light");
        if (floorMaterialSection != null) {
          warzone.getWarzoneMaterials().setLightBlock(
            new ItemStack(floorMaterialSection.getInt("id"), 1,
              (short) floorMaterialSection.getInt("data")));
        }
      }
      try {
View Full Code Here

    if (player == null || block == null) {
      return;
    }

    Team team = Team.getTeamByPlayerName(player.getName());
    Warzone zone = Warzone.getZoneByLocation(player);
    // Monument capturing
    if (team != null && block != null && zone != null
        && zone.isMonumentCenterBlock(block)
        && team.getKind().isTeamBlock(block.getState())) {
      Monument monument = zone.getMonumentFromCenterBlock(block);
      if (monument != null && !monument.hasOwner()) {
        monument.capture(team);
        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 + "capped by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"),
                          team.getKind().getMaterial(),
                          team.getKind().getData(),
                          10000);
            }
          }
        }
        zone.broadcast("zone.monument.capture", monument.getName(), team.getName());
        event.setCancelled(false);
        return; // important otherwise cancelled down a few line by isImportantblock
      } else {
        War.war.badMsg(player, "zone.monument.badblock");
        cancelAndKeepItem(event);
        return;
      }
    }

    boolean isZoneMaker = War.war.isZoneMaker(player);
    // prevent build in important parts
    if (zone != null
        && (zone.isImportantBlock(block) || zone.isOpponentSpawnPeripheryBlock(team, block))
        && (!isZoneMaker || (isZoneMaker && team != null))) {
      War.war.badMsg(player, "build.denied.location");
      cancelAndKeepItem(event);
      return;
    }

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

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

    // buildInZonesOnly
    if (zone == 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");
      }
      cancelAndKeepItem(event);
      return;
    }

    // can't place a block of your team's color
    if (team != null && block.getType() == team.getKind().getMaterial() && block.getState().getData() == team.getKind().getBlockData()) {
      War.war.badMsg(player, "build.denied.teamblock");
      cancelAndKeepItem(event);
      return;
    }

    // a flag thief can't drop his flag
    if (team != null && zone != null && zone.isFlagThief(player.getName())) {
      War.war.badMsg(player, "drop.flag.disabled");
      cancelAndKeepItem(event);
      return;
    }
   
    // a bomb thief can't drop his bomb
    if (team != null && zone != null && zone.isBombThief(player.getName())) {
      War.war.badMsg(player, "drop.bomb.disabled");
      cancelAndKeepItem(event);
      return;
    }
   
    // a cake thief can't drop his cake
    if (team != null && zone != null && zone.isCakeThief(player.getName())) {
      War.war.badMsg(player, "drop.cake.disabled");
      cancelAndKeepItem(event);
      return;
    }

    // unbreakableZoneBlocks
    if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)
        || (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)))
        && (!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.place");
      cancelAndKeepItem(event);
View Full Code Here

  }
 
  @EventHandler
  // Do not allow moving of block into or from important zones
  public void onBlockPistonExtend(final BlockPistonExtendEvent event) {
    Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
    if (zone!=null) {
      for (Block b : event.getBlocks()) {
        if (zone.isImportantBlock(b)) {
          event.setCancelled(true);
          return;
        }
      }
      if (zone.isImportantBlock(event.getBlock().getRelative(event.getDirection(), event.getLength()+1))) {
        event.setCancelled(true);
        return;
      }
    }
  }
View Full Code Here

    }
  }
 
  @EventHandler
  public void onBlockPistonRetract(final BlockPistonRetractEvent event) {
    Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation());
    if (zone!=null) {
      Block b = event.getBlock().getRelative(event.getDirection(), 2);
      if (zone.isImportantBlock(b)) {
        event.setCancelled(true);
        return;
      }
    }
  }
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.