diff --git a/minecraft.hmod.war/src/War.java b/minecraft.hmod.war/src/War.java index 2e179ad..3da707d 100644 --- a/minecraft.hmod.war/src/War.java +++ b/minecraft.hmod.war/src/War.java @@ -74,13 +74,16 @@ public class War extends Plugin { this.defaultLoadout.add(new Item(262, 12, 2)); this.defaultLoadout.add(new Item(274, 1, 3)); this.defaultLoadout.add(new Item(273, 1, 4)); - this.defaultLoadout.add(new Item(275, 1, 4)); - this.defaultLoadout.add(new Item(259, 1, 5)); + this.defaultLoadout.add(new Item(275, 1, 5)); + this.defaultLoadout.add(new Item(259, 1, 27)); this.defaultLoadout.add(new Item(297, 1, 6)); + this.defaultLoadout.add(new Item(3, 12, 8)); this.defaultLoadout.add(new Item(301, 1, 100)); this.defaultLoadout.add(new Item(300, 1, 101)); this.defaultLoadout.add(new Item(299, 1, 102)); this.defaultLoadout.add(new Item(298, 1, 103)); + this.defaultLifepool = 7; + this.defaultFriendlyFire = false; WarMapper.load(this); getLogger().info(name + " " + version + " initialized."); diff --git a/minecraft.hmod.war/src/WarListener.java b/minecraft.hmod.war/src/WarListener.java index d756459..c775a77 100644 --- a/minecraft.hmod.war/src/WarListener.java +++ b/minecraft.hmod.war/src/WarListener.java @@ -98,6 +98,10 @@ public class WarListener extends PluginListener { boolean foundTeam = false; for(Team team : teams) { if(team.getName().equals(name)) { + if(!warzone.hasPlayerInventory(player.getName())) { + warzone.keepPlayerInventory(player); + player.sendMessage(war.str("Your inventory is is storage until you /leave.")); + } team.addPlayer(player); Warzone zone = war.warzone(player.getLocation()); zone.respawnPlayer(team, player); @@ -111,11 +115,6 @@ public class WarListener extends PluginListener { } else { player.sendMessage(war.str("No such team. Try /teams.")); } - - if(!warzone.hasPlayerInventory(player.getName())) { - warzone.keepPlayerInventory(player); - player.sendMessage(war.str("Your inventory has been stored until you /leave.")); - } } return true; } @@ -163,7 +162,7 @@ public class WarListener extends PluginListener { } else { Warzone warzone = war.warzone(player.getLocation()); for(Team team: warzone.getTeams()) { - team.teamcast(war.str("The battle has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + "...")); + team.teamcast(war.str("The battle has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and life pools...")); } int resetBlocks = warzone.resetState(); player.sendMessage(war.str("Warzone reset. " + resetBlocks + " blocks reset.")); @@ -183,6 +182,7 @@ public class WarListener extends PluginListener { String name = split[1]; Team newTeam = new Team(name, player.getLocation()); Warzone warzone = war.warzone(player.getLocation()); + newTeam.setRemainingTickets(warzone.getLifePool()); warzone.getTeams().add(newTeam); warzone.addSpawnArea(newTeam, player.getLocation(), 41); player.sendMessage(war.str("Team " + name + " created with spawn here.")); @@ -332,6 +332,34 @@ public class WarListener extends PluginListener { return true; } + // /resetwarzone + else if(command.equals("/resetwarzone")) { + if(!war.inAnyWarzone(player.getLocation())) { + player.sendMessage(war.str("Usage: /resetwarzone . Must be in warzone.")); + } else { + Warzone warzone = war.warzone(player.getLocation()); + int resetBlocks = warzone.resetState(); + for(Team team: warzone.getTeams()) { + team.teamcast(war.str("The war has ended. " + getAllTeamsMsg(player) + " Resetting warzone " + warzone.getName() + " and teams...")); + for(Player p : team.getPlayers()) { + p.teleportTo(warzone.getTeleport()); + warzone.restorePlayerInventory(p); + player.sendMessage(war.str("You are now teamless. Your inventory has (hopefully) been restored.")); + } + } + war.getWarzones().remove(warzone); + Warzone resetWarzone = WarzoneMapper.load(war, warzone.getName()); + war.getWarzones().add(resetWarzone); + if(split.length > 1) { + int overideLifepool = Integer.parseInt(split[1]); + resetWarzone.setLifePool(overideLifepool); + } + resetWarzone.resetState(); + player.sendMessage(war.str("Warzone and teams reset. " + resetBlocks + " blocks reset.")); + } + return true; + } + // /deletewarzone else if(command.equals("/deletewarzone")) { if(!war.inAnyWarzone(player.getLocation())) { @@ -340,6 +368,8 @@ public class WarListener extends PluginListener { "Must be in the warzone (try /warzones and /warzone). ")); } else { Warzone warzone = war.warzone(player.getLocation()); + warzone.removeSoutheast(); + warzone.removeNorthwest(); for(Team t : warzone.getTeams()) { warzone.removeSpawnArea(t); } @@ -477,10 +507,10 @@ public class WarListener extends PluginListener { Block block = war.getServer().getBlockAt(x, y, z); ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z); Sign sign = (Sign)complexBlock; - sign.setText(0, "Team " + team.getName()); - sign.setText(1, "spawn"); - sign.setText(2, team.getPoints() + " pts"); - sign.setText(3, team.getRemainingTickets() + "/" + zone.getLifePool() + " lives left"); + sign.setText(0, "Team"); + sign.setText(1, t.getName()); + sign.setText(2, t.getPoints() + " pts"); + sign.setText(3, t.getRemainingTickets() + "/" + zone.getLifePool() + " lives left"); sign.update(); } } diff --git a/minecraft.hmod.war/src/WarMapper.java b/minecraft.hmod.war/src/WarMapper.java index 39d149a..b594cbf 100644 --- a/minecraft.hmod.war/src/WarMapper.java +++ b/minecraft.hmod.war/src/WarMapper.java @@ -1,3 +1,4 @@ +import java.io.IOException; import java.util.List; @@ -5,11 +6,23 @@ public class WarMapper { public static void load(War war) { PropertiesFile warConfig = new PropertiesFile("war.txt"); + try { + warConfig.load(); + } catch (IOException e) { + war.getLogger().info("Failed to load war.txt file."); + e.printStackTrace(); + } // Create file if need be if(!warConfig.containsKey("warzones")) { WarMapper.save(war); - war.getLogger().info("War config file created."); + 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 @@ -37,8 +50,8 @@ public class WarMapper { } } - // defaultLifepool - war.setDefaultLifepool(warConfig.getInt("defaultLifepool")); + // defaultLifePool + war.setDefaultLifepool(warConfig.getInt("defaultLifePool")); // defaultFriendlyFire war.setDefaultFriendlyFire(warConfig.getBoolean("defaultFriendlyFire")); diff --git a/minecraft.hmod.war/src/Warzone.java b/minecraft.hmod.war/src/Warzone.java index 9a7d18a..0f252d5 100644 --- a/minecraft.hmod.war/src/Warzone.java +++ b/minecraft.hmod.war/src/Warzone.java @@ -98,6 +98,13 @@ public class Warzone { saveState(); } + + public void removeNorthwest() { + int x = (int)northwest.x; + int y = (int)northwest.y; + int z = (int)northwest.z; + server.setBlockAt(0, x, y, z); + } public Location getNorthwest() { return northwest; @@ -130,6 +137,13 @@ public class Warzone { saveState(); } + + public void removeSoutheast() { + int x = (int)southeast.x; + int y = (int)southeast.y; + int z = (int)southeast.z; + server.setBlockAt(0, x, y, z); + } public Location getSoutheast() { return southeast; @@ -177,6 +191,7 @@ public class Warzone { */ public int resetState() { if(ready() && getInitialState() != null){ + // reset blocks int northSouth = ((int)(southeast.x)) - ((int)(northwest.x)); int eastWest = ((int)(northwest.z)) - ((int)(southeast.z)); @@ -209,12 +224,13 @@ public class Warzone { // everyone back to team spawn with full health for(Team team : teams) { Location spawn = team.getTeamSpawn(); - removeSpawnArea(team); // reset spawn - addSpawnArea(team, spawn, 41); +// removeSpawnArea(team); // reset spawn +// addSpawnArea(team, spawn, 41); for(Player player : team.getPlayers()) { respawnPlayer(team, player); } team.setRemainingTickets(lifePool); + resetSign(team, spawn); } // reset monuments @@ -328,15 +344,23 @@ public class Warzone { war.getServer().setBlockAt(blockType, x-1, y-1, z); war.getServer().setBlockAt(blockType, x-1, y-1, z-1); + resetSign(team, location); + } + + public void resetSign(Team team, Location location){ + int x = (int)location.x; + int y = (int)location.y; + int z = (int)location.z; + Block block = new Block(63, x, y, z, 8); war.getServer().setBlock(block); block = war.getServer().getBlockAt(x, y, z); ComplexBlock complexBlock = war.getServer().getComplexBlock(x, y, z); Sign sign = (Sign)complexBlock; - sign.setText(0, "Team " + team.getName()); - sign.setText(1, "spawn"); - sign.setText(2, "0 pts"); - sign.setText(3, lifePool + "/" + lifePool + " lives left"); + sign.setText(0, "Team"); + sign.setText(1, team.getName()); + sign.setText(2, team.getPoints() + " pts"); + sign.setText(3, team.getRemainingTickets() + "/" + lifePool + " lives left"); sign.update(); } @@ -386,11 +410,15 @@ public class Warzone { } public void restorePlayerInventory(Player player) { - Item[] contents = inventories.get(player.getName()); - player.getInventory().clearContents(); - player.getInventory().setContents(contents); + Item[] originalContents = inventories.remove(player.getName()); + Inventory playerInv = player.getInventory(); + playerInv.clearContents(); + playerInv.update(); + for(Item item : originalContents) { + playerInv.addItem(item); + } + playerInv.update(); player.getInventory().update(); - inventories.remove(player.getName()); } public boolean hasMonument(String monumentName) { @@ -453,4 +481,6 @@ public class Warzone { return false; } + + } diff --git a/minecraft.hmod.war/src/WarzoneMapper.java b/minecraft.hmod.war/src/WarzoneMapper.java index e7b9418..5eb7b83 100644 --- a/minecraft.hmod.war/src/WarzoneMapper.java +++ b/minecraft.hmod.war/src/WarzoneMapper.java @@ -1,4 +1,5 @@ import java.io.File; +import java.io.IOException; import java.util.List; @@ -6,12 +7,24 @@ public class WarzoneMapper { public static Warzone load(War war, String name) { PropertiesFile warzoneConfig = new PropertiesFile("warzone-" + name + ".txt"); + try { + warzoneConfig.load(); + } catch (IOException e) { + war.getLogger().info("Failed to load warzone-" + name + ".txt file."); + e.printStackTrace(); + } Warzone warzone = new Warzone(war, name); // Create file if needed if(!warzoneConfig.containsKey("name")) { WarzoneMapper.save(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(); + } } // northwest @@ -54,6 +67,7 @@ public class WarzoneMapper { int teamZ = Integer.parseInt(teamStrSplit[3]); Team team = new Team(teamStrSplit[0], new Location(teamX, teamY, teamZ)); + team.setRemainingTickets(warzone.getLifePool()); warzone.getTeams().add(team); } } @@ -116,6 +130,7 @@ public class WarzoneMapper { } } } + warzone.setInitialState(state); // monument blocks for(Monument monument: warzone.getMonuments()) {