Package org.bukkit

Examples of org.bukkit.World


  @Test
  public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X()
      throws NotSoutheastException, TooSmallException, TooBigException {
    // Arrange

    World worldMock = mock(World.class);
    Warzone zoneMock = mock(Warzone.class);
    when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
    when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
    ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
    Location se = new Location(worldMock, 64, 64, -64);
View Full Code Here


  @Test
  public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z()
      throws NotSoutheastException, TooSmallException, TooBigException {
    // Arrange

    World worldMock = mock(World.class);
    Warzone zoneMock = mock(Warzone.class);
    when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
    when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
    ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
    Location se = new Location(worldMock, 64, 64, -64);
View Full Code Here

   * Changes the lobby's position. Orientation is determined from the player location. Creates volume or resets. Saves new lobby blocks.
   *
   * @param playerLocation
   */
  public void setLocation(Location playerLocation) {
    World lobbyWorld = playerLocation.getWorld();
    this.createVolumeOrReset(lobbyWorld);

    // Lobby orientation
    int yaw = 0;
    if (playerLocation.getYaw() >= 0) {
      yaw = (int) (playerLocation.getYaw() % 360);
    } else {
      yaw = (int) (360 + (playerLocation.getYaw() % 360));
    }
    BlockFace facing = null;
    BlockFace opposite = null;
    if ((yaw >= 0 && yaw < 45) || (yaw >= 315 && yaw <= 360)) {
      facing = Direction.WEST();
      opposite = Direction.EAST();
    } else if (yaw >= 45 && yaw < 135) {
      facing = Direction.NORTH();
      opposite = Direction.SOUTH();
    } else if (yaw >= 135 && yaw < 225) {
      facing = Direction.EAST();
      opposite = Direction.WEST();
    } else if (yaw >= 225 && yaw < 315) {
      facing = Direction.SOUTH();
      opposite = Direction.NORTH();
    }

    this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall

    this.calculateLobbyWidth();
    this.lobbyMiddleWallBlock = lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6).getLocation();

    Block corner1 = null;
    Block corner2 = null;
    int x = this.lobbyMiddleWallBlock.getBlockX();
    int y = this.lobbyMiddleWallBlock.getBlockY();
    int z = this.lobbyMiddleWallBlock.getBlockZ();

    if (this.wall == Direction.NORTH()) {
      corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide);
      corner2 = lobbyWorld.getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, z - this.lobbyHalfSide);
    } else if (this.wall == Direction.EAST()) {
      corner1 = lobbyWorld.getBlockAt(x - this.lobbyHalfSide, y - 1, z);
      corner2 = lobbyWorld.getBlockAt(x + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
    } else if (this.wall == Direction.SOUTH()) {
      corner1 = lobbyWorld.getBlockAt(x, y - 1, z - this.lobbyHalfSide);
      corner2 = lobbyWorld.getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, z + this.lobbyHalfSide);
    } else if (this.wall == Direction.WEST()) {
      corner1 = lobbyWorld.getBlockAt(x + this.lobbyHalfSide, y - 1, z);
      corner2 = lobbyWorld.getBlockAt(x - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
    }

    this.saveLobbyBlocks(corner1, corner2);
  }
View Full Code Here

        War.war.getWarhubMaterials().setLightBlock(
          new ItemStack(floorMaterialSection.getInt("id"), 1,
            (short) floorMaterialSection.getInt("data")));
      }
    }
    World world = War.war.getServer().getWorld(worldName);
    if (world != null) {
      Location hubLocation = new Location(world, hubX, hubY, hubZ);
      WarHub hub = new WarHub(hubLocation, hubOrientation);
      War.war.setWarHub(hub);
      Volume vol;
View Full Code Here

    String[] hubStrSplit = this.hubStr.split(",");

    int hubX = Integer.parseInt(hubStrSplit[0]);
    int hubY = Integer.parseInt(hubStrSplit[1]);
    int hubZ = Integer.parseInt(hubStrSplit[2]);
    World world = null;
    String worldName;
    String hubOrientation = "west";
    if (hubStrSplit.length > 3) {
      worldName = hubStrSplit[3];
      world = War.war.getServer().getWorld(worldName);
View Full Code Here

    return changed;
  }

  public static void loadStructure(Volume volume, Connection databaseConnection) throws SQLException {
    String prefix = String.format("structure_%d", volume.getName().hashCode() & Integer.MAX_VALUE);
    World world = volume.getWorld();
    Validate.notNull(world, String.format("Cannot find the warzone for %s", prefix));
    Statement stmt = databaseConnection.createStatement();
    ResultSet cornerQuery = stmt.executeQuery("SELECT * FROM " + prefix + "_corners");
    cornerQuery.next();
    final Block corner1 = world.getBlockAt(cornerQuery.getInt("x"), cornerQuery.getInt("y"), cornerQuery.getInt("z"));
    cornerQuery.next();
    final Block corner2 = world.getBlockAt(cornerQuery.getInt("x"), cornerQuery.getInt("y"), cornerQuery.getInt("z"));
    cornerQuery.close();
    volume.setCornerOne(corner1);
    volume.setCornerTwo(corner2);
    volume.getBlocks().clear();
    ResultSet query = stmt.executeQuery("SELECT * FROM " + prefix + "_blocks");
View Full Code Here

      e.printStackTrace();
    }

    // world
    String worldStr = warzoneConfig.getProperty("world");
    World world = null;
    if (worldStr == null || worldStr.equals("")) {
      world = War.war.getServer().getWorlds().get(0); // default to first world
    } else {
      world = War.war.getServer().getWorld(worldStr);
    }

    if (world == null) {
      War.war.log("Failed to restore warzone " + name + ". The specified world (name: " + worldStr + ") does not exist!", Level.WARNING);
    } else {
      // Create the zone
      Warzone warzone = new Warzone(world, name);

      // Create file if needed
      if (!warzoneConfig.containsKey("name")) {
        WarzoneTxtMapper.save(warzone, false);
        War.war.getLogger().info("Warzone " + name + " config file created.");
        try {
          warzoneConfig.load();
        } catch (IOException e) {
          // war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
          e.printStackTrace();
        }
      }

      // teleport
      String teleportStr = warzoneConfig.getString("teleport");
      if (teleportStr != null && !teleportStr.equals("")) {
        String[] teleportSplit = teleportStr.split(",");
        int teleX = Integer.parseInt(teleportSplit[0]);
        int teleY = Integer.parseInt(teleportSplit[1]);
        int teleZ = Integer.parseInt(teleportSplit[2]);
        int yaw = Integer.parseInt(teleportSplit[3]);
        warzone.setTeleport(new Location(world, teleX, teleY, teleZ, yaw, 0));
     

      // ff
      if (warzoneConfig.containsKey("friendlyFire")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.FRIENDLYFIRE, warzoneConfig.getBoolean("friendlyFire"));
      }

      // loadout
      warzone.getDefaultInventories().clearLoadouts();
     
      String loadoutStr = warzoneConfig.getString("loadout");
      if (loadoutStr != null && !loadoutStr.equals("")) {
        warzone.getDefaultInventories().setLoadout("default", new HashMap<Integer, ItemStack>());
        LoadoutTxtMapper.fromStringToLoadout(loadoutStr, warzone.getDefaultInventories().getLoadout("default"));
      }
     
      // extraLoadouts
      String extraLoadoutStr = warzoneConfig.getString("extraLoadouts");
      String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
     
      for (String nameStr : extraLoadoutsSplit) {
        if (nameStr != null && !nameStr.equals("")) {
          warzone.getDefaultInventories().setLoadout(nameStr, new HashMap<Integer, ItemStack>());
        }
      }
     
      for (String extraName : extraLoadoutsSplit) {
        if (extraName != null && !extraName.equals("")) {
          String loadoutString = warzoneConfig.getString(extraName + "Loadout");
          HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadout(extraName);
          LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
        }
      }

      // authors
      if (warzoneConfig.containsKey("author") && !warzoneConfig.getString("author").equals("")) {
        for(String authorStr : warzoneConfig.getString("author").split(",")) {
          if (!authorStr.equals("")) {
            warzone.addAuthor(authorStr);
          }
        }
      }

      // life pool (always set after teams, so the teams' remaining lives get initialized properly by this setter)
      if (warzoneConfig.containsKey("lifePool")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warzoneConfig.getInt("lifePool"));
      }

      // monument heal
      if (warzoneConfig.containsKey("monumentHeal")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.MONUMENTHEAL, warzoneConfig.getInt("monumentHeal"));
      }

      // autoAssignOnly
      if (warzoneConfig.containsKey("autoAssignOnly")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.AUTOASSIGN, warzoneConfig.getBoolean("autoAssignOnly"));
      }

      // flagPointsOnly
      if (warzoneConfig.containsKey("flagPointsOnly")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warzoneConfig.getBoolean("flagPointsOnly"));
      }
     
      // flagMustBeHome
      if (warzoneConfig.containsKey("flagMustBeHome")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warzoneConfig.getBoolean("flagMustBeHome"));
      }

      // team cap
      if (warzoneConfig.containsKey("teamCap")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warzoneConfig.getInt("teamCap"));
      }
     
      // score cap
      if (warzoneConfig.containsKey("scoreCap")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warzoneConfig.getInt("scoreCap"));
      }
     
      // respawn timer
      if (warzoneConfig.containsKey("respawnTimer")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warzoneConfig.getInt("respawnTimer"));
      }

      // blockHeads
      if (warzoneConfig.containsKey("blockHeads")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.BLOCKHEADS, warzoneConfig.getBoolean("blockHeads"));
      }

      // spawnStyle
      String spawnStyle = warzoneConfig.getString("spawnStyle");
      if (spawnStyle != null && !spawnStyle.equals("")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle));
      }

      // flagReturn
      String flagReturn = warzoneConfig.getString("flagReturn");
      if (flagReturn != null && !flagReturn.equals("")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn));
      }

      // reward
      String rewardStr = warzoneConfig.getString("reward");
      if (rewardStr != null && !rewardStr.equals("")) {
        HashMap<Integer, ItemStack> reward = new HashMap<Integer, ItemStack>();
        LoadoutTxtMapper.fromStringToLoadout(rewardStr, reward);
        warzone.getDefaultInventories().setReward(reward);
      }

      // unbreakableZoneBlocks
      if (warzoneConfig.containsKey("unbreakableZoneBlocks")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.UNBREAKABLE, warzoneConfig.getBoolean("unbreakableZoneBlocks"));
      }

      // disabled
      if (warzoneConfig.containsKey("disabled")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.DISABLED, warzoneConfig.getBoolean("disabled"));
      }

      // noCreatures
      if (warzoneConfig.containsKey("noCreatures")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.NOCREATURES, warzoneConfig.getBoolean("noCreatures"));
      }
     
      // glassWalls
      if (warzoneConfig.containsKey("glassWalls")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.GLASSWALLS, warzoneConfig.getBoolean("glassWalls"));
      }
     
      // pvpInZone
      if (warzoneConfig.containsKey("pvpInZone")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.PVPINZONE, warzoneConfig.getBoolean("pvpInZone"));
      }
     
      // instaBreak
      if (warzoneConfig.containsKey("instaBreak")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.INSTABREAK, warzoneConfig.getBoolean("instaBreak"));
      }
     
      // noDrops
      if (warzoneConfig.containsKey("noDrops")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.NODROPS, warzoneConfig.getBoolean("noDrops"));
      }
     
      // noHunger
      if (warzoneConfig.containsKey("noHunger")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warzoneConfig.getBoolean("noHunger"));
      }
     
      // saturation
      if (warzoneConfig.containsKey("saturation")) {
        warzone.getTeamDefaultConfig().put(TeamConfig.SATURATION, warzoneConfig.getInt("saturation"));
      }
     
      // minPlayers
      if (warzoneConfig.containsKey("minPlayers")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.MINPLAYERS, warzoneConfig.getInt("minPlayers"));
      }
     
      // minTeams
      if (warzoneConfig.containsKey("minTeams")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.MINTEAMS, warzoneConfig.getInt("minTeams"));
      }

      // resetOnEmpty
      if (warzoneConfig.containsKey("resetOnEmpty")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.RESETONEMPTY, warzoneConfig.getBoolean("resetOnEmpty"));
      }

      // resetOnLoad
      if (warzoneConfig.containsKey("resetOnLoad")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.RESETONLOAD, warzoneConfig.getBoolean("resetOnLoad"));
      }

      // resetOnUnload
      if (warzoneConfig.containsKey("resetOnUnload")) {
        warzone.getWarzoneConfig().put(WarzoneConfig.RESETONUNLOAD, warzoneConfig.getBoolean("resetOnUnload"));
      }

      // rallyPoint
      String rallyPointStr = warzoneConfig.getString("rallyPoint");
      if (rallyPointStr != null && !rallyPointStr.equals("")) {
        String[] rallyPointStrSplit = rallyPointStr.split(",");

        int rpX = Integer.parseInt(rallyPointStrSplit[0]);
        int rpY = Integer.parseInt(rallyPointStrSplit[1]);
        int rpZ = Integer.parseInt(rallyPointStrSplit[2]);
        Location rallyPoint = new Location(world, rpX, rpY, rpZ);
        warzone.setRallyPoint(rallyPoint);
      }

      // monuments
      String monumentsStr = warzoneConfig.getString("monuments");
      if (monumentsStr != null && !monumentsStr.equals("")) {
        String[] monumentsSplit = monumentsStr.split(";");
        warzone.getMonuments().clear();
        for (String monumentStr : monumentsSplit) {
          if (monumentStr != null && !monumentStr.equals("")) {
            String[] monumentStrSplit = monumentStr.split(",");
            int monumentX = Integer.parseInt(monumentStrSplit[1]);
            int monumentY = Integer.parseInt(monumentStrSplit[2]);
            int monumentZ = Integer.parseInt(monumentStrSplit[3]);
            Monument monument = new Monument(monumentStrSplit[0], warzone, new Location(world, monumentX, monumentY, monumentZ));
            warzone.getMonuments().add(monument);
          }
        }
      }
     
      // teams
      String teamsStr = warzoneConfig.getString("teams");
      if (teamsStr != null && !teamsStr.equals("")) {
        String[] teamsSplit = teamsStr.split(";");
        warzone.getTeams().clear();
        for (String teamStr : teamsSplit) {
          if (teamStr != null && !teamStr.equals("")) {
            String[] teamStrSplit = teamStr.split(",");
            int teamX = Integer.parseInt(teamStrSplit[1]);
            int teamY = Integer.parseInt(teamStrSplit[2]);
            int teamZ = Integer.parseInt(teamStrSplit[3]);
            Location teamLocation = new Location(world, teamX, teamY, teamZ);
            if (teamStrSplit.length > 4) {
              int yaw = Integer.parseInt(teamStrSplit[4]);
              teamLocation.setYaw(yaw);
            }
            File original = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamStrSplit[0] + ".dat");
            File modified = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name + "/volume-" + teamStrSplit[0] + "0.dat");
            try {
              original.renameTo(modified);
            } catch (Exception ignored) {
            }

            Team team = new Team(teamStrSplit[0], TeamKind.teamKindFromString(teamStrSplit[0]), Arrays.asList(teamLocation), warzone);
            team.setRemainingLives(warzone.getTeamDefaultConfig().resolveInt(TeamConfig.LIFEPOOL));
            warzone.getTeams().add(team);
          }
        }
      }

      // teamFlags
      String teamFlagsStr = warzoneConfig.getString("teamFlags");
      if (teamFlagsStr != null && !teamFlagsStr.equals("")) {
        String[] teamFlagsSplit = teamFlagsStr.split(";");
        for (String teamFlagStr : teamFlagsSplit) {
          if (teamFlagStr != null && !teamFlagStr.equals("")) {
            String[] teamFlagStrSplit = teamFlagStr.split(",");
            Team team = warzone.getTeamByKind(TeamKind.teamKindFromString(teamFlagStrSplit[0]));
            if (team != null) {
              int teamFlagX = Integer.parseInt(teamFlagStrSplit[1]);
              int teamFlagY = Integer.parseInt(teamFlagStrSplit[2]);
              int teamFlagZ = Integer.parseInt(teamFlagStrSplit[3]);
              Location teamFlagLocation = new Location(world, teamFlagX, teamFlagY, teamFlagZ);
              if (teamFlagStrSplit.length > 4) {
                int yaw = Integer.parseInt(teamFlagStrSplit[4]);
                teamFlagLocation.setYaw(yaw);
              }
              team.setTeamFlag(teamFlagLocation); // this may screw things up
            }
          }
        }
      }

      // lobby
      String lobbyStr = warzoneConfig.getString("lobby");

      warzoneConfig.close();

      if (createNewVolume) {
        ZoneVolume zoneVolume = new ZoneVolume(warzone.getName(), world, warzone); // VolumeMapper.loadZoneVolume(warzone.getName(), warzone.getName(), war, warzone.getWorld(), warzone);
        warzone.setVolume(zoneVolume);
      }

      // monument blocks
      for (Monument monument : warzone.getMonuments()) {
        try {
          monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
        } catch (SQLException e) {
          War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
        }
      }

      // team spawn blocks
      for (Team team : warzone.getTeams()) {
        for (Location spawnLocation : team.getTeamSpawns()) {
          try {
            team.setSpawnVolume(spawnLocation, VolumeMapper.loadVolume(team.getName() + "0", warzone.getName(), world));
          } catch (SQLException e) {
            War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
          }
        }
        if (team.getTeamFlag() != null) {
          try {
            team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
          } catch (SQLException e) {
            War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
          }
        }
      }

      // lobby
      BlockFace lobbyFace = null;
      if (lobbyStr != null && !lobbyStr.equals("")) {
        String[] lobbyStrSplit = lobbyStr.split(",");
        if (lobbyStrSplit.length > 0) {
          // lobby orientation
          if (lobbyStrSplit[0].equals("south")) {
            lobbyFace = Direction.SOUTH();
          } else if (lobbyStrSplit[0].equals("east")) {
            lobbyFace = Direction.EAST();
          } else if (lobbyStrSplit[0].equals("north")) {
            lobbyFace = Direction.NORTH();
          } else if (lobbyStrSplit[0].equals("west")) {
            lobbyFace = Direction.WEST();
          }
         
          // lobby world
          World lobbyWorld = world;  // by default, warzone world
          if (lobbyStrSplit.length > 1) {
            World strWorld = War.war.getServer().getWorld(lobbyStrSplit[1]);
            if (strWorld != null) {
              lobbyWorld = strWorld;
            }
          }
         
View Full Code Here

        // 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);
View Full Code Here

     */
    private final int RADIUS = 5;
   
    @Override
    public void execute(Arena arena, MABoss boss) {
        World world = arena.getWorld();
        for (Player p : AbilityUtils.getNearbyPlayers(arena, boss.getEntity(), RADIUS)) {
            world.strikeLightning(p.getLocation());
        }
    }
View Full Code Here

    // Load an already existing arena node
    private Arena loadArena(String arenaname) {
        ConfigurationSection section  = makeSection(config, "arenas." + arenaname);
        ConfigurationSection settings = makeSection(section, "settings");
        String worldName = settings.getString("world", "");
        World world;

        if (!worldName.equals("")) {
            world = plugin.getServer().getWorld(worldName);
            if (world == null) {
                Messenger.warning("World '" + worldName + "' for arena '" + arenaname + "' was not found...");
                return null;
            }
        } else {
            world = plugin.getServer().getWorlds().get(0);
            Messenger.warning("Could not find the world for arena '" + arenaname + "'. Using default world ('" + world.getName() + "')! Check the config-file!");
        }

        ConfigUtils.addMissingRemoveObsolete(plugin, "settings.yml", settings);
        ConfigUtils.addIfEmpty(plugin, "waves.yml", makeSection(section, "waves"));
View Full Code Here

TOP

Related Classes of org.bukkit.World

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.