Warzone reset now works! Just need to test out the onDamage. Removed jars added by mistake.

This commit is contained in:
taoneill 2011-01-03 01:35:59 -05:00
parent e790fd9c18
commit ee93c182fc
11 changed files with 192 additions and 139 deletions

View File

@ -2,8 +2,8 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/Minecraft_Mod131.jar" sourcepath="/hmod"/>
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/minecraft_server28.jar"/>
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/mysql-connector-java-bin.jar"/>
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/Minecraft_Mod133.jar" sourcepath="/hmod"/>
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/minecraft_server-beta1.1_02.jar"/>
<classpathentry kind="lib" path="C:/dev/war/minecraft.hmod.war/lib/mysql-connector-java-bin133.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,29 @@
public class BlockColumnSetter implements Runnable {
private final int x;
private final int z;
private final Server server;
private final int[][][] initialState;
private final int i;
private final int k;
public BlockColumnSetter(Server server, int[][][] initialState, int x, int z, int i, int k) {
this.server = server;
this.initialState = initialState;
this.x = x;
this.z = z;
this.i = i;
this.k = k;
}
@Override
public void run() {
for(int j = 0; j < 128; j++) {
server.setBlockAt(initialState[i][j][k], x, j, z);
}
server.messageAll("Reset x=" + x + " z=" + z);
}
}

View File

@ -41,4 +41,18 @@ public class Team {
return name;
}
public boolean removePlayer(String name) {
Player thePlayer = null;
for(Player player : players) {
if(player.getName().equals(name)) {
thePlayer = player;
}
}
if(thePlayer != null) {
players.remove(thePlayer);
return true;
}
return false;
}
}

View File

@ -16,7 +16,6 @@ public class War extends Plugin {
private final List<Warzone> warzones = new ArrayList<Warzone>();
//private final WarMessenger messenger = new WarMessenger();
public void initialize() {
this.log = Logger.getLogger("Minecraft");
@ -39,6 +38,10 @@ public class War extends Plugin {
listener,
this,
PluginListener.Priority.HIGH);
etc.getLoader().addListener( PluginLoader.Hook.PLAYER_MOVE,
listener,
this,
PluginListener.Priority.MEDIUM);
// etc.getLoader().addListener(
// PluginLoader.Hook.BLOCK_CREATED,
@ -109,63 +112,10 @@ public class War extends Plugin {
}
public String str(String str) {
String out = "[war] " + str;
out = str(Colors.LightGray, out);
if(out.length() > 120) {
out = out.substring(0, 119);
}
log.log(Level.INFO, "Out: " + out);
String out = Colors.LightGray + "[war] " + Colors.White + str;
return out;
}
public String str(String color, String str) {
if(str.length() > 60) {
String out = "";
List<String> subStrs = toSubStrings(str);
List<String> coloredSubStrs = new ArrayList<String>();
for(String sub : subStrs) {
String colored = "";
if(sub.length() < 60) {
colored = color + sub;
}
else {
// colored = color + sub.charAt(0) + color + sub.charAt(1) + color + sub.charAt(2) + color + sub.charAt(3) + color + sub.charAt(4) +
// sub.substring(5);
//if(sub.length() > 10) {
colored = color + sub;
//.substring(5, sub.length() - 5);
//colored += color + sub.charAt(sub.length() - 5) + color + sub.charAt(sub.length() - 4) + color + sub.charAt(sub.length() - 3)
// + color + sub.charAt(sub.length() - 2) + color + sub.charAt(sub.length() - 1);
//}
}
coloredSubStrs.add(colored);
}
for(String sub : coloredSubStrs) {
out += sub;
}
return out;
} else {
return color + str;
}
}
private List<String> toSubStrings(String str) {
List<String> subStrings = new ArrayList<String>();
int start = 0;
int end = 60;
while(end < str.length()) {
subStrings.add(str.substring(start, end));
start += 60;
end += 60;
}
if(start < str.length()) {
subStrings.add(str.substring(start));
}
return subStrings;
}
public Warzone findWarzone(String warzoneName) {
for(Warzone warzone : warzones) {
if(warzone.getName().equals(warzoneName)) {

View File

@ -18,12 +18,15 @@ public class WarListener extends PluginListener {
public boolean onCommand(Player player, java.lang.String[] split) {
String command = split[0];
// Player commands: /warzones, /warzone, /teams, /join
// Player commands: /warzones, /warzone, /teams, /join, /leave
// warzones
if(command.equals("/warzones")){
String warzonesMessage = "Warzones: ";
if(war.getWarzones().isEmpty()){
warzonesMessage += "none.";
}
for(Warzone warzone : war.getWarzones()) {
warzonesMessage += warzone.getName() + " ("
@ -35,7 +38,7 @@ public class WarListener extends PluginListener {
warzonesMessage += playerTotal + " players) ";
}
player.sendMessage(war.str(warzonesMessage + " Use /warzone <zone-name> to " +
"teleport to warzone, " +
"teleport to a warzone, " +
"then use /teams and /join <team-name>."));
return true;
}
@ -46,21 +49,21 @@ public class WarListener extends PluginListener {
player.sendMessage(war.str("Usage: /warzone <warzone-name>."));
} else {
for(Warzone warzone : war.getWarzones()) {
if(warzone.getName().equals(split[2])){
if(warzone.getName().equals(split[1])){
player.teleportTo(warzone.getTeleport());
player.sendMessage(war.str("You've landed in the " + warzone.getName() +
" warzone. Use the /join command. " + getAllTeamsMsg(player)));
player.sendMessage(war.str("You've landed in warzone " + warzone.getName() +
". Use the /join command. " + getAllTeamsMsg(player)));
return true;
}
}
player.sendMessage("So such warzone.");
player.sendMessage("No such warzone.");
}
return true;
}
// /teams
if(command.equals("/teams")){
if(split.length < 2 || !war.inAnyWarzone(player.getLocation())) {
else if(command.equals("/teams")){
if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /teams. " +
"Must be in a warzone (try /warzones and /warzone)."));
} else {
@ -76,17 +79,30 @@ public class WarListener extends PluginListener {
" Teams are warzone specific." +
" You must be inside a warzone to join a team."));
} else {
// drop from old team if any
Team previousTeam = war.getPlayerTeam(player.getName());
if(previousTeam != null) {
if(!previousTeam.removePlayer(player.getName())){
war.getLogger().log(Level.WARNING, "Could not remove player " + player.getName() + " from team " + previousTeam.getName());
}
}
// join new team
String name = split[1];
List<Team> teams = war.warzone(player.getLocation()).getTeams();
boolean foundTeam = false;
for(Team team : teams) {
if(team.getName().equals(name)) {
team.addPlayer(player);
player.teleportTo(team.getTeamSpawn());
foundTeam = true;
}
}
if(foundTeam) {
etc.getServer().messageAll(war.str("" + player.getName() + " joined " + name));
for(Team team : teams){
team.teamcast(war.str("" + player.getName() + " joined " + name));
}
} else {
player.sendMessage(war.str("No such team. Try /teams."));
}
@ -94,20 +110,33 @@ public class WarListener extends PluginListener {
return true;
}
// /leave
else if(command.equals("/leave")) {
if(!war.inAnyWarzone(player.getLocation()) || war.getPlayerTeam(player.getName()) == null) {
player.sendMessage(war.str("Usage: /leave <message>. " +
"Must be in a team already."));
} else {
Team playerTeam = war.getPlayerTeam(player.getName());
playerTeam.removePlayer(player.getName());
player.sendMessage(war.str("Left the team. You can now exit the warzone."));
}
return true;
}
// /team <msg>
else if(command.equals("/team")) {
if(split.length < 2) {
if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /team <message>. " +
"Sends a message only to your teammates."));
} else {
Team playerTeam = war.getPlayerTeam(player.getName());
String teamMessage = "<"+ player.getName() + ":> ";
String teamMessage = player.getName();
for(int j = 1 ; j<split.length; j++) {
String part = split[j];
teamMessage += part + " ";
}
playerTeam.teamcast(war.str(Colors.LightBlue, teamMessage));
playerTeam.teamcast(war.str(teamMessage));
}
return true;
}
@ -123,14 +152,14 @@ public class WarListener extends PluginListener {
for(Team team: warzone.getTeams()) {
team.teamcast(war.str("Resetting warzone."));
}
warzone.resetState();
player.sendMessage(war.str("Warzone reset."));
int resetBlocks = warzone.resetState();
player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset."));
}
return true;
}
// Warzone maker commands: /setwarzone, /setwarzonestart, /resetwarzone, /newteam, /setteamspawn, .. /setmonument
// Warzone maker commands: /setwarzone, /setwarzonestart, /resetwarzone, /newteam, /setteamspawn, .. /setmonument?
// /newteam <teamname>
else if(command.equals("/newteam")) {
@ -162,7 +191,8 @@ public class WarListener extends PluginListener {
// /setwarzone
else if(command.equals("/setwarzone")) {
if(split.length < 3 || (split.length == 3 && (!split[2].equals("southeast") && !split[2].equals("northwest")))) {
if(split.length < 3 || (split.length == 3 && (!split[2].equals("southeast") && !split[2].equals("northwest")
&& !split[2].equals("se") && !split[2].equals("nw")))) {
player.sendMessage(war.str("Usage: /setwarzone <warzone-name> <'southeast'/'northwest'>. " +
"Defines the battleground boundary. " +
"The warzone is reset at the start of every battle. " +
@ -175,21 +205,21 @@ public class WarListener extends PluginListener {
// create the warzone
Warzone newZone = new Warzone(war.getServer(), split[1]);
war.addWarzone(newZone);
if(split[2].equals("northwest")) {
if(split[2].equals("northwest") || split[2].equals("nw")) {
newZone.setNorthwest(player.getLocation());
player.sendMessage(war.str("Warzone added. Northwesternmost point set."));
player.sendMessage(war.str("Warzone added. Northwesternmost point set at x=" + (int)newZone.getNorthwest().x + " z=" + (int)newZone.getNorthwest().z + "."));
} else {
newZone.setSoutheast(player.getLocation());
player.sendMessage(war.str("Warzone added. Southeasternmost point set."));
player.sendMessage(war.str("Warzone added. Southeasternmost point set at x=" + (int)newZone.getSoutheast().x + " z=" + (int)newZone.getSoutheast().z + "."));
}
} else {
String message = "";
if(split[2].equals("northwest")) {
if(split[2].equals("northwest") || split[2].equals("nw")) {
warzone.setNorthwest(player.getLocation());
message += "Northwesternmost point set." ;
message += "Northwesternmost point set at x=" + (int)warzone.getNorthwest().x + " z=" + (int)warzone.getNorthwest().z + ".";
} else {
warzone.setSoutheast(player.getLocation());
message += "Southeasternmost point set.";
message += "Southeasternmost point set at x=" + (int)warzone.getSoutheast().x + " z=" + (int)warzone.getSoutheast().z + ".";
}
if(warzone.getNorthwest() == null) {
@ -216,7 +246,7 @@ public class WarListener extends PluginListener {
}
// /setwarzonestate
// /setwarzonestart
else if(command.equals("/setwarzonestart")) {
if(!war.inAnyWarzone(player.getLocation())) {
player.sendMessage(war.str("Usage: /setwarzonestart. Must be in warzone. " +
@ -228,9 +258,9 @@ public class WarListener extends PluginListener {
"or /resetwarzone before changing start state). "));
} else {
Warzone warzone = war.warzone(player.getLocation());
warzone.saveState();
int savedBlocks = warzone.saveState();
warzone.setTeleport(player.getLocation());
player.sendMessage(war.str("Warzone initial state and teleport location changed."));
player.sendMessage(war.str("Warzone initial state and teleport location changed. Saved " + savedBlocks + " blocks."));
}
return true;
}
@ -244,8 +274,9 @@ public class WarListener extends PluginListener {
for(Team team: warzone.getTeams()) {
team.teamcast(war.str("Resetting warzone..."));
}
warzone.resetState();
player.sendMessage(war.str("Warzone reset."));
int resetBlocks = warzone.resetState();
Location playerLoc = player.getLocation();
player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset."));
}
return true;
}
@ -281,21 +312,31 @@ public class WarListener extends PluginListener {
public boolean onHealthChange(Player player, int before, int after) {
if(after < 0) {
if(after <= 0) {
Team team = war.getPlayerTeam(player.getName());
if(team != null){
// teleport to team spawn upon death
player.setHealth(20);
player.teleportTo(team.getTeamSpawn());
after = 20;
war.getLogger().log(Level.INFO, player.getName() + " died and was tp'd back to team " + team.getName() + "'s spawn");
return true;
}
}
return false;
}
public void onPlayerMove(Player player, Location from, Location to) {
if(player != null && from != null && to != null &&
war.getPlayerTeam(player.getName()) != null && !war.warzone(from).contains(to)) {
player.sendMessage(war.str("Can't go outside the warzone boundary! Use /leave to exit the battle."));
player.teleportTo(from);
}
}
private String getAllTeamsMsg(Player player){
String teamsMessage = "Teams: ";
if(war.warzone(player.getLocation()).getTeams().isEmpty()){
teamsMessage += "none.";
}
for(Team team : war.warzone(player.getLocation()).getTeams()) {
teamsMessage += team.getName() + " (";
for(Player member : team.getPlayers()) {

View File

@ -1,12 +0,0 @@
public class WarMessenger {
public void sendMessage(Player player, String msg) {
// TODO Auto-generated method stub
}
}

View File

@ -67,45 +67,6 @@ public class Warzone {
}
}
public void saveState() {
if(ready()){
int northSouth = (int)(southeast.x - northwest.x);
int eastWest = (int)(northwest.z - southeast.z);
initialState = new int[northSouth][128][eastWest];
for(int x = 0; x < northSouth; x++){
for(int y = 0; y < 128; y++) {
for(int z = 0; z < eastWest; z++) {
initialState[x][y][z] = server.getBlockAt(x, y, z).getType();
}
}
}
}
}
public void resetState() {
if(ready() && initialState != null){
// reset blocks
int northSouth = (int)(southeast.x - northwest.x);
int eastWest = (int)(northwest.z - southeast.z);
initialState = new int[northSouth][128][eastWest];
for(int x = 0; x < northSouth; x++){
for(int y = 0; y < 128; y++) {
for(int z = 0; z < eastWest; z++) {
server.setBlockAt(initialState[x][y][z],x, y, z);
}
}
}
// everyone back to team spawn with full health
for(Team team : teams) {
for(Player player : team.getPlayers()) {
player.setHealth(20);
player.teleportTo(team.getTeamSpawn());
}
}
}
}
public Location getNorthwest() {
return northwest;
}
@ -129,5 +90,75 @@ public class Warzone {
return this.teleport;
}
public int saveState() {
if(ready()){
int northSouth = ((int)(southeast.x)) - ((int)(northwest.x));
int eastWest = ((int)(northwest.z)) - ((int)(southeast.z));
initialState = new int[northSouth][128][eastWest];
int noOfSavedBlocks = 0;
int x = (int)northwest.x;
int minY = 0;
int maxY = 128;
for(int i = 0; i < northSouth; i++){
int y = minY;
for(int j = 0; j < maxY - minY; j++) {
int z = (int)southeast.z;
for(int k = 0; k < eastWest; k++) {
initialState[i][j][k] = server.getBlockIdAt(x, y, z);
noOfSavedBlocks++;
z++;
}
y++;
}
x++;
}
return noOfSavedBlocks;
}
return 0;
}
public int resetState() {
if(ready() && initialState != null){
// reset blocks
int northSouth = ((int)(southeast.x)) - ((int)(northwest.x));
int eastWest = ((int)(northwest.z)) - ((int)(southeast.z));
int noOfResetBlocks = 0;
int noOfFailures = 0;
int x = (int)northwest.x;
int minY = 0;
int maxY = 128;
for(int i = 0; i < northSouth; i++){
int y = minY;
for(int j = 0; j < maxY - minY; j++) {
int z = (int)southeast.z;
for(int k = 0; k < eastWest; k++) {
int currentType = server.getBlockIdAt(x, y, z);
int initialType = initialState[i][j][k];
if(currentType != initialType) {
if(server.setBlockAt(initialType,x, y, z)) {
noOfResetBlocks++;
} else {
noOfFailures++;
}
}
z++;
}
y++;
}
x++;
}
// everyone back to team spawn with full health
for(Team team : teams) {
for(Player player : team.getPlayers()) {
player.setHealth(20);
player.teleportTo(team.getTeamSpawn());
}
}
return noOfResetBlocks;
}
return 0;
}
}