Merge pull request #684 from taoneill/nimitz-file-format-r3

Nimitz file format. Support for custom blocks. Old warzone volume files get converted to .sl3 when you first run your server with these changes - this may take a while if you have many warzones.

Thanks @cmastudios for all the hard work on these changes.
This commit is contained in:
taoneill 2013-10-23 21:45:41 -07:00
commit df6f47907f
32 changed files with 1549 additions and 2022 deletions

View File

@ -39,6 +39,9 @@
<url>http://ci.tommytony.com</url>
</ciManagement>
<scm>
<connection>scm:git:git://github.com/taoneill/war.git</connection>
<developerConnection>scm:git:git@github.com:taoneill/war.git</developerConnection>
<tag>HEAD</tag>
<url>https://github.com/taoneill/war</url>
</scm>
<build>

View File

@ -36,7 +36,6 @@ import com.tommytony.war.config.TeamSpawnStyle;
import com.tommytony.war.structure.Bomb;
import com.tommytony.war.structure.Cake;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -581,19 +580,13 @@ public class Team {
public void initializeTeamFlag() {
// make air (old two-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.flagVolume.getCornerOne().getX(),
this.flagVolume.getCornerOne().getY() + 1,
this.flagVolume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.flagVolume.getCornerTwo().getX(),
this.flagVolume.getCornerOne().getY() + 2,
this.flagVolume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.flagVolume.getWorld(),
this.flagVolume.getCornerOne().getX(), this.flagVolume
.getCornerOne().getY() + 1, this.flagVolume
.getCornerOne().getZ()), new Location(
this.flagVolume.getWorld(), this.flagVolume.getCornerTwo()
.getX(), this.flagVolume.getCornerOne().getY() + 2,
this.flagVolume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
// Set the flag blocks

View File

@ -151,6 +151,13 @@ public class War extends JavaPlugin {
} catch (ClassNotFoundException e) {
isSpoutServer = false;
}
try {
Class.forName("org.sqlite.JDBC").newInstance();
} catch (Exception e) {
this.log("SQLite3 driver not found!", Level.SEVERE);
this.getServer().getPluginManager().disablePlugin(this);
return;
}
// Register events
PluginManager pm = this.getServer().getPluginManager();
@ -176,6 +183,7 @@ public class War extends JavaPlugin {
warConfig.put(WarConfig.MAXZONES, 12);
warConfig.put(WarConfig.PVPINZONESONLY, false);
warConfig.put(WarConfig.TNTINZONESONLY, false);
warConfig.put(WarConfig.RESETSPEED, 5000);
warzoneDefaultConfig.put(WarzoneConfig.AUTOASSIGN, false);
warzoneDefaultConfig.put(WarzoneConfig.BLOCKHEADS, true);

View File

@ -62,7 +62,6 @@ import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.LoadoutSelection;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.PotionEffectHelper;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
@ -253,11 +252,11 @@ public class Warzone {
}
}
int saved = this.volume.saveBlocks();
this.volume.saveBlocks();
if (clearArtifacts) {
this.initializeZone(); // bring back stuff
}
return saved;
return this.volume.size();
}
return 0;
}
@ -1102,7 +1101,6 @@ public class Warzone {
public void reinitialize() {
this.isReinitializing = true;
this.getVolume().resetBlocksAsJob();
this.initializeZoneAsJob();
}
public void handlePlayerLeave(Player player, Location destination, PlayerMoveEvent event, boolean removeFromTeam) {
@ -1556,10 +1554,15 @@ public class Warzone {
for (Team maybeOpponent : this.getTeams()) {
if (maybeOpponent != team) {
for (Volume teamSpawnVolume : maybeOpponent.getSpawnVolumes().values()) {
Volume periphery = new Volume("periphery", this.getWorld());
periphery.setCornerOne(new BlockInfo(teamSpawnVolume.getMinX()-1 , teamSpawnVolume.getMinY()-1, teamSpawnVolume.getMinZ()-1, 0, (byte)0));
periphery.setCornerTwo(new BlockInfo(teamSpawnVolume.getMaxX()+1, teamSpawnVolume.getMaxY()+1, teamSpawnVolume.getMaxZ()+1, 0, (byte)0));
Volume periphery = new Volume(new Location(
teamSpawnVolume.getWorld(),
teamSpawnVolume.getMinX() - 1,
teamSpawnVolume.getMinY() - 1,
teamSpawnVolume.getMinZ() - 1), new Location(
teamSpawnVolume.getWorld(),
teamSpawnVolume.getMaxX() + 1,
teamSpawnVolume.getMaxY() + 1,
teamSpawnVolume.getMaxZ() + 1));
if (periphery.contains(block)) {
return true;
}

View File

@ -1,6 +1,7 @@
package com.tommytony.war.command;
import java.io.File;
import java.sql.SQLException;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
@ -79,9 +80,18 @@ public class RenameZoneCommand extends AbstractZoneMakerCommand {
War.war.log("Loading zone " + newName + "...", Level.INFO);
Warzone newZone = WarzoneYmlMapper.load(newName, false);
War.war.getWarzones().add(newZone);
newZone.getVolume().loadCorners();
zone.getVolume().loadCorners();
try {
newZone.getVolume().loadCorners();
} catch (SQLException ex) {
War.war.log("Failed to load warzone " + newZone.getName() + ": " + ex.getMessage(), Level.WARNING);
throw new RuntimeException(ex);
}
try {
zone.getVolume().loadCorners();
} catch (SQLException ex) {
War.war.log("Failed to load warzone " + zone.getName() + ": " + ex.getMessage(), Level.WARNING);
throw new RuntimeException(ex);
}
if (zone.getLobby() != null) {
zone.getLobby().getVolume().resetBlocks();
}

View File

@ -41,7 +41,7 @@ public class ZoneSetter {
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
warzone.addAuthor(player.getName());
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setNorthwest(northwestBlock);
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its nw corner", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
@ -49,7 +49,7 @@ public class ZoneSetter {
} else {
// change existing warzone
this.resetWarzone(warzone, msgString);
warzone.getVolume().setNorthwest(northwestBlock);
warzone.getVolume().setNorthwest(northwestBlock.getLocation());
msgString.append("Warzone " + warzone.getName() + " modified. Northwesternmost point set to x:" + warzone.getVolume().getNorthwestX() + " z:" + warzone.getVolume().getNorthwestZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its nw corner", Level.INFO);
}
@ -86,7 +86,7 @@ public class ZoneSetter {
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
warzone.addAuthor(player.getName());
War.war.getIncompleteZones().add(warzone);
warzone.getVolume().setSoutheast(southeastBlock);
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
War.war.msg(this.player, "Warzone " + warzone.getName() + " created. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its se corner", Level.INFO);
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
@ -94,7 +94,7 @@ public class ZoneSetter {
} else {
// change existing warzone
this.resetWarzone(warzone, msgString);
warzone.getVolume().setSoutheast(southeastBlock);
warzone.getVolume().setSoutheast(southeastBlock.getLocation());
msgString.append("Warzone " + warzone.getName() + " modified. Southeasternmost point set to x:" + warzone.getVolume().getSoutheastX() + " z:" + warzone.getVolume().getSoutheastZ() + ". ");
War.war.log(player.getName() + " updated warzone " + zoneName + " by setting its se corner", Level.INFO);
}
@ -220,8 +220,8 @@ public class ZoneSetter {
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
warzone.getLobby().getVolume().resetBlocks();
}
int reset = warzone.getVolume().resetBlocks();
msgString.append(reset + " blocks reset. ");
warzone.getVolume().resetBlocks();
msgString.append(warzone.getVolume().size() + " blocks reset. ");
}
}

View File

@ -8,7 +8,8 @@ public enum WarConfig {
KEEPOLDZONEVERSIONS (Boolean.class),
MAXZONES (Integer.class),
PVPINZONESONLY (Boolean.class),
TNTINZONESONLY (Boolean.class);
TNTINZONESONLY (Boolean.class),
RESETSPEED (Integer.class);
private final Class<?> configType;

View File

@ -0,0 +1,85 @@
package com.tommytony.war.job;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.logging.Level;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.volume.ZoneVolume;
public class PartialZoneResetJob extends BukkitRunnable implements Cloneable {
private final Warzone zone;
private final ZoneVolume volume;
private final int speed;
private final int total;
private int completed = 0;
private final long startTime = System.currentTimeMillis();
private long messageCounter = System.currentTimeMillis();
public static final long MESSAGE_INTERVAL = 3000;
// Ticks between job runs
public static final int JOB_INTERVAL = 1;
/**
* Reset a warzone's blocks at a certain speed.
*
* @param volume
* Warzone to reset.
* @param speed
* Blocks to modify per #INTERVAL.
*/
public PartialZoneResetJob(Warzone zone, int speed) {
this.zone = zone;
this.volume = zone.getVolume();
this.speed = speed;
this.total = volume.size();
}
@Override
public void run() {
try {
volume.resetSection(completed, speed);
completed += speed;
if (completed < total) {
if (System.currentTimeMillis() - messageCounter > MESSAGE_INTERVAL) {
messageCounter = System.currentTimeMillis();
int percent = (int) (((double) completed / (double) total) * 100);
long seconds = (System.currentTimeMillis() - startTime) / 1000;
String message = MessageFormat.format(
War.war.getString("zone.battle.resetprogress"),
percent, seconds);
for (Player player : War.war.getServer().getOnlinePlayers()) {
ZoneLobby lobby = ZoneLobby.getLobbyByLocation(player);
if (zone.getPlayers().contains(player)
|| (lobby != null && lobby.getZone() == zone)) {
War.war.msg(player, message);
}
}
}
War.war.getServer().getScheduler()
.runTaskLater(War.war, this.clone(), JOB_INTERVAL);
} else {
zone.initializeZone();
War.war.getLogger().info(
"Finished reset cycle for warzone " + volume.getName());
}
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING,
"Failed to load zone during reset loop", e);
}
}
@Override
protected PartialZoneResetJob clone() {
try {
return (PartialZoneResetJob) super.clone();
} catch (CloneNotSupportedException e) {
throw new Error(e);
}
}
}

View File

@ -1,5 +1,6 @@
package com.tommytony.war.job;
import java.sql.SQLException;
import java.util.logging.Level;
import org.bukkit.Location;
@ -43,7 +44,12 @@ public class RestoreWarhubJob implements Runnable {
Location hubLocation = new Location(world, hubX, hubY, hubZ);
WarHub hub = new WarHub(hubLocation, hubOrientation);
War.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", world);
Volume vol;
try {
vol = VolumeMapper.loadVolume("warhub", "", world);
} catch (SQLException e) {
throw new RuntimeException(e);
}
hub.setVolume(vol);
hub.getVolume().resetBlocks();
hub.initialize();

View File

@ -1,8 +1,8 @@
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;
@ -32,7 +32,12 @@ public class RestoreWarzonesJob implements Runnable {
Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall);
if (zone != null) { // could have failed, would've been logged already
War.war.getWarzones().add(zone);
zone.getVolume().loadCorners();
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();

View File

@ -1,5 +1,6 @@
package com.tommytony.war.job;
import java.sql.SQLException;
import java.util.logging.Level;
import org.bukkit.Location;
@ -84,7 +85,12 @@ public class RestoreYmlWarhubJob implements Runnable {
Location hubLocation = new Location(world, hubX, hubY, hubZ);
WarHub hub = new WarHub(hubLocation, hubOrientation);
War.war.setWarHub(hub);
Volume vol = VolumeMapper.loadVolume("warhub", "", world);
Volume vol;
try {
vol = VolumeMapper.loadVolume("warhub", "", world);
} catch (SQLException e) {
throw new RuntimeException(e);
}
hub.setVolume(vol);
hub.getVolume().resetBlocks();
hub.initialize();

View File

@ -1,9 +1,9 @@
package com.tommytony.war.job;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarzoneConfig;
@ -28,8 +28,12 @@ public class RestoreYmlWarzonesJob implements Runnable {
Warzone zone = WarzoneYmlMapper.load(warzoneName, !this.newWarInstall);
if (zone != null) { // could have failed, would've been logged already
War.war.getWarzones().add(zone);
zone.getVolume().loadCorners();
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();
}

View File

@ -1,9 +1,15 @@
package com.tommytony.war.job;
import com.tommytony.war.War;
import com.tommytony.war.mapper.ZoneVolumeMapper;
import com.tommytony.war.volume.Volume;
public class ZoneVolumeSaveJob extends Thread {
import java.sql.SQLException;
import java.util.logging.Level;
import org.bukkit.scheduler.BukkitRunnable;
public class ZoneVolumeSaveJob extends BukkitRunnable {
private final Volume volume;
private final String zoneName;
@ -14,6 +20,10 @@ public class ZoneVolumeSaveJob extends Thread {
@Override
public void run() {
ZoneVolumeMapper.save(this.volume, this.zoneName);
try {
ZoneVolumeMapper.save(this.volume, this.zoneName);
} catch (SQLException ex) {
War.war.log(ex.getMessage(), Level.SEVERE);
}
}
}

View File

@ -7,27 +7,9 @@ import org.bukkit.inventory.ItemStack;
import com.tommytony.war.War;
@SuppressWarnings("deprecation")
public class LoadoutTxtMapper {
public static String fromLoadoutToString(HashMap<Integer, ItemStack> loadout) {
String loadoutString = "";
for (Integer slot : loadout.keySet()) {
ItemStack item = loadout.get(slot);
if (item != null) {
loadoutString += item.getTypeId() + "," + item.getAmount() + "," + slot + "," + item.getDurability() + "," + item.getData().getData();
if (item.getEnchantments().keySet().size() > 0) {
String enchantmentsStr = "";
for (Enchantment enchantment : item.getEnchantments().keySet()) {
enchantmentsStr += enchantment.getId() + ":" + item.getEnchantments().get(enchantment) + "::";
}
loadoutString += "," + enchantmentsStr;
}
}
loadoutString += ";";
}
return loadoutString;
}
public static void fromStringToLoadout(String loadoutString, HashMap<Integer, ItemStack> destinationLoadout) {
String[] rewardStrSplit = loadoutString.split(";");
destinationLoadout.clear();

View File

@ -1,10 +1,8 @@
package com.tommytony.war.mapper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -17,15 +15,12 @@ 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 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.Volume;
import com.tommytony.war.volume.ZoneVolume;
/**
@ -34,6 +29,7 @@ import com.tommytony.war.volume.ZoneVolume;
* @author tommytony
*
*/
@SuppressWarnings("deprecation")
public class PreDeGaulleZoneVolumeMapper {
private static List<ItemStack> readInventoryString(String invString) {
@ -283,151 +279,4 @@ public class PreDeGaulleZoneVolumeMapper {
}
return noOfResetBlocks;
}
public static int save(Volume volume, String zoneName, War war) {
int noOfSavedBlocks = 0;
if (volume.hasTwoCorners()) {
BufferedWriter out = null;
try {
(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
if (zoneName.equals("")) {
out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
} else {
out = new BufferedWriter(new FileWriter(new File(war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
}
out.write("corner1");
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getX()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getY()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getZ()));
out.newLine();
out.write("corner2");
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getX()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getY()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getZ()));
out.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();
out.write(typeId + "," + data + ",");
if (state instanceof Sign) {
// Signs
String extra = "";
Sign sign = (Sign) state;
if (sign.getLines() != null) {
for (String line : sign.getLines()) {
extra += line + ";;";
}
out.write(extra);
}
} else if (state instanceof Chest) {
// Chests
Chest chest = (Chest) state;
Inventory inv = chest.getInventory();
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);
}
}
String extra = "";
if (items != null) {
for (ItemStack item : items) {
if (item != null) {
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
if (item.getData() != null) {
extra += ";" + item.getData().getData();
}
extra += ";;";
}
}
out.write(extra);
}
} else if (state instanceof Dispenser) {
// Dispensers
Dispenser dispenser = (Dispenser) state;
Inventory inv = dispenser.getInventory();
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);
}
}
String extra = "";
if (items != null) {
for (ItemStack item : items) {
if (item != null) {
extra += item.getTypeId() + ";" + item.getAmount() + ";" + item.getDurability();
if (item.getData() != null) {
extra += ";" + item.getData().getData();
}
extra += ";;";
}
}
out.write(extra);
}
}
noOfSavedBlocks++;
out.newLine();
} catch (Exception e) {
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.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
} catch (Exception e) {
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 {
if (out != null) {
try {
out.close();
} catch (IOException e) {
war.log("Failed to close file writer for volume " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
}
}
return noOfSavedBlocks;
}
}

View File

@ -0,0 +1,459 @@
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);
}
}
}
}

View File

@ -1,23 +1,31 @@
package com.tommytony.war.mapper;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
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 org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
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;
@ -28,13 +36,67 @@ import com.tommytony.war.volume.Volume;
*/
public class VolumeMapper {
public static Volume loadVolume(String volumeName, String zoneName, World world) {
public static Volume loadVolume(String volumeName, String zoneName, World world) throws SQLException {
Volume volume = new Volume(volumeName, world);
VolumeMapper.load(volume, zoneName, world);
return volume;
}
public static void load(Volume volume, String zoneName, World world) {
public static void load(Volume volume, String zoneName, World world) throws SQLException {
File databaseFile = new File(War.war.getDataFolder(), String.format(
"/dat/volume-%s.sl3", volume.getName()));
if (!zoneName.isEmpty()) {
databaseFile = new File(War.war.getDataFolder(),
String.format("/dat/warzone-%s/volume-%s.sl3", zoneName,
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!");
return;
}
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement();
ResultSet versionQuery = stmt.executeQuery("PRAGMA user_version");
int version = versionQuery.getInt("user_version");
versionQuery.close();
if (version > DATABASE_VERSION) {
try {
throw new IllegalStateException("Unsupported zone format " + version);
} finally {
stmt.close();
databaseConnection.close();
}
} else if (version < DATABASE_VERSION) {
switch (version) {
// Run some update SQL for each old version
}
}
ResultSet cornerQuery = stmt.executeQuery("SELECT * FROM corners");
cornerQuery.next();
final Block corner1 = world.getBlockAt(cornerQuery.getInt("x"), cornerQuery.getInt("y"), cornerQuery.getInt("z"));
cornerQuery.next();
final Block corner2 = world.getBlockAt(cornerQuery.getInt("x"), cornerQuery.getInt("y"), cornerQuery.getInt("z"));
cornerQuery.close();
volume.setCornerOne(corner1);
volume.setCornerTwo(corner2);
ResultSet query = stmt.executeQuery("SELECT * FROM blocks");
while (query.next()) {
int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z");
BlockState modify = corner1.getRelative(x, y, z).getState();
ItemStack data = new ItemStack(Material.valueOf(query.getString("type")), 0, query.getShort("data"));
modify.setType(data.getType());
modify.setData(data.getData());
volume.getBlocks().add(modify);
}
query.close();
stmt.close();
databaseConnection.close();
}
@SuppressWarnings("deprecation")
public static void legacyLoad(Volume volume, String zoneName, World world) {
BufferedReader in = null;
try {
if (zoneName.equals("")) {
@ -64,8 +126,6 @@ public class VolumeMapper {
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
volume.setBlockTypes(new int[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
volume.setBlockDatas(new byte[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
int blockReads = 0;
for (int i = 0; i < volume.getSizeX(); i++) {
for (int j = 0; j < volume.getSizeY(); j++) {
@ -78,34 +138,10 @@ public class VolumeMapper {
int typeID = Integer.parseInt(blockSplit[0]);
byte data = Byte.parseByte(blockSplit[1]);
volume.getBlockTypes()[i][j][k] = typeID;
volume.getBlockDatas()[i][j][k] = data;
if (typeID == Material.WALL_SIGN.getId() || typeID == Material.SIGN_POST.getId()) {
// Signs
String linesStr = "";
if (blockSplit.length > 2) {
for (int o = 2; o < blockSplit.length; o++) {
linesStr += blockSplit[o];
}
String[] lines = linesStr.split(";;");
volume.getSignLines().put("sign-" + i + "-" + j + "-" + k, lines);
}
} else if (typeID == Material.CHEST.getId()) {
// Chests
List<ItemStack> items = new ArrayList<ItemStack>();
if (blockSplit.length > 2) {
items = readInventoryString(blockSplit[2]);
}
volume.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
} else if (typeID == Material.DISPENSER.getId()) {
// Dispensers
List<ItemStack> items = new ArrayList<ItemStack>();
if (blockSplit.length > 2) {
items = readInventoryString(blockSplit[2]);
}
volume.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
}
BlockState dummy = volume.getWorld().getBlockAt(x1 + i, y1 + j, z1 + k).getState();
dummy.setTypeId(typeID);
dummy.setRawData(data);
volume.getBlocks().add(dummy);
}
blockReads++;
}
@ -140,90 +176,56 @@ public class VolumeMapper {
}
}
public static void save(Volume volume, String zoneName) {
if (volume.hasTwoCorners()) {
BufferedWriter out = null;
try {
if (zoneName.equals("")) {
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
} else {
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
}
out.write("corner1");
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getX()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getY()));
out.newLine();
out.write(Integer.toString(volume.getCornerOne().getZ()));
out.newLine();
out.write("corner2");
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getX()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getY()));
out.newLine();
out.write(Integer.toString(volume.getCornerTwo().getZ()));
out.newLine();
int blockWrites = 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 {
int typeId = volume.getBlockTypes()[i][j][k];
byte data = volume.getBlockDatas()[i][j][k];
out.write(typeId + "," + data + ",");
if (typeId == Material.WALL_SIGN.getId() || typeId == Material.SIGN_POST.getId()) {
// Signs
String extra = "";
String[] lines = volume.getSignLines().get("sign-" + i + "-" + j + "-" + k);
if (lines != null) {
for (String line : lines) {
extra += line + ";;";
}
out.write(extra);
}
} else if (typeId == Material.CHEST.getId()) {
// Chests
String extra = "";
List<ItemStack> contents = volume.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
if (contents != null) {
out.write(buildInventoryStringFromItemList(contents));
out.write(extra);
}
} else if (typeId == Material.DISPENSER.getId()) {
// Dispensers
List<ItemStack> contents = volume.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
if (contents != null) {
out.write(buildInventoryStringFromItemList(contents));
}
}
out.newLine();
} catch (Exception e) {
War.war.log("Unexpected error while writing block into volume " + volume.getName() + " file for zone " + zoneName + ". Blocks written so far: " + blockWrites + "Position: x:" + i + " y:" + j + " z:" + k + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
}
}
}
} 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 {
if (out != null) {
try {
out.close();
} catch (IOException e) {
War.war.log("Failed to close file writer 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(
"/dat/volume-%s.sl3", volume.getName()));
if (!zoneName.isEmpty()) {
databaseFile = new File(War.war.getDataFolder(),
String.format("/dat/warzone-%s/volume-%s.sl3", zoneName,
volume.getName()));
}
Connection databaseConnection = DriverManager
.getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement();
stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION);
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS blocks (x BIGINT, y BIGINT, z BIGINT, type TEXT, data SMALLINT)");
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS corners (pos INTEGER PRIMARY KEY NOT NULL UNIQUE, x INTEGER NOT NULL, y INTEGER NOT NULL, z INTEGER NOT NULL)");
stmt.executeUpdate("DELETE FROM blocks");
stmt.executeUpdate("DELETE FROM corners");
stmt.close();
PreparedStatement cornerStmt = databaseConnection
.prepareStatement("INSERT INTO corners SELECT 1 AS pos, ? AS x, ? AS y, ? AS z UNION SELECT 2, ?, ?, ?");
cornerStmt.setInt(1, volume.getCornerOne().getBlockX());
cornerStmt.setInt(2, volume.getCornerOne().getBlockY());
cornerStmt.setInt(3, volume.getCornerOne().getBlockZ());
cornerStmt.setInt(4, volume.getCornerTwo().getBlockX());
cornerStmt.setInt(5, volume.getCornerTwo().getBlockY());
cornerStmt.setInt(6, volume.getCornerTwo().getBlockZ());
cornerStmt.executeUpdate();
cornerStmt.close();
PreparedStatement dataStmt = databaseConnection
.prepareStatement("INSERT INTO blocks VALUES (?, ?, ?, ?, ?)");
databaseConnection.setAutoCommit(false);
final int batchSize = 1000;
int changed = 0;
for (BlockState block : volume.getBlocks()) {
final Location relLoc = ZoneVolumeMapper.rebase(
volume.getCornerOne(), block.getLocation());
dataStmt.setInt(1, relLoc.getBlockX());
dataStmt.setInt(2, relLoc.getBlockY());
dataStmt.setInt(3, relLoc.getBlockZ());
dataStmt.setString(4, block.getType().toString());
dataStmt.setShort(5, block.getData().toItemStack().getDurability());
dataStmt.addBatch();
if (++changed % batchSize == 0) {
dataStmt.executeBatch();
}
}
dataStmt.executeBatch(); // insert remaining records
databaseConnection.commit();
dataStmt.close();
databaseConnection.close();
}
/**
@ -233,6 +235,7 @@ public class VolumeMapper {
* 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("")) {
@ -282,6 +285,7 @@ public class VolumeMapper {
* @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) {
@ -310,6 +314,7 @@ public class VolumeMapper {
* @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>();
@ -323,7 +328,8 @@ public class VolumeMapper {
}
public static void delete(Volume volume) {
File volFile = new File("War/dat/volume-" + volume.getName());
File volFile = new File(War.war.getDataFolder(), String.format(
"/dat/volume-%s.sl3", volume.getName()));
boolean deletedData = volFile.delete();
if (!deletedData) {
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);

View File

@ -2,6 +2,7 @@ package com.tommytony.war.mapper;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -189,7 +190,12 @@ public class WarYmlMapper {
hubConfigSection.set("materials.gate", War.war.getWarhubMaterials().getGateBlock());
hubConfigSection.set("materials.light", War.war.getWarhubMaterials().getLightBlock());
VolumeMapper.save(hub.getVolume(), "");
try {
VolumeMapper.save(hub.getVolume(), "");
} catch (SQLException e) {
// who really even cares
War.war.getLogger().log(Level.WARNING, "Failed to save warhub volume blocks", e);
}
}
ConfigurationSection killstreakSection = warRootSection.createSection("war.killstreak");

View File

@ -2,6 +2,7 @@ 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;
@ -344,16 +345,28 @@ public class WarzoneTxtMapper {
// monument blocks
for (Monument monument : warzone.getMonuments()) {
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
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()) {
team.setSpawnVolume(spawnLocation, VolumeMapper.loadVolume(team.getName(), warzone.getName(), world));
try {
team.setSpawnVolume(spawnLocation, VolumeMapper.loadVolume(team.getName(), warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load some ambiguous old volume", e);
}
}
if (team.getTeamFlag() != null) {
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
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);
}
}
}
@ -383,7 +396,13 @@ public class WarzoneTxtMapper {
}
// create the lobby
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
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);
}

View File

@ -2,6 +2,7 @@ package com.tommytony.war.mapper;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -282,26 +283,46 @@ public class WarzoneYmlMapper {
// monument blocks
for (Monument monument : warzone.getMonuments()) {
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
try {
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
}
}
// bomb blocks
for (Bomb bomb : warzone.getBombs()) {
bomb.setVolume(VolumeMapper.loadVolume("bomb-" + bomb.getName(), warzone.getName(), world));
try {
bomb.setVolume(VolumeMapper.loadVolume("bomb-" + bomb.getName(), warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
}
}
// cake blocks
for (Cake cake : warzone.getCakes()) {
cake.setVolume(VolumeMapper.loadVolume("cake-" + cake.getName(), warzone.getName(), world));
try {
cake.setVolume(VolumeMapper.loadVolume("cake-" + cake.getName(), warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
}
}
// team spawn blocks
for (Team team : warzone.getTeams()) {
for (Location teamSpawn : team.getTeamSpawns()) {
team.setSpawnVolume(teamSpawn, VolumeMapper.loadVolume(team.getName() + team.getTeamSpawns().indexOf(teamSpawn), warzone.getName(), world));
try {
team.setSpawnVolume(teamSpawn, VolumeMapper.loadVolume(team.getName() + team.getTeamSpawns().indexOf(teamSpawn), warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
}
}
if (team.getTeamFlag() != null) {
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
try {
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone structures volume", e);
}
}
}
@ -376,7 +397,12 @@ public class WarzoneYmlMapper {
World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName);
// create the lobby
Volume lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
Volume lobbyVolume = null;
try {
lobbyVolume = VolumeMapper.loadVolume("lobby", warzone.getName(), lobbyWorld);
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to load warzone lobby", e);
}
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
warzone.setLobby(lobby);
@ -626,31 +652,55 @@ public class WarzoneYmlMapper {
// monument blocks
for (Monument monument : warzone.getMonuments()) {
VolumeMapper.save(monument.getVolume(), warzone.getName());
try {
VolumeMapper.save(monument.getVolume(), warzone.getName());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// bomb blocks
for (Bomb bomb : warzone.getBombs()) {
VolumeMapper.save(bomb.getVolume(), warzone.getName());
try {
VolumeMapper.save(bomb.getVolume(), warzone.getName());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// cake blocks
for (Cake cake : warzone.getCakes()) {
VolumeMapper.save(cake.getVolume(), warzone.getName());
try {
VolumeMapper.save(cake.getVolume(), warzone.getName());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// team spawn & flag blocks
for (Team team : teams) {
for (Volume volume : team.getSpawnVolumes().values()) {
VolumeMapper.save(volume, warzone.getName());
try {
VolumeMapper.save(volume, warzone.getName());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
if (team.getFlagVolume() != null) {
VolumeMapper.save(team.getFlagVolume(), warzone.getName());
try {
VolumeMapper.save(team.getFlagVolume(), warzone.getName());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
}
if (warzone.getLobby() != null) {
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
try {
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
} catch (SQLException e) {
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
}
}
// Save to disk

View File

@ -1,458 +1,274 @@
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.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Note;
import org.bukkit.Note.Tone;
import org.bukkit.SkullType;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Dispenser;
import org.bukkit.block.CommandBlock;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.block.Jukebox;
import org.bukkit.block.NoteBlock;
import org.bukkit.block.Sign;
import org.bukkit.inventory.Inventory;
import org.bukkit.block.Skull;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.InventoryHolder;
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.
* Loads and saves zone blocks to SQLite3 database.
*
* @author tommytony, Tim Düsterhus
* @package com.tommytony.war.mappers
* @author cmastudios
* @since 1.8
*/
public class ZoneVolumeMapper {
public static final int DATABASE_VERSION = 1;
/**
* 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 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
* @param start Starting position to load blocks at
* @param total Amount of blocks to read
* @return integer Changed blocks
* @throws SQLException Error communicating with SQLite3 database
*/
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.
ZoneVolumeMapper.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;
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners, int start, int total) throws SQLException {
int changed = 0;
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.
changed = PreNimitzZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners);
ZoneVolumeMapper.save(volume, zoneName);
War.war.log("Warzone " + zoneName + " converted to nimitz format!", Level.INFO);
return changed;
}
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement();
ResultSet versionQuery = stmt.executeQuery("PRAGMA user_version");
int version = versionQuery.getInt("user_version");
versionQuery.close();
if (version > DATABASE_VERSION) {
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() || diskBlockType == Material.TRAPPED_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.getBlockInventory().clear();
for (ItemStack item : items) {
if (item != null) {
chest.getBlockInventory().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();
throw new IllegalStateException("Unsupported zone format " + version);
} 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();
}
stmt.close();
databaseConnection.close();
}
} else if (version < DATABASE_VERSION) {
switch (version) {
// Run some update SQL for each old version
}
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;
ResultSet cornerQuery = stmt.executeQuery("SELECT * FROM corners");
cornerQuery.next();
final Block corner1 = world.getBlockAt(cornerQuery.getInt("x"), cornerQuery.getInt("y"), cornerQuery.getInt("z"));
cornerQuery.next();
final Block corner2 = world.getBlockAt(cornerQuery.getInt("x"), cornerQuery.getInt("y"), cornerQuery.getInt("z"));
cornerQuery.close();
volume.setCornerOne(corner1);
volume.setCornerTwo(corner2);
if (onlyLoadCorners) {
stmt.close();
databaseConnection.close();
return 0;
}
ResultSet query = stmt.executeQuery("SELECT * FROM blocks ORDER BY rowid LIMIT " + start + ", " + total);
while (query.next()) {
int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z");
BlockState modify = corner1.getRelative(x, y, z).getState();
ItemStack data = new ItemStack(Material.valueOf(query.getString("type")), 0, query.getShort("data"));
modify.setType(data.getType());
modify.setData(data.getData());
modify.update(true, false); // No-physics update, preventing the need for deferring blocks
modify = corner1.getRelative(x, y, z).getState(); // Grab a new instance
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().getX()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getY()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerOne().getZ()));
cornersWriter.newLine();
cornersWriter.write("corner2");
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getX()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getY()));
cornersWriter.newLine();
cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ()));
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.getBlockInventory();
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++;
}
if (modify instanceof Sign) {
final String[] lines = query.getString("sign").split("\n");
for (int i = 0; i < lines.length; i++) {
((Sign) modify).setLine(i, lines[i]);
}
}
if (modify instanceof InventoryHolder && query.getString("container") != null) {
YamlConfiguration config = new YamlConfiguration();
config.loadFromString(query.getString("container"));
((InventoryHolder) modify).getInventory().clear();
for (Object obj : config.getList("items")) {
if (obj instanceof ItemStack) {
((InventoryHolder) modify).getInventory().addItem((ItemStack) obj);
}
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 (modify instanceof NoteBlock) {
String[] split = query.getString("note").split("\n");
Note note = new Note(Integer.parseInt(split[1]), Tone.valueOf(split[0]), Boolean.parseBoolean(split[2]));
((NoteBlock) modify).setNote(note);
}
if (modify instanceof Jukebox) {
((Jukebox) modify).setPlaying(Material.valueOf(query.getString("record")));
}
if (modify instanceof Skull && query.getString("skull") != null) {
String[] opts = query.getString("skull").split("\n");
((Skull) modify).setOwner(opts[0]);
((Skull) modify).setSkullType(SkullType.valueOf(opts[1]));
((Skull) modify).setRotation(BlockFace.valueOf(opts[2]));
}
if (modify instanceof CommandBlock && query.getString("command") != null) {
final String[] commandArray = query.getString("command").split("\n");
((CommandBlock) modify).setName(commandArray[0]);
((CommandBlock) modify).setCommand(commandArray[1]);
}
if (modify instanceof CreatureSpawner) {
((CreatureSpawner) modify).setSpawnedType(EntityType.valueOf(query.getString("mobid")));
}
} catch (Exception ex) {
War.war.getLogger().log(Level.WARNING, "Exception loading some tile data", ex);
}
modify.update(true, false);
changed++;
}
query.close();
stmt.close();
databaseConnection.close();
return changed;
}
/**
* Save all war zone blocks to a SQLite3 database file.
*
* @param volume Volume to save (takes corner data and loads from world).
* @param zoneName Name of warzone to save.
* @return amount of changed blocks
* @throws SQLException
*/
public static int save(Volume volume, String zoneName) throws SQLException {
int changed = 0;
File warzoneDir = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName);
warzoneDir.mkdirs();
File databaseFile = new File(War.war.getDataFolder(), String.format("/dat/warzone-%s/volume-%s.sl3", zoneName, volume.getName()));
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
Statement stmt = databaseConnection.createStatement();
stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION);
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS blocks (x BIGINT, y BIGINT, z BIGINT, type TEXT, data SMALLINT, sign TEXT, container BLOB, note INT, record TEXT, skull TEXT, command TEXT, mobid TEXT)");
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS corners (pos INTEGER PRIMARY KEY NOT NULL UNIQUE, x INTEGER NOT NULL, y INTEGER NOT NULL, z INTEGER NOT NULL)");
stmt.executeUpdate("DELETE FROM blocks");
stmt.executeUpdate("DELETE FROM corners");
stmt.close();
PreparedStatement cornerStmt = databaseConnection.prepareStatement("INSERT INTO corners SELECT 1 AS pos, ? AS x, ? AS y, ? AS z UNION SELECT 2, ?, ?, ?");
cornerStmt.setInt(1, volume.getCornerOne().getBlockX());
cornerStmt.setInt(2, volume.getCornerOne().getBlockY());
cornerStmt.setInt(3, volume.getCornerOne().getBlockZ());
cornerStmt.setInt(4, volume.getCornerTwo().getBlockX());
cornerStmt.setInt(5, volume.getCornerTwo().getBlockY());
cornerStmt.setInt(6, volume.getCornerTwo().getBlockZ());
cornerStmt.executeUpdate();
cornerStmt.close();
PreparedStatement dataStmt = databaseConnection.prepareStatement("INSERT INTO blocks VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
databaseConnection.setAutoCommit(false);
final int batchSize = 1000;
for (int i = 0, x = volume.getMinX(); i < volume.getSizeX(); i++, x++) {
for (int j = 0, y = volume.getMinY(); j < volume.getSizeY(); j++, y++) {
for (int k = 0, z = volume.getMinZ(); k < volume.getSizeZ(); k++, z++) {
final Block block = volume.getWorld().getBlockAt(x, y, z);
final Location relLoc = rebase(volume.getCornerOne(), block.getLocation());
dataStmt.setInt(1, relLoc.getBlockX());
dataStmt.setInt(2, relLoc.getBlockY());
dataStmt.setInt(3, relLoc.getBlockZ());
dataStmt.setString(4, block.getType().toString());
dataStmt.setShort(5, block.getState().getData().toItemStack().getDurability());
if (block.getState() instanceof Sign) {
final String signText = StringUtils.join(((Sign) block.getState()).getLines(), "\n");
dataStmt.setString(6, signText);
} else {
dataStmt.setNull(6, Types.VARCHAR);
}
if (blocksOutput != null) {
blocksOutput.close();
if (block.getState() instanceof InventoryHolder) {
List<ItemStack> items = Arrays.asList(((InventoryHolder) block.getState()).getInventory().getContents());
YamlConfiguration config = new YamlConfiguration();
// Serialize to config, then store config in database
config.set("items", items);
dataStmt.setString(7, config.saveToString());
} else {
dataStmt.setNull(7, Types.BLOB);
}
if (signsWriter != null) {
signsWriter.close();
if (block.getState() instanceof NoteBlock) {
Note note = ((NoteBlock) block.getState()).getNote();
dataStmt.setString(8, note.getTone().toString() + '\n' + note.getOctave() + '\n' + note.isSharped());
} else {
dataStmt.setNull(8, Types.VARCHAR);
}
if (invsWriter != null) {
invsWriter.close();
if (block.getState() instanceof Jukebox) {
dataStmt.setString(9, ((Jukebox) block.getState()).getPlaying().toString());
} else {
dataStmt.setNull(9, Types.VARCHAR);
}
if (block.getState() instanceof Skull) {
dataStmt.setString(10, String.format("%s\n%s\n%s",
((Skull) block.getState()).getOwner(),
((Skull) block.getState()).getSkullType().toString(),
((Skull) block.getState()).getRotation().toString()));
} else {
dataStmt.setNull(10, Types.VARCHAR);
}
if (block.getState() instanceof CommandBlock) {
dataStmt.setString(11, ((CommandBlock) block.getState()).getName()
+ "\n" + ((CommandBlock) block.getState()).getCommand());
} else {
dataStmt.setNull(11, Types.VARCHAR);
}
if (block.getState() instanceof CreatureSpawner) {
dataStmt.setString(12, ((CreatureSpawner) block.getState()).getSpawnedType().toString());
} else {
dataStmt.setNull(12, Types.VARCHAR);
}
dataStmt.addBatch();
if (++changed % batchSize == 0) {
dataStmt.executeBatch();
}
} 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);
dataStmt.executeBatch(); // insert remaining records
databaseConnection.commit();
dataStmt.close();
databaseConnection.close();
return changed;
}
/**
* Deletes the given volume
*
* @param Volume
* volume volume to delete
* @param War
* war Instance of war
*/
public static void delete(Volume volume) {
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat");
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners");
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks");
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs");
ZoneVolumeMapper.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);
}
}
public static Location rebase(final Location base, final Location exact) {
Validate.isTrue(base.getWorld().equals(exact.getWorld()),
"Locations must be in the same world");
return new Location(base.getWorld(),
exact.getBlockX() - base.getBlockX(),
exact.getBlockY() - base.getBlockY(),
exact.getBlockZ() - base.getBlockZ());
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.tommytony.war.Warzone;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -35,19 +34,12 @@ public class Bomb {
public void addBombBlocks() {
// make air (old two-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.volume.getCornerOne().getX(),
this.volume.getCornerOne().getY() + 1,
this.volume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.volume.getCornerTwo().getX(),
this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.volume.getWorld(),
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
.getY() + 1, this.volume.getCornerOne().getZ()),
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
.getX(), this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
int x = this.location.getBlockX();

View File

@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
import com.tommytony.war.Warzone;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -35,19 +34,12 @@ public class Cake {
public void addCakeBlocks() {
// make air (old two-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.volume.getCornerOne().getX(),
this.volume.getCornerOne().getY() + 1,
this.volume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.volume.getCornerTwo().getX(),
this.volume.getCornerOne().getY() + 2,
this.volume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.volume.getWorld(),
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
.getY() + 1, this.volume.getCornerOne().getZ()),
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
.getX(), this.volume.getCornerOne().getY() + 2,
this.volume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
int x = this.location.getBlockX();

View File

@ -10,7 +10,6 @@ import org.bukkit.material.MaterialData;
import com.tommytony.war.Team;
import com.tommytony.war.Warzone;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -36,19 +35,12 @@ public class Monument {
public void addMonumentBlocks() {
// make air (old three-high above floor)
Volume airGap = new Volume("airgap", this.warzone.getWorld());
airGap.setCornerOne(new BlockInfo(
this.volume.getCornerOne().getX(),
this.volume.getCornerOne().getY() + 1,
this.volume.getCornerOne().getZ(),
0,
(byte)0));
airGap.setCornerTwo(new BlockInfo(
this.volume.getCornerTwo().getX(),
this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ(),
0,
(byte)0));
Volume airGap = new Volume(new Location(this.volume.getWorld(),
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
.getY() + 1, this.volume.getCornerOne().getZ()),
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
.getX(), this.volume.getCornerOne().getY() + 3,
this.volume.getCornerTwo().getZ()));
airGap.setToMaterial(Material.AIR);
this.ownerTeam = null;

View File

@ -18,7 +18,6 @@ import com.tommytony.war.Warzone;
import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
/**
@ -171,7 +170,7 @@ public class WarHub {
warhubTpVolume.setToMaterial(Material.AIR);
// draw gates
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2);
Block currentGateBlock = this.volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2);
for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {

View File

@ -22,7 +22,6 @@ import com.tommytony.war.config.TeamConfig;
import com.tommytony.war.config.TeamKind;
import com.tommytony.war.config.WarzoneConfig;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.volume.BlockInfo;
import com.tommytony.war.volume.Volume;
import com.tommytony.war.volume.ZoneVolume;
@ -35,14 +34,14 @@ public class ZoneLobby {
private final Warzone warzone;
private BlockFace wall;
private Volume volume;
BlockInfo lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
Location lobbyMiddleWallBlock = null; // on the zone wall, one above the zone lobby floor
BlockInfo warHubLinkGate = null;
Location warHubLinkGate = null;
Map<String, BlockInfo> teamGateBlocks = new HashMap<String, BlockInfo>();
BlockInfo autoAssignGate = null;
Map<String, Location> teamGateBlocks = new HashMap<String, Location>();
Location autoAssignGate = null;
BlockInfo zoneTeleportBlock = null;
Location zoneTeleportBlock = null;
private final int lobbyHeight = 3;
private int lobbyHalfSide;
@ -99,13 +98,13 @@ public class ZoneLobby {
// we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own
if (wall == Direction.NORTH()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.EAST(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.EAST(), this.lobbyHalfSide).getLocation();
} else if (wall == Direction.EAST()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.SOUTH(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.SOUTH(), this.lobbyHalfSide).getLocation();
} else if (wall == Direction.SOUTH()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.WEST(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.WEST(), this.lobbyHalfSide).getLocation();
} else if (wall == Direction.WEST()) {
this.lobbyMiddleWallBlock = new BlockInfo(BlockInfo.getBlock(warzone.getWorld(), volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(Direction.NORTH(), this.lobbyHalfSide));
this.lobbyMiddleWallBlock = volume.getCornerOne().getBlock().getRelative(BlockFace.UP).getRelative(Direction.NORTH(), this.lobbyHalfSide).getLocation();
}
}
@ -157,13 +156,13 @@ public class ZoneLobby {
this.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
this.calculateLobbyWidth();
this.lobbyMiddleWallBlock = new BlockInfo(lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6));
this.lobbyMiddleWallBlock = lobbyWorld.getBlockAt(playerLocation.getBlockX(), playerLocation.getBlockY(), playerLocation.getBlockZ()).getRelative(facing, 6).getLocation();
Block corner1 = null;
Block corner2 = null;
int x = this.lobbyMiddleWallBlock.getX();
int y = this.lobbyMiddleWallBlock.getY();
int z = this.lobbyMiddleWallBlock.getZ();
int x = this.lobbyMiddleWallBlock.getBlockX();
int y = this.lobbyMiddleWallBlock.getBlockY();
int z = this.lobbyMiddleWallBlock.getBlockZ();
if (this.wall == Direction.NORTH()) {
corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide);
@ -204,7 +203,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(x, y, wallCenterPos).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos + this.lobbyHalfSide);
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide);
} else if (this.wall == Direction.EAST()) {
@ -214,7 +213,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(wallCenterPos, y, z).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y - 1, z);
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
} else if (this.wall == Direction.SOUTH()) {
@ -224,7 +223,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(x, y, wallCenterPos));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(x, y, wallCenterPos).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(x, y - 1, wallCenterPos - this.lobbyHalfSide);
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide);
} else if (this.wall == Direction.WEST()) {
@ -234,7 +233,7 @@ public class ZoneLobby {
int wallLength = wallEnd - wallStart + 1;
int wallCenterPos = wallStart + wallLength / 2;
int y = zoneVolume.getCenterY();
this.lobbyMiddleWallBlock = new BlockInfo(this.warzone.getWorld().getBlockAt(wallCenterPos, y, z));
this.lobbyMiddleWallBlock = this.warzone.getWorld().getBlockAt(wallCenterPos, y, z).getLocation();
corner1 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y - 1, z);
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos - this.lobbyHalfSide, y + 1 + this.lobbyHeight, z + this.lobbyDepth);
}
@ -276,7 +275,7 @@ public class ZoneLobby {
public void initialize() {
// maybe the number of teams change, now reset the gate positions
if (this.lobbyMiddleWallBlock != null && this.volume != null) {
this.setGatePositions(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock));
this.setGatePositions(this.lobbyMiddleWallBlock.getBlock());
if (!warzone.getLobbyMaterials().getFloorBlock().getType().equals(Material.AIR)) {
// If air, leave original blocks.
this.volume.setFaceMaterial(BlockFace.DOWN, warzone.getLobbyMaterials().getFloorBlock());
@ -289,7 +288,7 @@ public class ZoneLobby {
// add war hub link gate
if (War.war.getWarHub() != null) {
Block linkGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.warHubLinkGate);
Block linkGateBlock = this.warHubLinkGate.getBlock();
this.placeWarhubLinkGate(linkGateBlock, warzone.getLobbyMaterials().getGateBlock());
// add warhub sign
String[] lines = War.war.getString("sign.lobby.warhub").split("\n");
@ -299,15 +298,15 @@ public class ZoneLobby {
// add team gates or single auto assign gate
this.placeAutoAssignGate();
for (String teamName : this.teamGateBlocks.keySet()) {
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
this.placeTeamGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), TeamKind.teamKindFromString(teamName));
Block gateInfo = this.teamGateBlocks.get(teamName).getBlock();
this.placeTeamGate(gateInfo, TeamKind.teamKindFromString(teamName));
}
for (Team t : this.warzone.getTeams()) {
this.resetTeamGateSign(t);
}
// set zone tp
this.zoneTeleportBlock = new BlockInfo(BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 6));
this.zoneTeleportBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 6).getLocation();
int yaw = 0;
if (this.wall == Direction.WEST()) {
yaw = 180;
@ -339,7 +338,7 @@ public class ZoneLobby {
rightSide = Direction.SOUTH();
}
Block clearedPathStartBlock = BlockInfo.getBlock(this.warzone.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 2);
Block clearedPathStartBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 2);
Volume warzoneTeleportAir = new Volume("warzoneTeleport", clearedPathStartBlock.getWorld());
warzoneTeleportAir.setCornerOne(clearedPathStartBlock.getRelative(leftSide));
warzoneTeleportAir.setCornerTwo(clearedPathStartBlock.getRelative(rightSide).getRelative(front, 4).getRelative(BlockFace.UP));
@ -359,7 +358,7 @@ public class ZoneLobby {
clearedPathStartBlock.getRelative(this.wall).getRelative(this.wall).getRelative(this.wall).getRelative(this.wall).getRelative(this.wall).getRelative(BlockFace.UP).setType(Material.AIR);
// set zone sign
Block zoneSignBlock = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(this.wall, 4);
Block zoneSignBlock = this.lobbyMiddleWallBlock.getBlock().getRelative(this.wall, 4);
zoneSignBlock.setType(Material.SIGN_POST);
org.bukkit.block.Sign block = (org.bukkit.block.Sign) zoneSignBlock.getState();
org.bukkit.material.Sign data = (Sign) block.getData();
@ -377,20 +376,20 @@ public class ZoneLobby {
block.update(true);
// lets get some light in here
if (this.wall == Direction.NORTH() || this.wall == Direction.SOUTH()) {
BlockState one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.WEST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
BlockState one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.WEST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.EAST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.EAST(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
} else {
BlockState one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.NORTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
BlockState one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.NORTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
one = BlockInfo.getBlock(this.volume.getWorld(), this.lobbyMiddleWallBlock).getRelative(BlockFace.DOWN).getRelative(Direction.SOUTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one = this.lobbyMiddleWallBlock.getBlock().getRelative(BlockFace.DOWN).getRelative(Direction.SOUTH(), this.lobbyHalfSide - 1).getRelative(this.wall, 9).getState();
one.setType(warzone.getLobbyMaterials().getLightBlock().getType());
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
one.update(true);
@ -418,7 +417,7 @@ public class ZoneLobby {
}
this.teamGateBlocks.clear();
if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock);
this.autoAssignGate = lobbyMiddleWallBlock.getLocation();
} else {
this.autoAssignGate = null;
for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) {
@ -427,23 +426,23 @@ public class ZoneLobby {
if (this.warzone.getTeams().size() % 2 == 0) {
// even number of teams
if (doorIndex % 2 == 0) {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2 + 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2 + 2).getLocation());
} else {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2).getLocation());
}
} else {
if (doorIndex == 0) {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getLocation());
} else if (doorIndex % 2 == 0) {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(rightSide, doorIndex * 2).getLocation());
} else {
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2 + 2)));
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getRelative(leftSide, doorIndex * 2 + 2).getLocation());
}
}
}
}
this.warHubLinkGate = new BlockInfo(lobbyMiddleWallBlock.getRelative(this.wall, 9));
this.warHubLinkGate = lobbyMiddleWallBlock.getRelative(this.wall, 9).getLocation();
}
private void placeTeamGate(Block block, TeamKind teamKind) {
@ -573,7 +572,7 @@ public class ZoneLobby {
List<Team> teams = this.warzone.getTeams();
Block autoAssignGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate);
Block autoAssignGateBlock = this.autoAssignGate.getBlock();
// minimal air path
this.clearGatePath(autoAssignGateBlock, front, leftSide, rightSide, false);
@ -601,7 +600,7 @@ public class ZoneLobby {
}
public boolean isInTeamGate(Team team, Location location) {
BlockInfo info = this.teamGateBlocks.get(team.getName());
Location info = this.teamGateBlocks.get(team.getName());
if (info != null) {
if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) {
return true;
@ -648,13 +647,13 @@ public class ZoneLobby {
public boolean blockIsAGateBlock(Block block, BlockFace blockWall) {
if (blockWall == this.wall) {
for (String teamName : this.teamGateBlocks.keySet()) {
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
if (this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), block)) {
Location gateInfo = this.teamGateBlocks.get(teamName);
if (this.isPartOfGate(gateInfo.getBlock(), block)) {
return true;
}
}
if (this.autoAssignGate != null && this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), block)) {
if (this.autoAssignGate != null && this.isPartOfGate(this.autoAssignGate.getBlock(), block)) {
// auto assign
return true;
}
@ -689,9 +688,9 @@ public class ZoneLobby {
}
public void resetTeamGateSign(Team team) {
BlockInfo info = this.teamGateBlocks.get(team.getName());
Location info = this.teamGateBlocks.get(team.getName());
if (info != null) {
this.resetTeamGateSign(team, BlockInfo.getBlock(this.volume.getWorld(), info));
this.resetTeamGateSign(team, info.getBlock());
}
}
@ -783,14 +782,14 @@ public class ZoneLobby {
right = Direction.NORTH();
}
if (this.autoAssignGate != null) {
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate), inside, left, right)) {
if (this.leaving(location, this.autoAssignGate.getBlock(), inside, left, right)) {
return true;
}
}
for (String teamName : this.teamGateBlocks.keySet()) {
BlockInfo info = this.teamGateBlocks.get(teamName);
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), info), inside, left, right)) {
Location info = this.teamGateBlocks.get(teamName);
if (this.leaving(location, info.getBlock(), inside, left, right)) {
return true;
}
}

View File

@ -1,110 +0,0 @@
package com.tommytony.war.volume;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
/**
*
* @author tommytony
*
*/
public class BlockInfo {
private int x;
private int y;
private int z;
private int type;
private byte data;
// private String[] signLines;
public static Block getBlock(World world, BlockInfo info) {
return world.getBlockAt(info.getX(), info.getY(), info.getZ());
}
public BlockInfo(int x, int y, int z, int type, byte data) {
this.x = x;
this.y = y;
this.z = z;
this.type = type;
this.data = data;
}
public BlockInfo(Block block) {
this.x = block.getX();
this.y = block.getY();
this.z = block.getZ();
this.type = block.getTypeId();
this.data = block.getData();
// if (is(Material.SIGN) || is(Material.SIGN_POST)) {
// Sign sign = (Sign)block.getState();
// this.signLines = sign.getLines();
// }
}
// public BlockInfo(BlockState blockState) {
// this.x = blockState.getX();
// this.y = blockState.getY();
// this.z = blockState.getZ();
// this.type = blockState.getTypeId();
// this.data = blockState.getData().getData();
// // if (is(Material.SIGN) || is(Material.SIGN_POST)) {
// // Sign sign = (Sign)blockState;
// // this.signLines = sign.getLines();
// // }
// }
// public BlockInfo(int typeID, byte data, String[] lines) {
// type = typeID;
// this.data = data;
// //signLines = lines;
// }
public int getX() {
return this.x;
}
public int getY() {
return this.y;
}
public int getZ() {
return this.z;
}
// letting us mutate the BlockInfos might be a bad idea; use setters with care
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void setZ(int z) {
this.z = z;
}
public int getTypeId() {
return this.type;
}
public Material getType() {
return Material.getMaterial(this.type);
}
public byte getData() {
return this.data;
}
public boolean is(Material material) {
return this.getType() == material;
}
// public String[] getSignLines() {
// if (is(Material.SIGN) || is(Material.SIGN_POST)){
// return new String[4] {"", ""};
// }
// return null;
// }
}

View File

@ -1,171 +0,0 @@
package com.tommytony.war.volume;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import com.tommytony.war.War;
import com.tommytony.war.utility.Direction;
/**
*
* @author tommytony
*
*/
@Deprecated
public class VerticalVolume extends Volume {
public VerticalVolume(String name, World world) {
super(name, world);
}
@Override
public void setCornerOne(Block block) {
// corner one defaults to topmost corner
Block topBlock = this.getWorld().getBlockAt(block.getX(), 127, block.getZ());
super.setCornerOne(topBlock);
}
@Override
public void setCornerTwo(Block block) {
// corner two defaults to bottom most corner
Block bottomBlock = this.getWorld().getBlockAt(block.getX(), 0, block.getZ());
super.setCornerTwo(bottomBlock);
}
public boolean isWallBlock(Block block) {
return this.isEastWallBlock(block) || this.isNorthWallBlock(block) || this.isSouthWallBlock(block) || this.isWestWallBlock(block);
}
public boolean isEastWallBlock(Block block) {
if (this.getMinZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) {
return true; // east wall
}
return false;
}
public boolean isSouthWallBlock(Block block) {
if (this.getMaxX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) {
return true; // south wall
}
return false;
}
public boolean isNorthWallBlock(Block block) {
if (this.getMinX() == block.getX() && block.getZ() <= this.getMaxZ() && block.getZ() >= this.getMinZ()) {
return true; // north wall
}
return false;
}
public boolean isWestWallBlock(Block block) {
if (this.getMaxZ() == block.getZ() && block.getX() <= this.getMaxX() && block.getX() >= this.getMinX()) {
return true; // west wall
}
return false;
}
public int resetWallBlocks(BlockFace wall) {
int noOfResetBlocks = 0;
try {
if (this.hasTwoCorners() && this.getBlockTypes() != null) {
if (wall == Direction.EAST()) {
int z = this.getMinZ();
int k = 0;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int x = this.getMinX();
for (int i = 0; i < this.getSizeX(); i++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
x++;
}
y++;
}
} else if (wall == Direction.WEST()) {
int z = this.getMaxZ();
int k = this.getSizeZ() - 1;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int x = this.getMinX();
for (int i = 0; i < this.getSizeX(); i++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
x++;
}
y++;
}
} else if (wall == Direction.NORTH()) {
int x = this.getMinX();
int i = 0;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int z = this.getMinZ();
for (int k = 0; k < this.getSizeZ(); k++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
z++;
}
y++;
}
} else if (wall == Direction.SOUTH()) {
int x = this.getMaxX();
int i = this.getSizeX() - 1;
int y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
int z = this.getMinZ();
for (int k = 0; k < this.getSizeZ(); k++) {
int oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
if (this.resetBlock(oldBlockType, oldBlockData, currentBlock)) {
noOfResetBlocks++;
}
z++;
}
y++;
}
}
}
} catch (Exception e) {
War.war.log("Failed to reset wall " + wall + " in volume " + this.getName() + ". " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
}
return noOfResetBlocks;
}
private boolean resetBlock(int oldBlockType, byte oldBlockData, Block currentBlock) {
if (currentBlock.getTypeId() != oldBlockType || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlock.getTypeId() == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()))) {
currentBlock.setTypeId(oldBlockType);
currentBlock.setData(oldBlockData);
// if (oldBlockInfo.is(Material.SIGN) || oldBlockInfo.is(Material.SIGN_POST)) {
// BlockState state = currentBlock.getState();
// Sign currentSign = (Sign) state;
// currentSign.setLine(0, oldBlockInfo.getSignLines()[0]);
// currentSign.setLine(1, oldBlockInfo.getSignLines()[0]);
// currentSign.setLine(2, oldBlockInfo.getSignLines()[0]);
// currentSign.setLine(3, oldBlockInfo.getSignLines()[0]);
// state.update();
// }
return true;
}
return false;
}
}

View File

@ -1,9 +1,7 @@
package com.tommytony.war.volume;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
@ -12,13 +10,8 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
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.BlockResetJob;
import com.tommytony.war.utility.Direction;
@ -31,12 +24,9 @@ import com.tommytony.war.utility.Direction;
public class Volume {
private String name;
private World world;
private BlockInfo cornerOne;
private BlockInfo cornerTwo;
private int[][][] blockTypes = null;
private byte[][][] blockDatas = null;
private HashMap<String, String[]> signLines = new HashMap<String, String[]>();
private HashMap<String, List<ItemStack>> invBlockContents = new HashMap<String, List<ItemStack>>();
private Location cornerOne;
private Location cornerTwo;
private List<BlockState> blocks = new ArrayList<BlockState>();
public Volume(String name, World world) {
this.name = name;
@ -50,8 +40,8 @@ public class Volume {
public Volume(Location corner1, Location corner2) {
this(corner1.getWorld());
Validate.isTrue(corner1.getWorld() == corner2.getWorld(), "Cross-world volume");
this.cornerOne = new BlockInfo(corner1.getBlock());
this.cornerTwo = new BlockInfo(corner2.getBlock());
this.cornerOne = corner1;
this.cornerTwo = corner2;
}
public void setName(String newName) {
@ -71,88 +61,22 @@ public class Volume {
}
public void setCornerOne(Block block) {
this.cornerOne = new BlockInfo(block);
this.cornerOne = block.getLocation();
}
public void setCornerOne(BlockInfo blockInfo) {
this.cornerOne = blockInfo;
public void setCornerOne(Location location) {
this.cornerOne = location;
}
public int saveBlocks() {
int noOfSavedBlocks = 0;
int x = 0;
int y = 0;
int z = 0;
try {
if (this.hasTwoCorners()) {
this.setBlockTypes(new int[this.getSizeX()][this.getSizeY()][this.getSizeZ()]);
this.setBlockDatas(new byte[this.getSizeX()][this.getSizeY()][this.getSizeZ()]);
this.getSignLines().clear();
this.getInvBlockContents().clear();
x = this.getMinX();
for (int i = 0; i < this.getSizeX(); i++) {
y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
z = this.getMinZ();
for (int k = 0; k < this.getSizeZ(); k++) {
try {
Block block = this.getWorld().getBlockAt(x, y, z);
this.getBlockTypes()[i][j][k] = block.getTypeId();
this.getBlockDatas()[i][j][k] = block.getData();
BlockState state = block.getState();
if (state instanceof Sign) {
// Signs
Sign sign = (Sign) state;
if (sign.getLines() != null) {
this.getSignLines().put("sign-" + i + "-" + j + "-" + k, sign.getLines());
}
} else if (state instanceof Chest) {
// Chests
Chest chest = (Chest) state;
Inventory inv = chest.getInventory();
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);
}
}
this.getInvBlockContents().put("chest-" + i + "-" + j + "-" + k, items);
} else if (state instanceof Dispenser) {
// Dispensers
Dispenser dispenser = (Dispenser) state;
Inventory inv = dispenser.getInventory();
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);
}
}
this.getInvBlockContents().put("dispenser-" + i + "-" + j + "-" + k, items);
}
noOfSavedBlocks++;
} catch (Exception e) {
War.war.getLogger().warning("Failed to save block in volume " + this.getName() + ". Saved blocks so far:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + e.getMessage());
e.printStackTrace();
} finally {
z++;
}
}
y++;
}
x++;
public void saveBlocks() {
this.blocks.clear();
for (int x = this.getMinX(); x <= this.getMaxX(); x++) {
for (int y = this.getMinY(); y <= this.getMaxY(); y++) {
for (int z = this.getMinZ(); z <= this.getMaxZ(); z++) {
this.blocks.add(world.getBlockAt(x, y, z).getState());
}
}
} catch (Exception e) {
War.war.getLogger().warning("Failed to save volume " + this.getName() + " blocks. Saved blocks:" + noOfSavedBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Exception:" + e.getClass().toString() + " " + e.getMessage());
e.printStackTrace();
}
return noOfSavedBlocks;
}
public void resetBlocksAsJob() {
@ -160,182 +84,35 @@ public class Volume {
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
}
public int resetBlocks() {
int visitedBlocks = 0, noOfResetBlocks = 0, x = 0, y = 0, z = 0;
int currentBlockId = 0;
int oldBlockType = 0;
this.clearBlocksThatDontFloat();
try {
if (this.hasTwoCorners() && this.isSaved()) {
x = this.getMinX();
for (int i = 0; i < this.getSizeX(); i++) {
y = this.getMinY();
for (int j = 0; j < this.getSizeY(); j++) {
z = this.getMinZ();
for (int k = 0; k < this.getSizeZ(); k++) {
try {
oldBlockType = this.getBlockTypes()[i][j][k];
byte oldBlockData = this.getBlockDatas()[i][j][k];
Block currentBlock = this.getWorld().getBlockAt(x, y, z);
currentBlockId = currentBlock.getTypeId();
if (currentBlockId != oldBlockType || (currentBlockId == oldBlockType && currentBlock.getData() != oldBlockData) || (currentBlockId == oldBlockType && currentBlock.getData() == oldBlockData && (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId() || oldBlockType == Material.CHEST.getId() || oldBlockType == Material.DISPENSER.getId()))) {
if (oldBlockType == Material.WALL_SIGN.getId() || oldBlockType == Material.SIGN_POST.getId()) {
// Signs
if (oldBlockType == Material.SIGN_POST.getId() && ((oldBlockData & 0x04) == 0x04) && i + 1 != this.getSizeX()) {
Block southBlock = currentBlock.getRelative(Direction.SOUTH());
int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k];
byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k];
if (southBlock.getTypeId() != oldSouthBlockType) {
southBlock.setTypeId(oldSouthBlockType);
southBlock.setData(oldSouthBlockData);
}
}
currentBlock.setType(Material.getMaterial(oldBlockType));
BlockState state = currentBlock.getState();
state.setData(new org.bukkit.material.Sign(oldBlockType, oldBlockData));
if (state instanceof Sign) {
Sign sign = (Sign) state;
String[] lines = this.getSignLines().get("sign-" + i + "-" + j + "-" + k);
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 (oldBlockType == Material.CHEST.getId()) {
// Chests
currentBlock.setType(Material.getMaterial(oldBlockType));
currentBlock.setData(oldBlockData);
BlockState state = currentBlock.getState();
if (state instanceof Chest) {
Chest chest = (Chest) state;
List<ItemStack> contents = this.getInvBlockContents().get("chest-" + i + "-" + j + "-" + k);
if (contents != null) {
int ii = 0;
chest.getInventory().clear();
for (ItemStack item : contents) {
if (item != null) {
chest.getInventory().setItem(ii, item);
ii++;
}
}
chest.update(true);
}
}
} else if (oldBlockType == Material.DISPENSER.getId()) {
// Dispensers
currentBlock.setType(Material.getMaterial(oldBlockType));
currentBlock.setData(oldBlockData);
BlockState state = currentBlock.getState();
if (state instanceof Dispenser) {
Dispenser dispenser = (Dispenser) state;
List<ItemStack> contents = this.getInvBlockContents().get("dispenser-" + i + "-" + j + "-" + k);
if (contents != null) {
int ii = 0;
dispenser.getInventory().clear();
for (ItemStack item : contents) {
if (item != null) {
dispenser.getInventory().setItem(ii, item);
ii++;
}
}
dispenser.update(true);
}
}
} else if (oldBlockType == Material.WOODEN_DOOR.getId() || oldBlockType == Material.IRON_DOOR_BLOCK.getId()) {
// Door blocks
// Check if is bottom door block
if (j + 1 < this.getSizeY() && this.getBlockTypes()[i][j + 1][k] == oldBlockType) {
// set both door blocks right away
Block blockAbove = this.getWorld().getBlockAt(x, y + 1, z);
blockAbove.setType(Material.getMaterial(oldBlockType));
blockAbove.setData(this.getBlockDatas()[i][j + 1][k]);
currentBlock.setType(Material.getMaterial(oldBlockType));
currentBlock.setData(oldBlockData);
}
} else if (((oldBlockType == Material.TORCH.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_OFF.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.REDSTONE_TORCH_ON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LEVER.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.STONE_BUTTON.getId() && ((oldBlockData & 0x02) == 0x02)) || (oldBlockType == Material.LADDER.getId() && ((oldBlockData & 0x04) == 0x04)) || (oldBlockType == Material.RAILS.getId() && ((oldBlockData & 0x02) == 0x02))) && i + 1 != this.getSizeX()) {
// Blocks that hang on a block south of themselves need to make sure that block is there before placing themselves... lol
Block southBlock = currentBlock.getRelative(Direction.SOUTH());
int oldSouthBlockType = this.getBlockTypes()[i + 1][j][k];
byte oldSouthBlockData = this.getBlockDatas()[i + 1][j][k];
if (southBlock.getTypeId() != oldSouthBlockType) {
southBlock.setTypeId(oldSouthBlockType);
southBlock.setData(oldSouthBlockData);
}
// change the block itself, now that we have a block to set it on
currentBlock.setType(Material.getMaterial(oldBlockType));
currentBlock.setData(oldBlockData);
} else {
// regular block
currentBlock.setType(Material.getMaterial(oldBlockType));
currentBlock.setData(oldBlockData);
}
noOfResetBlocks++;
}
visitedBlocks++;
} catch (Exception e) {
War.war.getLogger().warning("Failed to reset block in volume " + this.getName() + ". 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++;
}
}
y++;
}
x++;
}
}
} catch (Exception e) {
War.war.log("Failed to reset volume " + this.getName() + " blocks. Blocks visited: " + visitedBlocks + ". Blocks reset: " + noOfResetBlocks + ". Error at x:" + x + " y:" + y + " z:" + z + ". Current block: " + currentBlockId + ". Old block: " + oldBlockType + ". Exception: " + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
public void resetBlocks() {
for (BlockState state : this.blocks) {
state.update(true, false);
}
return noOfResetBlocks;
}
public byte[][][] getBlockDatas() {
return this.blockDatas;
}
public void setBlockDatas(byte[][][] data) {
this.blockDatas = data;
}
public void setCornerTwo(Block block) {
this.cornerTwo = new BlockInfo(block);
this.cornerTwo = block.getLocation();
}
public void setCornerTwo(BlockInfo blockInfo) {
this.cornerTwo = blockInfo;
public void setCornerTwo(Location location) {
this.cornerTwo = location;
}
public BlockInfo getMinXBlock() {
public Location getMinXBlock() {
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
return this.cornerOne;
}
return this.cornerTwo;
}
public BlockInfo getMinYBlock() {
public Location getMinYBlock() {
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
return this.cornerOne;
}
return this.cornerTwo;
}
public BlockInfo getMinZBlock() {
public Location getMinZBlock() {
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
return this.cornerOne;
}
@ -343,32 +120,32 @@ public class Volume {
}
public int getMinX() {
return this.getMinXBlock().getX();
return this.getMinXBlock().getBlockX();
}
public int getMinY() {
return this.getMinYBlock().getY();
return this.getMinYBlock().getBlockY();
}
public int getMinZ() {
return this.getMinZBlock().getZ();
return this.getMinZBlock().getBlockZ();
}
public BlockInfo getMaxXBlock() {
public Location getMaxXBlock() {
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
return this.cornerTwo;
}
return this.cornerOne;
}
public BlockInfo getMaxYBlock() {
public Location getMaxYBlock() {
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
return this.cornerTwo;
}
return this.cornerOne;
}
public BlockInfo getMaxZBlock() {
public Location getMaxZBlock() {
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
return this.cornerTwo;
}
@ -376,15 +153,15 @@ public class Volume {
}
public int getMaxX() {
return this.getMaxXBlock().getX();
return this.getMaxXBlock().getBlockX();
}
public int getMaxY() {
return this.getMaxYBlock().getY();
return this.getMaxYBlock().getBlockY();
}
public int getMaxZ() {
return this.getMaxZBlock().getZ();
return this.getMaxZBlock().getBlockZ();
}
public int getSizeX() {
@ -400,18 +177,22 @@ public class Volume {
}
public boolean isSaved() {
return this.getBlockTypes() != null;
return this.blocks.size() > 0;
}
public int[][][] getBlockTypes() {
return this.blockTypes;
public List<BlockState> getBlocks() {
return blocks;
}
public BlockInfo getCornerOne() {
public void setBlocks(List<BlockState> blocks) {
this.blocks = blocks;
}
public Location getCornerOne() {
return this.cornerOne;
}
public BlockInfo getCornerTwo() {
public Location getCornerTwo() {
return this.cornerTwo;
}
@ -429,10 +210,6 @@ public class Volume {
return this.hasTwoCorners() && block.getWorld().getName().equals(this.world.getName()) && x <= this.getMaxX() && x >= this.getMinX() && y <= this.getMaxY() && y >= this.getMinY() && z <= this.getMaxZ() && z >= this.getMinZ();
}
public void setBlockTypes(int[][][] blockTypes) {
this.blockTypes = blockTypes;
}
public String getName() {
return this.name;
}
@ -532,29 +309,13 @@ public class Volume {
this.replaceMaterials(nonFloatingBlocks, Material.AIR);
}
public void setSignLines(HashMap<String, String[]> signLines) {
this.signLines = signLines;
}
public HashMap<String, String[]> getSignLines() {
return this.signLines;
}
public void setInvBlockContents(HashMap<String, List<ItemStack>> invBlockContents) {
this.invBlockContents = invBlockContents;
}
public HashMap<String, List<ItemStack>> getInvBlockContents() {
return this.invBlockContents;
}
@Override
public void finalize() {
this.blockDatas = null;
this.blockTypes = null;
this.signLines.clear();
this.signLines = null;
this.invBlockContents.clear();
this.invBlockContents = null;
this.blocks.clear();
this.blocks = null;
}
public int size() {
return this.getSizeX() * this.getSizeY() * this.getSizeZ();
}
}

View File

@ -1,12 +1,17 @@
package com.tommytony.war.volume;
import java.sql.SQLException;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import com.tommytony.war.Team;
import com.tommytony.war.War;
import com.tommytony.war.Warzone;
import com.tommytony.war.config.WarConfig;
import com.tommytony.war.job.PartialZoneResetJob;
import com.tommytony.war.mapper.ZoneVolumeMapper;
import com.tommytony.war.structure.Monument;
@ -26,12 +31,17 @@ public class ZoneVolume extends Volume {
}
@Override
public int saveBlocks() {
public void saveBlocks() {
// Save blocks directly to disk (i.e. don't put everything in memory)
int saved = ZoneVolumeMapper.save(this, this.zone.getName());
int saved = 0;
try {
saved = ZoneVolumeMapper.save(this, this.zone.getName());
} catch (SQLException ex) {
War.war.log("Failed to save warzone " + zone.getName() + ": " + ex.getMessage(), Level.WARNING);
ex.printStackTrace();
}
War.war.log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
this.isSaved = true;
return saved;
}
@Override
@ -39,35 +49,54 @@ public class ZoneVolume extends Volume {
return this.isSaved;
}
public void loadCorners() {
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true);
public void loadCorners() throws SQLException {
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true, 0, 0);
this.isSaved = true;
}
@Override
public int resetBlocks() {
public void resetBlocks() {
// Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks)
int reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), false);
int reset = 0;
try {
reset = ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), false, 0, Integer.MAX_VALUE);
} catch (SQLException ex) {
War.war.log("Failed to load warzone " + zone.getName() + ": " + ex.getMessage(), Level.WARNING);
ex.printStackTrace();
}
War.war.log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
this.isSaved = true;
return reset;
}
/**
* Reset a section of blocks in the warzone.
*
* @param start
* Starting position for reset.
* @param total
* Amount of blocks to reset.
* @throws SQLException
*/
public void resetSection(int start, int total) throws SQLException {
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), false, start, total);
}
@Override
public void setBlockTypes(int[][][] blockTypes) {
return;
/**
* Reset the blocks in this warzone at the speed defined in WarConfig#RESETSPEED.
* The job will automatically spawn new instances of itself to run every tick until it is done resetting all blocks.
*/
public void resetBlocksAsJob() {
PartialZoneResetJob job = new PartialZoneResetJob(zone, War.war
.getWarConfig().getInt(WarConfig.RESETSPEED));
War.war.getServer().getScheduler().runTask(War.war, job);
}
@Override
public void setBlockDatas(byte[][][] blockData) {
return;
}
public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException {
public void setNorthwest(Location block) throws NotNorthwestException, TooSmallException, TooBigException {
// northwest defaults to top block
BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData());
BlockInfo oldCornerOne = this.getCornerOne();
BlockInfo oldCornerTwo = this.getCornerTwo();
Location topBlock = new Location(block.getWorld(), block.getX(), block.getWorld().getMaxHeight(), block.getZ());
Location oldCornerOne = this.getCornerOne();
Location oldCornerTwo = this.getCornerTwo();
if (this.getCornerOne() == null) {
if (this.getCornerTwo() == null) {
// northwest defaults to corner 1
@ -89,10 +118,8 @@ public class ZoneVolume extends Volume {
if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) {
throw new NotNorthwestException();
}
BlockInfo minXBlock = this.getMinXBlock(); // north means min X
minXBlock.setX(block.getX()); // mutating, argh!
BlockInfo maxZBlock = this.getMaxZBlock(); // west means max Z
maxZBlock.setZ(block.getZ());
this.getMinXBlock().setX(block.getX()); // north means min X
this.getMaxZBlock().setZ(block.getZ()); // west means max Z
}
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerOne(oldCornerOne);
@ -121,11 +148,11 @@ public class ZoneVolume extends Volume {
}
}
public void setSoutheast(Block block) throws NotSoutheastException, TooSmallException, TooBigException {
public void setSoutheast(Location block) throws NotSoutheastException, TooSmallException, TooBigException {
// southeast defaults to bottom block
BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData());
BlockInfo oldCornerOne = this.getCornerOne();
BlockInfo oldCornerTwo = this.getCornerTwo();
Location bottomBlock = new Location(block.getWorld(), block.getX(), 0, block.getZ());
Location oldCornerOne = this.getCornerOne();
Location oldCornerTwo = this.getCornerTwo();
if (this.getCornerTwo() == null) {
if (this.getCornerOne() == null) {
// southeast defaults to corner 2
@ -147,10 +174,8 @@ public class ZoneVolume extends Volume {
if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) {
throw new NotSoutheastException();
}
BlockInfo maxXBlock = this.getMaxXBlock(); // south means max X
maxXBlock.setX(block.getX()); // mutating, argh!
BlockInfo minZBlock = this.getMinZBlock(); // east means min Z
minZBlock.setZ(block.getZ());
this.getMaxXBlock().setX(block.getX()); // south means max X
this.getMinZBlock().setZ(block.getZ()); // east means min Z
}
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerOne(oldCornerOne);
@ -189,7 +214,7 @@ public class ZoneVolume extends Volume {
}
public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException {
BlockInfo oldCornerOne = this.getCornerOne();
Location oldCornerOne = this.getCornerOne();
super.setCornerOne(block);
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerOne(oldCornerOne);
@ -201,7 +226,7 @@ public class ZoneVolume extends Volume {
}
public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException {
BlockInfo oldCornerTwo = this.getCornerTwo();
Location oldCornerTwo = this.getCornerTwo();
super.setCornerTwo(block);
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
super.setCornerTwo(oldCornerTwo);
@ -251,8 +276,8 @@ public class ZoneVolume extends Volume {
return false;
}
private boolean isInside(BlockInfo info) {
if (info.getX() <= this.getMaxX() && info.getX() >= this.getMinX() && info.getY() <= this.getMaxY() && info.getY() >= this.getMinY() && info.getZ() <= this.getMaxZ() && info.getZ() >= this.getMinZ()) {
private boolean isInside(Location location) {
if (location.getX() <= this.getMaxX() && location.getX() >= this.getMinX() && location.getY() <= this.getMaxY() && location.getY() >= this.getMinY() && location.getZ() <= this.getMaxZ() && location.getZ() >= this.getMinZ()) {
return true;
}
return false;

View File

@ -93,6 +93,7 @@ zone.battle.end = The battle is over. Team {0} lost: {1} died and the
zone.battle.newscores = New scores - {0}
zone.battle.next = The battle was interrupted. Resetting warzone {0}...
zone.battle.reset = A new battle begins. Resetting warzone...
zone.battle.resetprogress = Reset progress: {0}%, {1} seconds
zone.bomb.broadcast = {0} blew up team {1}''s spawn. Team {2} scores one point.
zone.cake.broadcast = {0} captured cake {1}. Team {2} scores one point and gets a full lifepool.
zone.flagcapture.broadcast = {0} captured team {1}''s flag. Team {2} scores one point.