diff --git a/minecraft.hmod.war.test/lib/mockito-all-1.8.5.jar b/minecraft.hmod.war.test/lib/mockito-all-1.8.5.jar deleted file mode 100644 index 4b0395e..0000000 Binary files a/minecraft.hmod.war.test/lib/mockito-all-1.8.5.jar and /dev/null differ diff --git a/minecraft.hmod.war/.classpath b/minecraft.hmod.war/.classpath index 3c17405..9f738ff 100644 --- a/minecraft.hmod.war/.classpath +++ b/minecraft.hmod.war/.classpath @@ -2,8 +2,8 @@ - - - + + + diff --git a/minecraft.hmod.war/lib/Minecraft_Mod131.jar b/minecraft.hmod.war/lib/Minecraft_Mod131.jar deleted file mode 100644 index 7986020..0000000 Binary files a/minecraft.hmod.war/lib/Minecraft_Mod131.jar and /dev/null differ diff --git a/minecraft.hmod.war/lib/minecraft_server28.jar b/minecraft.hmod.war/lib/minecraft_server28.jar deleted file mode 100644 index 3995341..0000000 Binary files a/minecraft.hmod.war/lib/minecraft_server28.jar and /dev/null differ diff --git a/minecraft.hmod.war/lib/mysql-connector-java-bin.jar b/minecraft.hmod.war/lib/mysql-connector-java-bin.jar deleted file mode 100644 index 0539039..0000000 Binary files a/minecraft.hmod.war/lib/mysql-connector-java-bin.jar and /dev/null differ diff --git a/minecraft.hmod.war/src/BlockColumnSetter.java b/minecraft.hmod.war/src/BlockColumnSetter.java new file mode 100644 index 0000000..97bb809 --- /dev/null +++ b/minecraft.hmod.war/src/BlockColumnSetter.java @@ -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); + } + +} diff --git a/minecraft.hmod.war/src/Team.java b/minecraft.hmod.war/src/Team.java index 1c2ab14..4a5806a 100644 --- a/minecraft.hmod.war/src/Team.java +++ b/minecraft.hmod.war/src/Team.java @@ -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; + } + } diff --git a/minecraft.hmod.war/src/War.java b/minecraft.hmod.war/src/War.java index b628a4b..f1436de 100644 --- a/minecraft.hmod.war/src/War.java +++ b/minecraft.hmod.war/src/War.java @@ -16,7 +16,6 @@ public class War extends Plugin { private final List warzones = new ArrayList(); - //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 subStrs = toSubStrings(str); - List coloredSubStrs = new ArrayList(); - 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 toSubStrings(String str) { - List subStrings = new ArrayList(); - 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)) { diff --git a/minecraft.hmod.war/src/WarListener.java b/minecraft.hmod.war/src/WarListener.java index 210c722..58f054a 100644 --- a/minecraft.hmod.war/src/WarListener.java +++ b/minecraft.hmod.war/src/WarListener.java @@ -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 to " + - "teleport to warzone, " + + "teleport to a warzone, " + "then use /teams and /join .")); return true; } @@ -46,21 +49,21 @@ public class WarListener extends PluginListener { player.sendMessage(war.str("Usage: /warzone .")); } 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 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 . " + + "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 else if(command.equals("/team")) { - if(split.length < 2) { + if(!war.inAnyWarzone(player.getLocation())) { player.sendMessage(war.str("Usage: /team . " + "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 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 <'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()) { diff --git a/minecraft.hmod.war/src/WarMessenger.java b/minecraft.hmod.war/src/WarMessenger.java deleted file mode 100644 index eca1b19..0000000 --- a/minecraft.hmod.war/src/WarMessenger.java +++ /dev/null @@ -1,12 +0,0 @@ - -public class WarMessenger { - - public void sendMessage(Player player, String msg) { - // TODO Auto-generated method stub - - } - - - - -} diff --git a/minecraft.hmod.war/src/Warzone.java b/minecraft.hmod.war/src/Warzone.java index 927d418..0ad30fc 100644 --- a/minecraft.hmod.war/src/Warzone.java +++ b/minecraft.hmod.war/src/Warzone.java @@ -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; + } }