mirror of
https://github.com/taoneill/war.git
synced 2025-01-03 06:17:33 +01:00
Drop all War backwards compatibility
Bukkit 1.13 removes item ID API entirely - therefore, it is impossible to load legacy War format files that still use item IDs.
This commit is contained in:
parent
0a02e25f4a
commit
69a148fc6a
@ -1,69 +0,0 @@
|
||||
package com.tommytony.war.job;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.mapper.WarYmlMapper;
|
||||
import com.tommytony.war.mapper.WarzoneTxtMapper;
|
||||
import com.tommytony.war.mapper.WarzoneYmlMapper;
|
||||
|
||||
public class RestoreWarzonesJob implements Runnable {
|
||||
|
||||
private final String warzonesStr;
|
||||
private final boolean newWarInstall;
|
||||
private final boolean convertingToYml;
|
||||
|
||||
public RestoreWarzonesJob(String warzonesStr, boolean newWarInstall, boolean convertingToYml) {
|
||||
this.warzonesStr = warzonesStr;
|
||||
this.newWarInstall = newWarInstall;
|
||||
this.convertingToYml = convertingToYml;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
String[] warzoneSplit = this.warzonesStr.split(",");
|
||||
War.war.getWarzones().clear();
|
||||
|
||||
for (String warzoneName : warzoneSplit) {
|
||||
if (warzoneName != null && !warzoneName.equals("")) {
|
||||
War.war.log("Loading zone " + warzoneName + "...", Level.INFO);
|
||||
Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall);
|
||||
if (zone != null) { // could have failed, would've been logged already
|
||||
War.war.getWarzones().add(zone);
|
||||
try {
|
||||
zone.getVolume().loadCorners();
|
||||
} catch (SQLException ex) {
|
||||
War.war.log("Failed to load warzone " + warzoneName + ": " + ex.getMessage(), Level.WARNING);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
if (zone.getLobby() != null) {
|
||||
zone.getLobby().getVolume().resetBlocks();
|
||||
}
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.RESETONLOAD)) {
|
||||
zone.getVolume().resetBlocks();
|
||||
}
|
||||
zone.initializeZone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.getWarzones().size() > 0) {
|
||||
War.war.log("Warzones ready.", Level.INFO);
|
||||
}
|
||||
|
||||
if (convertingToYml) {
|
||||
// Loading process is over, we can convert (i.e. save in new format)
|
||||
WarYmlMapper.save();
|
||||
War.war.log("Converted war.txt to war.yml.", Level.INFO);
|
||||
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
WarzoneYmlMapper.save(zone);
|
||||
War.war.log("Converted warzone-" + zone.getName() + ".txt to warzone-" + zone.getName() + ".yml.", Level.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -22,7 +22,6 @@ public class RestoreYmlWarhubJob implements Runnable {
|
||||
this.warhubConfig = warhubConfig;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void run() {
|
||||
int hubX = warhubConfig.getInt("x");
|
||||
int hubY = warhubConfig.getInt("y");
|
||||
@ -35,50 +34,18 @@ public class RestoreYmlWarhubJob implements Runnable {
|
||||
if (warhubConfig.isItemStack("materials.floor")) {
|
||||
War.war.getWarhubMaterials().setFloorBlock(
|
||||
warhubConfig.getItemStack("materials.floor"));
|
||||
} else {
|
||||
ConfigurationSection floorMaterialSection = warhubConfig
|
||||
.getConfigurationSection("materials.floor");
|
||||
if (floorMaterialSection != null) {
|
||||
War.war.getWarhubMaterials().setFloorBlock(
|
||||
new ItemStack(floorMaterialSection.getInt("id"), 1,
|
||||
(short) floorMaterialSection.getInt("data")));
|
||||
}
|
||||
}
|
||||
if (warhubConfig.isItemStack("materials.outline")) {
|
||||
War.war.getWarhubMaterials().setOutlineBlock(
|
||||
warhubConfig.getItemStack("materials.outline"));
|
||||
} else {
|
||||
ConfigurationSection floorMaterialSection = warhubConfig
|
||||
.getConfigurationSection("materials.outline");
|
||||
if (floorMaterialSection != null) {
|
||||
War.war.getWarhubMaterials().setOutlineBlock(
|
||||
new ItemStack(floorMaterialSection.getInt("id"), 1,
|
||||
(short) floorMaterialSection.getInt("data")));
|
||||
}
|
||||
}
|
||||
if (warhubConfig.isItemStack("materials.gate")) {
|
||||
War.war.getWarhubMaterials().setGateBlock(
|
||||
warhubConfig.getItemStack("materials.gate"));
|
||||
} else {
|
||||
ConfigurationSection floorMaterialSection = warhubConfig
|
||||
.getConfigurationSection("materials.gate");
|
||||
if (floorMaterialSection != null) {
|
||||
War.war.getWarhubMaterials().setGateBlock(
|
||||
new ItemStack(floorMaterialSection.getInt("id"), 1,
|
||||
(short) floorMaterialSection.getInt("data")));
|
||||
}
|
||||
}
|
||||
if (warhubConfig.isItemStack("materials.light")) {
|
||||
War.war.getWarhubMaterials().setLightBlock(
|
||||
warhubConfig.getItemStack("materials.light"));
|
||||
} else {
|
||||
ConfigurationSection floorMaterialSection = warhubConfig
|
||||
.getConfigurationSection("materials.light");
|
||||
if (floorMaterialSection != null) {
|
||||
War.war.getWarhubMaterials().setLightBlock(
|
||||
new ItemStack(floorMaterialSection.getInt("id"), 1,
|
||||
(short) floorMaterialSection.getInt("data")));
|
||||
}
|
||||
}
|
||||
World world = War.war.getServer().getWorld(worldName);
|
||||
if (world != null) {
|
||||
|
@ -1,46 +0,0 @@
|
||||
package com.tommytony.war.mapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class LoadoutTxtMapper {
|
||||
|
||||
public static void fromStringToLoadout(String loadoutString, HashMap<Integer, ItemStack> destinationLoadout) {
|
||||
String[] rewardStrSplit = loadoutString.split(";");
|
||||
destinationLoadout.clear();
|
||||
for (String itemStr : rewardStrSplit) {
|
||||
if (itemStr != null && !itemStr.equals("")) {
|
||||
String[] itemStrSplit = itemStr.split(",");
|
||||
ItemStack item = null;
|
||||
if (itemStrSplit.length == 3) {
|
||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
} else if (itemStrSplit.length == 5) {
|
||||
short durability = Short.parseShort(itemStrSplit[3]);
|
||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability);
|
||||
item.setDurability(durability);
|
||||
} else if (itemStrSplit.length == 6) {
|
||||
short durability = Short.parseShort(itemStrSplit[3]);
|
||||
item = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]), durability);
|
||||
item.setDurability(durability);
|
||||
|
||||
// enchantments
|
||||
String[] enchantmentsSplit = itemStrSplit[5].split("::");
|
||||
for (String enchantmentStr : enchantmentsSplit) {
|
||||
if (!enchantmentStr.equals("")) {
|
||||
String[] enchantmentSplit = enchantmentStr.split(":");
|
||||
int enchantId = Integer.parseInt(enchantmentSplit[0]);
|
||||
int level = Integer.parseInt(enchantmentSplit[1]);
|
||||
War.war.safelyEnchant(item, Enchantment.getById(enchantId), level);
|
||||
}
|
||||
}
|
||||
}
|
||||
destinationLoadout.put(Integer.parseInt(itemStrSplit[2]), item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -50,66 +50,16 @@ public class LoadoutYmlMapper {
|
||||
* @param loadoutName The name of the loadout
|
||||
* @return new style loadout
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Loadout fromConfigToLoadout(ConfigurationSection config, HashMap<Integer, ItemStack> loadout, String loadoutName) {
|
||||
List<Integer> slots = config.getIntegerList(loadoutName + ".slots");
|
||||
for (Integer slot : slots) {
|
||||
if (config.isItemStack(loadoutName + "." + Integer.toString(slot))) {
|
||||
loadout.put(slot, config.getItemStack(loadoutName + "." + Integer.toString(slot)));
|
||||
continue;
|
||||
}
|
||||
String prefix = loadoutName + "." + slot + ".";
|
||||
int id = config.getInt(prefix + "id");
|
||||
int amount = config.getInt(prefix + "amount");
|
||||
short durability = (short)config.getInt(prefix + "durability");
|
||||
|
||||
ItemStack stack = new ItemStack(id, amount, durability);
|
||||
stack.setDurability(durability);
|
||||
|
||||
if (config.contains(prefix + "enchantments")) {
|
||||
List<String> enchantmentStringList = config.getStringList(prefix + "enchantments");
|
||||
for (String enchantmentString : enchantmentStringList) {
|
||||
String[] enchantmentStringSplit = enchantmentString.split(",");
|
||||
if (enchantmentStringSplit.length == 2) {
|
||||
int enchantId = Integer.parseInt(enchantmentStringSplit[0]);
|
||||
int level = Integer.parseInt(enchantmentStringSplit[1]);
|
||||
War.war.safelyEnchant(stack, Enchantment.getById(enchantId), level);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.contains(prefix + "armorcolor")) {
|
||||
int rgb = config.getInt(prefix + "armorcolor");
|
||||
Color clr = Color.fromRGB(rgb);
|
||||
LeatherArmorMeta meta = (LeatherArmorMeta) stack.getItemMeta();
|
||||
meta.setColor(clr);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
if (config.contains(prefix + "name")) {
|
||||
String itemName = config.getString(prefix + "name");
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setDisplayName(itemName);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
if (config.contains(prefix + "lore")) {
|
||||
List<String> itemLore = config.getStringList(prefix + "lore");
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
meta.setLore(itemLore);
|
||||
stack.setItemMeta(meta);
|
||||
}
|
||||
loadout.put(slot, stack);
|
||||
}
|
||||
String permission = config.getString(loadoutName + ".permission", "");
|
||||
return new Loadout(loadoutName, loadout, permission);
|
||||
}
|
||||
|
||||
public static void fromLoadoutsToConfig(HashMap<String, HashMap<Integer, ItemStack>> loadouts, ConfigurationSection section) {
|
||||
List<String> sortedNames = sortNames(loadouts);
|
||||
|
||||
section.set("names", sortedNames);
|
||||
for (String name : sortedNames) {
|
||||
fromLoadoutToConfig(name, loadouts.get(name), section);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes a list of new style loadouts to the configuration.
|
||||
@ -144,11 +94,7 @@ public class LoadoutYmlMapper {
|
||||
}
|
||||
|
||||
private static List<Integer> toIntList(Set<Integer> keySet) {
|
||||
List<Integer> list = new ArrayList<Integer>();
|
||||
for (Integer key : keySet) {
|
||||
list.add(key);
|
||||
}
|
||||
return list;
|
||||
return new ArrayList<Integer>(keySet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,282 +0,0 @@
|
||||
package com.tommytony.war.mapper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.job.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.utility.DeferredBlockReset;
|
||||
import com.tommytony.war.volume.ZoneVolume;
|
||||
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PreDeGaulleZoneVolumeMapper {
|
||||
|
||||
private static List<ItemStack> readInventoryString(String invString) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
String[] itemsStrSplit = invString.split(";;");
|
||||
for (String itemStr : itemsStrSplit) {
|
||||
String[] itemStrSplit = itemStr.split(";");
|
||||
if (itemStrSplit.length == 4) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else if (itemStrSplit.length == 3) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else {
|
||||
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
|
||||
BufferedReader in = null;
|
||||
int noOfResetBlocks = 0;
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
String firstLine = in.readLine();
|
||||
|
||||
if (firstLine != null && !firstLine.equals("")) {
|
||||
boolean height129Fix = false;
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
int y1 = Integer.parseInt(in.readLine());
|
||||
if (y1 == 128) {
|
||||
height129Fix = true;
|
||||
y1 = 127;
|
||||
}
|
||||
int z1 = Integer.parseInt(in.readLine());
|
||||
in.readLine();
|
||||
int x2 = Integer.parseInt(in.readLine());
|
||||
int y2 = Integer.parseInt(in.readLine());
|
||||
if (y2 == 128) {
|
||||
height129Fix = true;
|
||||
y2 = 127;
|
||||
}
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
if (!onlyLoadCorners) {
|
||||
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
|
||||
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0;
|
||||
int diskBlockType;
|
||||
byte diskBlockData;
|
||||
Block worldBlock;
|
||||
int worldBlockId;
|
||||
volume.clearBlocksThatDontFloat();
|
||||
x = volume.getMinX();
|
||||
String blockLine;
|
||||
String[] blockSplit;
|
||||
for (i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
blockLine = in.readLine();
|
||||
|
||||
if (blockLine != null && !blockLine.equals("")) {
|
||||
blockSplit = blockLine.split(",");
|
||||
if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
diskBlockType = Integer.parseInt(blockSplit[0]);
|
||||
diskBlockData = Byte.parseByte(blockSplit[1]);
|
||||
worldBlock = volume.getWorld().getBlockAt(x, y, z);
|
||||
worldBlockId = worldBlock.getTypeId();
|
||||
if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) {
|
||||
if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) {
|
||||
// Signs read
|
||||
String linesStr = "";
|
||||
if (blockSplit.length > 2) {
|
||||
for (int o = 2; o < blockSplit.length; o++) {
|
||||
linesStr += blockSplit[o];
|
||||
}
|
||||
String[] lines = linesStr.split(";;");
|
||||
|
||||
// Signs set
|
||||
// A sign post hanging on a wall south of here will
|
||||
if (diskBlockType == Material.SIGN_POST.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
||||
} else {
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
BlockState state = worldBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if (lines != null && sign.getLines() != null) {
|
||||
if (lines.length > 0) {
|
||||
sign.setLine(0, lines[0]);
|
||||
}
|
||||
if (lines.length > 1) {
|
||||
sign.setLine(1, lines[1]);
|
||||
}
|
||||
if (lines.length > 2) {
|
||||
sign.setLine(2, lines[2]);
|
||||
}
|
||||
if (lines.length > 3) {
|
||||
sign.setLine(3, lines[3]);
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.CHEST.getId()) {
|
||||
// Chests read
|
||||
List<ItemStack> items = null;
|
||||
if (blockSplit.length > 2) {
|
||||
String itemsStr = blockSplit[2];
|
||||
items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr);
|
||||
}
|
||||
|
||||
// Chests set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Chest) {
|
||||
Chest chest = (Chest) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
chest.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
chest.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
chest.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.DISPENSER.getId()) {
|
||||
// Dispensers read
|
||||
List<ItemStack> items = null;
|
||||
if (blockSplit.length > 2) {
|
||||
String itemsStr = blockSplit[2];
|
||||
// String itemsStr = lineScanner.nextLine();
|
||||
items = PreDeGaulleZoneVolumeMapper.readInventoryString(itemsStr);
|
||||
}
|
||||
|
||||
// Dispensers set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Dispenser) {
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
dispenser.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
dispenser.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
dispenser.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
// Door blocks
|
||||
|
||||
if (j - 1 > 0) {
|
||||
Block blockBelow = world.getBlockAt(x, y - 1, z);
|
||||
boolean belowIsGlass = blockBelow.getTypeId() == Material.GLASS.getId();
|
||||
// Set current block to glass if block below isn't glass.
|
||||
// Having a glass block below means the current block is a door top.
|
||||
if (belowIsGlass) {
|
||||
// Top door block. Set both it and the block below as door.
|
||||
blockBelow.setType(Material.getMaterial(diskBlockType));
|
||||
blockBelow.setData(diskBlockData);
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
} else {
|
||||
worldBlock.setType(Material.GLASS);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) {
|
||||
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
|
||||
// Change the block itself later on:
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
|
||||
} else {
|
||||
// regular block
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
visitedBlocks++;
|
||||
}
|
||||
blockReads++;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
if (height129Fix && j == volume.getSizeY() - 1) {
|
||||
for (int skip = 0; skip < volume.getSizeZ(); skip++) {
|
||||
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
|
||||
// scanner.nextLine();
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if (!deferred.isEmpty()) {
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
// if (scanner != null)
|
||||
try {
|
||||
in.close();
|
||||
in = null;
|
||||
// scanner.close();
|
||||
// scanner = null;
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
}
|
@ -1,459 +0,0 @@
|
||||
package com.tommytony.war.mapper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.Dispenser;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.job.DeferredBlockResetsJob;
|
||||
import com.tommytony.war.job.ZoneVolumeSaveJob;
|
||||
import com.tommytony.war.utility.DeferredBlockReset;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import com.tommytony.war.volume.ZoneVolume;
|
||||
|
||||
/**
|
||||
* The ZoneVolumeMapper take the blocks from disk and sets them in the worlds, since the ZoneVolume doesn't hold its blocks in memory like regular Volumes.
|
||||
*
|
||||
* @author tommytony, Tim Düsterhus
|
||||
* @package com.tommytony.war.mappers
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PreNimitzZoneVolumeMapper {
|
||||
|
||||
/**
|
||||
* Loads the given volume
|
||||
*
|
||||
* @param ZoneVolume
|
||||
* volume Volume to load
|
||||
* @param String
|
||||
* zoneName Zone to load the volume from
|
||||
* @param World
|
||||
* world The world the zone is located
|
||||
* @param boolean onlyLoadCorners Should only the corners be loaded
|
||||
* @return integer Changed blocks
|
||||
*/
|
||||
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
|
||||
File cornersFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
|
||||
File blocksFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
|
||||
File signsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs");
|
||||
File invsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs");
|
||||
int noOfResetBlocks = 0;
|
||||
boolean failed = false;
|
||||
if (!blocksFile.exists()) {
|
||||
// The post 1.6 formatted files haven't been created yet so
|
||||
// we need to use the old load.
|
||||
noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners);
|
||||
|
||||
// The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ),
|
||||
// so let's save to the new format as soon as the zone is fully reset.
|
||||
PreNimitzZoneVolumeMapper.saveAsJob(volume, zoneName, 2);
|
||||
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO);
|
||||
|
||||
return noOfResetBlocks;
|
||||
} else {
|
||||
// 1.6 file exist, so go ahead with reset
|
||||
BufferedReader cornersReader = null;
|
||||
FileInputStream blocksStream = null;
|
||||
BufferedReader signsReader = null;
|
||||
BufferedReader invsReader = null;
|
||||
try {
|
||||
cornersReader = new BufferedReader(new FileReader(cornersFile));
|
||||
blocksStream = new FileInputStream(blocksFile);
|
||||
signsReader = new BufferedReader(new FileReader(signsFile));
|
||||
invsReader = new BufferedReader(new FileReader(invsFile));
|
||||
|
||||
// Get the corners
|
||||
cornersReader.readLine();
|
||||
int x1 = Integer.parseInt(cornersReader.readLine());
|
||||
int y1 = Integer.parseInt(cornersReader.readLine());
|
||||
int z1 = Integer.parseInt(cornersReader.readLine());
|
||||
cornersReader.readLine();
|
||||
int x2 = Integer.parseInt(cornersReader.readLine());
|
||||
int y2 = Integer.parseInt(cornersReader.readLine());
|
||||
int z2 = Integer.parseInt(cornersReader.readLine());
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
// Allocate block byte arrays
|
||||
int noOfBlocks = volume.getSizeX() * volume.getSizeY() * volume.getSizeZ();
|
||||
byte[] blockBytes = new byte[noOfBlocks * 2]; // one byte for type, one for data
|
||||
|
||||
blocksStream.read(blockBytes); // read it all
|
||||
|
||||
// Now use the block bytes to reset the world blocks
|
||||
if (!onlyLoadCorners) {
|
||||
DeferredBlockResetsJob deferred = new DeferredBlockResetsJob(world);
|
||||
int blockReads = 0, visitedBlocks = 0, x = 0, y = 0, z = 0, i = 0, j = 0, k = 0;
|
||||
int diskBlockType;
|
||||
byte diskBlockData;
|
||||
Block worldBlock;
|
||||
int worldBlockId;
|
||||
volume.clearBlocksThatDontFloat();
|
||||
x = volume.getMinX();
|
||||
for (i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
diskBlockType = blockBytes[visitedBlocks * 2];
|
||||
diskBlockData = blockBytes[visitedBlocks * 2 + 1];
|
||||
|
||||
worldBlock = volume.getWorld().getBlockAt(x, y, z);
|
||||
worldBlockId = worldBlock.getTypeId();
|
||||
if (worldBlockId != diskBlockType || (worldBlockId == diskBlockType && worldBlock.getData() != diskBlockData) || (worldBlockId == diskBlockType && worldBlock.getData() == diskBlockData && (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId() || diskBlockType == Material.CHEST.getId() || diskBlockType == Material.DISPENSER.getId()))) {
|
||||
if (diskBlockType == Material.WALL_SIGN.getId() || diskBlockType == Material.SIGN_POST.getId()) {
|
||||
// Signs read
|
||||
String linesStr = signsReader.readLine();
|
||||
String[] lines = linesStr.split(";;");
|
||||
|
||||
// Signs set
|
||||
if (diskBlockType == Material.WALL_SIGN.getId() && ((diskBlockData & 0x04) == 0x04) && i + 1 != volume.getSizeX()) {
|
||||
// A sign post hanging on a wall south of here needs that block to be set first
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData, lines));
|
||||
} else {
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
BlockState state = worldBlock.getState();
|
||||
state.setData(new org.bukkit.material.Sign(diskBlockType, diskBlockData));
|
||||
if (state instanceof Sign) {
|
||||
Sign sign = (Sign) state;
|
||||
if (lines != null && sign.getLines() != null) {
|
||||
if (lines.length > 0) {
|
||||
sign.setLine(0, lines[0]);
|
||||
}
|
||||
if (lines.length > 1) {
|
||||
sign.setLine(1, lines[1]);
|
||||
}
|
||||
if (lines.length > 2) {
|
||||
sign.setLine(2, lines[2]);
|
||||
}
|
||||
if (lines.length > 3) {
|
||||
sign.setLine(3, lines[3]);
|
||||
}
|
||||
sign.update(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.CHEST.getId()) {
|
||||
// Chests read
|
||||
List<ItemStack> items = VolumeMapper.readInventoryString(invsReader.readLine());
|
||||
|
||||
// Chests set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Chest) {
|
||||
Chest chest = (Chest) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
chest.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
chest.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
chest.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.DISPENSER.getId()) {
|
||||
// Dispensers read
|
||||
List<ItemStack> items = VolumeMapper.readInventoryString(invsReader.readLine());
|
||||
|
||||
// Dispensers set
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
BlockState state = worldBlock.getState();
|
||||
if (state instanceof Dispenser) {
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
if (items != null) {
|
||||
int ii = 0;
|
||||
dispenser.getInventory().clear();
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
dispenser.getInventory().setItem(ii, item);
|
||||
ii++;
|
||||
}
|
||||
}
|
||||
dispenser.update(true);
|
||||
}
|
||||
}
|
||||
} else if (diskBlockType == Material.WOODEN_DOOR.getId() || diskBlockType == Material.IRON_DOOR_BLOCK.getId()) {
|
||||
// Door blocks
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
|
||||
} else if (((diskBlockType == Material.TORCH.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.REDSTONE_TORCH_ON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LEVER.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.STONE_BUTTON.getId() && ((diskBlockData & 0x02) == 0x02)) || (diskBlockType == Material.LADDER.getId() && ((diskBlockData & 0x04) == 0x04)) || (diskBlockType == Material.RAILS.getId() && ((diskBlockData & 0x02) == 0x02))) && i + 1 != volume.getSizeX()) {
|
||||
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
|
||||
// Change the block itself later on:
|
||||
deferred.add(new DeferredBlockReset(x, y, z, diskBlockType, diskBlockData));
|
||||
} else {
|
||||
// regular block
|
||||
if (diskBlockType >= 0) {
|
||||
worldBlock.setType(Material.getMaterial(diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
} else {
|
||||
// The larger than 127 block types were stored as bytes,
|
||||
// but now -128 to -1 are the result of the bad cast from byte
|
||||
// to int array above. To make matters worse let's make this
|
||||
// quick a dirty patch. Anyway everything will break horribly
|
||||
// once block ids get higher than 255.
|
||||
worldBlock.setType(Material.getMaterial(256 + diskBlockType));
|
||||
worldBlock.setData(diskBlockData);
|
||||
}
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
visitedBlocks++;
|
||||
|
||||
blockReads++;
|
||||
|
||||
} catch (Exception e) {
|
||||
if (!failed) {
|
||||
// Don't spam the console
|
||||
War.war.getLogger().warning("Failed to reset block in zone volume " + volume.getName() + ". " + "Blocks read: " + blockReads + ". Visited blocks so far:" + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if (!deferred.isEmpty()) {
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 2);
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
War.war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (cornersReader != null) {
|
||||
cornersReader.close();
|
||||
}
|
||||
if (blocksStream != null) {
|
||||
blocksStream.close();
|
||||
}
|
||||
if (signsReader != null) {
|
||||
signsReader.close();
|
||||
}
|
||||
if (invsReader != null) {
|
||||
invsReader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the given volume
|
||||
*
|
||||
* @param Volume
|
||||
* volume Volume to save
|
||||
* @param String
|
||||
* zoneName The warzone the volume is located
|
||||
* @return integer Number of written blocks
|
||||
*/
|
||||
public static int save(Volume volume, String zoneName) {
|
||||
int noOfSavedBlocks = 0;
|
||||
if (volume.hasTwoCorners()) {
|
||||
BufferedWriter cornersWriter = null;
|
||||
FileOutputStream blocksOutput = null;
|
||||
BufferedWriter signsWriter = null;
|
||||
BufferedWriter invsWriter = null;
|
||||
try {
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
|
||||
String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
|
||||
cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners")));
|
||||
blocksOutput = new FileOutputStream(new File(path + ".blocks"));
|
||||
signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs")));
|
||||
invsWriter = new BufferedWriter(new FileWriter(new File(path + ".invs")));
|
||||
|
||||
cornersWriter.write("corner1");
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockX()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockY()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getBlockZ()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write("corner2");
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockX()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockY()));
|
||||
cornersWriter.newLine();
|
||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getBlockZ()));
|
||||
cornersWriter.newLine();
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int z = 0;
|
||||
Block block;
|
||||
int typeId;
|
||||
byte data;
|
||||
BlockState state;
|
||||
|
||||
x = volume.getMinX();
|
||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||
y = volume.getMinY();
|
||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||
z = volume.getMinZ();
|
||||
for (int k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
block = volume.getWorld().getBlockAt(x, y, z);
|
||||
typeId = block.getTypeId();
|
||||
data = block.getData();
|
||||
state = block.getState();
|
||||
|
||||
blocksOutput.write((byte) typeId);
|
||||
blocksOutput.write(data);
|
||||
|
||||
if (state instanceof Sign) {
|
||||
// Signs
|
||||
String extra = "";
|
||||
Sign sign = (Sign) state;
|
||||
if (sign.getLines() != null) {
|
||||
for (String line : sign.getLines()) {
|
||||
extra += line + ";;";
|
||||
}
|
||||
signsWriter.write(extra);
|
||||
signsWriter.newLine();
|
||||
}
|
||||
} else if (state instanceof Chest) {
|
||||
// Chests
|
||||
Chest chest = (Chest) state;
|
||||
Inventory inv = chest.getInventory();
|
||||
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
|
||||
invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
|
||||
invsWriter.newLine();
|
||||
} else if (state instanceof Dispenser) {
|
||||
// Dispensers
|
||||
Dispenser dispenser = (Dispenser) state;
|
||||
Inventory inv = dispenser.getInventory();
|
||||
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
|
||||
invsWriter.write(VolumeMapper.buildInventoryStringFromItemList(items));
|
||||
invsWriter.newLine();
|
||||
}
|
||||
noOfSavedBlocks++;
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error while saving a block to " + " file for zone " + zoneName + ". Blocks saved so far: " + noOfSavedBlocks + "Position: x:" + x + " y:" + y + " z:" + z + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
z++;
|
||||
}
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (cornersWriter != null) {
|
||||
cornersWriter.close();
|
||||
}
|
||||
if (blocksOutput != null) {
|
||||
blocksOutput.close();
|
||||
}
|
||||
if (signsWriter != null) {
|
||||
signsWriter.close();
|
||||
}
|
||||
if (invsWriter != null) {
|
||||
invsWriter.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Saves the Volume as a background-job
|
||||
*
|
||||
* @param ZoneVolme
|
||||
* volume volume to save
|
||||
* @param String
|
||||
* zoneName The zone the volume is located
|
||||
* @param War
|
||||
* war Instance of war
|
||||
* @param long tickDelay delay before beginning the task
|
||||
*/
|
||||
private static void saveAsJob(ZoneVolume volume, String zoneName, long tickDelay) {
|
||||
ZoneVolumeSaveJob job = new ZoneVolumeSaveJob(volume, zoneName);
|
||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job, tickDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given volume
|
||||
*
|
||||
* @param Volume
|
||||
* volume volume to delete
|
||||
* @param War
|
||||
* war Instance of war
|
||||
*/
|
||||
public static void delete(Volume volume) {
|
||||
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat");
|
||||
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners");
|
||||
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks");
|
||||
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs");
|
||||
PreNimitzZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".invs");
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a volume file
|
||||
*
|
||||
* @param String
|
||||
* path path of file
|
||||
* @param War
|
||||
* war Instance of war
|
||||
*/
|
||||
private static void deleteFile(String path) {
|
||||
File volFile = new File(path);
|
||||
if (volFile.exists()) {
|
||||
boolean deletedData = volFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +1,17 @@
|
||||
package com.tommytony.war.mapper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -49,9 +35,8 @@ public class VolumeMapper {
|
||||
volume.getName()));
|
||||
}
|
||||
if (!databaseFile.exists()) {
|
||||
legacyLoad(volume, zoneName, world);
|
||||
save(volume, zoneName);
|
||||
War.war.getLogger().info("Volume " + volume.getName() + " for warzone " + zoneName + " converted to nimitz format!");
|
||||
// dropped nimitz compatibility with the MC 1.13 update
|
||||
War.war.log("Volume " + volume.getName() + " for zone " + zoneName + " not found. Will not attempt converting legacy War version formats.", Level.WARNING);
|
||||
return;
|
||||
}
|
||||
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
|
||||
@ -93,87 +78,6 @@ public class VolumeMapper {
|
||||
databaseConnection.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void legacyLoad(Volume volume, String zoneName, World world) {
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
if (zoneName.equals("")) {
|
||||
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"))); // for the warhub
|
||||
} else {
|
||||
in = new BufferedReader(new FileReader(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
||||
}
|
||||
String firstLine = in.readLine();
|
||||
if (firstLine != null && !firstLine.equals("")) {
|
||||
boolean height129Fix = false;
|
||||
int x1 = Integer.parseInt(in.readLine());
|
||||
int y1 = Integer.parseInt(in.readLine());
|
||||
if (y1 == 128) {
|
||||
height129Fix = true;
|
||||
y1 = 127;
|
||||
}
|
||||
int z1 = Integer.parseInt(in.readLine());
|
||||
in.readLine();
|
||||
int x2 = Integer.parseInt(in.readLine());
|
||||
int y2 = Integer.parseInt(in.readLine());
|
||||
if (y2 == 128) {
|
||||
height129Fix = true;
|
||||
y2 = 127;
|
||||
}
|
||||
int z2 = Integer.parseInt(in.readLine());
|
||||
|
||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
||||
|
||||
int blockReads = 0;
|
||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||
for (int k = 0; k < volume.getSizeZ(); k++) {
|
||||
try {
|
||||
String blockLine = in.readLine();
|
||||
if (blockLine != null && !blockLine.equals("")) {
|
||||
String[] blockSplit = blockLine.split(",");
|
||||
if (blockLine != null && !blockLine.equals("") && blockSplit.length > 1) {
|
||||
int typeID = Integer.parseInt(blockSplit[0]);
|
||||
byte data = Byte.parseByte(blockSplit[1]);
|
||||
|
||||
BlockState dummy = volume.getWorld().getBlockAt(x1 + i, y1 + j, z1 + k).getState();
|
||||
dummy.setTypeId(typeID);
|
||||
dummy.setRawData(data);
|
||||
volume.getBlocks().add(dummy);
|
||||
}
|
||||
blockReads++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error while reading block from volume " + volume.getName() + " file for zone " + zoneName + ". Blocks read so far: " + blockReads + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (height129Fix && j == volume.getSizeY() - 1) {
|
||||
for (int skip = 0; skip < volume.getSizeZ(); skip++) {
|
||||
in.readLine(); // throw away the extra vertical block I used to save pre 0.8
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to read volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
War.war.log("Unexpected error caused failure to read volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to close file reader for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
public static void save(Volume volume, String zoneName) throws SQLException {
|
||||
File databaseFile = new File(War.war.getDataFolder(), String.format(
|
||||
@ -225,105 +129,6 @@ public class VolumeMapper {
|
||||
dataStmt.close();
|
||||
databaseConnection.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an inventory string
|
||||
*
|
||||
* @param String
|
||||
* invString string to parse
|
||||
* @return List<ItemStack> Parsed items
|
||||
*/
|
||||
@Deprecated
|
||||
public static List<ItemStack> readInventoryString(String invString) {
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
if (invString != null && !invString.equals("")) {
|
||||
String[] itemsStrSplit = invString.split(";;");
|
||||
for (String itemStr : itemsStrSplit) {
|
||||
String[] itemStrSplit = itemStr.split(";");
|
||||
if (itemStrSplit.length == 5) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
|
||||
// enchantments
|
||||
String[] enchantmentsSplit = itemStrSplit[4].split("::");
|
||||
for (String enchantmentStr : enchantmentsSplit) {
|
||||
if (!enchantmentStr.equals("")) {
|
||||
String[] enchantmentSplit = enchantmentStr.split(":");
|
||||
int enchantId = Integer.parseInt(enchantmentSplit[0]);
|
||||
int level = Integer.parseInt(enchantmentSplit[1]);
|
||||
War.war.safelyEnchant(stack, Enchantment.getById(enchantId), level);
|
||||
}
|
||||
}
|
||||
|
||||
items.add(stack);
|
||||
} else if (itemStrSplit.length == 4) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
stack.setData(new MaterialData(stack.getTypeId(), Byte.parseByte(itemStrSplit[3])));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else if (itemStrSplit.length == 3) {
|
||||
ItemStack stack = new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1]));
|
||||
short durability = (short) Integer.parseInt(itemStrSplit[2]);
|
||||
stack.setDurability(durability);
|
||||
items.add(stack);
|
||||
} else {
|
||||
items.add(new ItemStack(Integer.parseInt(itemStrSplit[0]), Integer.parseInt(itemStrSplit[1])));
|
||||
}
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string out of a list of items
|
||||
*
|
||||
* @param items The list of items
|
||||
* @return The list as a string
|
||||
*/
|
||||
@Deprecated
|
||||
public static String buildInventoryStringFromItemList(List<ItemStack> items) {
|
||||
String extra = "";
|
||||
for (ItemStack item : items) {
|
||||
if (item != null) {
|
||||
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
|
||||
if (item.getData() != null) {
|
||||
extra += ";" + item.getData().getData();
|
||||
}
|
||||
if (item.getEnchantments().keySet().size() > 0) {
|
||||
String enchantmentsStr = "";
|
||||
for (Enchantment enchantment : item.getEnchantments().keySet()) {
|
||||
enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::";
|
||||
}
|
||||
extra += ";" + enchantmentsStr;
|
||||
}
|
||||
extra += ";;";
|
||||
}
|
||||
}
|
||||
|
||||
return extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts a list of items from and inventory
|
||||
*
|
||||
* @param inv The inventory
|
||||
* @return The inventory as a list
|
||||
*/
|
||||
@Deprecated
|
||||
public static List<ItemStack> getItemListFromInv(Inventory inv) {
|
||||
int size = inv.getSize();
|
||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||
for (int invIndex = 0; invIndex < size; invIndex++) {
|
||||
ItemStack item = inv.getItem(invIndex);
|
||||
if (item != null && item.getType().getId() != Material.AIR.getId()) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public static void delete(Volume volume) {
|
||||
File volFile = new File(War.war.getDataFolder(), String.format(
|
||||
|
@ -1,459 +0,0 @@
|
||||
package com.tommytony.war.mapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.config.FlagReturn;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamSpawnStyle;
|
||||
import com.tommytony.war.config.WarConfig;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.job.RestoreWarhubJob;
|
||||
import com.tommytony.war.job.RestoreWarzonesJob;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarTxtMapper {
|
||||
|
||||
public static void load() {
|
||||
load(false);
|
||||
}
|
||||
|
||||
public static void load(boolean convertingToYml) {
|
||||
(War.war.getDataFolder()).mkdir();
|
||||
(new File(War.war.getDataFolder().getPath() + "/dat")).mkdir();
|
||||
PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to load war.txt file.", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Create file if need be
|
||||
boolean newWar = false;
|
||||
if (!warConfig.containsKey("warzones")) {
|
||||
newWar = true;
|
||||
WarTxtMapper.save();
|
||||
War.war.log("war.txt settings file created.", Level.INFO);
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
War.war.log("Failed to reload war.txt file after creating it.", Level.WARNING);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// warzones
|
||||
String warzonesStr = warConfig.getString("warzones");
|
||||
RestoreWarzonesJob restoreWarzones = new RestoreWarzonesJob(warzonesStr, newWar, convertingToYml);
|
||||
// make sure warhub job is over before this one ends, because this job will launch conversion (which needs the warhub)
|
||||
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarzones, 20) == -1) {
|
||||
War.war.log("Failed to schedule warzone-restore job. No warzone was loaded.", Level.WARNING);
|
||||
}
|
||||
|
||||
// zone makers
|
||||
String[] makers = warConfig.getString("zoneMakers").split(",");
|
||||
War.war.getZoneMakerNames().clear();
|
||||
for (String makerName : makers) {
|
||||
if (makerName != null && !makerName.equals("")) {
|
||||
War.war.getZoneMakerNames().add(makerName);
|
||||
}
|
||||
}
|
||||
|
||||
// command whitelist
|
||||
String[] whitelist = warConfig.getString("commandWhitelist").split(",");
|
||||
War.war.getCommandWhitelist().clear();
|
||||
for (String command : whitelist) {
|
||||
if (command != null && !command.equals("")) {
|
||||
War.war.getCommandWhitelist().add(command);
|
||||
}
|
||||
}
|
||||
|
||||
// defaultLoadout
|
||||
War.war.getDefaultInventories().clearLoadouts();
|
||||
|
||||
String loadoutStr = warConfig.getString("defaultLoadout");
|
||||
if (loadoutStr != null && !loadoutStr.equals("")) {
|
||||
War.war.getDefaultInventories().addLoadout("default", new HashMap<Integer, ItemStack>());
|
||||
LoadoutTxtMapper.fromStringToLoadout(loadoutStr, War.war.getDefaultInventories().getLoadout("default"));
|
||||
}
|
||||
|
||||
// defaultExtraLoadouts
|
||||
String extraLoadoutStr = warConfig.getString("defaultExtraLoadouts");
|
||||
String[] extraLoadoutsSplit = extraLoadoutStr.split(",");
|
||||
|
||||
for (String nameStr : extraLoadoutsSplit) {
|
||||
if (nameStr != null && !nameStr.equals("")) {
|
||||
War.war.getDefaultInventories().addLoadout(nameStr, new HashMap<Integer, ItemStack>());
|
||||
}
|
||||
}
|
||||
|
||||
for (String extraName : extraLoadoutsSplit) {
|
||||
if (extraName != null && !extraName.equals("")) {
|
||||
String loadoutString = warConfig.getString(extraName + "Loadout");
|
||||
HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadout(extraName);
|
||||
LoadoutTxtMapper.fromStringToLoadout(loadoutString, loadout);
|
||||
}
|
||||
}
|
||||
|
||||
// maxZones
|
||||
if (warConfig.keyExists("maxZones")) {
|
||||
War.war.getWarConfig().put(WarConfig.MAXZONES, warConfig.getInt("maxZones"));
|
||||
}
|
||||
|
||||
// defaultLifePool
|
||||
if (warConfig.keyExists("defaultLifePool")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.LIFEPOOL, warConfig.getInt("defaultLifePool"));
|
||||
}
|
||||
|
||||
// defaultMonumentHeal
|
||||
if (warConfig.keyExists("defaultMonumentHeal")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MONUMENTHEAL, warConfig.getInt("defaultMonumentHeal"));
|
||||
}
|
||||
|
||||
// defaultFriendlyFire
|
||||
if (warConfig.keyExists("defaultFriendlyFire")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.FRIENDLYFIRE, warConfig.getBoolean("defaultFriendlyFire"));
|
||||
}
|
||||
|
||||
// defaultAutoAssignOnly
|
||||
if (warConfig.keyExists("defaultAutoAssignOnly")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.AUTOASSIGN, warConfig.getBoolean("defaultAutoAssignOnly"));
|
||||
}
|
||||
|
||||
// defaultFlagPointsOnly
|
||||
if (warConfig.keyExists("defaultFlagPointsOnly")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGPOINTSONLY, warConfig.getBoolean("defaultFlagPointsOnly"));
|
||||
}
|
||||
|
||||
// defaultFlagMustBeHome
|
||||
if (warConfig.keyExists("defaultFlagMustBeHome")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGMUSTBEHOME, warConfig.getBoolean("defaultFlagMustBeHome"));
|
||||
}
|
||||
|
||||
// defaultTeamCap
|
||||
if (warConfig.keyExists("defaultTeamCap")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.TEAMSIZE, warConfig.getInt("defaultTeamCap"));
|
||||
}
|
||||
|
||||
// defaultScoreCap
|
||||
if (warConfig.keyExists("defaultScoreCap")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.MAXSCORE, warConfig.getInt("defaultScoreCap"));
|
||||
}
|
||||
|
||||
// defaultRespawnTimer
|
||||
if (warConfig.keyExists("defaultRespawnTimer")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.RESPAWNTIMER, warConfig.getInt("defaultRespawnTimer"));
|
||||
}
|
||||
|
||||
// pvpInZonesOnly
|
||||
if (warConfig.keyExists("pvpInZonesOnly")) {
|
||||
War.war.getWarConfig().put(WarConfig.PVPINZONESONLY, warConfig.getBoolean("pvpInZonesOnly"));
|
||||
}
|
||||
|
||||
// defaultBlockHeads
|
||||
if (warConfig.keyExists("defaultBlockHeads")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.BLOCKHEADS, warConfig.getBoolean("defaultBlockHeads"));
|
||||
}
|
||||
|
||||
// buildInZonesOnly
|
||||
if (warConfig.keyExists("buildInZonesOnly")) {
|
||||
War.war.getWarConfig().put(WarConfig.BUILDINZONESONLY, warConfig.getBoolean("buildInZonesOnly"));
|
||||
}
|
||||
|
||||
// disablePVPMessage
|
||||
if (warConfig.keyExists("disablePvpMessage")) {
|
||||
War.war.getWarConfig().put(WarConfig.DISABLEPVPMESSAGE, warConfig.getBoolean("disablePvpMessage"));
|
||||
}
|
||||
|
||||
// disableBuildMessage
|
||||
if (warConfig.keyExists("disableBuildMessage")) {
|
||||
War.war.getWarConfig().put(WarConfig.DISABLEBUILDMESSAGE, warConfig.getBoolean("disableBuildMessage"));
|
||||
}
|
||||
|
||||
// tntInZonesOnly
|
||||
if (warConfig.keyExists("tntInZonesOnly")) {
|
||||
War.war.getWarConfig().put(WarConfig.TNTINZONESONLY, warConfig.getBoolean("tntInZonesOnly"));
|
||||
}
|
||||
|
||||
// defaultSpawnStyle
|
||||
String spawnStyle = warConfig.getString("defaultspawnStyle");
|
||||
if (spawnStyle != null && !spawnStyle.equals("")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.getStyleFromString(spawnStyle));
|
||||
}
|
||||
|
||||
// defaultFlagReturn
|
||||
String flagReturn = warConfig.getString("defaultFlagReturn");
|
||||
if (flagReturn != null && !flagReturn.equals("")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.FLAGRETURN, FlagReturn.getFromString(flagReturn));
|
||||
}
|
||||
|
||||
// defaultReward
|
||||
String defaultRewardStr = warConfig.getString("defaultReward");
|
||||
if (defaultRewardStr != null && !defaultRewardStr.equals("")) {
|
||||
LoadoutTxtMapper.fromStringToLoadout(defaultRewardStr, War.war.getDefaultInventories().getReward());
|
||||
}
|
||||
|
||||
// defaultUnbreakableZoneBlocks
|
||||
if (warConfig.keyExists("defaultUnbreakableZoneBlocks")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.UNBREAKABLE, warConfig.getBoolean("defaultUnbreakableZoneBlocks"));
|
||||
}
|
||||
|
||||
// defaultNoCreatures
|
||||
if (warConfig.keyExists("defaultNoCreatures")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NOCREATURES, warConfig.getBoolean("defaultNoCreatures"));
|
||||
}
|
||||
|
||||
// defaultGlassWalls
|
||||
if (warConfig.keyExists("defaultGlassWalls")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.GLASSWALLS, warConfig.getBoolean("defaultGlassWalls"));
|
||||
}
|
||||
|
||||
// defaultPvpInZone
|
||||
if (warConfig.keyExists("defaultPvpInZone")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.PVPINZONE, warConfig.getBoolean("defaultPvpInZone"));
|
||||
}
|
||||
|
||||
// defaultInstaBreak
|
||||
if (warConfig.keyExists("defaultInstaBreak")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.INSTABREAK, warConfig.getBoolean("defaultInstaBreak"));
|
||||
}
|
||||
|
||||
// defaultNoDrops
|
||||
if (warConfig.keyExists("defaultNoDrops")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.NODROPS, warConfig.getBoolean("defaultNoDrops"));
|
||||
}
|
||||
|
||||
// defaultNoHunger
|
||||
if (warConfig.keyExists("defaultNoHunger")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.NOHUNGER, warConfig.getBoolean("defaultNoHunger"));
|
||||
}
|
||||
|
||||
// defaultSaturation
|
||||
if (warConfig.keyExists("defaultSaturation")) {
|
||||
War.war.getTeamDefaultConfig().put(TeamConfig.SATURATION, warConfig.getInt("defaultSaturation"));
|
||||
}
|
||||
|
||||
// defaultMinPlayers
|
||||
if (warConfig.keyExists("defaultMinPlayers")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINPLAYERS, warConfig.getInt("defaultMinPlayers"));
|
||||
}
|
||||
|
||||
// defaultMinTeams
|
||||
if (warConfig.keyExists("defaultMinTeams")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.MINTEAMS, warConfig.getInt("defaultMinTeams"));
|
||||
}
|
||||
|
||||
// defaultResetOnEmpty
|
||||
if (warConfig.keyExists("defaultResetOnEmpty")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONEMPTY, warConfig.getBoolean("defaultResetOnEmpty"));
|
||||
}
|
||||
|
||||
// defaultResetOnLoad
|
||||
if (warConfig.keyExists("defaultResetOnLoad")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONLOAD, warConfig.getBoolean("defaultResetOnLoad"));
|
||||
}
|
||||
|
||||
// defaultResetOnUnload
|
||||
if (warConfig.keyExists("defaultResetOnUnload")) {
|
||||
War.war.getWarzoneDefaultConfig().put(WarzoneConfig.RESETONUNLOAD, warConfig.getBoolean("defaultResetOnUnload"));
|
||||
}
|
||||
|
||||
// warhub
|
||||
String hubStr = warConfig.getString("warhub");
|
||||
if (hubStr != null && !hubStr.equals("")) {
|
||||
RestoreWarhubJob restoreWarhub = new RestoreWarhubJob(hubStr);
|
||||
if (War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, restoreWarhub) == -1) {
|
||||
War.war.log("Failed to schedule warhub-restore job. War hub was not loaded.", Level.WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
warConfig.close();
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
// PropertiesFile warConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/war.txt");
|
||||
// String warzonesStr = "";
|
||||
|
||||
War.war.log("Saving War with WarTxtMapper", Level.SEVERE);
|
||||
|
||||
// // warzones
|
||||
// for (Warzone zone : War.war.getWarzones()) {
|
||||
// warzonesStr += zone.getName() + ",";
|
||||
// }
|
||||
// warConfig.setString("warzones", warzonesStr);
|
||||
//
|
||||
// // zone makers: default is none and it means everyone can use /setzone
|
||||
// String makersStr = ""; // everyone
|
||||
// for (String name : War.war.getZoneMakerNames()) {
|
||||
// makersStr += name + ",";
|
||||
// }
|
||||
// warConfig.setString("zoneMakers", makersStr);
|
||||
//
|
||||
// // whitelisted commands during a game
|
||||
// String commandWhitelistStr = ""; // everyone
|
||||
// for (String command : War.war.getCommandWhitelist()) {
|
||||
// commandWhitelistStr += command + ",";
|
||||
// }
|
||||
// warConfig.setString("commandWhitelist", commandWhitelistStr);
|
||||
//
|
||||
// // defaultLoadout
|
||||
// HashMap<Integer, ItemStack> items = War.war.getDefaultInventories().getLoadouts().get("default");
|
||||
// warConfig.setString("defaultLoadout", LoadoutTxtMapper.fromLoadoutToString(items));
|
||||
//
|
||||
// // defaultExtraLoadouts
|
||||
// String extraLoadoutsStr = "";
|
||||
// for (String name : War.war.getDefaultInventories().getLoadouts().keySet()) {
|
||||
// if (!name.equals("default")) {
|
||||
// extraLoadoutsStr += name + ",";
|
||||
//
|
||||
// HashMap<Integer, ItemStack> loadout = War.war.getDefaultInventories().getLoadouts().get(name);
|
||||
// warConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout));
|
||||
// }
|
||||
// }
|
||||
// warConfig.setString("defaultExtraLoadouts", extraLoadoutsStr);
|
||||
//
|
||||
// // maxZones
|
||||
// warConfig.setInt("maxZones", War.war.getWarConfig().getInt(WarConfig.MAXZONES));
|
||||
//
|
||||
// // defaultLifepool
|
||||
// warConfig.setInt("defaultLifePool", War.war.getDefaultLifepool());
|
||||
//
|
||||
// // defaultMonumentHeal
|
||||
// warConfig.setInt("defaultMonumentHeal", War.war.getDefaultMonumentHeal());
|
||||
//
|
||||
// // defaultFriendlyFire
|
||||
// warConfig.setBoolean("defaultFriendlyFire", War.war.isDefaultFriendlyFire());
|
||||
//
|
||||
// // defaultAutoAssignOnly
|
||||
// warConfig.setBoolean("defaultAutoAssignOnly", War.war.isDefaultAutoAssignOnly());
|
||||
//
|
||||
// // defaultFlagPointsOnly
|
||||
// warConfig.setBoolean("defaultFlagPointsOnly", War.war.isDefaultFlagPointsOnly());
|
||||
//
|
||||
// // defaultFlagMustBeHome
|
||||
// warConfig.setBoolean("defaultFlagMustBeHome", War.war.isDefaultFlagMustBeHome());
|
||||
//
|
||||
// // defaultTeamCap
|
||||
// warConfig.setInt("defaultTeamCap", War.war.getDefaultTeamCap());
|
||||
//
|
||||
// // defaultScoreCap
|
||||
// warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap());
|
||||
//
|
||||
// // defaultRespawnTimer
|
||||
// warConfig.setInt("defaultRespawnTimer", War.war.getDefaultRespawnTimer());
|
||||
//
|
||||
// // pvpInZonesOnly
|
||||
// warConfig.setBoolean("pvpInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.PVPINZONESONLY));
|
||||
//
|
||||
// // defaultBlockHeads
|
||||
// warConfig.setBoolean("defaultBlockHeads", War.war.isDefaultBlockHeads());
|
||||
//
|
||||
// // buildInZonesOnly
|
||||
// warConfig.setBoolean("buildInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY));
|
||||
//
|
||||
// // disablePVPMessage
|
||||
// warConfig.setBoolean("disablePvpMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE));
|
||||
//
|
||||
// // disableBuildMessage
|
||||
// warConfig.setBoolean("disableBuildMessage", War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE));
|
||||
//
|
||||
// // tntInZonesOnly
|
||||
// warConfig.setBoolean("tntInZonesOnly", War.war.getWarConfig().getBoolean(WarConfig.TNTINZONESONLY));
|
||||
//
|
||||
// // spawnStyle
|
||||
// warConfig.setString("spawnStyle", War.war.getDefaultSpawnStyle().toString());
|
||||
//
|
||||
// // flagReturn
|
||||
// warConfig.setString("flagReturn", War.war.getDefaultFlagReturn().toString());
|
||||
//
|
||||
// // defaultReward
|
||||
// String defaultRewardStr = "";
|
||||
// HashMap<Integer, ItemStack> rewardItems = War.war.getDefaultInventories().getReward();
|
||||
// for (Integer slot : rewardItems.keySet()) {
|
||||
// ItemStack item = items.get(slot);
|
||||
// if (item != null) {
|
||||
// defaultRewardStr += item.getTypeId() + "," + item.getAmount() + "," + slot + ";";
|
||||
// }
|
||||
// }
|
||||
// warConfig.setString("defaultReward", defaultRewardStr);
|
||||
//
|
||||
// // defaultUnbreakableZoneBlocks
|
||||
// warConfig.setBoolean("defaultUnbreakableZoneBlocks", War.war.isDefaultUnbreakableZoneBlocks());
|
||||
//
|
||||
// // defaultNoCreatures
|
||||
// warConfig.setBoolean("defaultNoCreatures", War.war.isDefaultNoCreatures());
|
||||
//
|
||||
// // defaultGlassWalls
|
||||
// warConfig.setBoolean("defaultGlassWalls", War.war.isDefaultGlassWalls());
|
||||
//
|
||||
// // defaultPvpInZone
|
||||
// warConfig.setBoolean("defaultPvpInZone", War.war.isDefaultPvpInZone());
|
||||
//
|
||||
// // defaultInstaBreak
|
||||
// warConfig.setBoolean("defaultInstaBreak", War.war.isDefaultInstaBreak());
|
||||
//
|
||||
// // defaultNoDrops
|
||||
// warConfig.setBoolean("defaultNoDrops", War.war.isDefaultNoDrops());
|
||||
//
|
||||
// // defaultNoHunger
|
||||
// warConfig.setBoolean("defaultNoHunger", War.war.isDefaultNoHunger());
|
||||
//
|
||||
// // defaultSaturation
|
||||
// warConfig.setInt("defaultSaturation", War.war.getDefaultSaturation());
|
||||
//
|
||||
// // defaultMinPlayers
|
||||
// warConfig.setInt("defaultMinPlayers", War.war.getDefaultMinPlayers());
|
||||
//
|
||||
// // defaultMinTeams
|
||||
// warConfig.setInt("defaultMinTeams", War.war.getDefaultMinTeams());
|
||||
//
|
||||
// // defaultResetOnEmpty
|
||||
// warConfig.setBoolean("defaultResetOnEmpty", War.war.isDefaultResetOnEmpty());
|
||||
//
|
||||
// // defaultResetOnLoad
|
||||
// warConfig.setBoolean("defaultResetOnLoad", War.war.isDefaultResetOnLoad());
|
||||
//
|
||||
// // defaultResetOnUnload
|
||||
// warConfig.setBoolean("defaultResetOnUnload", War.war.isDefaultResetOnUnload());
|
||||
//
|
||||
// // warhub
|
||||
// String hubStr = "";
|
||||
// WarHub hub = War.war.getWarHub();
|
||||
// if (hub != null) {
|
||||
// String orientationStr = "";
|
||||
// switch (hub.getOrientation()) {
|
||||
// case SOUTH:
|
||||
// orientationStr = "south";
|
||||
// break;
|
||||
// case EAST:
|
||||
// orientationStr = "east";
|
||||
// break;
|
||||
// case NORTH:
|
||||
// orientationStr = "north";
|
||||
// break;
|
||||
// case WEST:
|
||||
// default:
|
||||
// orientationStr = "west";
|
||||
// break;
|
||||
// }
|
||||
// hubStr = hub.getLocation().getBlockX() + "," + hub.getLocation().getBlockY() + "," + hub.getLocation().getBlockZ() + ","
|
||||
// + hub.getLocation().getWorld().getName() + "," + orientationStr;
|
||||
// VolumeMapper.save(hub.getVolume(), "");
|
||||
// }
|
||||
// warConfig.setString("warhub", hubStr);
|
||||
//
|
||||
// warConfig.save();
|
||||
// warConfig.close();
|
||||
}
|
||||
}
|
@ -32,9 +32,8 @@ public class WarYmlMapper {
|
||||
|
||||
boolean newWar = false;
|
||||
if (warTxtFile.exists() && !warYmlFile.exists()) {
|
||||
// Load both War and warzones (with delay) in old format, save War to new format immediatly
|
||||
WarTxtMapper.load(true);
|
||||
// Warzones are getting loaded by TxtMapper launched job. That job will in turn save the Warzones to their new format.
|
||||
// dropped nimitz compatibility with the MC 1.13 update
|
||||
War.war.log("Failed to load War config file from older version - backwards compatibility was dropped with MC 1.13. Please delete war.txt to continue.", Level.WARNING);
|
||||
return;
|
||||
} else if (!warTxtFile.exists() && !warYmlFile.exists()) {
|
||||
// Save defaults to disk
|
||||
|
@ -1,657 +0,0 @@
|
||||
package com.tommytony.war.mapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.config.FlagReturn;
|
||||
import com.tommytony.war.config.TeamConfig;
|
||||
import com.tommytony.war.config.TeamKind;
|
||||
import com.tommytony.war.config.TeamSpawnStyle;
|
||||
import com.tommytony.war.config.WarzoneConfig;
|
||||
import com.tommytony.war.structure.Monument;
|
||||
import com.tommytony.war.structure.ZoneLobby;
|
||||
import com.tommytony.war.utility.Direction;
|
||||
import com.tommytony.war.volume.Volume;
|
||||
import com.tommytony.war.volume.ZoneVolume;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tommytony
|
||||
*
|
||||
*/
|
||||
public class WarzoneTxtMapper {
|
||||
|
||||
public static Warzone load(String name, boolean createNewVolume) {
|
||||
// war.getLogger().info("Loading warzone " + name + " config and blocks...");
|
||||
PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
try {
|
||||
warzoneConfig.load();
|
||||
} catch (IOException e) {
|
||||
War.war.getLogger().info("Failed to load warzone-" + name + ".txt file.");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// create the lobby
|
||||
Volume lobbyVolume = null;
|
||||
try {
|
||||
lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
|
||||
} catch (SQLException e) {
|
||||
// if the zone is this old is there any reason the lobby should be nimitz format
|
||||
War.war.getLogger().log(Level.WARNING, "Failed to load lobby for a really old warzone", e);
|
||||
}
|
||||
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
|
||||
warzone.setLobby(lobby);
|
||||
}
|
||||
}
|
||||
|
||||
return warzone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save(Warzone warzone, boolean saveAllBlocks) {
|
||||
|
||||
War.war.log("Saving War with WarzoneTxtMapper", Level.SEVERE);
|
||||
// (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + warzone.getName())).mkdir();
|
||||
// PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + warzone.getName() + ".txt");
|
||||
// // war.getLogger().info("Saving warzone " + warzone.getName() + "...");
|
||||
//
|
||||
// // name
|
||||
// warzoneConfig.setString("name", warzone.getName());
|
||||
//
|
||||
// // world
|
||||
// warzoneConfig.setString("world", warzone.getWorld().getName()); // default for now
|
||||
//
|
||||
// // teleport
|
||||
// String teleportStr = "";
|
||||
// Location tele = warzone.getTeleport();
|
||||
// if (tele != null) {
|
||||
// int intYaw = 0;
|
||||
// if (tele.getYaw() >= 0) {
|
||||
// intYaw = (int) (tele.getYaw() % 360);
|
||||
// } else {
|
||||
// intYaw = (int) (360 + (tele.getYaw() % 360));
|
||||
// }
|
||||
// teleportStr = tele.getBlockX() + "," + tele.getBlockY() + "," + tele.getBlockZ() + "," + intYaw;
|
||||
// }
|
||||
// warzoneConfig.setString("teleport", teleportStr);
|
||||
//
|
||||
// // teams
|
||||
// String teamsStr = "";
|
||||
// List<Team> teams = warzone.getTeams();
|
||||
// for (Team team : teams) {
|
||||
// Location spawn = team.getTeamSpawn();
|
||||
// int intYaw = 0;
|
||||
// if (spawn.getYaw() >= 0) {
|
||||
// intYaw = (int) (spawn.getYaw() % 360);
|
||||
// } else {
|
||||
// intYaw = (int) (360 + (spawn.getYaw() % 360));
|
||||
// }
|
||||
// teamsStr += team.getName() + "," + spawn.getBlockX() + "," + spawn.getBlockY() + "," + spawn.getBlockZ() + "," + intYaw + ";";
|
||||
// }
|
||||
// warzoneConfig.setString("teams", teamsStr);
|
||||
//
|
||||
// // team flags
|
||||
// String teamFlagsStr = "";;
|
||||
// for (Team team : teams) {
|
||||
// if (team.getFlagVolume() != null) {
|
||||
// Location flag = team.getTeamFlag();
|
||||
// int intYaw = 0;
|
||||
// if (flag.getYaw() >= 0) {
|
||||
// intYaw = (int) (flag.getYaw() % 360);
|
||||
// } else {
|
||||
// intYaw = (int) (360 + (flag.getYaw() % 360));
|
||||
// }
|
||||
// teamFlagsStr += team.getName() + "," + flag.getBlockX() + "," + flag.getBlockY() + "," + flag.getBlockZ() + "," + intYaw + ";";
|
||||
// }
|
||||
// }
|
||||
// warzoneConfig.setString("teamFlags", teamFlagsStr);
|
||||
//
|
||||
// // ff
|
||||
// warzoneConfig.setBoolean("friendlyFire", warzone.getFriendlyFire());
|
||||
//
|
||||
// // loadout
|
||||
// HashMap<Integer, ItemStack> items = warzone.getDefaultInventories().getLoadouts().get("default");
|
||||
// warzoneConfig.setString("loadout", LoadoutTxtMapper.fromLoadoutToString(items));
|
||||
//
|
||||
// // defaultExtraLoadouts
|
||||
// String extraLoadoutsStr = "";
|
||||
// for (String name : warzone.getDefaultInventories().getLoadouts().keySet()) {
|
||||
// if (!name.equals("default")) {
|
||||
// extraLoadoutsStr += name + ",";
|
||||
//
|
||||
// HashMap<Integer, ItemStack> loadout = warzone.getDefaultInventories().getLoadouts().get(name);
|
||||
// warzoneConfig.setString(name + "Loadout", LoadoutTxtMapper.fromLoadoutToString(loadout));
|
||||
// }
|
||||
// }
|
||||
// warzoneConfig.setString("extraLoadouts", extraLoadoutsStr);
|
||||
//
|
||||
// // authors
|
||||
// warzoneConfig.setString("author", warzone.getAuthorsString());
|
||||
//
|
||||
// // life pool
|
||||
// warzoneConfig.setInt("lifePool", warzone.getLifePool());
|
||||
//
|
||||
// // monument heal
|
||||
// warzoneConfig.setInt("monumentHeal", warzone.getMonumentHeal());
|
||||
//
|
||||
// // autoAssignOnly
|
||||
// warzoneConfig.setBoolean("autoAssignOnly", warzone.isAutoAssignOnly());
|
||||
//
|
||||
// // flagPointsOnly
|
||||
// warzoneConfig.setBoolean("flagPointsOnly", warzone.isFlagPointsOnly());
|
||||
//
|
||||
// // flagMustBeHome
|
||||
// warzoneConfig.setBoolean("flagMustBeHome", warzone.isFlagMustBeHome());
|
||||
//
|
||||
// // team cap
|
||||
// warzoneConfig.setInt("teamCap", warzone.getTeamCap());
|
||||
//
|
||||
// // score cap
|
||||
// warzoneConfig.setInt("scoreCap", warzone.getScoreCap());
|
||||
//
|
||||
// // respawn timer
|
||||
// warzoneConfig.setInt("respawnTimer", warzone.getRespawnTimer());
|
||||
//
|
||||
// // blockHeads
|
||||
// warzoneConfig.setBoolean("blockHeads", warzone.isBlockHeads());
|
||||
//
|
||||
// // spawnStyle
|
||||
// warzoneConfig.setString("spawnStyle", warzone.getSpawnStyle().toString());
|
||||
//
|
||||
// // flagReturn
|
||||
// warzoneConfig.setString("flagReturn", warzone.getFlagReturn().toString());
|
||||
//
|
||||
// // reward
|
||||
// HashMap<Integer, ItemStack> rewardItems = warzone.getDefaultInventories().getReward();
|
||||
// warzoneConfig.setString("reward", LoadoutTxtMapper.fromLoadoutToString(rewardItems));
|
||||
//
|
||||
// // unbreakableZoneBlocks
|
||||
// warzoneConfig.setBoolean("unbreakableZoneBlocks", warzone.isUnbreakableZoneBlocks());
|
||||
//
|
||||
// // disabled
|
||||
// warzoneConfig.setBoolean("disabled", warzone.isDisabled());
|
||||
//
|
||||
// // noCreatures
|
||||
// warzoneConfig.setBoolean("noCreatures", warzone.isNoCreatures());
|
||||
//
|
||||
// // glassWalls
|
||||
// warzoneConfig.setBoolean("glassWalls", warzone.isGlassWalls());
|
||||
//
|
||||
// // pvpInZone
|
||||
// warzoneConfig.setBoolean("pvpInZone", warzone.isPvpInZone());
|
||||
//
|
||||
// // instaBreak
|
||||
// warzoneConfig.setBoolean("instaBreak", warzone.isInstaBreak());
|
||||
//
|
||||
// // noDrops
|
||||
// warzoneConfig.setBoolean("noDrops", warzone.isNoDrops());
|
||||
//
|
||||
// // noHunger
|
||||
// warzoneConfig.setBoolean("noHunger", warzone.isNoHunger());
|
||||
//
|
||||
// // saturation
|
||||
// warzoneConfig.setInt("saturation", warzone.getSaturation());
|
||||
//
|
||||
// // minPlayers
|
||||
// warzoneConfig.setInt("minPlayers", warzone.getMinPlayers());
|
||||
//
|
||||
// // minTeams
|
||||
// warzoneConfig.setInt("minTeams", warzone.getMinTeams());
|
||||
//
|
||||
// // resetOnEmpty
|
||||
// warzoneConfig.setBoolean("resetOnEmpty", warzone.isResetOnEmpty());
|
||||
//
|
||||
// // resetOnLoad
|
||||
// warzoneConfig.setBoolean("resetOnLoad", warzone.isResetOnLoad());
|
||||
//
|
||||
// // resetOnUnload
|
||||
// warzoneConfig.setBoolean("resetOnUnload", warzone.isResetOnUnload());
|
||||
//
|
||||
// // rallyPoint
|
||||
// String rpStr = "";
|
||||
// Location rp = warzone.getRallyPoint();
|
||||
// if (rp != null) {
|
||||
// rpStr = rp.getBlockX() + "," + rp.getBlockY() + "," + rp.getBlockZ();
|
||||
// }
|
||||
// warzoneConfig.setString("rallyPoint", rpStr);
|
||||
//
|
||||
// // defaultDropLootOnDeath
|
||||
// // warzoneConfig.setBoolean("dropLootOnDeath", warzone.isDropLootOnDeath());
|
||||
//
|
||||
// // monuments
|
||||
// String monumentsStr = "";
|
||||
// List<Monument> monuments = warzone.getMonuments();
|
||||
// for (Monument monument : monuments) {
|
||||
// Location monumentLoc = monument.getLocation();
|
||||
// monumentsStr += monument.getName() + "," + monumentLoc.getBlockX() + "," + monumentLoc.getBlockY() + "," + monumentLoc.getBlockZ() + ";";
|
||||
// }
|
||||
// warzoneConfig.setString("monuments", monumentsStr);
|
||||
//
|
||||
// // lobby
|
||||
// String lobbyStr = "";
|
||||
// if (warzone.getLobby() != null) {
|
||||
// if (Direction.SOUTH() == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "south";
|
||||
// } else if (Direction.EAST() == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "east";
|
||||
// } else if (Direction.NORTH() == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "north";
|
||||
// } else if (Direction.WEST() == warzone.getLobby().getWall()) {
|
||||
// lobbyStr = "west";
|
||||
// }
|
||||
// }
|
||||
// warzoneConfig.setString("lobby", lobbyStr + "," + warzone.getLobby().getVolume().getWorld().getName());
|
||||
//
|
||||
// warzoneConfig.save();
|
||||
// warzoneConfig.close();
|
||||
//
|
||||
// // monument blocks
|
||||
// for (Monument monument : monuments) {
|
||||
// VolumeMapper.save(monument.getVolume(), warzone.getName());
|
||||
// }
|
||||
//
|
||||
// // team spawn & flag blocks
|
||||
// for (Team team : teams) {
|
||||
// VolumeMapper.save(team.getSpawnVolume(), warzone.getName());
|
||||
// if (team.getFlagVolume() != null) {
|
||||
// VolumeMapper.save(team.getFlagVolume(), warzone.getName());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (warzone.getLobby() != null) {
|
||||
// VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
|
||||
// }
|
||||
}
|
||||
|
||||
public static void delete(String name) {
|
||||
File zoneFolder = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + name);
|
||||
File[] files = zoneFolder.listFiles();
|
||||
for (File file : files) {
|
||||
boolean deletedData = file.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + file.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
boolean deletedData = zoneFolder.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete folder " + zoneFolder.getName(), Level.WARNING);
|
||||
}
|
||||
File zoneFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
deletedData = zoneFile.delete();
|
||||
if (!deletedData) {
|
||||
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,18 +30,15 @@ import com.tommytony.war.volume.ZoneVolume;
|
||||
|
||||
public class WarzoneYmlMapper {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Warzone load(String name) { // removed createNewVolume, as it did nothing
|
||||
File warzoneTxtFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".txt");
|
||||
File warzoneYmlFile = new File(War.war.getDataFolder().getPath() + "/warzone-" + name + ".yml");
|
||||
|
||||
// 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);
|
||||
// dropped nimitz compatibility with the MC 1.13 update
|
||||
War.war.log("Failed to load Warzone " + name + " - backwards compatibility was dropped with MC 1.13. Please delete this zone to continue.", Level.WARNING);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!warzoneYmlFile.exists()) {
|
||||
@ -385,50 +382,18 @@ public class WarzoneYmlMapper {
|
||||
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
|
||||
@ -449,38 +414,14 @@ public class WarzoneYmlMapper {
|
||||
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 {
|
||||
connection.close();
|
||||
|
@ -56,10 +56,8 @@ public class ZoneVolumeMapper {
|
||||
public static Connection getZoneConnection(ZoneVolume volume, String zoneName, World world) throws SQLException {
|
||||
File databaseFile = new File(War.war.getDataFolder(), String.format("/dat/warzone-%s/volume-%s.sl3", zoneName, volume.getName()));
|
||||
if (!databaseFile.exists()) {
|
||||
// Convert warzone to nimitz file format.
|
||||
PreNimitzZoneVolumeMapper.load(volume, zoneName, world, false);
|
||||
ZoneVolumeMapper.save(volume, zoneName);
|
||||
War.war.log("Warzone " + zoneName + " converted to nimitz format!", Level.INFO);
|
||||
// dropped nimitz compatibility with the MC 1.13 update
|
||||
War.war.log("Warzone " + zoneName + " not found - creating new file. Will not attempt converting legacy War version formats.", Level.WARNING);
|
||||
}
|
||||
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
|
||||
Statement stmt = databaseConnection.createStatement();
|
||||
|
Loading…
Reference in New Issue
Block a user