mirror of
https://github.com/taoneill/war.git
synced 2024-11-27 20:59:39 +01:00
Volumes - a sort of self made cuboid abstraction. Refactored warzones, monuments and team spawns into volumes. Can finally start adding new features again soon.
This commit is contained in:
parent
dbe7fdfc11
commit
20032dddbf
@ -447,7 +447,6 @@ public class WarListener extends PluginListener {
|
||||
if(attackerTeam != null && defenderTeam != null
|
||||
&& attackerTeam != defenderTeam
|
||||
&& attackerWarzone == defenderWarzone) {
|
||||
war.getLogger().log(Level.INFO, a.getName() + " hit " + d.getName() + " for " + damageAmount);
|
||||
return false; // adversaries!
|
||||
} else if (attackerTeam != null && defenderTeam != null
|
||||
&& attackerTeam == defenderTeam
|
||||
@ -475,7 +474,7 @@ public class WarListener extends PluginListener {
|
||||
} else if (attackerWarzone != defenderWarzone) {
|
||||
a.sendMessage(war.str("Your target is playing in another warzone."));
|
||||
}
|
||||
return true; // can't attack someone inside awarzone if you're not in a team
|
||||
return true; // can't attack someone inside a warzone if you're not in a team
|
||||
}
|
||||
}
|
||||
// mobs are always dangerous
|
||||
|
@ -2,60 +2,54 @@ package com.tommytony.war;
|
||||
|
||||
import org.bukkit.*;
|
||||
|
||||
import com.tommytony.war.volumes.CenteredVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
public class Monument {
|
||||
private Location location;
|
||||
private int[] initialState = new int[26];
|
||||
private World world = null;
|
||||
private CenteredVolume volume;
|
||||
|
||||
private Team ownerTeam = null;
|
||||
private final String name;
|
||||
private Warzone warzone;
|
||||
|
||||
public Monument(String name, World world, Location location) {
|
||||
public Monument(String name, War war, Warzone warzone, Location location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.world = world;
|
||||
this.warzone = warzone;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
volume = new CenteredVolume("name", location, war, warzone);
|
||||
volume.setSideSize(5);
|
||||
volume.saveBlocks();
|
||||
|
||||
this.addMonumentBlocks();
|
||||
}
|
||||
|
||||
public void addMonumentBlocks() {
|
||||
// TODO Auto-generated method stub
|
||||
this.ownerTeam = null;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
|
||||
// center
|
||||
getInitialState()[0] = world.getBlockAt(x, y, z).getTypeID();
|
||||
getInitialState()[1] = world.getBlockAt(x, y-1, z).getTypeID();
|
||||
warzone.getWorld().getBlockAt(x, y, z).setType(Material.Air);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z).setType(Material.Soil);
|
||||
|
||||
// inner ring
|
||||
getInitialState()[2] = world.getBlockAt(x+1, y-1, z+1).getTypeID();
|
||||
getInitialState()[3] = world.getBlockAt(x+1, y-1, z).getTypeID();
|
||||
getInitialState()[4] = world.getBlockAt(x+1, y-1, z-1).getTypeID();
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z+1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
getInitialState()[5] = world.getBlockAt(x, y-1, z+1).getTypeID();
|
||||
getInitialState()[6] = world.getBlockAt(x, y-1, z-1).getTypeID();
|
||||
warzone.getWorld().getBlockAt(x, y-1, z+1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
getInitialState()[7] = world.getBlockAt(x-1, y-1, z+1).getTypeID();
|
||||
getInitialState()[9] = world.getBlockAt(x-1, y-1, z).getTypeID();
|
||||
getInitialState()[9] = world.getBlockAt(x-1, y-1, z-1).getTypeID();
|
||||
|
||||
// outer ring
|
||||
getInitialState()[10] = world.getBlockAt(x+2, y-1, z+2).getTypeID();
|
||||
getInitialState()[11] = world.getBlockAt(x+2, y-1, z+1).getTypeID();
|
||||
getInitialState()[12] = world.getBlockAt(x+2, y-1, z).getTypeID();
|
||||
getInitialState()[13] = world.getBlockAt(x+2, y-1, z-1).getTypeID();
|
||||
getInitialState()[14] = world.getBlockAt(x+2, y-1, z-2).getTypeID();
|
||||
|
||||
getInitialState()[15] = world.getBlockAt(x-1, y-1, z+2).getTypeID();
|
||||
getInitialState()[16] = world.getBlockAt(x-1, y-1, z-2).getTypeID();
|
||||
|
||||
getInitialState()[17] = world.getBlockAt(x, y-1, z+2).getTypeID();
|
||||
getInitialState()[18] = world.getBlockAt(x, y-1, z-2).getTypeID();
|
||||
|
||||
getInitialState()[19] = world.getBlockAt(x+1, y-1, z+2).getTypeID();
|
||||
getInitialState()[20] = world.getBlockAt(x+1, y-1, z-2).getTypeID();
|
||||
|
||||
getInitialState()[21] = world.getBlockAt(x-2, y-1, z+2).getTypeID();
|
||||
getInitialState()[22] = world.getBlockAt(x-2, y-1, z+1).getTypeID();
|
||||
getInitialState()[23] = world.getBlockAt(x-2, y-1, z).getTypeID();
|
||||
getInitialState()[24] = world.getBlockAt(x-2, y-1, z-1).getTypeID();
|
||||
getInitialState()[25] = world.getBlockAt(x-2, y-1, z-2).getTypeID();
|
||||
|
||||
this.reset();
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z+1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z-1).setType(Material.CoalOre);
|
||||
}
|
||||
|
||||
public boolean isNear(Location playerLocation) {
|
||||
@ -91,16 +85,16 @@ public class Monument {
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
|
||||
world.getBlockAt(x+1, y-1, z+1).setType(Material.GlowingRedstoneOre);
|
||||
world.getBlockAt(x+1, y-1, z).setType(Material.GlowingRedstoneOre);
|
||||
world.getBlockAt(x+1, y-1, z-1).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z+1).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z-1).setType(Material.GlowingRedstoneOre);
|
||||
|
||||
world.getBlockAt(x, y-1, z+1).setType(Material.GlowingRedstoneOre);
|
||||
world.getBlockAt(x, y-1, z-1).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z+1).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z-1).setType(Material.GlowingRedstoneOre);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+1).setType(Material.GlowingRedstoneOre);
|
||||
world.getBlockAt(x-1, y-1, z).setType(Material.GlowingRedstoneOre);
|
||||
world.getBlockAt(x-1, y-1, z-1).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z+1).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z).setType(Material.GlowingRedstoneOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z-1).setType(Material.GlowingRedstoneOre);
|
||||
}
|
||||
|
||||
public void smother() {
|
||||
@ -108,106 +102,21 @@ public class Monument {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
world.getBlockAt(x+1, y-1, z+1).setType(Material.CoalOre);
|
||||
world.getBlockAt(x+1, y-1, z).setType(Material.CoalOre);
|
||||
world.getBlockAt(x+1, y-1, z-1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z+1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
world.getBlockAt(x, y-1, z+1).setType(Material.CoalOre);
|
||||
world.getBlockAt(x, y-1, z-1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z+1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+1).setType(Material.CoalOre);
|
||||
world.getBlockAt(x-1, y-1, z).setType(Material.CoalOre);
|
||||
world.getBlockAt(x-1, y-1, z-1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z+1).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z).setType(Material.CoalOre);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.ownerTeam = null;
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
|
||||
// center
|
||||
world.getBlockAt(x, y, z).setType(Material.Air);
|
||||
world.getBlockAt(x, y-1, z).setType(Material.Soil);
|
||||
|
||||
// inner ring
|
||||
world.getBlockAt(x+1, y-1, z+1).setType(Material.CoalOre);
|
||||
world.getBlockAt(x+1, y-1, z).setType(Material.CoalOre);
|
||||
world.getBlockAt(x+1, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
world.getBlockAt(x, y-1, z+1).setType(Material.CoalOre);
|
||||
world.getBlockAt(x, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+1).setType(Material.CoalOre);
|
||||
world.getBlockAt(x-1, y-1, z).setType(Material.CoalOre);
|
||||
world.getBlockAt(x-1, y-1, z-1).setType(Material.CoalOre);
|
||||
|
||||
// outer ring
|
||||
//world.getBlockAt(x+2, y-1, z+2).setType(Material.Obsidian);
|
||||
world.getBlockAt(x+2, y-1, z+1).setType(Material.Obsidian);
|
||||
world.getBlockAt(x+2, y-1, z).setType(Material.Obsidian);
|
||||
world.getBlockAt(x+2, y-1, z-1).setType(Material.Obsidian);
|
||||
//world.getBlockAt(x+2, y-1, z-2).setType(Material.Obsidian);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+2).setType(Material.Obsidian);
|
||||
world.getBlockAt(x-1, y-1, z-2).setType(Material.Obsidian);
|
||||
|
||||
world.getBlockAt(x, y-1, z+2).setType(Material.Obsidian);
|
||||
world.getBlockAt(x, y-1, z-2).setType(Material.Obsidian);
|
||||
|
||||
world.getBlockAt(x+1, y-1, z+2).setType(Material.Obsidian);
|
||||
world.getBlockAt(x+1, y-1, z-2).setType(Material.Obsidian);
|
||||
|
||||
//world.getBlockAt(x-2, y-1, z+2).setType(Material.Obsidian);
|
||||
world.getBlockAt(x-2, y-1, z+1).setType(Material.Obsidian);
|
||||
world.getBlockAt(x-2, y-1, z).setType(Material.Obsidian);
|
||||
world.getBlockAt(x-2, y-1, z-1).setType(Material.Obsidian);
|
||||
//world.getBlockAt(x-2, y-1, z-2).setType(Material.Obsidian);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
|
||||
// center
|
||||
world.getBlockAt(x, y, z).setTypeID(getInitialState()[0]);
|
||||
world.getBlockAt(x, y - 1, z).setTypeID(getInitialState()[1]);
|
||||
|
||||
// inner ring
|
||||
world.getBlockAt(x+1, y-1, z+1).setTypeID(getInitialState()[2]);
|
||||
world.getBlockAt(x+1, y-1, z).setTypeID(getInitialState()[3]);
|
||||
world.getBlockAt(x+1, y-1, z-1).setTypeID(getInitialState()[4]);
|
||||
|
||||
world.getBlockAt(x, y-1, z+1).setTypeID(getInitialState()[5]);
|
||||
world.getBlockAt(x, y-1, z-1).setTypeID(getInitialState()[6]);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+1).setTypeID(getInitialState()[7]);
|
||||
world.getBlockAt(x-1, y-1, z).setTypeID(getInitialState()[8]);
|
||||
world.getBlockAt(x-1, y-1, z-1).setTypeID(getInitialState()[9]);
|
||||
|
||||
// outer ring
|
||||
world.getBlockAt(x+2, y-1, z+2).setTypeID(getInitialState()[10]);
|
||||
world.getBlockAt(x+2, y-1, z+1).setTypeID(getInitialState()[11]);
|
||||
world.getBlockAt(x+2, y-1, z).setTypeID(getInitialState()[12]);
|
||||
world.getBlockAt(x+2, y-1, z-1).setTypeID(getInitialState()[13]);
|
||||
world.getBlockAt(x+2, y-1, z-2).setTypeID(getInitialState()[14]);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+2).setTypeID(getInitialState()[15]);
|
||||
world.getBlockAt(x-1, y-1, z-2).setTypeID(getInitialState()[16]);
|
||||
|
||||
world.getBlockAt(x, y-1, z+2).setTypeID(getInitialState()[17]);
|
||||
world.getBlockAt(x, y-1, z-2).setTypeID(getInitialState()[18]);
|
||||
|
||||
world.getBlockAt(x+1, y-1, z+2).setTypeID(getInitialState()[19]);
|
||||
world.getBlockAt(x+1, y-1, z-2).setTypeID(getInitialState()[20]);
|
||||
|
||||
world.getBlockAt(x-2, y-1, z+2).setTypeID(getInitialState()[21]);
|
||||
world.getBlockAt(x-2, y-1, z+1).setTypeID(getInitialState()[22]);
|
||||
world.getBlockAt(x-2, y-1, z).setTypeID(getInitialState()[23]);
|
||||
world.getBlockAt(x-2, y-1, z-1).setTypeID(getInitialState()[24]);
|
||||
world.getBlockAt(x-2, y-1, z-2).setTypeID(getInitialState()[25]);
|
||||
volume.resetBlocks();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
@ -236,17 +145,8 @@ public class Monument {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
getInitialState()[0] = world.getBlockAt(x+1, y-1, z+1).getTypeID();
|
||||
getInitialState()[1] = world.getBlockAt(x+1, y-1, z).getTypeID();
|
||||
getInitialState()[2] = world.getBlockAt(x+1, y-1, z-1).getTypeID();
|
||||
getInitialState()[3] = world.getBlockAt(x, y-1, z+1).getTypeID();
|
||||
getInitialState()[4] = world.getBlockAt(x, y-1, z).getTypeID();
|
||||
getInitialState()[5] = world.getBlockAt(x, y-1, z-1).getTypeID();
|
||||
getInitialState()[6] = world.getBlockAt(x-1, y-1, z+1).getTypeID();
|
||||
getInitialState()[7] = world.getBlockAt(x-1, y-1, z).getTypeID();
|
||||
getInitialState()[8] = world.getBlockAt(x-1, y-1, z-1).getTypeID();
|
||||
getInitialState()[9] = world.getBlockAt(x, y, z).getTypeID();
|
||||
this.reset();
|
||||
volume.setCenter(warzone.getWorld().getBlockAt(x, y, z)); // resets the volume blocks
|
||||
this.addMonumentBlocks();
|
||||
}
|
||||
|
||||
public boolean contains(Block block) {
|
||||
|
@ -1,6 +1,12 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import com.tommytony.war.volumes.CenteredVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -9,16 +15,68 @@ public class Team {
|
||||
private Location teamSpawn = null;
|
||||
private String name;
|
||||
private int remainingTickets;
|
||||
private int startTickets;
|
||||
private int[] oldSpawnState = new int[10];
|
||||
private int points = 0;
|
||||
private CenteredVolume volume;
|
||||
private final War war;
|
||||
private final Warzone warzone;
|
||||
|
||||
public Team(String name, Location teamSpawn) {
|
||||
public Team(String name, Location teamSpawn, War war, Warzone warzone) {
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
this.setName(name);
|
||||
this.teamSpawn = teamSpawn;
|
||||
this.volume = new CenteredVolume(name, teamSpawn, war, warzone);
|
||||
}
|
||||
|
||||
public void setTeamSpawn(Location teamSpawn) {
|
||||
|
||||
if(teamSpawn != null) volume.resetBlocks();
|
||||
this.teamSpawn = teamSpawn;
|
||||
Volume newTeamSpawn = new CenteredVolume(name, teamSpawn, war, warzone);
|
||||
volume.saveBlocks();
|
||||
|
||||
// Set the spawn
|
||||
int x = teamSpawn.getBlockX();
|
||||
int y = teamSpawn.getBlockY();
|
||||
int z = teamSpawn.getBlockZ();
|
||||
|
||||
// first ring
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z+1).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z-1).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z+1).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z-1).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z+1).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z).setType(Material.LightStone);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z-1).setType(Material.LightStone);
|
||||
|
||||
// outer ring
|
||||
//world.getBlockAt(x+2, y-1, z+2).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x+2, y-1, z+1).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x+2, y-1, z).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x+2, y-1, z-1).setType(Material.Stone);
|
||||
//world.getBlockAt(x+2, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z+2).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x-1, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
warzone.getWorld().getBlockAt(x, y-1, z+2).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z+2).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x+1, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
//world.getBlockAt(x-2, y-1, z+2).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x-2, y-1, z+1).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x-2, y-1, z).setType(Material.Stone);
|
||||
warzone.getWorld().getBlockAt(x-2, y-1, z-1).setType(Material.Stone);
|
||||
//world.getBlockAt(x-2, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
resetSign();
|
||||
|
||||
}
|
||||
|
||||
public Location getTeamSpawn() {
|
||||
@ -63,7 +121,6 @@ public class Team {
|
||||
|
||||
public void setRemainingTickets(int remainingTickets) {
|
||||
this.remainingTickets = remainingTickets;
|
||||
|
||||
}
|
||||
|
||||
public int getRemainingTickets() {
|
||||
@ -108,4 +165,27 @@ public class Team {
|
||||
return false;
|
||||
}
|
||||
|
||||
public CenteredVolume getVolume() {
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
public void resetSign(){
|
||||
int x = teamSpawn.getBlockX();
|
||||
int y = teamSpawn.getBlockY();
|
||||
int z = teamSpawn.getBlockZ();
|
||||
|
||||
Block block = warzone.getWorld().getBlockAt(x, y, z);
|
||||
block.setType(Material.SignPost);
|
||||
|
||||
BlockState state = block.getState();
|
||||
Sign sign = (Sign) state;
|
||||
sign.setLine(0, "Team");
|
||||
sign.setLine(1, name);
|
||||
sign.setLine(2, points + " pts");
|
||||
sign.setLine(3, remainingTickets + "/" + warzone.getLifePool() + " lives left");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,160 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
public class Volume {
|
||||
private final String name;
|
||||
private final World world;
|
||||
private Block cornerOne;
|
||||
private Block cornerTwo;
|
||||
private Block[][][] blocks = null;
|
||||
private final War war;
|
||||
|
||||
public Volume(String name, War war, World world) {
|
||||
this.name = name;
|
||||
this.war = war;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public boolean hasTwoCorners() {
|
||||
return cornerOne != null && cornerTwo != null;
|
||||
}
|
||||
|
||||
public void setCornerOne(Block block) {
|
||||
this.cornerOne = block;
|
||||
}
|
||||
|
||||
public boolean saveBlocks() {
|
||||
try {
|
||||
if(hasTwoCorners()) {
|
||||
this.blocks = new Block[getSizeX()][getSizeY()][getSizeZ()];
|
||||
int x = getMinX();
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
int y = getMinY();
|
||||
for(int j = 0; j < getSizeY(); j++){
|
||||
int z = getMinZ();
|
||||
for(int k = 0;k < getSizeZ(); k++) {
|
||||
this.blocks[i][j][k] = world.getBlockAt(x, y, z);
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
this.war.getLogger().warning(war.str("Failed to save volume " + name + " blocks. " + e.getMessage()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean resetBlocks() {
|
||||
try {
|
||||
if(hasTwoCorners() && blocks != null) {
|
||||
int x = getMinX();
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
int y = getMinY();
|
||||
for(int j = 0; j < getSizeY(); j++){
|
||||
int z = getMinZ();
|
||||
for(int k = 0;k < getSizeZ(); k++) {
|
||||
Block oldBlock = blocks[i][j][k];
|
||||
Block currentBlock = world.getBlockAt(x, y, z);
|
||||
currentBlock.setType(oldBlock.getType());
|
||||
currentBlock.setData(currentBlock.getData());
|
||||
if(oldBlock instanceof Sign) {
|
||||
Sign oldSign = (Sign) oldBlock;
|
||||
Sign currentSign = (Sign) currentBlock;
|
||||
currentSign.setLine(0, oldSign.getLine(0));
|
||||
currentSign.setLine(1, oldSign.getLine(1));
|
||||
currentSign.setLine(2, oldSign.getLine(2));
|
||||
currentSign.setLine(3, oldSign.getLine(3));
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
this.war.getLogger().warning(war.str("Failed to reset volume " + name + " blocks. " + e.getMessage()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCornerTwo(Block block) {
|
||||
this.cornerTwo = block;
|
||||
}
|
||||
|
||||
public Block getMinXBlock() {
|
||||
if(cornerOne.getX() < cornerTwo.getX()) return cornerOne;
|
||||
return cornerTwo;
|
||||
}
|
||||
|
||||
public Block getMinYBlock() {
|
||||
if(cornerOne.getY() < cornerTwo.getY()) return cornerOne;
|
||||
return cornerTwo;
|
||||
}
|
||||
|
||||
public Block getMinZBlock() {
|
||||
if(cornerOne.getZ() < cornerTwo.getZ()) return cornerOne;
|
||||
return cornerTwo;
|
||||
}
|
||||
|
||||
public int getMinX() {
|
||||
return getMinXBlock().getX();
|
||||
}
|
||||
|
||||
public int getMinY() {
|
||||
return getMinYBlock().getY();
|
||||
}
|
||||
|
||||
public int getMinZ() {
|
||||
return getMinZBlock().getZ();
|
||||
}
|
||||
|
||||
public Block getMaxXBlock() {
|
||||
if(cornerOne.getX() < cornerTwo.getX()) return cornerTwo;
|
||||
return cornerOne;
|
||||
}
|
||||
|
||||
public Block getMaxYBlock() {
|
||||
if(cornerOne.getY() < cornerTwo.getY()) return cornerTwo;
|
||||
return cornerOne;
|
||||
}
|
||||
|
||||
public Block getMaxZBlock() {
|
||||
if(cornerOne.getZ() < cornerTwo.getZ()) return cornerTwo;
|
||||
return cornerOne;
|
||||
}
|
||||
|
||||
public int getMaxX() {
|
||||
return getMaxXBlock().getX();
|
||||
}
|
||||
|
||||
public int getMaxY() {
|
||||
return getMaxYBlock().getY();
|
||||
}
|
||||
|
||||
public int getMaxZ() {
|
||||
return getMaxZBlock().getZ();
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return getMaxX() - getMinX();
|
||||
}
|
||||
|
||||
public int getSizeY() {
|
||||
return getMaxY() - getMinY();
|
||||
}
|
||||
|
||||
public int getSizeZ() {
|
||||
return getMaxZ() - getMinZ();
|
||||
}
|
||||
}
|
@ -105,7 +105,7 @@ public class War extends JavaPlugin {
|
||||
|
||||
public Warzone warzone(Location location) {
|
||||
for(Warzone warzone : warzones) {
|
||||
if(warzone.contains(location)) return warzone;
|
||||
if(warzone.getVolume().contains(location)) return warzone;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -59,8 +59,6 @@ public class WarEntityListener extends EntityListener {
|
||||
handleDeath(d);
|
||||
event.setCancelled(true); // Don't let the killing blow fall down.
|
||||
}
|
||||
|
||||
war.getLogger().log(Level.INFO, a.getName() + " hit " + d.getName() + " for " + event.getDamage());
|
||||
} else if (attackerTeam != null && defenderTeam != null
|
||||
&& attackerTeam == defenderTeam
|
||||
&& attackerWarzone == defenderWarzone) {
|
||||
@ -109,7 +107,7 @@ public class WarEntityListener extends EntityListener {
|
||||
if(!t.getName().equals(team.getName())) {
|
||||
// all other teams get a point
|
||||
t.addPoint();
|
||||
zone.resetSign(t);
|
||||
t.resetSign();
|
||||
}
|
||||
}
|
||||
zone.resetState();
|
||||
@ -121,7 +119,7 @@ public class WarEntityListener extends EntityListener {
|
||||
if(!roundOver) {
|
||||
zone.respawnPlayer(team, player);
|
||||
player.sendMessage(war.str("You died!"));
|
||||
zone.resetSign(team);
|
||||
team.resetSign();
|
||||
war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
|
||||
} else {
|
||||
war.getLogger().log(Level.INFO, player.getName() + " died and battle ended in team " + team.getName() + "'s disfavor");
|
||||
|
@ -1,97 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class WarMapper {
|
||||
|
||||
public static void load(War war) {
|
||||
war.getLogger().info("Loading war config...");
|
||||
(new File(war.getName())).mkdir();
|
||||
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt");
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().info("Failed to load war.txt file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Create file if need be
|
||||
boolean newWar = false;
|
||||
if(!warConfig.containsKey("warzones")) {
|
||||
newWar = true;
|
||||
WarMapper.save(war);
|
||||
war.getLogger().info("War config file created.");
|
||||
try {
|
||||
warConfig.load();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().info("Failed to reload war.txt file after creating it.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// warzones
|
||||
String warzonesStr = warConfig.getString("warzones");
|
||||
String[] warzoneSplit = warzonesStr.split(",");
|
||||
war.getWarzones().clear();
|
||||
for(String warzoneName : warzoneSplit) {
|
||||
if(warzoneName != null && !warzoneName.equals("")){
|
||||
Warzone zone = WarzoneMapper.load(war, warzoneName, !newWar); // cascade load, only load blocks if warzone exists
|
||||
war.getWarzones().add(zone);
|
||||
zone.resetState(); // is this wise?
|
||||
}
|
||||
}
|
||||
|
||||
// defaultLoadout
|
||||
// String defaultLoadoutStr = warConfig.getString("defaultLoadout");
|
||||
// String[] defaultLoadoutSplit = defaultLoadoutStr.split(";");
|
||||
// war.getDefaultLoadout().clear();
|
||||
// for(String itemStr : defaultLoadoutSplit) {
|
||||
// if(itemStr != null && !itemStr.equals("")) {
|
||||
// String[] itemStrSplit = itemStr.split(",");
|
||||
// ItemStack item = new ItemStack(Integer.parseInt(itemStrSplit[0]),
|
||||
// Integer.parseInt(itemStrSplit[1]));
|
||||
// war.getDefaultLoadout().add(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
// defaultLifePool
|
||||
war.setDefaultLifepool(warConfig.getInt("defaultLifePool"));
|
||||
|
||||
// defaultFriendlyFire
|
||||
war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire"));
|
||||
|
||||
warConfig.close();
|
||||
war.getLogger().info("Loaded war config.");
|
||||
}
|
||||
|
||||
public static void save(War war) {
|
||||
war.getLogger().info("Saving war config...");
|
||||
PropertiesFile warConfig = new PropertiesFile(war.getName() + "/war.txt");
|
||||
String warzonesStr = "";
|
||||
|
||||
// warzones
|
||||
for(Warzone zone : war.getWarzones()) {
|
||||
warzonesStr += zone.getName() + ",";
|
||||
}
|
||||
warConfig.setString("warzones", warzonesStr);
|
||||
|
||||
// defaultLoadout
|
||||
// String defaultLoadoutStr = "";
|
||||
// List<Item> items = war.getDefaultLoadout();
|
||||
// for(Item item : items) {
|
||||
// defaultLoadoutStr += item.getItemId() + "," + item.getAmount() + "," + item.getSlot() + ";";
|
||||
// }
|
||||
// warConfig.setString("defaultLoadout", defaultLoadoutStr);
|
||||
|
||||
// defaultLifepool
|
||||
warConfig.setInt("defaultLifePool", war.getDefaultLifepool());
|
||||
|
||||
// defaultFriendlyFire
|
||||
warConfig.setBoolean("defaultFriendlyFire", war.getDefaultFriendlyFire());
|
||||
|
||||
warConfig.save();
|
||||
warConfig.close();
|
||||
war.getLogger().info("Saved war config.");
|
||||
}
|
||||
}
|
@ -205,11 +205,11 @@ public class WarPlayerListener extends PlayerListener {
|
||||
"Must be in a warzone (try /warzones and /warzone). "));
|
||||
} else {
|
||||
String name = split[1];
|
||||
Team newTeam = new Team(name, player.getLocation());
|
||||
Warzone warzone = war.warzone(player.getLocation());
|
||||
Team newTeam = new Team(name, player.getLocation(), war, warzone);
|
||||
newTeam.setRemainingTickets(warzone.getLifePool());
|
||||
warzone.getTeams().add(newTeam);
|
||||
warzone.addSpawnArea(newTeam, player.getLocation(), 41);
|
||||
newTeam.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + name + " created with spawn here."));
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
}
|
||||
@ -232,8 +232,8 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
if(team != null) {
|
||||
warzone.removeSpawnArea(team);
|
||||
warzone.addSpawnArea(team, player.getLocation(), 41);
|
||||
team.getVolume().resetBlocks();
|
||||
team.setTeamSpawn(player.getLocation());
|
||||
team.setTeamSpawn(player.getLocation());
|
||||
player.sendMessage(war.str("Team " + team.getName() + " spawn relocated."));
|
||||
} else {
|
||||
@ -264,7 +264,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
if(team != null) {
|
||||
warzone.removeSpawnArea(team);
|
||||
team.getVolume().resetBlocks();
|
||||
warzone.getTeams().remove(team);
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
player.sendMessage(war.str("Team " + name + " removed."));
|
||||
@ -397,7 +397,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
warzone.removeSoutheast();
|
||||
warzone.removeNorthwest();
|
||||
for(Team t : warzone.getTeams()) {
|
||||
warzone.removeSpawnArea(t);
|
||||
t.getVolume().resetBlocks();
|
||||
}
|
||||
for(Monument m : warzone.getMonuments()) {
|
||||
m.remove();
|
||||
@ -425,7 +425,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " was moved."));
|
||||
} else {
|
||||
// create a new monument
|
||||
Monument monument = new Monument(split[1], warzone.getWorld(), player.getLocation());
|
||||
Monument monument = new Monument(split[1], war, warzone, player.getLocation());
|
||||
warzone.getMonuments().add(monument);
|
||||
player.sendMessage(war.str("Monument " + monument.getName() + " created."));
|
||||
}
|
||||
@ -465,9 +465,9 @@ public class WarPlayerListener extends PlayerListener {
|
||||
Warzone playerWarzone = war.getPlayerWarzone(player.getName());
|
||||
Team playerTeam = war.getPlayerTeam(player.getName());
|
||||
if(player != null && from != null && to != null &&
|
||||
playerTeam != null && !playerWarzone.contains(to)) {
|
||||
playerTeam != null && !playerWarzone.getVolume().contains(to)) {
|
||||
player.sendMessage(war.str("Can't go outside the warzone boundary! Use /leave to exit the battle."));
|
||||
if(playerWarzone.contains(from)){
|
||||
if(playerWarzone.getVolume().contains(from)){
|
||||
player.teleportTo(from);
|
||||
} else {
|
||||
// somehow the player made it out of the zone
|
||||
|
@ -1,5 +1,10 @@
|
||||
package com.tommytony.war;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import com.tommytony.war.volumes.CenteredVolume;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -7,12 +12,12 @@ import java.util.List;
|
||||
|
||||
public class Warzone {
|
||||
private String name;
|
||||
private VerticalVolume volume;
|
||||
private Location northwest;
|
||||
private Location southeast;
|
||||
private final List<Team> teams = new ArrayList<Team>();
|
||||
private final List<Monument> monuments = new ArrayList<Monument>();
|
||||
|
||||
private int[][][] initialState = null;
|
||||
private Location teleport;
|
||||
private boolean friendlyFire;
|
||||
private War war;
|
||||
@ -49,12 +54,6 @@ public class Warzone {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(Location point) {
|
||||
return ready() && point.getBlockX() <= getSoutheast().getBlockX() && point.getBlockX() >= getNorthwest().getBlockX()
|
||||
&& point.getBlockZ() <= getNorthwest().getBlockZ() && point.getBlockZ() >= getSoutheast().getBlockZ();
|
||||
}
|
||||
|
||||
|
||||
public List<Team> getTeams() {
|
||||
return teams;
|
||||
}
|
||||
@ -80,6 +79,8 @@ public class Warzone {
|
||||
removeNorthwest();
|
||||
}
|
||||
this.northwest = northwest;
|
||||
this.volume.setCornerOne(world.getBlockAt(northwest.getBlockX(), northwest.getBlockY(), northwest.getBlockZ()));
|
||||
|
||||
// add sign
|
||||
int x = northwest.getBlockX();
|
||||
int y = northwest.getBlockY();
|
||||
@ -89,12 +90,11 @@ public class Warzone {
|
||||
block.setType(Material.SignPost);
|
||||
block.setData((byte)10); // towards southeast
|
||||
|
||||
// BUKKIT
|
||||
// SignPost sign = (SignPost)complexBlock;
|
||||
// sign.setText(0, "Northwest");
|
||||
// sign.setText(1, "corner of");
|
||||
// sign.setText(2, "warzone");
|
||||
// sign.setText(3, name);
|
||||
Sign sign = (Sign)block;
|
||||
sign.setLine(0, "Northwest");
|
||||
sign.setLine(1, "corner of");
|
||||
sign.setLine(2, "warzone");
|
||||
sign.setLine(3, name);
|
||||
|
||||
saveState();
|
||||
}
|
||||
@ -116,6 +116,7 @@ public class Warzone {
|
||||
removeSoutheast();
|
||||
}
|
||||
this.southeast = southeast;
|
||||
this.volume.setCornerOne(world.getBlockAt(southeast.getBlockX(), southeast.getBlockY(), southeast.getBlockZ()));
|
||||
// add sign
|
||||
int x = southeast.getBlockX();
|
||||
int y = southeast.getBlockY();
|
||||
@ -124,12 +125,11 @@ public class Warzone {
|
||||
block.setType(Material.SignPost);
|
||||
block.setData((byte)2);;
|
||||
|
||||
// BUKKIT
|
||||
// SignPost sign = (SignPostblockk;
|
||||
// sign.setText(0, "Southeast");
|
||||
// sign.setText(1, "corner of");
|
||||
// sign.setText(2, "warzone");
|
||||
// sign.setText(3, name);
|
||||
Sign sign = (Sign)block;
|
||||
sign.setLine(0, "Southeast");
|
||||
sign.setLine(1, "corner of");
|
||||
sign.setLine(2, "warzone");
|
||||
sign.setLine(3, name);
|
||||
|
||||
saveState();
|
||||
}
|
||||
@ -155,27 +155,7 @@ public class Warzone {
|
||||
|
||||
public int saveState() {
|
||||
if(ready()){
|
||||
int northSouth = ((int)(southeast.getBlockX())) - ((int)(northwest.getBlockX()));
|
||||
int eastWest = ((int)(northwest.getBlockZ())) - ((int)(southeast.getBlockZ()));
|
||||
setInitialState(new int[northSouth + 6][128][eastWest + 6]);
|
||||
int noOfSavedBlocks = 0;
|
||||
int x = (int)northwest.getBlockX() - 2;
|
||||
int minY = 0;
|
||||
int maxY = 128;
|
||||
for(int i = 0; i < northSouth + 3; i++){
|
||||
int y = minY;
|
||||
for(int j = 0; j < 128; j++) {
|
||||
int z = (int)southeast.getBlockZ() - 2;
|
||||
for(int k = 0; k < eastWest + 3; k++) {
|
||||
getInitialState()[i][j][k] = world.getBlockAt(x, y, z).getTypeID();
|
||||
noOfSavedBlocks++;
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
return volume.saveBlocks();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -186,34 +166,8 @@ public class Warzone {
|
||||
* @return
|
||||
*/
|
||||
public int resetState() {
|
||||
if(ready() && getInitialState() != null){
|
||||
|
||||
// reset blocks
|
||||
int northSouth = ((int)(southeast.getBlockX())) - ((int)(northwest.getBlockX()));
|
||||
int eastWest = ((int)(northwest.getBlockZ())) - ((int)(southeast.getBlockZ()));
|
||||
int noOfResetBlocks = 0;
|
||||
int noOfFailures = 0;
|
||||
int x = northwest.getBlockX() - 2;
|
||||
int minY = 0;
|
||||
int maxY = 128;
|
||||
for(int i = 0; i < northSouth + 3; i++){
|
||||
int y = minY;
|
||||
for(int j = 0; j < 128; j++) {
|
||||
int z = (int)southeast.getBlockZ() - 2;
|
||||
for(int k = 0; k < eastWest + 3; k++) {
|
||||
Block currentBlock = world.getBlockAt(x, y, z);
|
||||
int currentType = currentBlock.getTypeID();
|
||||
int initialType = getInitialState()[i][j][k];
|
||||
if(currentType != initialType) { // skip block if nothing changed
|
||||
currentBlock.setTypeID(initialType);
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
if(ready() && volume.isSaved()){
|
||||
int reset = volume.resetBlocks();
|
||||
|
||||
// everyone back to team spawn with full health
|
||||
for(Team team : teams) {
|
||||
@ -221,18 +175,19 @@ public class Warzone {
|
||||
respawnPlayer(team, player);
|
||||
}
|
||||
team.setRemainingTickets(lifePool);
|
||||
resetSign(team);
|
||||
team.resetSign();
|
||||
}
|
||||
|
||||
// reset monuments
|
||||
for(Monument monument : monuments) {
|
||||
monument.reset();
|
||||
monument.remove();
|
||||
monument.addMonumentBlocks();
|
||||
}
|
||||
|
||||
this.setNorthwest(this.getNorthwest());
|
||||
this.setSoutheast(this.getSoutheast());
|
||||
|
||||
return noOfResetBlocks;
|
||||
return reset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -290,154 +245,16 @@ public class Warzone {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeSpawnArea(Team team) {
|
||||
// Reset spawn to what it was before the gold blocks
|
||||
int[] spawnState = team.getOldSpawnState();
|
||||
int x = (int)team.getTeamSpawn().getBlockX();
|
||||
int y = (int)team.getTeamSpawn().getBlockY();
|
||||
int z = (int)team.getTeamSpawn().getBlockZ();
|
||||
// public void removeSpawnArea(Team team) {
|
||||
// // Reset spawn to what it was before the gold blocks
|
||||
// team.getVolume().resetBlocks();
|
||||
// }
|
||||
|
||||
// center
|
||||
world.getBlockAt(x, y, z).setTypeID(spawnState[0]);
|
||||
world.getBlockAt(x, y-1, z).setTypeID(spawnState[1]);
|
||||
// public void addSpawnArea(Team team, Location location) {
|
||||
// // Save the spawn state
|
||||
// team.setTeamSpawn(location);
|
||||
// }
|
||||
|
||||
// inner ring
|
||||
world.getBlockAt(x+1, y-1, z+1).setTypeID(spawnState[2]);
|
||||
world.getBlockAt(x+1, y-1, z).setTypeID(spawnState[3]);
|
||||
world.getBlockAt(x+1, y-1, z-1).setTypeID(spawnState[4]);
|
||||
|
||||
world.getBlockAt(x, y-1, z+1).setTypeID(spawnState[5]);
|
||||
world.getBlockAt(x, y-1, z-1).setTypeID(spawnState[6]);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+1).setTypeID(spawnState[7]);
|
||||
world.getBlockAt(x-1, y-1, z).setTypeID(spawnState[8]);
|
||||
world.getBlockAt(x-1, y-1, z-1).setTypeID(spawnState[9]);
|
||||
|
||||
// outer ring
|
||||
world.getBlockAt(x+2, y-1, z+2).setTypeID(spawnState[10]);
|
||||
world.getBlockAt(x+2, y-1, z+1).setTypeID(spawnState[11]);
|
||||
world.getBlockAt(x+2, y-1, z).setTypeID(spawnState[12]);
|
||||
world.getBlockAt(x+2, y-1, z-1).setTypeID(spawnState[13]);
|
||||
world.getBlockAt(x+2, y-1, z-2).setTypeID(spawnState[14]);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+2).setTypeID(spawnState[15]);
|
||||
world.getBlockAt(x-1, y-1, z-2).setTypeID(spawnState[16]);
|
||||
|
||||
world.getBlockAt(x, y-1, z+2).setTypeID(spawnState[17]);
|
||||
world.getBlockAt(x, y-1, z-2).setTypeID(spawnState[18]);
|
||||
|
||||
world.getBlockAt(x+1, y-1, z+2).setTypeID(spawnState[19]);
|
||||
world.getBlockAt(x+1, y-1, z-2).setTypeID(spawnState[20]);
|
||||
|
||||
world.getBlockAt(x-2, y-1, z+2).setTypeID(spawnState[21]);
|
||||
world.getBlockAt(x-2, y-1, z+1).setTypeID(spawnState[22]);
|
||||
world.getBlockAt(x-2, y-1, z).setTypeID(spawnState[23]);
|
||||
world.getBlockAt(x-2, y-1, z-1).setTypeID(spawnState[24]);
|
||||
world.getBlockAt(x-2, y-1, z-2).setTypeID(spawnState[25]);
|
||||
|
||||
}
|
||||
|
||||
public void addSpawnArea(Team team, Location location, int blockType) {
|
||||
// Save the spawn state (i.e. the nine block under the player spawn)
|
||||
int[] spawnState = new int[26];
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
// center
|
||||
spawnState[0] = world.getBlockAt(x, y, z).getTypeID();
|
||||
spawnState[1] = world.getBlockAt(x, y-1, z).getTypeID();
|
||||
|
||||
// inner ring
|
||||
spawnState[2] = world.getBlockAt(x+1, y-1, z+1).getTypeID();
|
||||
spawnState[3] = world.getBlockAt(x+1, y-1, z).getTypeID();
|
||||
spawnState[4] = world.getBlockAt(x+1, y-1, z-1).getTypeID();
|
||||
|
||||
spawnState[5] = world.getBlockAt(x, y-1, z+1).getTypeID();
|
||||
spawnState[6] = world.getBlockAt(x, y-1, z-1).getTypeID();
|
||||
|
||||
spawnState[7] = world.getBlockAt(x-1, y-1, z+1).getTypeID();
|
||||
spawnState[8] = world.getBlockAt(x-1, y-1, z).getTypeID();
|
||||
spawnState[9] = world.getBlockAt(x-1, y-1, z-1).getTypeID();
|
||||
|
||||
// outer ring
|
||||
spawnState[10] = world.getBlockAt(x+2, y-1, z+2).getTypeID();
|
||||
spawnState[11] = world.getBlockAt(x+2, y-1, z+1).getTypeID();
|
||||
spawnState[12] = world.getBlockAt(x+2, y-1, z).getTypeID();
|
||||
spawnState[13] = world.getBlockAt(x+2, y-1, z-1).getTypeID();
|
||||
spawnState[14] = world.getBlockAt(x+2, y-1, z-2).getTypeID();
|
||||
|
||||
spawnState[15] = world.getBlockAt(x-1, y-1, z+2).getTypeID();
|
||||
spawnState[16] = world.getBlockAt(x-1, y-1, z-2).getTypeID();
|
||||
|
||||
spawnState[17] = world.getBlockAt(x, y-1, z+2).getTypeID();
|
||||
spawnState[18] = world.getBlockAt(x, y-1, z-2).getTypeID();
|
||||
|
||||
spawnState[19] = world.getBlockAt(x+1, y-1, z+2).getTypeID();
|
||||
spawnState[20] = world.getBlockAt(x+1, y-1, z-2).getTypeID();
|
||||
|
||||
spawnState[21] = world.getBlockAt(x-2, y-1, z+2).getTypeID();
|
||||
spawnState[22] = world.getBlockAt(x-2, y-1, z+1).getTypeID();
|
||||
spawnState[23] = world.getBlockAt(x-2, y-1, z).getTypeID();
|
||||
spawnState[24] = world.getBlockAt(x-2, y-1, z-1).getTypeID();
|
||||
spawnState[25] = world.getBlockAt(x-2, y-1, z-2).getTypeID();
|
||||
|
||||
team.setTeamSpawn(location);
|
||||
team.setOldSpawnState(spawnState);
|
||||
|
||||
// Set the spawn
|
||||
|
||||
// first ring
|
||||
world.getBlockAt(x+1, y-1, z+1).setType(Material.LightStone);
|
||||
world.getBlockAt(x+1, y-1, z).setType(Material.LightStone);
|
||||
world.getBlockAt(x+1, y-1, z-1).setType(Material.LightStone);
|
||||
world.getBlockAt(x, y-1, z+1).setType(Material.LightStone);
|
||||
world.getBlockAt(x, y-1, z).setType(Material.Stone);
|
||||
world.getBlockAt(x, y-1, z-1).setType(Material.LightStone);
|
||||
world.getBlockAt(x-1, y-1, z+1).setType(Material.LightStone);
|
||||
world.getBlockAt(x-1, y-1, z).setType(Material.LightStone);
|
||||
world.getBlockAt(x-1, y-1, z-1).setType(Material.LightStone);
|
||||
|
||||
// outer ring
|
||||
//world.getBlockAt(x+2, y-1, z+2).setType(Material.Stone);
|
||||
world.getBlockAt(x+2, y-1, z+1).setType(Material.Stone);
|
||||
world.getBlockAt(x+2, y-1, z).setType(Material.Stone);
|
||||
world.getBlockAt(x+2, y-1, z-1).setType(Material.Stone);
|
||||
//world.getBlockAt(x+2, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
world.getBlockAt(x-1, y-1, z+2).setType(Material.Stone);
|
||||
world.getBlockAt(x-1, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
world.getBlockAt(x, y-1, z+2).setType(Material.Stone);
|
||||
world.getBlockAt(x, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
world.getBlockAt(x+1, y-1, z+2).setType(Material.Stone);
|
||||
world.getBlockAt(x+1, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
//world.getBlockAt(x-2, y-1, z+2).setType(Material.Stone);
|
||||
world.getBlockAt(x-2, y-1, z+1).setType(Material.Stone);
|
||||
world.getBlockAt(x-2, y-1, z).setType(Material.Stone);
|
||||
world.getBlockAt(x-2, y-1, z-1).setType(Material.Stone);
|
||||
//world.getBlockAt(x-2, y-1, z-2).setType(Material.Stone);
|
||||
|
||||
resetSign(team);
|
||||
}
|
||||
|
||||
public void resetSign(Team team){
|
||||
int x = team.getTeamSpawn().getBlockX();
|
||||
int y = team.getTeamSpawn().getBlockY();
|
||||
int z = team.getTeamSpawn().getBlockZ();
|
||||
|
||||
Block block = world.getBlockAt(x, y, z);
|
||||
block.setType(Material.SignPost);
|
||||
|
||||
// BUKKIT
|
||||
// SignPost sign = (SignPost) block;
|
||||
// sign.setText(0, "Team");
|
||||
// sign.setText(1, team.getName());
|
||||
// sign.setText(2, team.getPoints() + " pts");
|
||||
// sign.setText(3, team.getRemainingTickets() + "/" + lifePool + " lives left");
|
||||
|
||||
}
|
||||
|
||||
public List<Monument> getMonuments() {
|
||||
return monuments;
|
||||
@ -468,14 +285,6 @@ public class Warzone {
|
||||
this.friendlyFire = ffOn;
|
||||
}
|
||||
|
||||
public void setInitialState(int[][][] initialState) {
|
||||
this.initialState = initialState;
|
||||
}
|
||||
|
||||
public int[][][] getInitialState() {
|
||||
return initialState;
|
||||
}
|
||||
|
||||
public boolean hasPlayerInventory(String playerName) {
|
||||
return inventories.containsKey(playerName);
|
||||
}
|
||||
@ -568,6 +377,14 @@ public class Warzone {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public Volume getVolume() {
|
||||
return volume;
|
||||
}
|
||||
|
||||
public void setVolume(VerticalVolume zoneVolume) {
|
||||
this.volume = zoneVolume;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,313 +0,0 @@
|
||||
package com.tommytony.war;
|
||||
|
||||
import org.bukkit.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class WarzoneMapper {
|
||||
|
||||
public static Warzone load(War war, String name, boolean loadBlocks) {
|
||||
war.getLogger().info("Loading warzone " + name + " config and blocks...");
|
||||
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + name + ".txt");
|
||||
try {
|
||||
warzoneConfig.load();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().info("Failed to load warzone-" + name + ".txt file.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
World[] worlds = war.getServer().getWorlds();
|
||||
World world = worlds[0];
|
||||
Warzone warzone = new Warzone(war, world, name);
|
||||
|
||||
// Create file if needed
|
||||
if(!warzoneConfig.containsKey("name")) {
|
||||
WarzoneMapper.save(war, warzone, false);
|
||||
war.getLogger().info("Warzone " + name + " config file created.");
|
||||
try {
|
||||
warzoneConfig.load();
|
||||
} catch (IOException e) {
|
||||
war.getLogger().info("Failed to reload warzone-" + name + ".txt file after creating it.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// world
|
||||
String worldStr = warzoneConfig.getProperty("world");
|
||||
|
||||
warzone.setWorld(world); // default world for now
|
||||
|
||||
// northwest
|
||||
String nwStr = warzoneConfig.getString("northWest");
|
||||
String[] nwStrSplit = nwStr.split(",");
|
||||
int nwX = Integer.parseInt(nwStrSplit[0]);
|
||||
int nwY = Integer.parseInt(nwStrSplit[1]);
|
||||
int nwZ = Integer.parseInt(nwStrSplit[2]);
|
||||
Location nw = new Location(world, nwX, nwY, nwZ);
|
||||
warzone.setNorthwest(nw);
|
||||
|
||||
// southeast
|
||||
String seStr = warzoneConfig.getString("southEast");
|
||||
String[] seStrSplit = seStr.split(",");
|
||||
int seX = Integer.parseInt(seStrSplit[0]);
|
||||
int seY = Integer.parseInt(seStrSplit[1]);
|
||||
int seZ = Integer.parseInt(seStrSplit[2]);
|
||||
Location se = new Location(world, seX, seY, seZ);
|
||||
warzone.setSoutheast(se);
|
||||
|
||||
// teleport
|
||||
String teleportStr = warzoneConfig.getString("teleport");
|
||||
if(teleportStr != null && !teleportStr.equals("")) {
|
||||
String[] teleportSplit = teleportStr.split(",");
|
||||
int teleX = Integer.parseInt(teleportSplit[0]);
|
||||
int teleY = Integer.parseInt(teleportSplit[1]);
|
||||
int teleZ = Integer.parseInt(teleportSplit[2]);
|
||||
warzone.setTeleport(new Location(world, teleX, teleY, teleZ));
|
||||
}
|
||||
|
||||
// teams
|
||||
String teamsStr = warzoneConfig.getString("teams");
|
||||
String[] teamsSplit = teamsStr.split(";");
|
||||
warzone.getTeams().clear();
|
||||
for(String teamStr : teamsSplit) {
|
||||
if(teamStr != null && !teamStr.equals("")){
|
||||
String[] teamStrSplit = teamStr.split(",");
|
||||
int teamX = Integer.parseInt(teamStrSplit[1]);
|
||||
int teamY = Integer.parseInt(teamStrSplit[2]);
|
||||
int teamZ = Integer.parseInt(teamStrSplit[3]);
|
||||
Team team = new Team(teamStrSplit[0],
|
||||
new Location(world, teamX, teamY, teamZ));
|
||||
team.setRemainingTickets(warzone.getLifePool());
|
||||
warzone.getTeams().add(team);
|
||||
}
|
||||
}
|
||||
|
||||
// ff
|
||||
warzone.setFriendlyFire(warzoneConfig.getBoolean("friendlyFire"));
|
||||
|
||||
// loadout
|
||||
// String loadoutStr = warzoneConfig.getString("loadout");
|
||||
// String[] loadoutStrSplit = loadoutStr.split(";");
|
||||
// warzone.getLoadout().clear();
|
||||
// for(String itemStr : loadoutStrSplit) {
|
||||
// if(itemStr != null && !itemStr.equals("")) {
|
||||
// String[] itemStrSplit = itemStr.split(",");
|
||||
// Item item = new Item(Integer.parseInt(itemStrSplit[0]),
|
||||
// Integer.parseInt(itemStrSplit[1]), Integer.parseInt(itemStrSplit[2]));
|
||||
// warzone.getLoadout().add(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
// life pool
|
||||
warzone.setLifePool(warzoneConfig.getInt("lifePool"));
|
||||
|
||||
// monuments
|
||||
String monumentsStr = warzoneConfig.getString("monuments");
|
||||
String[] monumentsSplit = monumentsStr.split(";");
|
||||
warzone.getMonuments().clear();
|
||||
for(String monumentStr : monumentsSplit) {
|
||||
if(monumentStr != null && !monumentStr.equals("")){
|
||||
String[] monumentStrSplit = monumentStr.split(",");
|
||||
int monumentX = Integer.parseInt(monumentStrSplit[1]);
|
||||
int monumentY = Integer.parseInt(monumentStrSplit[2]);
|
||||
int monumentZ = Integer.parseInt(monumentStrSplit[3]);
|
||||
Monument monument = new Monument(monumentStrSplit[0], world,
|
||||
new Location(world, monumentX, monumentY, monumentZ));
|
||||
warzone.getMonuments().add(monument);
|
||||
}
|
||||
}
|
||||
|
||||
warzoneConfig.close();
|
||||
|
||||
if(loadBlocks) {
|
||||
// zone blocks
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
int northSouth = ((int)(warzone.getSoutheast().getBlockX())) - ((int)(warzone.getNorthwest().getBlockX()));
|
||||
int eastWest = ((int)(warzone.getNorthwest().getBlockZ())) - ((int)(warzone.getSoutheast().getBlockZ()));
|
||||
int minY = 0;
|
||||
int maxY = 128;
|
||||
int[][][] state = new int[northSouth + 6][128][eastWest + 6];
|
||||
String stateStr = warzoneBlocksFile.getString("zoneBlocks");
|
||||
String[] stateStrSplit = stateStr.split(",");
|
||||
int splitIndex = 0;
|
||||
if(stateStrSplit.length > 1000) {
|
||||
for(int i = 0; i < northSouth + 3; i++){
|
||||
for(int j = 0; j < 128; j++) {
|
||||
for(int k = 0; k < eastWest + 3; k++) {
|
||||
String currentBlockType = stateStrSplit[splitIndex];
|
||||
if(currentBlockType != null && !currentBlockType.equals("")) {
|
||||
state[i][j][k] = Integer.parseInt(currentBlockType);
|
||||
}
|
||||
splitIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
warzone.setInitialState(state);
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: warzone.getMonuments()) {
|
||||
String monumentBlocksStr = warzoneBlocksFile.getString("monument"+monument.getName()+"Blocks");
|
||||
String[] monumentBlocksSplit = monumentBlocksStr.split(",");
|
||||
int[] monumentState = new int[10];
|
||||
for(int i = 0; i < monumentBlocksSplit.length; i++) {
|
||||
String split = monumentBlocksSplit[i];
|
||||
if(split != null && !split.equals("")) {
|
||||
monumentState[i] = Integer.parseInt(split);
|
||||
}
|
||||
}
|
||||
monument.setInitialState(monumentState);
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for(Team team : warzone.getTeams()) {
|
||||
String teamBlocksStr = warzoneBlocksFile.getString("team"+team.getName()+"Blocks");
|
||||
String[] teamBlocksSplit = teamBlocksStr.split(",");
|
||||
int[] teamState = new int[10];
|
||||
for(int i = 0; i < teamBlocksSplit.length; i++) {
|
||||
String split = teamBlocksSplit[i];
|
||||
if(split != null && !split.equals("")) {
|
||||
teamState[i] = Integer.parseInt(split);
|
||||
}
|
||||
}
|
||||
team.setOldSpawnState(teamState);
|
||||
}
|
||||
|
||||
warzoneBlocksFile.close();
|
||||
war.getLogger().info("Loaded warzone " + name + " config and blocks.");
|
||||
} else {
|
||||
war.getLogger().info("Loaded warzone " + name + " config.");
|
||||
}
|
||||
|
||||
return warzone;
|
||||
|
||||
}
|
||||
|
||||
public static void save(War war, Warzone warzone, boolean saveBlocks) {
|
||||
PropertiesFile warzoneConfig = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".txt");
|
||||
war.getLogger().info("Saving warzone " + warzone.getName() + "...");
|
||||
|
||||
// name
|
||||
warzoneConfig.setString("name", warzone.getName());
|
||||
|
||||
// world
|
||||
warzoneConfig.setString("world", "world"); // default for now
|
||||
|
||||
// northwest
|
||||
String nwStr = "";
|
||||
Location nw = warzone.getNorthwest();
|
||||
if(nw != null) {
|
||||
nwStr = (int)nw.getBlockX() + "," + (int)nw.getBlockY() + "," + (int)nw.getBlockZ();
|
||||
}
|
||||
warzoneConfig.setString("northWest", nwStr);
|
||||
|
||||
// southeast
|
||||
String seStr = "";
|
||||
Location se = warzone.getSoutheast();
|
||||
if(se != null) {
|
||||
seStr = (int)se.getBlockX() + "," + (int)se.getBlockY() + "," + (int)se.getBlockZ();
|
||||
}
|
||||
warzoneConfig.setString("southEast", seStr);
|
||||
|
||||
// teleport
|
||||
String teleportStr = "";
|
||||
Location tele = warzone.getTeleport();
|
||||
if(tele != null) {
|
||||
teleportStr = (int)tele.getBlockX() + "," + (int)tele.getBlockY() + "," + (int)tele.getBlockZ();
|
||||
}
|
||||
warzoneConfig.setString("teleport", teleportStr);
|
||||
|
||||
// teams
|
||||
String teamsStr = "";
|
||||
List<Team> teams = warzone.getTeams();
|
||||
for(Team team : teams) {
|
||||
Location spawn = team.getTeamSpawn();
|
||||
teamsStr += team.getName() + "," + (int)spawn.getBlockX() + "," + (int)spawn.getBlockY() + "," + (int)spawn.getBlockZ() + ";";
|
||||
}
|
||||
warzoneConfig.setString("teams", teamsStr);
|
||||
|
||||
// ff
|
||||
warzoneConfig.setBoolean("firendlyFire", warzone.getFriendlyFire());
|
||||
|
||||
// loadout
|
||||
// String loadoutStr = "";
|
||||
// List<Item> items = warzone.getLoadout();
|
||||
// for(Item item : items) {
|
||||
// loadoutStr += item.getItemId() + "," + item.getAmount() + "," + item.getSlot() + ";";
|
||||
// }
|
||||
// warzoneConfig.setString("loadout", loadoutStr);
|
||||
|
||||
// life pool
|
||||
warzoneConfig.setInt("lifePool", warzone.getLifePool());
|
||||
|
||||
// monuments
|
||||
String monumentsStr = "";
|
||||
List<Monument> monuments = warzone.getMonuments();
|
||||
for(Monument monument : monuments) {
|
||||
Location monumentLoc = monument.getLocation();
|
||||
monumentsStr += monument.getName() + "," + (int)monumentLoc.getBlockX() + "," + (int)monumentLoc.getBlockY() + "," + (int)monumentLoc.getBlockZ() + ";";
|
||||
}
|
||||
warzoneConfig.setString("monuments", monumentsStr);
|
||||
warzoneConfig.save();
|
||||
warzoneConfig.close();
|
||||
|
||||
if(saveBlocks) {
|
||||
// zone blocks
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
int northSouth = warzone.getSoutheast().getBlockX() - warzone.getNorthwest().getBlockX();
|
||||
int eastWest = warzone.getNorthwest().getBlockZ() - warzone.getSoutheast().getBlockZ();
|
||||
int[][][] state = warzone.getInitialState();
|
||||
StringBuilder stateBuilder = new StringBuilder();
|
||||
int savedBlocks = 0;
|
||||
if(state.length > 1) {
|
||||
for(int i = 0; i < northSouth + 3; i++){
|
||||
for(int j = 0; j < 128; j++) {
|
||||
for(int k = 0; k < eastWest + 3; k++) {
|
||||
stateBuilder.append(state[i][j][k] + ",");
|
||||
savedBlocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
warzoneBlocksFile.setString("zoneBlocks", stateBuilder.toString());
|
||||
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: monuments) {
|
||||
String monumentBlocksStr = "";
|
||||
for(int type : monument.getInitialState()) {
|
||||
monumentBlocksStr += type + ",";
|
||||
}
|
||||
warzoneBlocksFile.setString("monument"+monument.getName()+"Blocks", monumentBlocksStr);
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
for(Team team : teams) {
|
||||
String teamBlocksStr = "";
|
||||
for(int type : team.getOldSpawnState()) {
|
||||
teamBlocksStr += type + ",";
|
||||
}
|
||||
warzoneBlocksFile.setString("team"+team.getName()+"Blocks", teamBlocksStr);
|
||||
}
|
||||
|
||||
warzoneBlocksFile.save();
|
||||
warzoneBlocksFile.close();
|
||||
}
|
||||
|
||||
if(saveBlocks) {
|
||||
war.getLogger().info("Saved warzone " + warzone.getName() + " config and blocks.");
|
||||
} else {
|
||||
war.getLogger().info("Saved warzone " + warzone.getName() + " config.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void delete(War war, String name) {
|
||||
File warzoneConfig = new File(war.getName() + "/warzone-" + name + ".txt");
|
||||
warzoneConfig.delete();
|
||||
File warzoneBlocksFile = new File(war.getName() + "/warzone-" + name + ".dat");
|
||||
warzoneBlocksFile.delete();
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.tommytony.war.mappers;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.World;
|
||||
|
||||
import com.tommytony.war.Volume;
|
||||
import com.tommytony.war.War;
|
||||
|
||||
public class BlockMapper {
|
||||
public static Block load(War war, World world, String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save(War war, Volume volume) {
|
||||
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ import com.tommytony.war.PropertiesFile;
|
||||
import com.tommytony.war.Team;
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
import com.tommytony.war.volumes.VerticalVolume;
|
||||
import com.tommytony.war.volumes.Volume;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -85,7 +87,8 @@ public class WarzoneMapper {
|
||||
int teamY = Integer.parseInt(teamStrSplit[2]);
|
||||
int teamZ = Integer.parseInt(teamStrSplit[3]);
|
||||
Team team = new Team(teamStrSplit[0],
|
||||
new Location(world, teamX, teamY, teamZ));
|
||||
new Location(world, teamX, teamY, teamZ),
|
||||
war, warzone );
|
||||
team.setRemainingTickets(warzone.getLifePool());
|
||||
warzone.getTeams().add(team);
|
||||
}
|
||||
@ -120,7 +123,7 @@ public class WarzoneMapper {
|
||||
int monumentX = Integer.parseInt(monumentStrSplit[1]);
|
||||
int monumentY = Integer.parseInt(monumentStrSplit[2]);
|
||||
int monumentZ = Integer.parseInt(monumentStrSplit[3]);
|
||||
Monument monument = new Monument(monumentStrSplit[0], world,
|
||||
Monument monument = new Monument(monumentStrSplit[0], war, warzone,
|
||||
new Location(world, monumentX, monumentY, monumentZ));
|
||||
warzone.getMonuments().add(monument);
|
||||
}
|
||||
@ -129,43 +132,20 @@ public class WarzoneMapper {
|
||||
warzoneConfig.close();
|
||||
|
||||
if(loadBlocks) {
|
||||
// zone blocks
|
||||
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
int northSouth = ((int)(warzone.getSoutheast().getBlockX())) - ((int)(warzone.getNorthwest().getBlockX()));
|
||||
int eastWest = ((int)(warzone.getNorthwest().getBlockZ())) - ((int)(warzone.getSoutheast().getBlockZ()));
|
||||
int minY = 0;
|
||||
int maxY = 128;
|
||||
int[][][] state = new int[northSouth + 6][128][eastWest + 6];
|
||||
|
||||
// zone blocks
|
||||
VerticalVolume zoneVolume = new VerticalVolume("zone", war, warzone);
|
||||
String stateStr = warzoneBlocksFile.getString("zoneBlocks");
|
||||
String[] stateStrSplit = stateStr.split(",");
|
||||
int splitIndex = 0;
|
||||
if(stateStrSplit.length > 1000) {
|
||||
for(int i = 0; i < northSouth + 3; i++){
|
||||
for(int j = 0; j < 128; j++) {
|
||||
for(int k = 0; k < eastWest + 3; k++) {
|
||||
String currentBlockType = stateStrSplit[splitIndex];
|
||||
if(currentBlockType != null && !currentBlockType.equals("")) {
|
||||
state[i][j][k] = Integer.parseInt(currentBlockType);
|
||||
}
|
||||
splitIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
warzone.setInitialState(state);
|
||||
zoneVolume.blocksFromString(stateStr);
|
||||
warzone.setVolume(zoneVolume);
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: warzone.getMonuments()) {
|
||||
Volume monumentVolume = new Volume(monument.getName(), war, warzone);
|
||||
String monumentBlocksStr = warzoneBlocksFile.getString("monument"+monument.getName()+"Blocks");
|
||||
String[] monumentBlocksSplit = monumentBlocksStr.split(",");
|
||||
int[] monumentState = new int[10];
|
||||
for(int i = 0; i < monumentBlocksSplit.length; i++) {
|
||||
String split = monumentBlocksSplit[i];
|
||||
if(split != null && !split.equals("")) {
|
||||
monumentState[i] = Integer.parseInt(split);
|
||||
}
|
||||
}
|
||||
monument.setInitialState(monumentState);
|
||||
monumentVolume.blocksFromString(monumentBlocksStr);
|
||||
}
|
||||
|
||||
// team spawn blocks
|
||||
@ -263,23 +243,8 @@ public class WarzoneMapper {
|
||||
if(saveBlocks) {
|
||||
// zone blocks
|
||||
PropertiesFile warzoneBlocksFile = new PropertiesFile(war.getName() + "/warzone-" + warzone.getName() + ".dat");
|
||||
int northSouth = warzone.getSoutheast().getBlockX() - warzone.getNorthwest().getBlockX();
|
||||
int eastWest = warzone.getNorthwest().getBlockZ() - warzone.getSoutheast().getBlockZ();
|
||||
int[][][] state = warzone.getInitialState();
|
||||
StringBuilder stateBuilder = new StringBuilder();
|
||||
int savedBlocks = 0;
|
||||
if(state.length > 1) {
|
||||
for(int i = 0; i < northSouth + 3; i++){
|
||||
for(int j = 0; j < 128; j++) {
|
||||
for(int k = 0; k < eastWest + 3; k++) {
|
||||
stateBuilder.append(state[i][j][k] + ",");
|
||||
savedBlocks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
warzoneBlocksFile.setString("zoneBlocks", stateBuilder.toString());
|
||||
|
||||
StringBuilder zoneBlocksBuilder = new StringBuilder();
|
||||
warzoneBlocksFile.setString("zoneBlocks", warzone.getVolume().blocksToString()); // oh boy
|
||||
|
||||
// monument blocks
|
||||
for(Monument monument: monuments) {
|
||||
|
76
war/src/main/java/com/tommytony/war/volumes/BlockInfo.java
Normal file
76
war/src/main/java/com/tommytony/war/volumes/BlockInfo.java
Normal file
@ -0,0 +1,76 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
public class BlockInfo {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int type;
|
||||
private byte data;
|
||||
private String[] signLines;
|
||||
|
||||
public BlockInfo(Block block) {
|
||||
this.x = block.getX();
|
||||
this.y = block.getX();
|
||||
this.z = block.getX();
|
||||
this.type = block.getTypeID();
|
||||
this.data = block.getData();
|
||||
}
|
||||
|
||||
public BlockInfo(BlockState blockState) {
|
||||
this.x = blockState.getX();
|
||||
this.y = blockState.getX();
|
||||
this.z = blockState.getX();
|
||||
this.type = blockState.getTypeID();
|
||||
this.data = blockState.getData();
|
||||
if(is(Material.Sign) || is(Material.SignPost)) {
|
||||
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 x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public int getTypeID() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public Material getType() {
|
||||
return Material.getMaterial(type);
|
||||
}
|
||||
|
||||
public byte getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public boolean is(Material material) {
|
||||
return getType() == material;
|
||||
}
|
||||
|
||||
public String[] getSignLines() {
|
||||
if(is(Material.Sign) || is(Material.SignPost)){
|
||||
return signLines;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class CenteredVolume extends Volume {
|
||||
|
||||
private Block center;
|
||||
private int sideSize = -1;
|
||||
|
||||
public CenteredVolume(String name, Location center, War war, Warzone warzone) {
|
||||
super(name, war, warzone);
|
||||
setCenter(warzone.getWorld().getBlockAt(center.getBlockX(), center.getBlockY(), center.getBlockZ()));
|
||||
}
|
||||
|
||||
public void setCenter(Block block) {
|
||||
this.resetBlocks();
|
||||
this.center = block;
|
||||
if(sideSize != -1) {
|
||||
calculateCorners();
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateCorners() {
|
||||
int topHalfOfSide = sideSize / 2;
|
||||
|
||||
int x = center.getX() + topHalfOfSide;
|
||||
int y = center.getY() + topHalfOfSide;
|
||||
int z = center.getZ() + topHalfOfSide;
|
||||
Block cornerOne = getWarzone().getWorld().getBlockAt(x, y, z);
|
||||
setCornerOne(cornerOne);
|
||||
|
||||
int bottomHalfOfSide = sideSize - topHalfOfSide;
|
||||
x = center.getX() - bottomHalfOfSide;
|
||||
y = center.getY() - bottomHalfOfSide;
|
||||
z = center.getZ() - bottomHalfOfSide;
|
||||
Block cornerTwo = getWarzone().getWorld().getBlockAt(x, y, z);
|
||||
setCornerTwo(cornerTwo);
|
||||
}
|
||||
|
||||
public void setSideSize(int sideSize) {
|
||||
this.resetBlocks();
|
||||
this.sideSize = sideSize;
|
||||
if(center != null) {
|
||||
calculateCorners();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import org.bukkit.Block;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class VerticalVolume extends Volume{
|
||||
|
||||
public VerticalVolume(String name, War war, Warzone warzone) {
|
||||
super(name, war, warzone);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCornerOne(Block block){
|
||||
// corner one defaults to topmost corner
|
||||
Block topBlock = getWorld().getBlockAt(block.getX(), 128, block.getZ());
|
||||
super.setCornerOne(topBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCornerTwo(Block block){
|
||||
// corner one defaults to bottom most corner
|
||||
Block bottomBlock = getWorld().getBlockAt(block.getX(), 0, block.getZ());
|
||||
super.setCornerTwo(bottomBlock);
|
||||
}
|
||||
}
|
266
war/src/main/java/com/tommytony/war/volumes/Volume.java
Normal file
266
war/src/main/java/com/tommytony/war/volumes/Volume.java
Normal file
@ -0,0 +1,266 @@
|
||||
package com.tommytony.war.volumes;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.bukkit.Block;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
|
||||
import com.tommytony.war.War;
|
||||
import com.tommytony.war.Warzone;
|
||||
|
||||
public class Volume {
|
||||
private final String name;
|
||||
private final World world;
|
||||
private final Warzone warzone;
|
||||
private Block cornerOne;
|
||||
private Block cornerTwo;
|
||||
private BlockInfo[][][] blockInfos = null;
|
||||
private final War war;
|
||||
|
||||
public Volume(String name, War war, Warzone warzone) {
|
||||
this.name = name;
|
||||
this.war = war;
|
||||
this.warzone = warzone;
|
||||
this.world = warzone.getWorld();
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public boolean hasTwoCorners() {
|
||||
return cornerOne != null && cornerTwo != null;
|
||||
}
|
||||
|
||||
public void setCornerOne(Block block) {
|
||||
this.cornerOne = block;
|
||||
}
|
||||
|
||||
public int saveBlocks() {
|
||||
int noOfSavedBlocks = 0;
|
||||
try {
|
||||
if(hasTwoCorners()) {
|
||||
this.blockInfos = new BlockInfo[getSizeX()][getSizeY()][getSizeZ()];
|
||||
int x = getMinX();
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
int y = getMinY();
|
||||
for(int j = 0; j < getSizeY(); j++){
|
||||
int z = getMinZ();
|
||||
for(int k = 0;k < getSizeZ(); k++) {
|
||||
this.blockInfos[i][j][k] = new BlockInfo(world.getBlockAt(x, y, z));
|
||||
z++;
|
||||
noOfSavedBlocks++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.war.getLogger().warning(war.str("Failed to save volume " + name + " blocks. " + e.getMessage()));
|
||||
}
|
||||
return noOfSavedBlocks;
|
||||
}
|
||||
|
||||
public int resetBlocks() {
|
||||
int noOfResetBlocks = 0;
|
||||
try {
|
||||
if(hasTwoCorners() && blockInfos != null) {
|
||||
int x = getMinX();
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
int y = getMinY();
|
||||
for(int j = 0; j < getSizeY(); j++){
|
||||
int z = getMinZ();
|
||||
for(int k = 0;k < getSizeZ(); k++) {
|
||||
BlockInfo oldBlockInfo = blockInfos[i][j][k];
|
||||
Block currentBlock = world.getBlockAt(x, y, z);
|
||||
if(currentBlock.getTypeID() != oldBlockInfo.getTypeID() ||
|
||||
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() != oldBlockInfo.getData()) ||
|
||||
(currentBlock.getTypeID() == oldBlockInfo.getTypeID() && currentBlock.getData() == oldBlockInfo.getData() &&
|
||||
(oldBlockInfo.is(Material.Sign) || oldBlockInfo.is(Material.SignPost))
|
||||
)
|
||||
) {
|
||||
currentBlock.setType(oldBlockInfo.getType());
|
||||
currentBlock.setData(oldBlockInfo.getData());
|
||||
if(oldBlockInfo.is(Material.Sign) || oldBlockInfo.is(Material.SignPost)) {
|
||||
Sign currentSign = (Sign) currentBlock;
|
||||
currentSign.setLine(0, oldBlockInfo.getSignLines()[0]);
|
||||
currentSign.setLine(1, oldBlockInfo.getSignLines()[0]);
|
||||
currentSign.setLine(2, oldBlockInfo.getSignLines()[0]);
|
||||
currentSign.setLine(3, oldBlockInfo.getSignLines()[0]);
|
||||
}
|
||||
noOfResetBlocks++;
|
||||
}
|
||||
z++;
|
||||
}
|
||||
y++;
|
||||
}
|
||||
x++;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.war.getLogger().warning(war.str("Failed to reset volume " + name + " blocks. " + e.getMessage()));
|
||||
}
|
||||
return noOfResetBlocks;
|
||||
}
|
||||
|
||||
public void setCornerTwo(Block block) {
|
||||
this.cornerTwo = block;
|
||||
}
|
||||
|
||||
public Block getMinXBlock() {
|
||||
if(cornerOne.getX() < cornerTwo.getX()) return cornerOne;
|
||||
return cornerTwo;
|
||||
}
|
||||
|
||||
public Block getMinYBlock() {
|
||||
if(cornerOne.getY() < cornerTwo.getY()) return cornerOne;
|
||||
return cornerTwo;
|
||||
}
|
||||
|
||||
public Block getMinZBlock() {
|
||||
if(cornerOne.getZ() < cornerTwo.getZ()) return cornerOne;
|
||||
return cornerTwo;
|
||||
}
|
||||
|
||||
public int getMinX() {
|
||||
return getMinXBlock().getX();
|
||||
}
|
||||
|
||||
public int getMinY() {
|
||||
return getMinYBlock().getY();
|
||||
}
|
||||
|
||||
public int getMinZ() {
|
||||
return getMinZBlock().getZ();
|
||||
}
|
||||
|
||||
public Block getMaxXBlock() {
|
||||
if(cornerOne.getX() < cornerTwo.getX()) return cornerTwo;
|
||||
return cornerOne;
|
||||
}
|
||||
|
||||
public Block getMaxYBlock() {
|
||||
if(cornerOne.getY() < cornerTwo.getY()) return cornerTwo;
|
||||
return cornerOne;
|
||||
}
|
||||
|
||||
public Block getMaxZBlock() {
|
||||
if(cornerOne.getZ() < cornerTwo.getZ()) return cornerTwo;
|
||||
return cornerOne;
|
||||
}
|
||||
|
||||
public int getMaxX() {
|
||||
return getMaxXBlock().getX();
|
||||
}
|
||||
|
||||
public int getMaxY() {
|
||||
return getMaxYBlock().getY();
|
||||
}
|
||||
|
||||
public int getMaxZ() {
|
||||
return getMaxZBlock().getZ();
|
||||
}
|
||||
|
||||
public int getSizeX() {
|
||||
return getMaxX() - getMinX();
|
||||
}
|
||||
|
||||
public int getSizeY() {
|
||||
return getMaxY() - getMinY();
|
||||
}
|
||||
|
||||
public int getSizeZ() {
|
||||
return getMaxZ() - getMinZ();
|
||||
}
|
||||
|
||||
public boolean isSaved() {
|
||||
return blockInfos != null;
|
||||
}
|
||||
|
||||
public BlockInfo[][][] getBlockInfos() {
|
||||
return blockInfos;
|
||||
}
|
||||
|
||||
public String blocksToString() {
|
||||
StringBuilder volumeStringBuilder = new StringBuilder();
|
||||
volumeStringBuilder.append(cornerOne.getX() + "," + cornerOne.getY() + "," + cornerOne.getZ() + ";");
|
||||
volumeStringBuilder.append(cornerTwo.getX() + "," + cornerTwo.getY() + "," + cornerTwo.getZ() + ";");
|
||||
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
for(int j = 0; j < getSizeY(); j++) {
|
||||
for(int k = 0; k < getSizeZ(); k++) {
|
||||
BlockInfo info = getBlockInfos()[i][j][k];
|
||||
volumeStringBuilder.append(info.getTypeID() + "," + info.getData() + "," + info.getSignLines()[0]);
|
||||
if(info.getType() == Material.Sign || info.getType() == Material.SignPost) {
|
||||
String[] lines = info.getSignLines();
|
||||
volumeStringBuilder.append(lines[0] + "\n");
|
||||
volumeStringBuilder.append(lines[1] + "\n");
|
||||
volumeStringBuilder.append(lines[2] + "\n");
|
||||
volumeStringBuilder.append(lines[3] + "\n");
|
||||
}
|
||||
volumeStringBuilder.append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
return volumeStringBuilder.toString();
|
||||
}
|
||||
|
||||
public void blocksFromString(String volumeString) {
|
||||
Scanner scanner = new Scanner(volumeString);
|
||||
int x1 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int y1 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int z1 = scanner.nextInt();
|
||||
scanner.next(";");
|
||||
cornerOne = world.getBlockAt(x1, y1, z1);
|
||||
int x2 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int y2 = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
int z2 = scanner.nextInt();
|
||||
scanner.next(";");
|
||||
cornerOne = world.getBlockAt(x2, y2, z2);
|
||||
|
||||
blockInfos = new BlockInfo[getSizeX()][getSizeY()][getSizeZ()];
|
||||
for(int i = 0; i < getSizeX(); i++){
|
||||
for(int j = 0; j < getSizeY(); j++) {
|
||||
for(int k = 0; k < getSizeZ(); k++) {
|
||||
// scan ne
|
||||
int typeID = scanner.nextInt();
|
||||
scanner.next(",");
|
||||
byte data = scanner.nextByte();
|
||||
String[] lines = null;
|
||||
if(typeID == Material.Sign.getID() || typeID == Material.SignPost.getID()) {
|
||||
scanner.next(",");
|
||||
lines = new String[4];
|
||||
lines[0] = scanner.nextLine();
|
||||
lines[1] = scanner.nextLine();
|
||||
lines[2] = scanner.nextLine();
|
||||
lines[3] = scanner.nextLine();
|
||||
}
|
||||
scanner.next(";");
|
||||
getBlockInfos()[i][j][k] = new BlockInfo(typeID, data, lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Warzone getWarzone() {
|
||||
return warzone;
|
||||
}
|
||||
|
||||
public boolean contains(Location location) {
|
||||
int x = location.getBlockX();
|
||||
int y = location.getBlockY();
|
||||
int z = location.getBlockZ();
|
||||
return x <= getMaxX() && x >= getMinX() &&
|
||||
y <= getMaxY() && y >= getMinY() &&
|
||||
z <= getMaxZ() && z >= getMinZ();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user