mirror of
https://github.com/taoneill/war.git
synced 2024-11-30 22:23:27 +01:00
Fixed broken build. Volume mapping is much cleaner now. Getting started on WarHub and ZoneLobby.
This commit is contained in:
parent
e33a19cc4f
commit
e5497786f3
@ -53,8 +53,7 @@ public class War extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
this.log = Logger.getLogger("Minecraft");
|
this.log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
// Register hMod hooks
|
// Register hooks
|
||||||
|
|
||||||
PluginManager pm = getServer().getPluginManager();
|
PluginManager pm = getServer().getPluginManager();
|
||||||
|
|
||||||
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
|
pm.registerEvent(Event.Type.PLAYER_LOGIN, playerListener, Priority.Normal, this);
|
||||||
@ -71,7 +70,7 @@ public class War extends JavaPlugin {
|
|||||||
pm.registerEvent(Event.Type.BLOCK_CANBUILD, blockListener, Priority.Normal, this); // BLOCK_PLACE
|
pm.registerEvent(Event.Type.BLOCK_CANBUILD, blockListener, Priority.Normal, this); // BLOCK_PLACE
|
||||||
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); // BROKEN
|
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this); // BROKEN
|
||||||
|
|
||||||
// Load files from disk or create them
|
// Load files from disk or create them (using these defaults)
|
||||||
this.defaultLoadout.put(0, new ItemStack(Material.StoneSword));
|
this.defaultLoadout.put(0, new ItemStack(Material.StoneSword));
|
||||||
this.defaultLoadout.put(1, new ItemStack(Material.Bow));
|
this.defaultLoadout.put(1, new ItemStack(Material.Bow));
|
||||||
this.defaultLoadout.put(2, new ItemStack(Material.Arrow, 7));
|
this.defaultLoadout.put(2, new ItemStack(Material.Arrow, 7));
|
||||||
@ -176,7 +175,7 @@ public class War extends JavaPlugin {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Warzone zoneOfTooCloseZoneWall(Location location) {
|
public Warzone zoneOfZoneWallAtProximity(Location location) {
|
||||||
for(Warzone zone : warzones) {
|
for(Warzone zone : warzones) {
|
||||||
if(zone.isNearWall(location)) return zone;
|
if(zone.isNearWall(location)) return zone;
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ public class WarPlayerListener extends PlayerListener {
|
|||||||
|
|
||||||
// Zone walls
|
// Zone walls
|
||||||
if(to != null) {
|
if(to != null) {
|
||||||
Warzone nearbyZone = war.zoneOfTooCloseZoneWall(to);
|
Warzone nearbyZone = war.zoneOfZoneWallAtProximity(to);
|
||||||
if(nearbyZone != null) {
|
if(nearbyZone != null) {
|
||||||
nearbyZone.protectZoneWallAgainstPlayer(player);
|
nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,7 +15,7 @@ import com.tommytony.war.volumes.Volume;
|
|||||||
*/
|
*/
|
||||||
public class Monument {
|
public class Monument {
|
||||||
private Location location;
|
private Location location;
|
||||||
private Volume volume;
|
private CenteredVolume volume;
|
||||||
|
|
||||||
private Team ownerTeam = null;
|
private Team ownerTeam = null;
|
||||||
private final String name;
|
private final String name;
|
||||||
@ -151,11 +151,11 @@ public class Monument {
|
|||||||
this.addMonumentBlocks();
|
this.addMonumentBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Volume getVolume() {
|
public CenteredVolume getVolume() {
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVolume(Volume newVolume) {
|
public void setVolume(CenteredVolume newVolume) {
|
||||||
this.volume = newVolume;
|
this.volume = newVolume;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ public class Team {
|
|||||||
this.warzone = warzone;
|
this.warzone = warzone;
|
||||||
this.setName(name);
|
this.setName(name);
|
||||||
this.teamSpawn = teamSpawn;
|
this.teamSpawn = teamSpawn;
|
||||||
this.volume = new Volume(name, war, warzone);
|
this.setVolume(new Volume(name, war, warzone.getWorld()));
|
||||||
this.material = material;
|
this.material = material;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ public class Team {
|
|||||||
|
|
||||||
// this resets the block to old state
|
// this resets the block to old state
|
||||||
this.setVolume();
|
this.setVolume();
|
||||||
volume.saveBlocks();
|
getVolume().saveBlocks();
|
||||||
|
|
||||||
initializeTeamSpawn(teamSpawn);
|
initializeTeamSpawn(teamSpawn);
|
||||||
}
|
}
|
||||||
@ -214,4 +214,8 @@ public class Team {
|
|||||||
state.update(true);
|
state.update(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVolume(Volume volume) {
|
||||||
|
this.volume = volume;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class WarHub {
|
|||||||
this.war = war;
|
this.war = war;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.volume = new Volume("warHub", war, warzone);
|
this.volume = new Volume("warHub", war, world);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class Warzone {
|
|||||||
private World world;
|
private World world;
|
||||||
private Material originalSouthEastBlock;
|
private Material originalSouthEastBlock;
|
||||||
private Material originalNorthWestBlock;
|
private Material originalNorthWestBlock;
|
||||||
private final int minSafeDistanceFromWall = 4;
|
private final int minSafeDistanceFromWall = 5;
|
||||||
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
private List<ZoneWallGuard> zoneWallGuards = new ArrayList<ZoneWallGuard>();
|
||||||
private War war;
|
private War war;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ public class Warzone {
|
|||||||
this.setLifePool(war.getDefaultLifepool());
|
this.setLifePool(war.getDefaultLifepool());
|
||||||
this.setLoadout(war.getDefaultLoadout());
|
this.setLoadout(war.getDefaultLoadout());
|
||||||
this.drawZoneOutline = war.getDefaultDrawZoneOutline();
|
this.drawZoneOutline = war.getDefaultDrawZoneOutline();
|
||||||
this.volume = new VerticalVolume(name, war, this);
|
this.volume = new VerticalVolume(name, war, this.getWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ready() {
|
public boolean ready() {
|
||||||
|
5
war/src/main/java/com/tommytony/war/ZoneLobby.java
Normal file
5
war/src/main/java/com/tommytony/war/ZoneLobby.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package com.tommytony.war;
|
||||||
|
|
||||||
|
public class ZoneLobby {
|
||||||
|
|
||||||
|
}
|
@ -13,14 +13,37 @@ import org.bukkit.World;
|
|||||||
import bukkit.tommytony.war.War;
|
import bukkit.tommytony.war.War;
|
||||||
|
|
||||||
import com.tommytony.war.volumes.BlockInfo;
|
import com.tommytony.war.volumes.BlockInfo;
|
||||||
|
import com.tommytony.war.volumes.CenteredVolume;
|
||||||
|
import com.tommytony.war.volumes.VerticalVolume;
|
||||||
import com.tommytony.war.volumes.Volume;
|
import com.tommytony.war.volumes.Volume;
|
||||||
|
|
||||||
public class VolumeMapper {
|
public class VolumeMapper {
|
||||||
public static Volume load(String zoneName, String volumeName, War war, World world) {
|
|
||||||
|
public static Volume loadVolume(String volumeName, String zoneName,
|
||||||
|
War war, World world) {
|
||||||
|
Volume volume = new Volume(volumeName, war, world);
|
||||||
|
load(volume, zoneName, war, world);
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VerticalVolume loadVerticalVolume(String volumeName, String zoneName,
|
||||||
|
War war, World world) {
|
||||||
|
VerticalVolume volume = new VerticalVolume(volumeName, war, world);
|
||||||
|
load(volume, zoneName, war, world);
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CenteredVolume loadCenteredVolume(String volumeName, String zoneName, int sideSize,
|
||||||
|
War war, World world) {
|
||||||
|
CenteredVolume volume = new CenteredVolume(volumeName, null, sideSize, war, world);
|
||||||
|
load(volume, zoneName, war, world);
|
||||||
|
return volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load(Volume volume, String zoneName, War war, World world) {
|
||||||
BufferedReader in = null;
|
BufferedReader in = null;
|
||||||
Volume volume = null;
|
|
||||||
try {
|
try {
|
||||||
in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volumeName)));
|
in = new BufferedReader(new FileReader(new File("War/warzone-" + zoneName + "/volume-" + volume.getName())));
|
||||||
String firstLine = in.readLine();
|
String firstLine = in.readLine();
|
||||||
if(firstLine != null && !firstLine.equals("")) {
|
if(firstLine != null && !firstLine.equals("")) {
|
||||||
int x1 = Integer.parseInt(in.readLine());
|
int x1 = Integer.parseInt(in.readLine());
|
||||||
@ -30,9 +53,13 @@ public class VolumeMapper {
|
|||||||
int y2 = Integer.parseInt(in.readLine());
|
int y2 = Integer.parseInt(in.readLine());
|
||||||
int z2 = Integer.parseInt(in.readLine());
|
int z2 = Integer.parseInt(in.readLine());
|
||||||
|
|
||||||
volume = new Volume(volumeName, war, world);
|
if(volume instanceof CenteredVolume) {
|
||||||
|
((CenteredVolume)volume).setCenter(world.getBlockAt(x1, y1, z1));
|
||||||
|
((CenteredVolume)volume).calculateCorners();
|
||||||
|
} else {
|
||||||
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.setBlockInfos(new BlockInfo[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
|
volume.setBlockInfos(new BlockInfo[volume.getSizeX()][volume.getSizeY()][volume.getSizeZ()]);
|
||||||
for(int i = 0; i < volume.getSizeX(); i++){
|
for(int i = 0; i < volume.getSizeX(); i++){
|
||||||
@ -65,7 +92,7 @@ public class VolumeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
war.getLogger().warning("Failed to read volume file " + volumeName +
|
war.getLogger().warning("Failed to read volume file " + volume.getName() +
|
||||||
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@ -73,12 +100,11 @@ public class VolumeMapper {
|
|||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
war.getLogger().warning("Failed to close file reader for volume " + volumeName +
|
war.getLogger().warning("Failed to close file reader for volume " + volume.getName() +
|
||||||
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
" for warzone " + zoneName + ". " + e.getClass().getName() + " " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return volume;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save(Volume volume, String zoneName, War war) {
|
public static void save(Volume volume, String zoneName, War war) {
|
||||||
@ -132,4 +158,5 @@ public class VolumeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ import com.tommytony.war.Team;
|
|||||||
import com.tommytony.war.TeamMaterials;
|
import com.tommytony.war.TeamMaterials;
|
||||||
import com.tommytony.war.Warzone;
|
import com.tommytony.war.Warzone;
|
||||||
import com.tommytony.war.volumes.VerticalVolume;
|
import com.tommytony.war.volumes.VerticalVolume;
|
||||||
import com.tommytony.war.volumes.Volume;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -153,29 +152,16 @@ public class WarzoneMapper {
|
|||||||
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
if(loadBlocks && warzone.getNorthwest() != null && warzone.getSoutheast() != null) {
|
||||||
|
|
||||||
// zone blocks
|
// zone blocks
|
||||||
VerticalVolume zoneVolume = VolumeMapper.load(warzone.getName(), "zone", war, warzone.getWorld());
|
VerticalVolume zoneVolume = VolumeMapper.loadVerticalVolume(warzone.getName(), "zone", war, warzone.getWorld());
|
||||||
|
|
||||||
// monument blocks
|
// monument blocks
|
||||||
for(Monument monument: warzone.getMonuments()) {
|
for(Monument monument: warzone.getMonuments()) {
|
||||||
monument.setVolume(VolumeMapper.load(warzone.getName(), monument.getName(), war, world));
|
monument.setVolume(VolumeMapper.loadCenteredVolume(warzone.getName(), monument.getName(), 7, war, world));
|
||||||
try {
|
|
||||||
monument.getVolume().fromDisk();
|
|
||||||
} catch (IOException e) {
|
|
||||||
war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() +
|
|
||||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// team spawn blocks
|
// team spawn blocks
|
||||||
for(Team team : warzone.getTeams()) {
|
for(Team team : warzone.getTeams()) {
|
||||||
try {
|
team.setVolume(VolumeMapper.loadVolume(team.getName(), warzone.getName(), war, world));
|
||||||
team.getVolume().fromDisk();
|
|
||||||
} catch (IOException e) {
|
|
||||||
war.getLogger().warning("Failed to read volume file " + warzone.getVolume().getName() +
|
|
||||||
" for warzone " + warzone.getName() + ". " + e.getClass().getName() + " " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//war.getLogger().info("Loaded warzone " + name + " config and blocks.");
|
//war.getLogger().info("Loaded warzone " + name + " config and blocks.");
|
||||||
|
@ -33,11 +33,11 @@ public class CenteredVolume extends Volume {
|
|||||||
this.calculateCorners();
|
this.calculateCorners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCenter(Block block) {
|
public void setCenter(Block block) {
|
||||||
this.center = block;
|
this.center = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateCorners() {
|
public void calculateCorners() {
|
||||||
int topHalfOfSide = sideSize / 2;
|
int topHalfOfSide = sideSize / 2;
|
||||||
|
|
||||||
int x = center.getX() + topHalfOfSide;
|
int x = center.getX() + topHalfOfSide;
|
||||||
|
Loading…
Reference in New Issue
Block a user