mirror of
https://github.com/taoneill/war.git
synced 2024-11-10 20:50:04 +01:00
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:
commit
df6f47907f
@ -39,6 +39,9 @@
|
|||||||
<url>http://ci.tommytony.com</url>
|
<url>http://ci.tommytony.com</url>
|
||||||
</ciManagement>
|
</ciManagement>
|
||||||
<scm>
|
<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>
|
<url>https://github.com/taoneill/war</url>
|
||||||
</scm>
|
</scm>
|
||||||
<build>
|
<build>
|
||||||
|
@ -36,7 +36,6 @@ import com.tommytony.war.config.TeamSpawnStyle;
|
|||||||
import com.tommytony.war.structure.Bomb;
|
import com.tommytony.war.structure.Bomb;
|
||||||
import com.tommytony.war.structure.Cake;
|
import com.tommytony.war.structure.Cake;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -581,19 +580,13 @@ public class Team {
|
|||||||
|
|
||||||
public void initializeTeamFlag() {
|
public void initializeTeamFlag() {
|
||||||
// make air (old two-high above floor)
|
// make air (old two-high above floor)
|
||||||
Volume airGap = new Volume("airgap", this.warzone.getWorld());
|
Volume airGap = new Volume(new Location(this.flagVolume.getWorld(),
|
||||||
airGap.setCornerOne(new BlockInfo(
|
this.flagVolume.getCornerOne().getX(), this.flagVolume
|
||||||
this.flagVolume.getCornerOne().getX(),
|
.getCornerOne().getY() + 1, this.flagVolume
|
||||||
this.flagVolume.getCornerOne().getY() + 1,
|
.getCornerOne().getZ()), new Location(
|
||||||
this.flagVolume.getCornerOne().getZ(),
|
this.flagVolume.getWorld(), this.flagVolume.getCornerTwo()
|
||||||
0,
|
.getX(), this.flagVolume.getCornerOne().getY() + 2,
|
||||||
(byte)0));
|
this.flagVolume.getCornerTwo().getZ()));
|
||||||
airGap.setCornerTwo(new BlockInfo(
|
|
||||||
this.flagVolume.getCornerTwo().getX(),
|
|
||||||
this.flagVolume.getCornerOne().getY() + 2,
|
|
||||||
this.flagVolume.getCornerTwo().getZ(),
|
|
||||||
0,
|
|
||||||
(byte)0));
|
|
||||||
airGap.setToMaterial(Material.AIR);
|
airGap.setToMaterial(Material.AIR);
|
||||||
|
|
||||||
// Set the flag blocks
|
// Set the flag blocks
|
||||||
|
@ -151,6 +151,13 @@ public class War extends JavaPlugin {
|
|||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
isSpoutServer = false;
|
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
|
// Register events
|
||||||
PluginManager pm = this.getServer().getPluginManager();
|
PluginManager pm = this.getServer().getPluginManager();
|
||||||
@ -176,6 +183,7 @@ public class War extends JavaPlugin {
|
|||||||
warConfig.put(WarConfig.MAXZONES, 12);
|
warConfig.put(WarConfig.MAXZONES, 12);
|
||||||
warConfig.put(WarConfig.PVPINZONESONLY, false);
|
warConfig.put(WarConfig.PVPINZONESONLY, false);
|
||||||
warConfig.put(WarConfig.TNTINZONESONLY, false);
|
warConfig.put(WarConfig.TNTINZONESONLY, false);
|
||||||
|
warConfig.put(WarConfig.RESETSPEED, 5000);
|
||||||
|
|
||||||
warzoneDefaultConfig.put(WarzoneConfig.AUTOASSIGN, false);
|
warzoneDefaultConfig.put(WarzoneConfig.AUTOASSIGN, false);
|
||||||
warzoneDefaultConfig.put(WarzoneConfig.BLOCKHEADS, true);
|
warzoneDefaultConfig.put(WarzoneConfig.BLOCKHEADS, true);
|
||||||
|
@ -62,7 +62,6 @@ import com.tommytony.war.utility.Loadout;
|
|||||||
import com.tommytony.war.utility.LoadoutSelection;
|
import com.tommytony.war.utility.LoadoutSelection;
|
||||||
import com.tommytony.war.utility.PlayerState;
|
import com.tommytony.war.utility.PlayerState;
|
||||||
import com.tommytony.war.utility.PotionEffectHelper;
|
import com.tommytony.war.utility.PotionEffectHelper;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
import com.tommytony.war.volume.ZoneVolume;
|
import com.tommytony.war.volume.ZoneVolume;
|
||||||
|
|
||||||
@ -253,11 +252,11 @@ public class Warzone {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int saved = this.volume.saveBlocks();
|
this.volume.saveBlocks();
|
||||||
if (clearArtifacts) {
|
if (clearArtifacts) {
|
||||||
this.initializeZone(); // bring back stuff
|
this.initializeZone(); // bring back stuff
|
||||||
}
|
}
|
||||||
return saved;
|
return this.volume.size();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1102,7 +1101,6 @@ public class Warzone {
|
|||||||
public void reinitialize() {
|
public void reinitialize() {
|
||||||
this.isReinitializing = true;
|
this.isReinitializing = true;
|
||||||
this.getVolume().resetBlocksAsJob();
|
this.getVolume().resetBlocksAsJob();
|
||||||
this.initializeZoneAsJob();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handlePlayerLeave(Player player, Location destination, PlayerMoveEvent event, boolean removeFromTeam) {
|
public void handlePlayerLeave(Player player, Location destination, PlayerMoveEvent event, boolean removeFromTeam) {
|
||||||
@ -1556,10 +1554,15 @@ public class Warzone {
|
|||||||
for (Team maybeOpponent : this.getTeams()) {
|
for (Team maybeOpponent : this.getTeams()) {
|
||||||
if (maybeOpponent != team) {
|
if (maybeOpponent != team) {
|
||||||
for (Volume teamSpawnVolume : maybeOpponent.getSpawnVolumes().values()) {
|
for (Volume teamSpawnVolume : maybeOpponent.getSpawnVolumes().values()) {
|
||||||
Volume periphery = new Volume("periphery", this.getWorld());
|
Volume periphery = new Volume(new Location(
|
||||||
periphery.setCornerOne(new BlockInfo(teamSpawnVolume.getMinX()-1 , teamSpawnVolume.getMinY()-1, teamSpawnVolume.getMinZ()-1, 0, (byte)0));
|
teamSpawnVolume.getWorld(),
|
||||||
periphery.setCornerTwo(new BlockInfo(teamSpawnVolume.getMaxX()+1, teamSpawnVolume.getMaxY()+1, teamSpawnVolume.getMaxZ()+1, 0, (byte)0));
|
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)) {
|
if (periphery.contains(block)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.tommytony.war.command;
|
package com.tommytony.war.command;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -79,9 +80,18 @@ public class RenameZoneCommand extends AbstractZoneMakerCommand {
|
|||||||
War.war.log("Loading zone " + newName + "...", Level.INFO);
|
War.war.log("Loading zone " + newName + "...", Level.INFO);
|
||||||
Warzone newZone = WarzoneYmlMapper.load(newName, false);
|
Warzone newZone = WarzoneYmlMapper.load(newName, false);
|
||||||
War.war.getWarzones().add(newZone);
|
War.war.getWarzones().add(newZone);
|
||||||
|
try {
|
||||||
newZone.getVolume().loadCorners();
|
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();
|
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) {
|
if (zone.getLobby() != null) {
|
||||||
zone.getLobby().getVolume().resetBlocks();
|
zone.getLobby().getVolume().resetBlocks();
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class ZoneSetter {
|
|||||||
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
warzone = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||||
warzone.addAuthor(player.getName());
|
warzone.addAuthor(player.getName());
|
||||||
War.war.getIncompleteZones().add(warzone);
|
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.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);
|
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its nw corner", Level.INFO);
|
||||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||||
@ -49,7 +49,7 @@ public class ZoneSetter {
|
|||||||
} else {
|
} else {
|
||||||
// change existing warzone
|
// change existing warzone
|
||||||
this.resetWarzone(warzone, msgString);
|
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() + ". ");
|
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);
|
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 = new Warzone(this.player.getLocation().getWorld(), this.zoneName);
|
||||||
warzone.addAuthor(player.getName());
|
warzone.addAuthor(player.getName());
|
||||||
War.war.getIncompleteZones().add(warzone);
|
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.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);
|
War.war.log(player.getName() + " created warzone " + zoneName + " by setting its se corner", Level.INFO);
|
||||||
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
} else if (!this.isPlayerAuthorOfZoneOrAdmin(warzone)) {
|
||||||
@ -94,7 +94,7 @@ public class ZoneSetter {
|
|||||||
} else {
|
} else {
|
||||||
// change existing warzone
|
// change existing warzone
|
||||||
this.resetWarzone(warzone, msgString);
|
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() + ". ");
|
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);
|
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) {
|
if (warzone.getLobby() != null && warzone.getLobby().getVolume() != null) {
|
||||||
warzone.getLobby().getVolume().resetBlocks();
|
warzone.getLobby().getVolume().resetBlocks();
|
||||||
}
|
}
|
||||||
int reset = warzone.getVolume().resetBlocks();
|
warzone.getVolume().resetBlocks();
|
||||||
msgString.append(reset + " blocks reset. ");
|
msgString.append(warzone.getVolume().size() + " blocks reset. ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ public enum WarConfig {
|
|||||||
KEEPOLDZONEVERSIONS (Boolean.class),
|
KEEPOLDZONEVERSIONS (Boolean.class),
|
||||||
MAXZONES (Integer.class),
|
MAXZONES (Integer.class),
|
||||||
PVPINZONESONLY (Boolean.class),
|
PVPINZONESONLY (Boolean.class),
|
||||||
TNTINZONESONLY (Boolean.class);
|
TNTINZONESONLY (Boolean.class),
|
||||||
|
RESETSPEED (Integer.class);
|
||||||
|
|
||||||
private final Class<?> configType;
|
private final Class<?> configType;
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -43,7 +44,12 @@ public class RestoreWarhubJob implements Runnable {
|
|||||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||||
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
||||||
War.war.setWarHub(hub);
|
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.setVolume(vol);
|
||||||
hub.getVolume().resetBlocks();
|
hub.getVolume().resetBlocks();
|
||||||
hub.initialize();
|
hub.initialize();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.config.WarzoneConfig;
|
import com.tommytony.war.config.WarzoneConfig;
|
||||||
@ -32,7 +32,12 @@ public class RestoreWarzonesJob implements Runnable {
|
|||||||
Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall);
|
Warzone zone = WarzoneTxtMapper.load(warzoneName, !this.newWarInstall);
|
||||||
if (zone != null) { // could have failed, would've been logged already
|
if (zone != null) { // could have failed, would've been logged already
|
||||||
War.war.getWarzones().add(zone);
|
War.war.getWarzones().add(zone);
|
||||||
|
try {
|
||||||
zone.getVolume().loadCorners();
|
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) {
|
if (zone.getLobby() != null) {
|
||||||
zone.getLobby().getVolume().resetBlocks();
|
zone.getLobby().getVolume().resetBlocks();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -84,7 +85,12 @@ public class RestoreYmlWarhubJob implements Runnable {
|
|||||||
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
Location hubLocation = new Location(world, hubX, hubY, hubZ);
|
||||||
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
WarHub hub = new WarHub(hubLocation, hubOrientation);
|
||||||
War.war.setWarHub(hub);
|
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.setVolume(vol);
|
||||||
hub.getVolume().resetBlocks();
|
hub.getVolume().resetBlocks();
|
||||||
hub.initialize();
|
hub.initialize();
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.config.WarzoneConfig;
|
import com.tommytony.war.config.WarzoneConfig;
|
||||||
@ -28,8 +28,12 @@ public class RestoreYmlWarzonesJob implements Runnable {
|
|||||||
Warzone zone = WarzoneYmlMapper.load(warzoneName, !this.newWarInstall);
|
Warzone zone = WarzoneYmlMapper.load(warzoneName, !this.newWarInstall);
|
||||||
if (zone != null) { // could have failed, would've been logged already
|
if (zone != null) { // could have failed, would've been logged already
|
||||||
War.war.getWarzones().add(zone);
|
War.war.getWarzones().add(zone);
|
||||||
|
try {
|
||||||
zone.getVolume().loadCorners();
|
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) {
|
if (zone.getLobby() != null) {
|
||||||
zone.getLobby().getVolume().resetBlocks();
|
zone.getLobby().getVolume().resetBlocks();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
package com.tommytony.war.job;
|
package com.tommytony.war.job;
|
||||||
|
|
||||||
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.mapper.ZoneVolumeMapper;
|
import com.tommytony.war.mapper.ZoneVolumeMapper;
|
||||||
import com.tommytony.war.volume.Volume;
|
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 Volume volume;
|
||||||
private final String zoneName;
|
private final String zoneName;
|
||||||
|
|
||||||
@ -14,6 +20,10 @@ public class ZoneVolumeSaveJob extends Thread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
try {
|
||||||
ZoneVolumeMapper.save(this.volume, this.zoneName);
|
ZoneVolumeMapper.save(this.volume, this.zoneName);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
War.war.log(ex.getMessage(), Level.SEVERE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,27 +7,9 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class LoadoutTxtMapper {
|
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) {
|
public static void fromStringToLoadout(String loadoutString, HashMap<Integer, ItemStack> destinationLoadout) {
|
||||||
String[] rewardStrSplit = loadoutString.split(";");
|
String[] rewardStrSplit = loadoutString.split(";");
|
||||||
destinationLoadout.clear();
|
destinationLoadout.clear();
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package com.tommytony.war.mapper;
|
package com.tommytony.war.mapper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -17,15 +15,12 @@ import org.bukkit.block.BlockState;
|
|||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.Chest;
|
||||||
import org.bukkit.block.Dispenser;
|
import org.bukkit.block.Dispenser;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.job.DeferredBlockResetsJob;
|
import com.tommytony.war.job.DeferredBlockResetsJob;
|
||||||
import com.tommytony.war.utility.DeferredBlockReset;
|
import com.tommytony.war.utility.DeferredBlockReset;
|
||||||
import com.tommytony.war.volume.Volume;
|
|
||||||
import com.tommytony.war.volume.ZoneVolume;
|
import com.tommytony.war.volume.ZoneVolume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -34,6 +29,7 @@ import com.tommytony.war.volume.ZoneVolume;
|
|||||||
* @author tommytony
|
* @author tommytony
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class PreDeGaulleZoneVolumeMapper {
|
public class PreDeGaulleZoneVolumeMapper {
|
||||||
|
|
||||||
private static List<ItemStack> readInventoryString(String invString) {
|
private static List<ItemStack> readInventoryString(String invString) {
|
||||||
@ -283,151 +279,4 @@ public class PreDeGaulleZoneVolumeMapper {
|
|||||||
}
|
}
|
||||||
return noOfResetBlocks;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,23 +1,31 @@
|
|||||||
package com.tommytony.war.mapper;
|
package com.tommytony.war.mapper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.World;
|
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.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.MaterialData;
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
|
|
||||||
@ -28,13 +36,67 @@ import com.tommytony.war.volume.Volume;
|
|||||||
*/
|
*/
|
||||||
public class VolumeMapper {
|
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);
|
Volume volume = new Volume(volumeName, world);
|
||||||
VolumeMapper.load(volume, zoneName, world);
|
VolumeMapper.load(volume, zoneName, world);
|
||||||
return volume;
|
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;
|
BufferedReader in = null;
|
||||||
try {
|
try {
|
||||||
if (zoneName.equals("")) {
|
if (zoneName.equals("")) {
|
||||||
@ -64,8 +126,6 @@ public class VolumeMapper {
|
|||||||
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
volume.setCornerOne(world.getBlockAt(x1, y1, z1));
|
||||||
volume.setCornerTwo(world.getBlockAt(x2, y2, z2));
|
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;
|
int blockReads = 0;
|
||||||
for (int i = 0; i < volume.getSizeX(); i++) {
|
for (int i = 0; i < volume.getSizeX(); i++) {
|
||||||
for (int j = 0; j < volume.getSizeY(); j++) {
|
for (int j = 0; j < volume.getSizeY(); j++) {
|
||||||
@ -78,34 +138,10 @@ public class VolumeMapper {
|
|||||||
int typeID = Integer.parseInt(blockSplit[0]);
|
int typeID = Integer.parseInt(blockSplit[0]);
|
||||||
byte data = Byte.parseByte(blockSplit[1]);
|
byte data = Byte.parseByte(blockSplit[1]);
|
||||||
|
|
||||||
volume.getBlockTypes()[i][j][k] = typeID;
|
BlockState dummy = volume.getWorld().getBlockAt(x1 + i, y1 + j, z1 + k).getState();
|
||||||
volume.getBlockDatas()[i][j][k] = data;
|
dummy.setTypeId(typeID);
|
||||||
|
dummy.setRawData(data);
|
||||||
if (typeID == Material.WALL_SIGN.getId() || typeID == Material.SIGN_POST.getId()) {
|
volume.getBlocks().add(dummy);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
blockReads++;
|
blockReads++;
|
||||||
}
|
}
|
||||||
@ -140,90 +176,56 @@ public class VolumeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save(Volume volume, String zoneName) {
|
public static final int DATABASE_VERSION = 1;
|
||||||
if (volume.hasTwoCorners()) {
|
public static void save(Volume volume, String zoneName) throws SQLException {
|
||||||
BufferedWriter out = null;
|
File databaseFile = new File(War.war.getDataFolder(), String.format(
|
||||||
try {
|
"/dat/volume-%s.sl3", volume.getName()));
|
||||||
if (zoneName.equals("")) {
|
if (!zoneName.isEmpty()) {
|
||||||
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat")));
|
databaseFile = new File(War.war.getDataFolder(),
|
||||||
} else {
|
String.format("/dat/warzone-%s/volume-%s.sl3", zoneName,
|
||||||
out = new BufferedWriter(new FileWriter(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".dat")));
|
volume.getName()));
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
* invString string to parse
|
||||||
* @return List<ItemStack> Parsed items
|
* @return List<ItemStack> Parsed items
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static List<ItemStack> readInventoryString(String invString) {
|
public static List<ItemStack> readInventoryString(String invString) {
|
||||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
if (invString != null && !invString.equals("")) {
|
if (invString != null && !invString.equals("")) {
|
||||||
@ -282,6 +285,7 @@ public class VolumeMapper {
|
|||||||
* @param items The list of items
|
* @param items The list of items
|
||||||
* @return The list as a string
|
* @return The list as a string
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static String buildInventoryStringFromItemList(List<ItemStack> items) {
|
public static String buildInventoryStringFromItemList(List<ItemStack> items) {
|
||||||
String extra = "";
|
String extra = "";
|
||||||
for (ItemStack item : items) {
|
for (ItemStack item : items) {
|
||||||
@ -310,6 +314,7 @@ public class VolumeMapper {
|
|||||||
* @param inv The inventory
|
* @param inv The inventory
|
||||||
* @return The inventory as a list
|
* @return The inventory as a list
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static List<ItemStack> getItemListFromInv(Inventory inv) {
|
public static List<ItemStack> getItemListFromInv(Inventory inv) {
|
||||||
int size = inv.getSize();
|
int size = inv.getSize();
|
||||||
List<ItemStack> items = new ArrayList<ItemStack>();
|
List<ItemStack> items = new ArrayList<ItemStack>();
|
||||||
@ -323,7 +328,8 @@ public class VolumeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void delete(Volume volume) {
|
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();
|
boolean deletedData = volFile.delete();
|
||||||
if (!deletedData) {
|
if (!deletedData) {
|
||||||
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
|
||||||
|
@ -2,6 +2,7 @@ package com.tommytony.war.mapper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -189,7 +190,12 @@ public class WarYmlMapper {
|
|||||||
hubConfigSection.set("materials.gate", War.war.getWarhubMaterials().getGateBlock());
|
hubConfigSection.set("materials.gate", War.war.getWarhubMaterials().getGateBlock());
|
||||||
hubConfigSection.set("materials.light", War.war.getWarhubMaterials().getLightBlock());
|
hubConfigSection.set("materials.light", War.war.getWarhubMaterials().getLightBlock());
|
||||||
|
|
||||||
|
try {
|
||||||
VolumeMapper.save(hub.getVolume(), "");
|
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");
|
ConfigurationSection killstreakSection = warRootSection.createSection("war.killstreak");
|
||||||
|
@ -2,6 +2,7 @@ package com.tommytony.war.mapper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
@ -344,16 +345,28 @@ public class WarzoneTxtMapper {
|
|||||||
|
|
||||||
// monument blocks
|
// monument blocks
|
||||||
for (Monument monument : warzone.getMonuments()) {
|
for (Monument monument : warzone.getMonuments()) {
|
||||||
|
try {
|
||||||
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
|
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
|
// team spawn blocks
|
||||||
for (Team team : warzone.getTeams()) {
|
for (Team team : warzone.getTeams()) {
|
||||||
for (Location spawnLocation : team.getTeamSpawns()) {
|
for (Location spawnLocation : team.getTeamSpawns()) {
|
||||||
|
try {
|
||||||
team.setSpawnVolume(spawnLocation, VolumeMapper.loadVolume(team.getName(), warzone.getName(), world));
|
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) {
|
if (team.getTeamFlag() != null) {
|
||||||
|
try {
|
||||||
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
|
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
|
// 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);
|
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
|
||||||
warzone.setLobby(lobby);
|
warzone.setLobby(lobby);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.tommytony.war.mapper;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -282,26 +283,46 @@ public class WarzoneYmlMapper {
|
|||||||
|
|
||||||
// monument blocks
|
// monument blocks
|
||||||
for (Monument monument : warzone.getMonuments()) {
|
for (Monument monument : warzone.getMonuments()) {
|
||||||
|
try {
|
||||||
monument.setVolume(VolumeMapper.loadVolume(monument.getName(), warzone.getName(), world));
|
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
|
// bomb blocks
|
||||||
for (Bomb bomb : warzone.getBombs()) {
|
for (Bomb bomb : warzone.getBombs()) {
|
||||||
|
try {
|
||||||
bomb.setVolume(VolumeMapper.loadVolume("bomb-" + bomb.getName(), warzone.getName(), world));
|
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
|
// cake blocks
|
||||||
for (Cake cake : warzone.getCakes()) {
|
for (Cake cake : warzone.getCakes()) {
|
||||||
|
try {
|
||||||
cake.setVolume(VolumeMapper.loadVolume("cake-" + cake.getName(), warzone.getName(), world));
|
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
|
// team spawn blocks
|
||||||
for (Team team : warzone.getTeams()) {
|
for (Team team : warzone.getTeams()) {
|
||||||
for (Location teamSpawn : team.getTeamSpawns()) {
|
for (Location teamSpawn : team.getTeamSpawns()) {
|
||||||
|
try {
|
||||||
team.setSpawnVolume(teamSpawn, VolumeMapper.loadVolume(team.getName() + team.getTeamSpawns().indexOf(teamSpawn), warzone.getName(), world));
|
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) {
|
if (team.getTeamFlag() != null) {
|
||||||
|
try {
|
||||||
team.setFlagVolume(VolumeMapper.loadVolume(team.getName() + "flag", warzone.getName(), world));
|
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);
|
World lobbyWorld = War.war.getServer().getWorld(lobbyWorldName);
|
||||||
|
|
||||||
// create the lobby
|
// 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);
|
ZoneLobby lobby = new ZoneLobby(warzone, lobbyFace, lobbyVolume);
|
||||||
warzone.setLobby(lobby);
|
warzone.setLobby(lobby);
|
||||||
|
|
||||||
@ -626,31 +652,55 @@ public class WarzoneYmlMapper {
|
|||||||
|
|
||||||
// monument blocks
|
// monument blocks
|
||||||
for (Monument monument : warzone.getMonuments()) {
|
for (Monument monument : warzone.getMonuments()) {
|
||||||
|
try {
|
||||||
VolumeMapper.save(monument.getVolume(), warzone.getName());
|
VolumeMapper.save(monument.getVolume(), warzone.getName());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// bomb blocks
|
// bomb blocks
|
||||||
for (Bomb bomb : warzone.getBombs()) {
|
for (Bomb bomb : warzone.getBombs()) {
|
||||||
|
try {
|
||||||
VolumeMapper.save(bomb.getVolume(), warzone.getName());
|
VolumeMapper.save(bomb.getVolume(), warzone.getName());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
War.war.getLogger().log(Level.WARNING, "Failed to save warzone structures volume", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// cake blocks
|
// cake blocks
|
||||||
for (Cake cake : warzone.getCakes()) {
|
for (Cake cake : warzone.getCakes()) {
|
||||||
|
try {
|
||||||
VolumeMapper.save(cake.getVolume(), warzone.getName());
|
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
|
// team spawn & flag blocks
|
||||||
for (Team team : teams) {
|
for (Team team : teams) {
|
||||||
for (Volume volume : team.getSpawnVolumes().values()) {
|
for (Volume volume : team.getSpawnVolumes().values()) {
|
||||||
|
try {
|
||||||
VolumeMapper.save(volume, warzone.getName());
|
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) {
|
if (team.getFlagVolume() != null) {
|
||||||
|
try {
|
||||||
VolumeMapper.save(team.getFlagVolume(), warzone.getName());
|
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) {
|
if (warzone.getLobby() != null) {
|
||||||
|
try {
|
||||||
VolumeMapper.save(warzone.getLobby().getVolume(), warzone.getName());
|
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
|
// Save to disk
|
||||||
|
@ -1,458 +1,274 @@
|
|||||||
package com.tommytony.war.mapper;
|
package com.tommytony.war.mapper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.sql.Connection;
|
||||||
import java.io.FileNotFoundException;
|
import java.sql.DriverManager;
|
||||||
import java.io.FileOutputStream;
|
import java.sql.PreparedStatement;
|
||||||
import java.io.FileReader;
|
import java.sql.ResultSet;
|
||||||
import java.io.FileWriter;
|
import java.sql.SQLException;
|
||||||
import java.io.IOException;
|
import java.sql.Statement;
|
||||||
|
import java.sql.Types;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
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.Material;
|
||||||
|
import org.bukkit.Note;
|
||||||
|
import org.bukkit.Note.Tone;
|
||||||
|
import org.bukkit.SkullType;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.block.Chest;
|
import org.bukkit.block.CommandBlock;
|
||||||
import org.bukkit.block.Dispenser;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
|
import org.bukkit.block.Jukebox;
|
||||||
|
import org.bukkit.block.NoteBlock;
|
||||||
import org.bukkit.block.Sign;
|
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 org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
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.Volume;
|
||||||
import com.tommytony.war.volume.ZoneVolume;
|
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
|
* @author cmastudios
|
||||||
* @package com.tommytony.war.mappers
|
* @since 1.8
|
||||||
*/
|
*/
|
||||||
public class ZoneVolumeMapper {
|
public class ZoneVolumeMapper {
|
||||||
|
|
||||||
|
public static final int DATABASE_VERSION = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the given volume
|
* Loads the given volume
|
||||||
*
|
*
|
||||||
* @param ZoneVolume
|
* @param ZoneVolume volume Volume to load
|
||||||
* volume Volume to load
|
* @param String zoneName Zone to load the volume from
|
||||||
* @param String
|
* @param World world The world the zone is located
|
||||||
* 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 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
|
* @return integer Changed blocks
|
||||||
|
* @throws SQLException Error communicating with SQLite3 database
|
||||||
*/
|
*/
|
||||||
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners) {
|
public static int load(ZoneVolume volume, String zoneName, World world, boolean onlyLoadCorners, int start, int total) throws SQLException {
|
||||||
File cornersFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".corners");
|
int changed = 0;
|
||||||
File blocksFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".blocks");
|
File databaseFile = new File(War.war.getDataFolder(), String.format("/dat/warzone-%s/volume-%s.sl3", zoneName, volume.getName()));
|
||||||
File signsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".signs");
|
if (!databaseFile.exists()) {
|
||||||
File invsFile = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName() + ".invs");
|
// Convert warzone to nimitz file format.
|
||||||
int noOfResetBlocks = 0;
|
changed = PreNimitzZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners);
|
||||||
boolean failed = false;
|
ZoneVolumeMapper.save(volume, zoneName);
|
||||||
if (!blocksFile.exists()) {
|
War.war.log("Warzone " + zoneName + " converted to nimitz format!", Level.INFO);
|
||||||
// The post 1.6 formatted files haven't been created yet so
|
return changed;
|
||||||
// we need to use the old load.
|
}
|
||||||
noOfResetBlocks = PreDeGaulleZoneVolumeMapper.load(volume, zoneName, world, onlyLoadCorners);
|
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
|
||||||
|
Statement stmt = databaseConnection.createStatement();
|
||||||
// The new 1.6 files aren't created yet. We just reset the zone (except deferred blocks which will soon execute on main thread ),
|
ResultSet versionQuery = stmt.executeQuery("PRAGMA user_version");
|
||||||
// so let's save to the new format as soon as the zone is fully reset.
|
int version = versionQuery.getInt("user_version");
|
||||||
ZoneVolumeMapper.saveAsJob(volume, zoneName, 2);
|
versionQuery.close();
|
||||||
War.war.log("Warzone " + zoneName + " file converted!", Level.INFO);
|
if (version > DATABASE_VERSION) {
|
||||||
|
|
||||||
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 {
|
try {
|
||||||
cornersReader = new BufferedReader(new FileReader(cornersFile));
|
throw new IllegalStateException("Unsupported zone format " + version);
|
||||||
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 {
|
} finally {
|
||||||
z++;
|
stmt.close();
|
||||||
|
databaseConnection.close();
|
||||||
|
}
|
||||||
|
} else if (version < DATABASE_VERSION) {
|
||||||
|
switch (version) {
|
||||||
|
// Run some update SQL for each old version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
y++;
|
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;
|
||||||
}
|
}
|
||||||
x++;
|
ResultSet query = stmt.executeQuery("SELECT * FROM blocks ORDER BY rowid LIMIT " + start + ", " + total);
|
||||||
}
|
while (query.next()) {
|
||||||
if (!deferred.isEmpty()) {
|
int x = query.getInt("x"), y = query.getInt("y"), z = query.getInt("z");
|
||||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, deferred, 2);
|
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());
|
||||||
} catch (FileNotFoundException e) {
|
modify.setData(data.getData());
|
||||||
War.war.log("Failed to find volume file " + volume.getName() + " for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
modify.update(true, false); // No-physics update, preventing the need for deferring blocks
|
||||||
e.printStackTrace();
|
modify = corner1.getRelative(x, y, z).getState(); // Grab a new instance
|
||||||
} 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 {
|
try {
|
||||||
if (cornersReader != null) {
|
if (modify instanceof Sign) {
|
||||||
cornersReader.close();
|
final String[] lines = query.getString("sign").split("\n");
|
||||||
}
|
for (int i = 0; i < lines.length; i++) {
|
||||||
if (blocksStream != null) {
|
((Sign) modify).setLine(i, lines[i]);
|
||||||
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;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the given volume
|
* Save all war zone blocks to a SQLite3 database file.
|
||||||
*
|
*
|
||||||
* @param Volume
|
* @param volume Volume to save (takes corner data and loads from world).
|
||||||
* volume Volume to save
|
* @param zoneName Name of warzone to save.
|
||||||
* @param String
|
* @return amount of changed blocks
|
||||||
* zoneName The warzone the volume is located
|
* @throws SQLException
|
||||||
* @return integer Number of written blocks
|
|
||||||
*/
|
*/
|
||||||
public static int save(Volume volume, String zoneName) {
|
public static int save(Volume volume, String zoneName) throws SQLException {
|
||||||
int noOfSavedBlocks = 0;
|
int changed = 0;
|
||||||
if (volume.hasTwoCorners()) {
|
File warzoneDir = new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName);
|
||||||
BufferedWriter cornersWriter = null;
|
warzoneDir.mkdirs();
|
||||||
FileOutputStream blocksOutput = null;
|
File databaseFile = new File(War.war.getDataFolder(), String.format("/dat/warzone-%s/volume-%s.sl3", zoneName, volume.getName()));
|
||||||
BufferedWriter signsWriter = null;
|
Connection databaseConnection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getPath());
|
||||||
BufferedWriter invsWriter = null;
|
Statement stmt = databaseConnection.createStatement();
|
||||||
try {
|
stmt.executeUpdate("PRAGMA user_version = " + DATABASE_VERSION);
|
||||||
(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName)).mkdir();
|
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)");
|
||||||
String path = War.war.getDataFolder().getPath() + "/dat/warzone-" + zoneName + "/volume-" + volume.getName();
|
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)");
|
||||||
cornersWriter = new BufferedWriter(new FileWriter(new File(path + ".corners")));
|
stmt.executeUpdate("DELETE FROM blocks");
|
||||||
blocksOutput = new FileOutputStream(new File(path + ".blocks"));
|
stmt.executeUpdate("DELETE FROM corners");
|
||||||
signsWriter = new BufferedWriter(new FileWriter(new File(path + ".signs")));
|
stmt.close();
|
||||||
invsWriter = new BufferedWriter(new FileWriter(new File(path + ".invs")));
|
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());
|
||||||
cornersWriter.write("corner1");
|
cornerStmt.setInt(2, volume.getCornerOne().getBlockY());
|
||||||
cornersWriter.newLine();
|
cornerStmt.setInt(3, volume.getCornerOne().getBlockZ());
|
||||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getX()));
|
cornerStmt.setInt(4, volume.getCornerTwo().getBlockX());
|
||||||
cornersWriter.newLine();
|
cornerStmt.setInt(5, volume.getCornerTwo().getBlockY());
|
||||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getY()));
|
cornerStmt.setInt(6, volume.getCornerTwo().getBlockZ());
|
||||||
cornersWriter.newLine();
|
cornerStmt.executeUpdate();
|
||||||
cornersWriter.write(Integer.toString(volume.getCornerOne().getZ()));
|
cornerStmt.close();
|
||||||
cornersWriter.newLine();
|
PreparedStatement dataStmt = databaseConnection.prepareStatement("INSERT INTO blocks VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
cornersWriter.write("corner2");
|
databaseConnection.setAutoCommit(false);
|
||||||
cornersWriter.newLine();
|
final int batchSize = 1000;
|
||||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getX()));
|
for (int i = 0, x = volume.getMinX(); i < volume.getSizeX(); i++, x++) {
|
||||||
cornersWriter.newLine();
|
for (int j = 0, y = volume.getMinY(); j < volume.getSizeY(); j++, y++) {
|
||||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getY()));
|
for (int k = 0, z = volume.getMinZ(); k < volume.getSizeZ(); k++, z++) {
|
||||||
cornersWriter.newLine();
|
final Block block = volume.getWorld().getBlockAt(x, y, z);
|
||||||
cornersWriter.write(Integer.toString(volume.getCornerTwo().getZ()));
|
final Location relLoc = rebase(volume.getCornerOne(), block.getLocation());
|
||||||
cornersWriter.newLine();
|
dataStmt.setInt(1, relLoc.getBlockX());
|
||||||
|
dataStmt.setInt(2, relLoc.getBlockY());
|
||||||
int x = 0;
|
dataStmt.setInt(3, relLoc.getBlockZ());
|
||||||
int y = 0;
|
dataStmt.setString(4, block.getType().toString());
|
||||||
int z = 0;
|
dataStmt.setShort(5, block.getState().getData().toItemStack().getDurability());
|
||||||
Block block;
|
if (block.getState() instanceof Sign) {
|
||||||
int typeId;
|
final String signText = StringUtils.join(((Sign) block.getState()).getLines(), "\n");
|
||||||
byte data;
|
dataStmt.setString(6, signText);
|
||||||
BlockState state;
|
} else {
|
||||||
|
dataStmt.setNull(6, Types.VARCHAR);
|
||||||
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);
|
if (block.getState() instanceof InventoryHolder) {
|
||||||
signsWriter.newLine();
|
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);
|
||||||
}
|
}
|
||||||
} else if (state instanceof Chest) {
|
if (block.getState() instanceof NoteBlock) {
|
||||||
// Chests
|
Note note = ((NoteBlock) block.getState()).getNote();
|
||||||
Chest chest = (Chest) state;
|
dataStmt.setString(8, note.getTone().toString() + '\n' + note.getOctave() + '\n' + note.isSharped());
|
||||||
Inventory inv = chest.getBlockInventory();
|
} else {
|
||||||
List<ItemStack> items = VolumeMapper.getItemListFromInv(inv);
|
dataStmt.setNull(8, Types.VARCHAR);
|
||||||
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++;
|
if (block.getState() instanceof Jukebox) {
|
||||||
} catch (Exception e) {
|
dataStmt.setString(9, ((Jukebox) block.getState()).getPlaying().toString());
|
||||||
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);
|
} else {
|
||||||
e.printStackTrace();
|
dataStmt.setNull(9, Types.VARCHAR);
|
||||||
} finally {
|
|
||||||
z++;
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
y++;
|
if (block.getState() instanceof CommandBlock) {
|
||||||
|
dataStmt.setString(11, ((CommandBlock) block.getState()).getName()
|
||||||
|
+ "\n" + ((CommandBlock) block.getState()).getCommand());
|
||||||
|
} else {
|
||||||
|
dataStmt.setNull(11, Types.VARCHAR);
|
||||||
}
|
}
|
||||||
x++;
|
if (block.getState() instanceof CreatureSpawner) {
|
||||||
|
dataStmt.setString(12, ((CreatureSpawner) block.getState()).getSpawnedType().toString());
|
||||||
|
} else {
|
||||||
|
dataStmt.setNull(12, Types.VARCHAR);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
dataStmt.addBatch();
|
||||||
War.war.log("Failed to write volume file " + zoneName + " for warzone " + volume.getName() + ". " + e.getClass().getName() + " " + e.getMessage(), Level.WARNING);
|
if (++changed % batchSize == 0) {
|
||||||
e.printStackTrace();
|
dataStmt.executeBatch();
|
||||||
} 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;
|
}
|
||||||
|
dataStmt.executeBatch(); // insert remaining records
|
||||||
|
databaseConnection.commit();
|
||||||
|
dataStmt.close();
|
||||||
|
databaseConnection.close();
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Location rebase(final Location base, final Location exact) {
|
||||||
|
Validate.isTrue(base.getWorld().equals(exact.getWorld()),
|
||||||
/**
|
"Locations must be in the same world");
|
||||||
* Saves the Volume as a background-job
|
return new Location(base.getWorld(),
|
||||||
*
|
exact.getBlockX() - base.getBlockX(),
|
||||||
* @param ZoneVolme
|
exact.getBlockY() - base.getBlockY(),
|
||||||
* volume volume to save
|
exact.getBlockZ() - base.getBlockZ());
|
||||||
* @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) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,19 +34,12 @@ public class Bomb {
|
|||||||
|
|
||||||
public void addBombBlocks() {
|
public void addBombBlocks() {
|
||||||
// make air (old two-high above floor)
|
// make air (old two-high above floor)
|
||||||
Volume airGap = new Volume("airgap", this.warzone.getWorld());
|
Volume airGap = new Volume(new Location(this.volume.getWorld(),
|
||||||
airGap.setCornerOne(new BlockInfo(
|
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
|
||||||
this.volume.getCornerOne().getX(),
|
.getY() + 1, this.volume.getCornerOne().getZ()),
|
||||||
this.volume.getCornerOne().getY() + 1,
|
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
|
||||||
this.volume.getCornerOne().getZ(),
|
.getX(), this.volume.getCornerOne().getY() + 3,
|
||||||
0,
|
this.volume.getCornerTwo().getZ()));
|
||||||
(byte)0));
|
|
||||||
airGap.setCornerTwo(new BlockInfo(
|
|
||||||
this.volume.getCornerTwo().getX(),
|
|
||||||
this.volume.getCornerOne().getY() + 3,
|
|
||||||
this.volume.getCornerTwo().getZ(),
|
|
||||||
0,
|
|
||||||
(byte)0));
|
|
||||||
airGap.setToMaterial(Material.AIR);
|
airGap.setToMaterial(Material.AIR);
|
||||||
|
|
||||||
int x = this.location.getBlockX();
|
int x = this.location.getBlockX();
|
||||||
|
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,19 +34,12 @@ public class Cake {
|
|||||||
|
|
||||||
public void addCakeBlocks() {
|
public void addCakeBlocks() {
|
||||||
// make air (old two-high above floor)
|
// make air (old two-high above floor)
|
||||||
Volume airGap = new Volume("airgap", this.warzone.getWorld());
|
Volume airGap = new Volume(new Location(this.volume.getWorld(),
|
||||||
airGap.setCornerOne(new BlockInfo(
|
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
|
||||||
this.volume.getCornerOne().getX(),
|
.getY() + 1, this.volume.getCornerOne().getZ()),
|
||||||
this.volume.getCornerOne().getY() + 1,
|
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
|
||||||
this.volume.getCornerOne().getZ(),
|
.getX(), this.volume.getCornerOne().getY() + 2,
|
||||||
0,
|
this.volume.getCornerTwo().getZ()));
|
||||||
(byte)0));
|
|
||||||
airGap.setCornerTwo(new BlockInfo(
|
|
||||||
this.volume.getCornerTwo().getX(),
|
|
||||||
this.volume.getCornerOne().getY() + 2,
|
|
||||||
this.volume.getCornerTwo().getZ(),
|
|
||||||
0,
|
|
||||||
(byte)0));
|
|
||||||
airGap.setToMaterial(Material.AIR);
|
airGap.setToMaterial(Material.AIR);
|
||||||
|
|
||||||
int x = this.location.getBlockX();
|
int x = this.location.getBlockX();
|
||||||
|
@ -10,7 +10,6 @@ import org.bukkit.material.MaterialData;
|
|||||||
import com.tommytony.war.Team;
|
import com.tommytony.war.Team;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,19 +35,12 @@ public class Monument {
|
|||||||
|
|
||||||
public void addMonumentBlocks() {
|
public void addMonumentBlocks() {
|
||||||
// make air (old three-high above floor)
|
// make air (old three-high above floor)
|
||||||
Volume airGap = new Volume("airgap", this.warzone.getWorld());
|
Volume airGap = new Volume(new Location(this.volume.getWorld(),
|
||||||
airGap.setCornerOne(new BlockInfo(
|
this.volume.getCornerOne().getX(), this.volume.getCornerOne()
|
||||||
this.volume.getCornerOne().getX(),
|
.getY() + 1, this.volume.getCornerOne().getZ()),
|
||||||
this.volume.getCornerOne().getY() + 1,
|
new Location(this.volume.getWorld(), this.volume.getCornerTwo()
|
||||||
this.volume.getCornerOne().getZ(),
|
.getX(), this.volume.getCornerOne().getY() + 3,
|
||||||
0,
|
this.volume.getCornerTwo().getZ()));
|
||||||
(byte)0));
|
|
||||||
airGap.setCornerTwo(new BlockInfo(
|
|
||||||
this.volume.getCornerTwo().getX(),
|
|
||||||
this.volume.getCornerOne().getY() + 3,
|
|
||||||
this.volume.getCornerTwo().getZ(),
|
|
||||||
0,
|
|
||||||
(byte)0));
|
|
||||||
airGap.setToMaterial(Material.AIR);
|
airGap.setToMaterial(Material.AIR);
|
||||||
|
|
||||||
this.ownerTeam = null;
|
this.ownerTeam = null;
|
||||||
|
@ -18,7 +18,6 @@ import com.tommytony.war.Warzone;
|
|||||||
import com.tommytony.war.config.TeamConfig;
|
import com.tommytony.war.config.TeamConfig;
|
||||||
import com.tommytony.war.config.WarzoneConfig;
|
import com.tommytony.war.config.WarzoneConfig;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,7 +170,7 @@ public class WarHub {
|
|||||||
warhubTpVolume.setToMaterial(Material.AIR);
|
warhubTpVolume.setToMaterial(Material.AIR);
|
||||||
|
|
||||||
// draw gates
|
// 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
|
for (Warzone zone : War.war.getWarzones()) { // gonna use the index to find it again
|
||||||
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||||
|
@ -22,7 +22,6 @@ import com.tommytony.war.config.TeamConfig;
|
|||||||
import com.tommytony.war.config.TeamKind;
|
import com.tommytony.war.config.TeamKind;
|
||||||
import com.tommytony.war.config.WarzoneConfig;
|
import com.tommytony.war.config.WarzoneConfig;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
import com.tommytony.war.volume.BlockInfo;
|
|
||||||
import com.tommytony.war.volume.Volume;
|
import com.tommytony.war.volume.Volume;
|
||||||
import com.tommytony.war.volume.ZoneVolume;
|
import com.tommytony.war.volume.ZoneVolume;
|
||||||
|
|
||||||
@ -35,14 +34,14 @@ public class ZoneLobby {
|
|||||||
private final Warzone warzone;
|
private final Warzone warzone;
|
||||||
private BlockFace wall;
|
private BlockFace wall;
|
||||||
private Volume volume;
|
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>();
|
Map<String, Location> teamGateBlocks = new HashMap<String, Location>();
|
||||||
BlockInfo autoAssignGate = null;
|
Location autoAssignGate = null;
|
||||||
|
|
||||||
BlockInfo zoneTeleportBlock = null;
|
Location zoneTeleportBlock = null;
|
||||||
|
|
||||||
private final int lobbyHeight = 3;
|
private final int lobbyHeight = 3;
|
||||||
private int lobbyHalfSide;
|
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
|
// we're setting the zoneVolume directly, so we need to figure out the lobbyMiddleWallBlock on our own
|
||||||
if (wall == Direction.NORTH()) {
|
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()) {
|
} 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()) {
|
} 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()) {
|
} 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.wall = opposite; // a player facing south places a lobby that looks just like a lobby stuck to the north wall
|
||||||
|
|
||||||
this.calculateLobbyWidth();
|
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 corner1 = null;
|
||||||
Block corner2 = null;
|
Block corner2 = null;
|
||||||
int x = this.lobbyMiddleWallBlock.getX();
|
int x = this.lobbyMiddleWallBlock.getBlockX();
|
||||||
int y = this.lobbyMiddleWallBlock.getY();
|
int y = this.lobbyMiddleWallBlock.getBlockY();
|
||||||
int z = this.lobbyMiddleWallBlock.getZ();
|
int z = this.lobbyMiddleWallBlock.getBlockZ();
|
||||||
|
|
||||||
if (this.wall == Direction.NORTH()) {
|
if (this.wall == Direction.NORTH()) {
|
||||||
corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide);
|
corner1 = lobbyWorld.getBlockAt(x, y - 1, z + this.lobbyHalfSide);
|
||||||
@ -204,7 +203,7 @@ public class ZoneLobby {
|
|||||||
int wallLength = wallEnd - wallStart + 1;
|
int wallLength = wallEnd - wallStart + 1;
|
||||||
int wallCenterPos = wallStart + wallLength / 2;
|
int wallCenterPos = wallStart + wallLength / 2;
|
||||||
int y = zoneVolume.getCenterY();
|
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);
|
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);
|
corner2 = this.warzone.getWorld().getBlockAt(x - this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos - this.lobbyHalfSide);
|
||||||
} else if (this.wall == Direction.EAST()) {
|
} else if (this.wall == Direction.EAST()) {
|
||||||
@ -214,7 +213,7 @@ public class ZoneLobby {
|
|||||||
int wallLength = wallEnd - wallStart + 1;
|
int wallLength = wallEnd - wallStart + 1;
|
||||||
int wallCenterPos = wallStart + wallLength / 2;
|
int wallCenterPos = wallStart + wallLength / 2;
|
||||||
int y = zoneVolume.getCenterY();
|
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);
|
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);
|
corner2 = this.warzone.getWorld().getBlockAt(wallCenterPos + this.lobbyHalfSide, y + 1 + this.lobbyHeight, z - this.lobbyDepth);
|
||||||
} else if (this.wall == Direction.SOUTH()) {
|
} else if (this.wall == Direction.SOUTH()) {
|
||||||
@ -224,7 +223,7 @@ public class ZoneLobby {
|
|||||||
int wallLength = wallEnd - wallStart + 1;
|
int wallLength = wallEnd - wallStart + 1;
|
||||||
int wallCenterPos = wallStart + wallLength / 2;
|
int wallCenterPos = wallStart + wallLength / 2;
|
||||||
int y = zoneVolume.getCenterY();
|
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);
|
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);
|
corner2 = this.warzone.getWorld().getBlockAt(x + this.lobbyDepth, y + 1 + this.lobbyHeight, wallCenterPos + this.lobbyHalfSide);
|
||||||
} else if (this.wall == Direction.WEST()) {
|
} else if (this.wall == Direction.WEST()) {
|
||||||
@ -234,7 +233,7 @@ public class ZoneLobby {
|
|||||||
int wallLength = wallEnd - wallStart + 1;
|
int wallLength = wallEnd - wallStart + 1;
|
||||||
int wallCenterPos = wallStart + wallLength / 2;
|
int wallCenterPos = wallStart + wallLength / 2;
|
||||||
int y = zoneVolume.getCenterY();
|
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);
|
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);
|
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() {
|
public void initialize() {
|
||||||
// maybe the number of teams change, now reset the gate positions
|
// maybe the number of teams change, now reset the gate positions
|
||||||
if (this.lobbyMiddleWallBlock != null && this.volume != null) {
|
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 (!warzone.getLobbyMaterials().getFloorBlock().getType().equals(Material.AIR)) {
|
||||||
// If air, leave original blocks.
|
// If air, leave original blocks.
|
||||||
this.volume.setFaceMaterial(BlockFace.DOWN, warzone.getLobbyMaterials().getFloorBlock());
|
this.volume.setFaceMaterial(BlockFace.DOWN, warzone.getLobbyMaterials().getFloorBlock());
|
||||||
@ -289,7 +288,7 @@ public class ZoneLobby {
|
|||||||
|
|
||||||
// add war hub link gate
|
// add war hub link gate
|
||||||
if (War.war.getWarHub() != null) {
|
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());
|
this.placeWarhubLinkGate(linkGateBlock, warzone.getLobbyMaterials().getGateBlock());
|
||||||
// add warhub sign
|
// add warhub sign
|
||||||
String[] lines = War.war.getString("sign.lobby.warhub").split("\n");
|
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
|
// add team gates or single auto assign gate
|
||||||
this.placeAutoAssignGate();
|
this.placeAutoAssignGate();
|
||||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||||
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
|
Block gateInfo = this.teamGateBlocks.get(teamName).getBlock();
|
||||||
this.placeTeamGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), TeamKind.teamKindFromString(teamName));
|
this.placeTeamGate(gateInfo, TeamKind.teamKindFromString(teamName));
|
||||||
}
|
}
|
||||||
for (Team t : this.warzone.getTeams()) {
|
for (Team t : this.warzone.getTeams()) {
|
||||||
this.resetTeamGateSign(t);
|
this.resetTeamGateSign(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set zone tp
|
// 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;
|
int yaw = 0;
|
||||||
if (this.wall == Direction.WEST()) {
|
if (this.wall == Direction.WEST()) {
|
||||||
yaw = 180;
|
yaw = 180;
|
||||||
@ -339,7 +338,7 @@ public class ZoneLobby {
|
|||||||
rightSide = Direction.SOUTH();
|
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());
|
Volume warzoneTeleportAir = new Volume("warzoneTeleport", clearedPathStartBlock.getWorld());
|
||||||
warzoneTeleportAir.setCornerOne(clearedPathStartBlock.getRelative(leftSide));
|
warzoneTeleportAir.setCornerOne(clearedPathStartBlock.getRelative(leftSide));
|
||||||
warzoneTeleportAir.setCornerTwo(clearedPathStartBlock.getRelative(rightSide).getRelative(front, 4).getRelative(BlockFace.UP));
|
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);
|
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
|
// 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);
|
zoneSignBlock.setType(Material.SIGN_POST);
|
||||||
org.bukkit.block.Sign block = (org.bukkit.block.Sign) zoneSignBlock.getState();
|
org.bukkit.block.Sign block = (org.bukkit.block.Sign) zoneSignBlock.getState();
|
||||||
org.bukkit.material.Sign data = (Sign) block.getData();
|
org.bukkit.material.Sign data = (Sign) block.getData();
|
||||||
@ -377,20 +376,20 @@ public class ZoneLobby {
|
|||||||
block.update(true);
|
block.update(true);
|
||||||
// lets get some light in here
|
// lets get some light in here
|
||||||
if (this.wall == Direction.NORTH() || this.wall == Direction.SOUTH()) {
|
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.setType(warzone.getLobbyMaterials().getLightBlock().getType());
|
||||||
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
||||||
one.update(true);
|
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.setType(warzone.getLobbyMaterials().getLightBlock().getType());
|
||||||
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
||||||
one.update(true);
|
one.update(true);
|
||||||
} else {
|
} 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.setType(warzone.getLobbyMaterials().getLightBlock().getType());
|
||||||
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
||||||
one.update(true);
|
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.setType(warzone.getLobbyMaterials().getLightBlock().getType());
|
||||||
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
one.setData(warzone.getLobbyMaterials().getLightBlock().getData());
|
||||||
one.update(true);
|
one.update(true);
|
||||||
@ -418,7 +417,7 @@ public class ZoneLobby {
|
|||||||
}
|
}
|
||||||
this.teamGateBlocks.clear();
|
this.teamGateBlocks.clear();
|
||||||
if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
if (this.warzone.getWarzoneConfig().getBoolean(WarzoneConfig.AUTOASSIGN)) {
|
||||||
this.autoAssignGate = new BlockInfo(lobbyMiddleWallBlock);
|
this.autoAssignGate = lobbyMiddleWallBlock.getLocation();
|
||||||
} else {
|
} else {
|
||||||
this.autoAssignGate = null;
|
this.autoAssignGate = null;
|
||||||
for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) {
|
for (int doorIndex = 0; doorIndex < this.warzone.getTeams().size(); doorIndex++) {
|
||||||
@ -427,23 +426,23 @@ public class ZoneLobby {
|
|||||||
if (this.warzone.getTeams().size() % 2 == 0) {
|
if (this.warzone.getTeams().size() % 2 == 0) {
|
||||||
// even number of teams
|
// even number of teams
|
||||||
if (doorIndex % 2 == 0) {
|
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 {
|
} 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 {
|
} else {
|
||||||
if (doorIndex == 0) {
|
if (doorIndex == 0) {
|
||||||
this.teamGateBlocks.put(team.getName(), new BlockInfo(lobbyMiddleWallBlock));
|
this.teamGateBlocks.put(team.getName(), lobbyMiddleWallBlock.getLocation());
|
||||||
} else if (doorIndex % 2 == 0) {
|
} 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 {
|
} 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) {
|
private void placeTeamGate(Block block, TeamKind teamKind) {
|
||||||
@ -573,7 +572,7 @@ public class ZoneLobby {
|
|||||||
|
|
||||||
List<Team> teams = this.warzone.getTeams();
|
List<Team> teams = this.warzone.getTeams();
|
||||||
|
|
||||||
Block autoAssignGateBlock = BlockInfo.getBlock(this.volume.getWorld(), this.autoAssignGate);
|
Block autoAssignGateBlock = this.autoAssignGate.getBlock();
|
||||||
|
|
||||||
// minimal air path
|
// minimal air path
|
||||||
this.clearGatePath(autoAssignGateBlock, front, leftSide, rightSide, false);
|
this.clearGatePath(autoAssignGateBlock, front, leftSide, rightSide, false);
|
||||||
@ -601,7 +600,7 @@ public class ZoneLobby {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInTeamGate(Team team, Location location) {
|
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 (info != null) {
|
||||||
if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) {
|
if (location.getBlockX() == info.getX() && location.getBlockY() == info.getY() && location.getBlockZ() == info.getZ()) {
|
||||||
return true;
|
return true;
|
||||||
@ -648,13 +647,13 @@ public class ZoneLobby {
|
|||||||
public boolean blockIsAGateBlock(Block block, BlockFace blockWall) {
|
public boolean blockIsAGateBlock(Block block, BlockFace blockWall) {
|
||||||
if (blockWall == this.wall) {
|
if (blockWall == this.wall) {
|
||||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||||
BlockInfo gateInfo = this.teamGateBlocks.get(teamName);
|
Location gateInfo = this.teamGateBlocks.get(teamName);
|
||||||
if (this.isPartOfGate(BlockInfo.getBlock(this.volume.getWorld(), gateInfo), block)) {
|
if (this.isPartOfGate(gateInfo.getBlock(), block)) {
|
||||||
return true;
|
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
|
// auto assign
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -689,9 +688,9 @@ public class ZoneLobby {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void resetTeamGateSign(Team team) {
|
public void resetTeamGateSign(Team team) {
|
||||||
BlockInfo info = this.teamGateBlocks.get(team.getName());
|
Location info = this.teamGateBlocks.get(team.getName());
|
||||||
if (info != null) {
|
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();
|
right = Direction.NORTH();
|
||||||
}
|
}
|
||||||
if (this.autoAssignGate != null) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (String teamName : this.teamGateBlocks.keySet()) {
|
for (String teamName : this.teamGateBlocks.keySet()) {
|
||||||
|
|
||||||
BlockInfo info = this.teamGateBlocks.get(teamName);
|
Location info = this.teamGateBlocks.get(teamName);
|
||||||
if (this.leaving(location, BlockInfo.getBlock(this.volume.getWorld(), info), inside, left, right)) {
|
if (this.leaving(location, info.getBlock(), inside, left, right)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
// }
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,9 +1,7 @@
|
|||||||
package com.tommytony.war.volume;
|
package com.tommytony.war.volume;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -12,13 +10,8 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.block.BlockState;
|
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.inventory.ItemStack;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.job.BlockResetJob;
|
import com.tommytony.war.job.BlockResetJob;
|
||||||
import com.tommytony.war.utility.Direction;
|
import com.tommytony.war.utility.Direction;
|
||||||
@ -31,12 +24,9 @@ import com.tommytony.war.utility.Direction;
|
|||||||
public class Volume {
|
public class Volume {
|
||||||
private String name;
|
private String name;
|
||||||
private World world;
|
private World world;
|
||||||
private BlockInfo cornerOne;
|
private Location cornerOne;
|
||||||
private BlockInfo cornerTwo;
|
private Location cornerTwo;
|
||||||
private int[][][] blockTypes = null;
|
private List<BlockState> blocks = new ArrayList<BlockState>();
|
||||||
private byte[][][] blockDatas = null;
|
|
||||||
private HashMap<String, String[]> signLines = new HashMap<String, String[]>();
|
|
||||||
private HashMap<String, List<ItemStack>> invBlockContents = new HashMap<String, List<ItemStack>>();
|
|
||||||
|
|
||||||
public Volume(String name, World world) {
|
public Volume(String name, World world) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -50,8 +40,8 @@ public class Volume {
|
|||||||
public Volume(Location corner1, Location corner2) {
|
public Volume(Location corner1, Location corner2) {
|
||||||
this(corner1.getWorld());
|
this(corner1.getWorld());
|
||||||
Validate.isTrue(corner1.getWorld() == corner2.getWorld(), "Cross-world volume");
|
Validate.isTrue(corner1.getWorld() == corner2.getWorld(), "Cross-world volume");
|
||||||
this.cornerOne = new BlockInfo(corner1.getBlock());
|
this.cornerOne = corner1;
|
||||||
this.cornerTwo = new BlockInfo(corner2.getBlock());
|
this.cornerTwo = corner2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String newName) {
|
public void setName(String newName) {
|
||||||
@ -71,271 +61,58 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCornerOne(Block block) {
|
public void setCornerOne(Block block) {
|
||||||
this.cornerOne = new BlockInfo(block);
|
this.cornerOne = block.getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCornerOne(BlockInfo blockInfo) {
|
public void setCornerOne(Location location) {
|
||||||
this.cornerOne = blockInfo;
|
this.cornerOne = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int saveBlocks() {
|
public void saveBlocks() {
|
||||||
int noOfSavedBlocks = 0;
|
this.blocks.clear();
|
||||||
int x = 0;
|
for (int x = this.getMinX(); x <= this.getMaxX(); x++) {
|
||||||
int y = 0;
|
for (int y = this.getMinY(); y <= this.getMaxY(); y++) {
|
||||||
int z = 0;
|
for (int z = this.getMinZ(); z <= this.getMaxZ(); z++) {
|
||||||
try {
|
this.blocks.add(world.getBlockAt(x, y, z).getState());
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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() {
|
public void resetBlocksAsJob() {
|
||||||
BlockResetJob job = new BlockResetJob(this);
|
BlockResetJob job = new BlockResetJob(this);
|
||||||
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int resetBlocks() {
|
public void resetBlocks() {
|
||||||
int visitedBlocks = 0, noOfResetBlocks = 0, x = 0, y = 0, z = 0;
|
for (BlockState state : this.blocks) {
|
||||||
int currentBlockId = 0;
|
state.update(true, false);
|
||||||
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();
|
|
||||||
}
|
|
||||||
return noOfResetBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[][][] getBlockDatas() {
|
|
||||||
return this.blockDatas;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBlockDatas(byte[][][] data) {
|
|
||||||
this.blockDatas = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCornerTwo(Block block) {
|
public void setCornerTwo(Block block) {
|
||||||
this.cornerTwo = new BlockInfo(block);
|
this.cornerTwo = block.getLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCornerTwo(BlockInfo blockInfo) {
|
public void setCornerTwo(Location location) {
|
||||||
this.cornerTwo = blockInfo;
|
this.cornerTwo = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getMinXBlock() {
|
public Location getMinXBlock() {
|
||||||
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
|
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
|
||||||
return this.cornerOne;
|
return this.cornerOne;
|
||||||
}
|
}
|
||||||
return this.cornerTwo;
|
return this.cornerTwo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getMinYBlock() {
|
public Location getMinYBlock() {
|
||||||
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
|
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
|
||||||
return this.cornerOne;
|
return this.cornerOne;
|
||||||
}
|
}
|
||||||
return this.cornerTwo;
|
return this.cornerTwo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getMinZBlock() {
|
public Location getMinZBlock() {
|
||||||
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
|
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
|
||||||
return this.cornerOne;
|
return this.cornerOne;
|
||||||
}
|
}
|
||||||
@ -343,32 +120,32 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getMinX() {
|
public int getMinX() {
|
||||||
return this.getMinXBlock().getX();
|
return this.getMinXBlock().getBlockX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinY() {
|
public int getMinY() {
|
||||||
return this.getMinYBlock().getY();
|
return this.getMinYBlock().getBlockY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMinZ() {
|
public int getMinZ() {
|
||||||
return this.getMinZBlock().getZ();
|
return this.getMinZBlock().getBlockZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getMaxXBlock() {
|
public Location getMaxXBlock() {
|
||||||
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
|
if (this.cornerOne.getX() < this.cornerTwo.getX()) {
|
||||||
return this.cornerTwo;
|
return this.cornerTwo;
|
||||||
}
|
}
|
||||||
return this.cornerOne;
|
return this.cornerOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getMaxYBlock() {
|
public Location getMaxYBlock() {
|
||||||
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
|
if (this.cornerOne.getY() < this.cornerTwo.getY()) {
|
||||||
return this.cornerTwo;
|
return this.cornerTwo;
|
||||||
}
|
}
|
||||||
return this.cornerOne;
|
return this.cornerOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getMaxZBlock() {
|
public Location getMaxZBlock() {
|
||||||
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
|
if (this.cornerOne.getZ() < this.cornerTwo.getZ()) {
|
||||||
return this.cornerTwo;
|
return this.cornerTwo;
|
||||||
}
|
}
|
||||||
@ -376,15 +153,15 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxX() {
|
public int getMaxX() {
|
||||||
return this.getMaxXBlock().getX();
|
return this.getMaxXBlock().getBlockX();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxY() {
|
public int getMaxY() {
|
||||||
return this.getMaxYBlock().getY();
|
return this.getMaxYBlock().getBlockY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxZ() {
|
public int getMaxZ() {
|
||||||
return this.getMaxZBlock().getZ();
|
return this.getMaxZBlock().getBlockZ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSizeX() {
|
public int getSizeX() {
|
||||||
@ -400,18 +177,22 @@ public class Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSaved() {
|
public boolean isSaved() {
|
||||||
return this.getBlockTypes() != null;
|
return this.blocks.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[][][] getBlockTypes() {
|
public List<BlockState> getBlocks() {
|
||||||
return this.blockTypes;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getCornerOne() {
|
public void setBlocks(List<BlockState> blocks) {
|
||||||
|
this.blocks = blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location getCornerOne() {
|
||||||
return this.cornerOne;
|
return this.cornerOne;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockInfo getCornerTwo() {
|
public Location getCornerTwo() {
|
||||||
return this.cornerTwo;
|
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();
|
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() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
@ -532,29 +309,13 @@ public class Volume {
|
|||||||
this.replaceMaterials(nonFloatingBlocks, Material.AIR);
|
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
|
@Override
|
||||||
public void finalize() {
|
public void finalize() {
|
||||||
this.blockDatas = null;
|
this.blocks.clear();
|
||||||
this.blockTypes = null;
|
this.blocks = null;
|
||||||
this.signLines.clear();
|
}
|
||||||
this.signLines = null;
|
|
||||||
this.invBlockContents.clear();
|
public int size() {
|
||||||
this.invBlockContents = null;
|
return this.getSizeX() * this.getSizeY() * this.getSizeZ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package com.tommytony.war.volume;
|
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.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
|
||||||
|
|
||||||
import com.tommytony.war.Team;
|
import com.tommytony.war.Team;
|
||||||
import com.tommytony.war.War;
|
import com.tommytony.war.War;
|
||||||
import com.tommytony.war.Warzone;
|
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.mapper.ZoneVolumeMapper;
|
||||||
import com.tommytony.war.structure.Monument;
|
import com.tommytony.war.structure.Monument;
|
||||||
|
|
||||||
@ -26,12 +31,17 @@ public class ZoneVolume extends Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int saveBlocks() {
|
public void saveBlocks() {
|
||||||
// Save blocks directly to disk (i.e. don't put everything in memory)
|
// 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);
|
War.war.log("Saved " + saved + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
|
||||||
this.isSaved = true;
|
this.isSaved = true;
|
||||||
return saved;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,35 +49,54 @@ public class ZoneVolume extends Volume {
|
|||||||
return this.isSaved;
|
return this.isSaved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCorners() {
|
public void loadCorners() throws SQLException {
|
||||||
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true);
|
ZoneVolumeMapper.load(this, this.zone.getName(), this.getWorld(), true, 0, 0);
|
||||||
this.isSaved = true;
|
this.isSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int resetBlocks() {
|
public void resetBlocks() {
|
||||||
// Load blocks directly from disk and onto the map (i.e. no more in-memory warzone blocks)
|
// 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);
|
War.war.log("Reset " + reset + " blocks in warzone " + this.zone.getName() + ".", java.util.logging.Level.INFO);
|
||||||
this.isSaved = true;
|
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
|
@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 setNorthwest(Location block) throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
public void setBlockDatas(byte[][][] blockData) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNorthwest(Block block) throws NotNorthwestException, TooSmallException, TooBigException {
|
|
||||||
// northwest defaults to top block
|
// northwest defaults to top block
|
||||||
BlockInfo topBlock = new BlockInfo(block.getX(), 127, block.getZ(), block.getTypeId(), block.getData());
|
Location topBlock = new Location(block.getWorld(), block.getX(), block.getWorld().getMaxHeight(), block.getZ());
|
||||||
BlockInfo oldCornerOne = this.getCornerOne();
|
Location oldCornerOne = this.getCornerOne();
|
||||||
BlockInfo oldCornerTwo = this.getCornerTwo();
|
Location oldCornerTwo = this.getCornerTwo();
|
||||||
if (this.getCornerOne() == null) {
|
if (this.getCornerOne() == null) {
|
||||||
if (this.getCornerTwo() == null) {
|
if (this.getCornerTwo() == null) {
|
||||||
// northwest defaults to corner 1
|
// northwest defaults to corner 1
|
||||||
@ -89,10 +118,8 @@ public class ZoneVolume extends Volume {
|
|||||||
if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) {
|
if (this.getSoutheastX() <= block.getX() || this.getSoutheastZ() >= block.getZ()) {
|
||||||
throw new NotNorthwestException();
|
throw new NotNorthwestException();
|
||||||
}
|
}
|
||||||
BlockInfo minXBlock = this.getMinXBlock(); // north means min X
|
this.getMinXBlock().setX(block.getX()); // north means min X
|
||||||
minXBlock.setX(block.getX()); // mutating, argh!
|
this.getMaxZBlock().setZ(block.getZ()); // west means max Z
|
||||||
BlockInfo maxZBlock = this.getMaxZBlock(); // west means max Z
|
|
||||||
maxZBlock.setZ(block.getZ());
|
|
||||||
}
|
}
|
||||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||||
super.setCornerOne(oldCornerOne);
|
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
|
// southeast defaults to bottom block
|
||||||
BlockInfo bottomBlock = new BlockInfo(block.getX(), 0, block.getZ(), block.getTypeId(), block.getData());
|
Location bottomBlock = new Location(block.getWorld(), block.getX(), 0, block.getZ());
|
||||||
BlockInfo oldCornerOne = this.getCornerOne();
|
Location oldCornerOne = this.getCornerOne();
|
||||||
BlockInfo oldCornerTwo = this.getCornerTwo();
|
Location oldCornerTwo = this.getCornerTwo();
|
||||||
if (this.getCornerTwo() == null) {
|
if (this.getCornerTwo() == null) {
|
||||||
if (this.getCornerOne() == null) {
|
if (this.getCornerOne() == null) {
|
||||||
// southeast defaults to corner 2
|
// southeast defaults to corner 2
|
||||||
@ -147,10 +174,8 @@ public class ZoneVolume extends Volume {
|
|||||||
if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) {
|
if (this.getNorthwestX() >= block.getX() || this.getNorthwestZ() <= block.getZ()) {
|
||||||
throw new NotSoutheastException();
|
throw new NotSoutheastException();
|
||||||
}
|
}
|
||||||
BlockInfo maxXBlock = this.getMaxXBlock(); // south means max X
|
this.getMaxXBlock().setX(block.getX()); // south means max X
|
||||||
maxXBlock.setX(block.getX()); // mutating, argh!
|
this.getMinZBlock().setZ(block.getZ()); // east means min Z
|
||||||
BlockInfo minZBlock = this.getMinZBlock(); // east means min Z
|
|
||||||
minZBlock.setZ(block.getZ());
|
|
||||||
}
|
}
|
||||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||||
super.setCornerOne(oldCornerOne);
|
super.setCornerOne(oldCornerOne);
|
||||||
@ -189,7 +214,7 @@ public class ZoneVolume extends Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException {
|
public void setZoneCornerOne(Block block) throws TooSmallException, TooBigException {
|
||||||
BlockInfo oldCornerOne = this.getCornerOne();
|
Location oldCornerOne = this.getCornerOne();
|
||||||
super.setCornerOne(block);
|
super.setCornerOne(block);
|
||||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||||
super.setCornerOne(oldCornerOne);
|
super.setCornerOne(oldCornerOne);
|
||||||
@ -201,7 +226,7 @@ public class ZoneVolume extends Volume {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException {
|
public void setZoneCornerTwo(Block block) throws TooSmallException, TooBigException {
|
||||||
BlockInfo oldCornerTwo = this.getCornerTwo();
|
Location oldCornerTwo = this.getCornerTwo();
|
||||||
super.setCornerTwo(block);
|
super.setCornerTwo(block);
|
||||||
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
if (this.tooSmall() || this.zoneStructuresAreOutside()) {
|
||||||
super.setCornerTwo(oldCornerTwo);
|
super.setCornerTwo(oldCornerTwo);
|
||||||
@ -251,8 +276,8 @@ public class ZoneVolume extends Volume {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInside(BlockInfo info) {
|
private boolean isInside(Location location) {
|
||||||
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()) {
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -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.newscores = New scores - {0}
|
||||||
zone.battle.next = The battle was interrupted. Resetting warzone {0}...
|
zone.battle.next = The battle was interrupted. Resetting warzone {0}...
|
||||||
zone.battle.reset = A new battle begins. Resetting warzone...
|
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.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.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.
|
zone.flagcapture.broadcast = {0} captured team {1}''s flag. Team {2} scores one point.
|
||||||
|
@ -1,52 +1,52 @@
|
|||||||
package com.tommytony.war.spec.volumes;
|
package com.tommytony.war.spec.volumes;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import com.tommytony.war.Team;
|
||||||
import static org.mockito.Mockito.*;
|
import com.tommytony.war.Warzone;
|
||||||
|
|
||||||
import com.tommytony.war.*;
|
|
||||||
import com.tommytony.war.structure.Monument;
|
import com.tommytony.war.structure.Monument;
|
||||||
import com.tommytony.war.volume.*;
|
import com.tommytony.war.volume.NotNorthwestException;
|
||||||
|
import com.tommytony.war.volume.NotSoutheastException;
|
||||||
|
import com.tommytony.war.volume.TooBigException;
|
||||||
|
import com.tommytony.war.volume.TooSmallException;
|
||||||
|
import com.tommytony.war.volume.ZoneVolume;
|
||||||
|
|
||||||
public class ZoneVolumeSpecTest {
|
public class ZoneVolumeSpecTest {
|
||||||
|
|
||||||
// setNorthwest
|
// setNorthwest
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop() throws NotNorthwestException, TooSmallException, TooBigException{
|
public void setNorthwest_whenCreatingAndNoCornersAreSet_shouldSetCorner1AtTop()
|
||||||
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
|
when(worldMock.getMaxHeight()).thenReturn(256);
|
||||||
Warzone zoneMock = mock(Warzone.class);
|
Warzone zoneMock = mock(Warzone.class);
|
||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, 0, 64, 0);
|
||||||
when(blockMock.getX()).thenReturn(0);
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(0);
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
volume.setNorthwest(blockMock);
|
volume.setNorthwest(nw);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals(null, volume.getCornerTwo());
|
Location movedOne = new Location(worldMock, 0, 256, 0);
|
||||||
assertEquals(0, volume.getCornerOne().getX());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(127, volume.getCornerOne().getY()); // the corner should shoot up to the top
|
|
||||||
assertEquals(0, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(10, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = NotNorthwestException.class)
|
||||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToEastOfCorner2_shouldThrowNotNorthwestException()
|
||||||
|
throws TooSmallException, TooBigException, NotNorthwestException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -54,33 +54,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
boolean failed = false;
|
volume.setNorthwest(nw);
|
||||||
try {
|
|
||||||
volume.setNorthwest(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotNorthwestException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
@Test(expected = NotNorthwestException.class)
|
||||||
// first corner shouldn't move
|
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException()
|
||||||
assertTrue(failed);
|
throws TooSmallException, TooBigException, NotNorthwestException {
|
||||||
assertEquals(null, volume.getCornerOne());
|
|
||||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsToSouthOfCorner2_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -88,33 +72,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, 64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
boolean failed = false;
|
volume.setNorthwest(nw);
|
||||||
try {
|
|
||||||
volume.setNorthwest(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotNorthwestException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
@Test(expected = TooSmallException.class)
|
||||||
// first corner shouldn't move
|
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException()
|
||||||
assertTrue(failed);
|
throws NotNorthwestException, TooBigException, TooSmallException {
|
||||||
assertEquals(null, volume.getCornerOne());
|
|
||||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooCloseToCorner2_shouldThrowTooSmallException() throws NotNorthwestException, TooBigException{
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -122,33 +90,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -5, 64, 5);
|
||||||
when(blockMock.getX()).thenReturn(-5); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(5); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
boolean failed = false;
|
volume.setNorthwest(nw);
|
||||||
try {
|
|
||||||
volume.setNorthwest(blockMock);
|
|
||||||
}
|
|
||||||
catch(TooSmallException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
@Test(expected = TooBigException.class)
|
||||||
// first corner shouldn't move
|
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException()
|
||||||
assertTrue(failed);
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
assertEquals(null, volume.getCornerOne());
|
|
||||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setNorthwest_whenCreating_AndNoCorner1IsSet_ButCorner2Set_AndNewCornerBlockIsTooFarFromCorner2_shouldThrowTooBigException() throws NotNorthwestException, TooSmallException{
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -156,103 +108,43 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -1000, 64, 1000);
|
||||||
when(blockMock.getX()).thenReturn(-1000); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(1000); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
boolean failed = false;
|
volume.setNorthwest(nw);
|
||||||
try {
|
|
||||||
volume.setNorthwest(blockMock);
|
|
||||||
}
|
|
||||||
catch(TooBigException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// first corner shouldn't move
|
|
||||||
assertTrue(failed);
|
|
||||||
assertEquals(null, volume.getCornerOne());
|
|
||||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop() throws NotNorthwestException, TooSmallException, TooBigException{ // nw always goes to top
|
public void setNorthwest_whenCreatingAndCorner1AlreadySet_shouldSetCorner2AtTop()
|
||||||
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
|
when(worldMock.getMaxHeight()).thenReturn(256);
|
||||||
Warzone zoneMock = mock(Warzone.class);
|
Warzone zoneMock = mock(Warzone.class);
|
||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
volume.setNorthwest(blockMock);
|
volume.setNorthwest(nw);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner shouldn't move
|
// first corner shouldn't move
|
||||||
assertEquals(0, volume.getCornerOne().getX());
|
|
||||||
assertEquals(64, volume.getCornerOne().getY());
|
|
||||||
assertEquals(0, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(4, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
assertEquals(-64, volume.getCornerTwo().getX());
|
|
||||||
assertEquals(127, volume.getCornerTwo().getY()); // the new corner should shoot up to the top
|
|
||||||
assertEquals(64, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(10, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerTwo().getData());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
|
||||||
// Arrange
|
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
|
||||||
Warzone zoneMock = mock(Warzone.class);
|
|
||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
|
||||||
Block blockMock = mock(Block.class);
|
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
|
||||||
boolean failed = false;
|
|
||||||
try {
|
|
||||||
volume.setNorthwest(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotNorthwestException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// first corner shouldn't move
|
|
||||||
assertTrue(failed);
|
|
||||||
assertEquals(null, volume.getCornerTwo());
|
|
||||||
assertEquals(existingCorner1, volume.getCornerOne());
|
assertEquals(existingCorner1, volume.getCornerOne());
|
||||||
|
|
||||||
|
Location nwMax = new Location(worldMock, -64, 256, 64);
|
||||||
|
assertEquals(nwMax, volume.getCornerTwo());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = NotNorthwestException.class)
|
||||||
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException() throws TooSmallException, TooBigException{
|
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsEastOfCorner1_shouldThrowNotNorthwestException()
|
||||||
|
throws TooSmallException, TooBigException, NotNorthwestException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -260,33 +152,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
boolean failed = false;
|
volume.setNorthwest(nw);
|
||||||
try {
|
|
||||||
volume.setNorthwest(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotNorthwestException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
@Test(expected = NotNorthwestException.class)
|
||||||
// first corner shouldn't move
|
public void setNorthwest_whenCreating_AndCorner1AlreadySet_ButNewCornerBlockIsSouthOfCorner1_shouldThrowNotNorthwestException()
|
||||||
assertTrue(failed);
|
throws TooSmallException, TooBigException, NotNorthwestException {
|
||||||
assertEquals(null, volume.getCornerTwo());
|
|
||||||
assertEquals(existingCorner1, volume.getCornerOne());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1() throws NotNorthwestException, TooSmallException, TooBigException{
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -294,38 +170,45 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, 64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, 32, 2, (byte)2); // corner 1 at minX and maxZ (nw)
|
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, -32, 4, (byte)4); // corner 2 at maxX and minZ (se)
|
volume.setNorthwest(nw);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setNorthwest_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner1()
|
||||||
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
World worldMock = mock(World.class);
|
||||||
|
Warzone zoneMock = mock(Warzone.class);
|
||||||
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
|
Location nw = new Location(worldMock, -64, 64, 64);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Location existingCorner1 = new Location(worldMock, -32, 32, 32); // nw
|
||||||
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
|
Location existingCorner2 = new Location(worldMock, 32, 96, -32); // se
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setNorthwest(blockMock);
|
volume.setNorthwest(nw);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner should move but not along y
|
// first corner should move but not along y
|
||||||
assertEquals(-64, volume.getCornerOne().getX());
|
Location movedOne = new Location(worldMock, -64, 32, 64);
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(64, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner shouldn't move
|
// second corner shouldn't move
|
||||||
assertEquals(32, volume.getCornerTwo().getX());
|
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||||
assertEquals(96, volume.getCornerTwo().getY()); // moving an existing corner shouldn't change its height
|
|
||||||
assertEquals(-32, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2() throws NotNorthwestException, TooSmallException, TooBigException{
|
public void setNorthwest_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner2()
|
||||||
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -333,38 +216,27 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, -32, 2, (byte)2); // corner 1 at maxX and minZ (se)
|
Location existingCorner1 = new Location(worldMock, 32, 32, -32); // nw
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, 32, 4, (byte)4); // corner 2 at minX and maxZ (nw)
|
Location existingCorner2 = new Location(worldMock, -32, 96, 32); // se
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setNorthwest(blockMock);
|
volume.setNorthwest(nw);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner shouldn't move
|
// first corner shouldn't move
|
||||||
assertEquals(32, volume.getCornerOne().getX());
|
assertEquals(existingCorner1, volume.getCornerOne());
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
|
||||||
assertEquals(-32, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner should move but not along y
|
// second corner should move but not along y
|
||||||
assertEquals(-64, volume.getCornerTwo().getX());
|
Location movedTwo = new Location(worldMock, -64, 96, 64);
|
||||||
assertEquals(96, volume.getCornerTwo().getY()); // moving an existing corner shouldn't change its height
|
assertEquals(movedTwo, volume.getCornerTwo());
|
||||||
assertEquals(64, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z() throws NotNorthwestException, TooSmallException, TooBigException{
|
public void setNorthwest_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1XAndCorner2Z()
|
||||||
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -372,38 +244,28 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, -32, 2, (byte)2); // corner 1 at minX and minZ (ne)
|
Location existingCorner1 = new Location(worldMock, -32, 32, -32); // ne
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, 32, 4, (byte)4); // corner 2 at maxX and maxZ (sw)
|
Location existingCorner2 = new Location(worldMock, 32, 96, 32); // sw
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setNorthwest(blockMock);
|
volume.setNorthwest(nw);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner should move along x but not along y or z
|
// first corner should move along x but not along y or z
|
||||||
assertEquals(-64, volume.getCornerOne().getX());
|
Location movedOne = new Location(worldMock, -64, 32, -32);
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(-32, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner should move along z but not along x or y
|
// second corner should move along z but not along x or y
|
||||||
assertEquals(32, volume.getCornerTwo().getX());
|
Location movedTwo = new Location(worldMock, 32, 96, 64);
|
||||||
assertEquals(96, volume.getCornerTwo().getY());
|
assertEquals(movedTwo, volume.getCornerTwo());
|
||||||
assertEquals(64, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X() throws NotNorthwestException, TooSmallException, TooBigException{
|
public void setNorthwest_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1ZAndCorner2X()
|
||||||
|
throws NotNorthwestException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -411,34 +273,23 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location nw = new Location(worldMock, -64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, 32, 2, (byte)2); // corner 1 at maxX and maxZ (sw)
|
Location existingCorner1 = new Location(worldMock, 32, 32, 32); // sw
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, -32, 4, (byte)4); // corner 2 at minX and minZ (ne)
|
Location existingCorner2 = new Location(worldMock, -32, 96, -32); // ne
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setNorthwest(blockMock);
|
volume.setNorthwest(nw);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner should move along z but not along x or y
|
// first corner should move along z but not along x or y
|
||||||
assertEquals(32, volume.getCornerOne().getX());
|
Location movedOne = new Location(worldMock, 32, 32, 64);
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(64, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner should move along x but not along y or z
|
// second corner should move along x but not along y or z
|
||||||
assertEquals(-64, volume.getCornerTwo().getX());
|
Location movedTwo = new Location(worldMock, -64, 96, -32);
|
||||||
assertEquals(96, volume.getCornerTwo().getY());
|
assertEquals(movedTwo, volume.getCornerTwo());
|
||||||
assertEquals(-32, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getNorthwestX
|
// getNorthwestX
|
||||||
@ -448,7 +299,8 @@ public class ZoneVolumeSpecTest {
|
|||||||
// setSoutheast
|
// setSoutheast
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{
|
public void setSoutheast_whenCreatingAndNoCornersAreSet_shouldSetCorner2AtBottom()
|
||||||
|
throws NotSoutheastException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -456,27 +308,19 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 0, 64, 0);
|
||||||
when(blockMock.getX()).thenReturn(0);
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(0);
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
volume.setSoutheast(blockMock);
|
volume.setSoutheast(se);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
assertEquals(null, volume.getCornerOne());
|
Location movedOne = new Location(worldMock, 0, 0, 0);
|
||||||
assertEquals(0, volume.getCornerTwo().getX());
|
assertEquals(movedOne, volume.getCornerTwo());
|
||||||
assertEquals(0, volume.getCornerTwo().getY()); // the corner should shoot down
|
|
||||||
assertEquals(0, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(10, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = NotSoutheastException.class)
|
||||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToWestOfCorner1_shouldThrowNotSoutheastException()
|
||||||
|
throws TooSmallException, TooBigException, NotSoutheastException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -484,33 +328,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
boolean failed = false;
|
volume.setSoutheast(se);
|
||||||
try {
|
|
||||||
volume.setSoutheast(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotSoutheastException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
@Test(expected = NotSoutheastException.class)
|
||||||
// first corner shouldn't move
|
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException()
|
||||||
assertTrue(failed);
|
throws TooSmallException, TooBigException, NotSoutheastException {
|
||||||
assertEquals(null, volume.getCornerTwo());
|
|
||||||
assertEquals(existingCorner1, volume.getCornerOne());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setSoutheast_whenCreatingAndNoCorner2IsSet_ButCorner1IsAlreadySet_AndNewCornerBlockIsToNorthOfCorner1_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -518,33 +346,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, -64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner1 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
boolean failed = false;
|
volume.setSoutheast(se);
|
||||||
try {
|
|
||||||
volume.setSoutheast(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotSoutheastException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// first corner shouldn't move
|
|
||||||
assertTrue(failed);
|
|
||||||
assertEquals(null, volume.getCornerTwo());
|
|
||||||
assertEquals(existingCorner1, volume.getCornerOne());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom() throws NotSoutheastException, TooSmallException, TooBigException{ // se always goes to bottom
|
public void setSoutheast_whenCreatingAndCorner2AlreadySet_shouldSetCorner1AtBottom()
|
||||||
|
throws NotSoutheastException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -552,69 +364,24 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setSoutheast(blockMock);
|
volume.setSoutheast(se);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner shouldn't move
|
// first corner shouldn't move
|
||||||
assertEquals(0, volume.getCornerTwo().getX());
|
|
||||||
assertEquals(64, volume.getCornerTwo().getY());
|
|
||||||
assertEquals(0, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
|
|
||||||
assertEquals(64, volume.getCornerOne().getX());
|
|
||||||
assertEquals(0, volume.getCornerOne().getY()); // the new corner should shoot down
|
|
||||||
assertEquals(-64, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(10, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
|
||||||
// Arrange
|
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
|
||||||
Warzone zoneMock = mock(Warzone.class);
|
|
||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
|
||||||
Block blockMock = mock(Block.class);
|
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(64); // further west
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
|
||||||
boolean failed = false;
|
|
||||||
try {
|
|
||||||
volume.setSoutheast(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotSoutheastException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert
|
|
||||||
// first corner shouldn't move
|
|
||||||
assertTrue(failed);
|
|
||||||
assertEquals(null, volume.getCornerOne());
|
|
||||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||||
|
|
||||||
|
Location movedSe = new Location(worldMock, 64, 0, -64);
|
||||||
|
assertEquals(movedSe, volume.getCornerOne());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected = NotSoutheastException.class)
|
||||||
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException() throws TooSmallException, TooBigException{
|
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToWestOfCorner2_shouldThrowNotSoutheastException()
|
||||||
|
throws TooSmallException, TooBigException, NotSoutheastException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -622,33 +389,17 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 64, 64, 64);
|
||||||
when(blockMock.getX()).thenReturn(-64); // further north
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner2 = new BlockInfo(0, 64, 0, 4, (byte)4);
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
boolean failed = false;
|
volume.setSoutheast(se);
|
||||||
try {
|
|
||||||
volume.setSoutheast(blockMock);
|
|
||||||
}
|
|
||||||
catch(NotSoutheastException e) {
|
|
||||||
failed = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert
|
@Test(expected = NotSoutheastException.class)
|
||||||
// first corner shouldn't move
|
public void setSoutheast_whenCreating_AndCorner2AlreadySet_ButNewCornerBlockIsToNorthOfCorner2_shouldThrowNotSoutheastException()
|
||||||
assertTrue(failed);
|
throws TooSmallException, TooBigException, NotSoutheastException {
|
||||||
assertEquals(null, volume.getCornerOne());
|
|
||||||
assertEquals(existingCorner2, volume.getCornerTwo());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2() throws NotSoutheastException, TooSmallException, TooBigException{
|
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -656,38 +407,45 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, -64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, 32, 2, (byte)2); // corner 1 at minX and maxZ (nw)
|
Location existingCorner2 = new Location(worldMock, 0, 64, 0);
|
||||||
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
|
volume.setSoutheast(se);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setSoutheast_whenChangingVolumeWithCorner1NwCorner2Se_shouldMoveCorner2()
|
||||||
|
throws NotSoutheastException, TooSmallException, TooBigException {
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
World worldMock = mock(World.class);
|
||||||
|
Warzone zoneMock = mock(Warzone.class);
|
||||||
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
|
Location se = new Location(worldMock, 64, 64, -64);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
Location existingCorner1 = new Location(worldMock, -32, 32, 32); // nw
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, -32, 4, (byte)4); // corner 2 at maxX and minZ (se)
|
Location existingCorner2 = new Location(worldMock, 32, 96, -32); // se
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setSoutheast(blockMock);
|
volume.setSoutheast(se);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner shouldn't move
|
// first corner shouldn't move
|
||||||
assertEquals(-32, volume.getCornerOne().getX());
|
assertEquals(existingCorner1, volume.getCornerOne());
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
|
||||||
assertEquals(32, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner should move but not along y
|
// second corner should move but not along y
|
||||||
assertEquals(64, volume.getCornerTwo().getX());
|
Location movedTwo = new Location(worldMock, 64, 96, -64);
|
||||||
assertEquals(96, volume.getCornerTwo().getY());
|
assertEquals(movedTwo, volume.getCornerTwo());
|
||||||
assertEquals(-64, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1() throws NotSoutheastException, TooSmallException, TooBigException{
|
public void setSoutheast_whenChangingVolumeWithCorner1SeCorner2Nw_shouldMoveCorner1()
|
||||||
|
throws NotSoutheastException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -695,38 +453,27 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, -32, 2, (byte)2); // corner 1 at maxX and minZ (se)
|
Location existingCorner1 = new Location(worldMock, 32, 32, -32); // se
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, 32, 4, (byte)4); // corner 2 at minX and maxZ (nw)
|
Location existingCorner2 = new Location(worldMock, -32, 96, 32); // nw
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setSoutheast(blockMock);
|
volume.setSoutheast(se);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner should move but not along y
|
// first corner should move but not along y
|
||||||
assertEquals(64, volume.getCornerOne().getX());
|
Location movedOne = new Location(worldMock, 64, 32, -64);
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(-64, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner shouldn't move
|
// second corner shouldn't move
|
||||||
assertEquals(-32, volume.getCornerTwo().getX());
|
assertEquals(existingCorner2, volume.getCornerTwo());
|
||||||
assertEquals(96, volume.getCornerTwo().getY());
|
|
||||||
assertEquals(32, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X() throws NotSoutheastException, TooSmallException, TooBigException{
|
public void setSoutheast_whenChangingVolumeWithCorner1NeCorner2Sw_shouldMoveCorner1ZAndCorner2X()
|
||||||
|
throws NotSoutheastException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -734,38 +481,28 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(-32, 32, -32, 2, (byte)2); // corner 1 at minX and minZ (ne)
|
Location existingCorner1 = new Location(worldMock, -32, 32, -32); // ne
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(32, 96, 32, 4, (byte)4); // corner 2 at maxX and maxZ (sw)
|
Location existingCorner2 = new Location(worldMock, 32, 96, 32); // sw
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setSoutheast(blockMock);
|
volume.setSoutheast(se);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner should move along z but not along x or y
|
// first corner should move along z but not along x or y
|
||||||
assertEquals(-32, volume.getCornerOne().getX());
|
Location movedOne = new Location(worldMock, -32, 32, -64);
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(-64, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner should move along x but not along y or z
|
// second corner should move along x but not along y or z
|
||||||
assertEquals(64, volume.getCornerTwo().getX());
|
Location movedTwo = new Location(worldMock, 64, 96, 32);
|
||||||
assertEquals(96, volume.getCornerTwo().getY());
|
assertEquals(movedTwo, volume.getCornerTwo());
|
||||||
assertEquals(32, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z() throws NotSoutheastException, TooSmallException, TooBigException{
|
public void setSoutheast_whenChangingVolumeWithCorner1SwCorner2Ne_shouldMoveCorner1XAndCorner2Z()
|
||||||
|
throws NotSoutheastException, TooSmallException, TooBigException {
|
||||||
// Arrange
|
// Arrange
|
||||||
|
|
||||||
World worldMock = mock(World.class);
|
World worldMock = mock(World.class);
|
||||||
@ -773,34 +510,23 @@ public class ZoneVolumeSpecTest {
|
|||||||
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
when(zoneMock.getTeams()).thenReturn(new ArrayList<Team>());
|
||||||
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
when(zoneMock.getMonuments()).thenReturn(new ArrayList<Monument>());
|
||||||
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
ZoneVolume volume = new ZoneVolume("test", worldMock, zoneMock);
|
||||||
Block blockMock = mock(Block.class);
|
Location se = new Location(worldMock, 64, 64, -64);
|
||||||
when(blockMock.getX()).thenReturn(64); // further south
|
|
||||||
when(blockMock.getY()).thenReturn(64); // at sea level
|
|
||||||
when(blockMock.getZ()).thenReturn(-64); // further east
|
|
||||||
when(blockMock.getTypeId()).thenReturn(10);
|
|
||||||
when(blockMock.getData()).thenReturn((byte)2);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
BlockInfo existingCorner1 = new BlockInfo(32, 32, 32, 2, (byte)2); // corner 1 at maxX and maxZ (sw)
|
Location existingCorner1 = new Location(worldMock, 32, 32, 32); // sw
|
||||||
volume.setCornerOne(existingCorner1); // corner 1 already set
|
volume.setCornerOne(existingCorner1); // corner 1 already set
|
||||||
BlockInfo existingCorner2 = new BlockInfo(-32, 96, -32, 4, (byte)4); // corner 2 at minX and minZ (ne)
|
Location existingCorner2 = new Location(worldMock, -32, 96, -32); // ne
|
||||||
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
volume.setCornerTwo(existingCorner2); // corner 2 already set
|
||||||
volume.setSoutheast(blockMock);
|
volume.setSoutheast(se);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
// first corner should move along x but not along y or z
|
// first corner should move along x but not along y or z
|
||||||
assertEquals(64, volume.getCornerOne().getX());
|
Location movedOne = new Location(worldMock, 64, 32, 32);
|
||||||
assertEquals(32, volume.getCornerOne().getY());
|
assertEquals(movedOne, volume.getCornerOne());
|
||||||
assertEquals(32, volume.getCornerOne().getZ());
|
|
||||||
assertEquals(2, volume.getCornerOne().getTypeId());
|
|
||||||
assertEquals((byte)2, volume.getCornerOne().getData());
|
|
||||||
|
|
||||||
// second corner should move along z but not along x or y
|
// second corner should move along z but not along x or y
|
||||||
assertEquals(-32, volume.getCornerTwo().getX());
|
Location movedTwo = new Location(worldMock, -32, 96, -64);
|
||||||
assertEquals(96, volume.getCornerTwo().getY());
|
assertEquals(movedTwo, volume.getCornerTwo());
|
||||||
assertEquals(-64, volume.getCornerTwo().getZ());
|
|
||||||
assertEquals(4, volume.getCornerTwo().getTypeId());
|
|
||||||
assertEquals((byte)4, volume.getCornerTwo().getData());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSoutheastX
|
// getSoutheastX
|
||||||
|
Loading…
Reference in New Issue
Block a user