From 1061c24c5ba4d8593d013be93c009427ec7515da Mon Sep 17 00:00:00 2001 From: Chris Sp Date: Fri, 2 Dec 2011 17:44:05 +0100 Subject: [PATCH] Added respawn timer and immunity, fixe join loadout, fixed a bug - You will not get the loadout as soon you join - Fixed a bug where you would be kicked out of the zone if you walk into the glass walls above a team gate on a block layer equal with the roof of the gate - Made respawn timer configurable ("respawntimer", defaults to 10) - Can't attack/be attacked while respawning (this is already done by the spawn protection already, so this is something for an upcoming feature) --- .../main/java/bukkit/tommytony/war/War.java | 19 +++++++ .../tommytony/war/WarBlockListener.java | 41 +++++++++++++++- .../tommytony/war/WarEntityListener.java | 9 ++++ .../tommytony/war/WarPlayerListener.java | 7 ++- .../main/java/com/tommytony/war/Warzone.java | 49 ++++++++++++++----- .../java/com/tommytony/war/ZoneLobby.java | 2 +- .../com/tommytony/war/mappers/WarMapper.java | 8 +++ .../tommytony/war/mappers/WarzoneMapper.java | 10 +++- 8 files changed, 127 insertions(+), 18 deletions(-) diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index d3cb5df..5309d61 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -88,6 +88,7 @@ public class War extends JavaPlugin { private boolean defaultInstaBreak = false; private boolean defaultNoDrops = false; private boolean defaultNoHunger = false; + private int defaultRespawnTimer = 10; private int defaultSaturation = 10; private int defaultMinPlayers = 1; // By default, 1 player on 1 team is enough for unlocking the cant-exit-spawn guard private int defaultMinTeams = 1; @@ -152,6 +153,8 @@ public class War extends JavaPlugin { pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Priority.Normal, this); + pm.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Priority.Normal, this); } // Load files from disk or create them (using these defaults) @@ -315,6 +318,10 @@ public class War extends JavaPlugin { warzone.setScoreCap(Integer.parseInt(namedParams.get("maxscore"))); returnMessage.append(" maxscore set to " + warzone.getScoreCap() + "."); } + if (namedParams.containsKey("respawntimer")) { + warzone.setRespawnTimer(Integer.parseInt(namedParams.get("respawntimer"))); + returnMessage.append(" respawntimer set to " + warzone.getRespawnTimer() + "."); + } if (namedParams.containsKey("ff")) { String onOff = namedParams.get("ff"); warzone.setFriendlyFire(onOff.equals("on") || onOff.equals("true")); @@ -539,6 +546,10 @@ public class War extends JavaPlugin { this.setDefaultScoreCap(Integer.parseInt(namedParams.get("maxscore"))); returnMessage.append(" maxscore set to " + war.getDefaultScoreCap() + "."); } + if (namedParams.containsKey("respawntimer")) { + this.setDefaultRespawnTimer(Integer.parseInt(namedParams.get("respawntimer"))); + returnMessage.append(" respawntimer set to " + war.getDefaultRespawnTimer() + "."); + } if (namedParams.containsKey("ff")) { String onOff = namedParams.get("ff"); this.setDefaultFriendlyFire(onOff.equals("on") || onOff.equals("true")); @@ -1365,5 +1376,13 @@ public class War extends JavaPlugin { public int getMaxZones() { return maxZones; } + + public void setDefaultRespawnTimer(int defaultRespawnTimer) { + this.defaultRespawnTimer = defaultRespawnTimer; + } + + public int getDefaultRespawnTimer() { + return defaultRespawnTimer; + } } diff --git a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java index 0cfa689..df76e48 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarBlockListener.java @@ -1,6 +1,7 @@ package bukkit.tommytony.war; import java.util.List; +import java.util.logging.Level; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -11,7 +12,9 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockListener; +import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.inventory.ItemStack; import com.tommytony.war.FlagReturn; @@ -113,8 +116,44 @@ public class WarBlockListener extends BlockListener { event.setCancelled(true); return; } + + /*// disallow placing of sticky pistons near flags. If the flag is pulled from the right position, you can't pick it up + if (block.getType() == Material.PISTON_STICKY_BASE && Team.getTeamByPlayerName(player.getName()).getTeamFlag().distance(block.getLocation()) < 4) { + War.war.badMsg(player, "You can't place sticky pistons this close to the flag."); + event.setCancelled(true); + return; + }*/ } - + + /*public void onPistonExtend(BlockPistonExtendEvent event) { + Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation()); + if (zone!=null) { + for (Block b : event.getBlocks()) { + if (zone.isMonumentCenterBlock(b) || zone.isFlagBlock(b)) { + event.setCancelled(true); + return; + } + } + } + } + + public void onPistonRetract(BlockPistonRetractEvent event) { + Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation()); + if (zone!=null) { + Block b = event.getBlock(); + if (zone.isImportantBlock(b)) { + event.setCancelled(true); + return; + } + } + }*/ + public void onPistonExtend(BlockPistonExtendEvent event) { + War.war.log("EXTENDING",Level.INFO); + } + public void onPistonRetract(BlockPistonRetractEvent event) { + War.war.log("RETRACTING",Level.INFO); + } + /** * @see BlockListener.onBlockBreak() */ diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 4233996..55fc7df 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -86,6 +86,15 @@ public class WarEntityListener extends EntityListener { event.setCancelled(true); return; } + // Make sure none of them are respawning + } else if (defenderWarzone.isRespawning(d)) { + War.war.badMsg(a, "The target is currently respawning!"); + event.setCancelled(true); + return; + } else if (attackerWarzone.isRespawning(a)) { + War.war.badMsg(a, "You can't attack while respawning!"); + event.setCancelled(true); + return; } if (!attackerWarzone.isPvpInZone()) { diff --git a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java index b76c544..8c27096 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarPlayerListener.java @@ -331,11 +331,11 @@ public class WarPlayerListener extends PlayerListener { } zone.keepPlayerState(player); War.war.msg(player, "Your inventory is in storage until you exit with '/war leave'."); + zone.resetInventory(team, player); zone.respawnPlayer(event, team, player); for (Team t : zone.getTeams()) { t.teamcast("" + player.getName() + " joined team " + team.getName() + "."); } - zone.resetInventory(team, player); } else { event.setTo(zone.getTeleport()); War.war.badMsg(player, "Team " + team.getName() + " is full."); @@ -437,7 +437,10 @@ public class WarPlayerListener extends PlayerListener { return; } if (playerWarzone.isRespawning(player)) { - War.war.badMsg(player, "Can't leave spawn for 10 seconds after spawning!"); + int rt = playerWarzone.getRespawnTimer(); + String isS = "s"; + if (rt==1) isS = ""; + War.war.badMsg(player, "Can't leave spawn for "+rt+" second"+isS+" after spawning!"); event.setTo(playerTeam.getTeamSpawn()); return; } diff --git a/war/src/main/java/com/tommytony/war/Warzone.java b/war/src/main/java/com/tommytony/war/Warzone.java index 16a2a88..c49d4e9 100755 --- a/war/src/main/java/com/tommytony/war/Warzone.java +++ b/war/src/main/java/com/tommytony/war/Warzone.java @@ -73,6 +73,7 @@ public class Warzone { private boolean instaBreak = false; private boolean noDrops = false; private boolean noHunger = false; + private int respawnTimer = 10; private int saturation = 10; private int minPlayers = 1; private int minTeams = 1; @@ -109,6 +110,7 @@ public class Warzone { this.setInstaBreak(War.war.isDefaultInstaBreak()); this.setNoDrops(War.war.isDefaultNoDrops()); this.setNoHunger(War.war.isDefaultNoHunger()); + this.setRespawnTimer(War.war.getDefaultRespawnTimer()); this.setSaturation(War.war.getDefaultSaturation()); this.setMinPlayers(War.war.getDefaultMinPlayers()); this.setMinTeams(War.war.getDefaultMinTeams()); @@ -340,7 +342,7 @@ public class Warzone { player.setFoodLevel(20); player.setSaturation(this.getSaturation()); player.setExhaustion(0); - player.setFireTicks(0); + player.setFireTicks(0); //this works fine here, why put it in LoudoutResetJob...? I'll keep it over there though player.getInventory().clear(); @@ -351,18 +353,22 @@ public class Warzone { this.getNewlyRespawned().put(player.getName(), 0); } - // "Respawn" Timer - player will not be able to leave spawn for 10 seconds - // TODO: Customizable "respawn" time - respawn.add(player); + // "Respawn" Timer - player will not be able to leave spawn for a few seconds final Warzone w = this; - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, new Runnable() { - public void run() { - respawn.remove(player); - // Getting the Loadout as visual cue - LoadoutResetJob job = new LoadoutResetJob(w, team, player, newlyRespawned.get(player.getName())); - War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); - } - }, 10 * 20L); // 20 ticks = 1 second. So 10*20 ticks = 10 seconds. + if (respawnTimer==0) { + LoadoutResetJob job = new LoadoutResetJob(w, team, player); + War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); + } else { + respawn.add(player); + War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, new Runnable() { + public void run() { + respawn.remove(player); + // Getting the Loadout as visual cue + LoadoutResetJob job = new LoadoutResetJob(w, team, player, newlyRespawned.get(player.getName())); + War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job); + } + }, respawnTimer * 20L); // 20 ticks = 1 second + } } public void resetInventory(Team team, Player player) { @@ -775,11 +781,11 @@ public class Warzone { this.keepPlayerState(player); } War.war.msg(player, "Your inventory is in storage until you use '/war leave'."); + this.resetInventory(lowestNoOfPlayers, player); this.respawnPlayer(lowestNoOfPlayers, player); for (Team team : this.teams) { team.teamcast("" + player.getName() + " joined team " + lowestNoOfPlayers.getName() + "."); } - resetInventory(lowestNoOfPlayers, player); } return lowestNoOfPlayers; } @@ -966,6 +972,15 @@ public class Warzone { } return false; } + + public boolean isFlagBlock(Block block) { + for (Team team : this.teams) { + if (team.isTeamFlagBlock(block)) { + return true; + } + } + return false; + } public Team getTeamForFlagBlock(Block block) { for (Team team : this.teams) { @@ -1275,4 +1290,12 @@ public class Warzone { } return authors; } + + public void setRespawnTimer(int respawnTimer) { + this.respawnTimer = respawnTimer; + } + + public int getRespawnTimer() { + return this.respawnTimer; + } } diff --git a/war/src/main/java/com/tommytony/war/ZoneLobby.java b/war/src/main/java/com/tommytony/war/ZoneLobby.java index e318686..be105e8 100644 --- a/war/src/main/java/com/tommytony/war/ZoneLobby.java +++ b/war/src/main/java/com/tommytony/war/ZoneLobby.java @@ -682,7 +682,7 @@ public class ZoneLobby { Volume gateExitVolume = new Volume("tempGateExit", location.getWorld()); Block out = gate.getFace(inside); gateExitVolume.setCornerOne(out.getFace(left).getFace(BlockFace.DOWN)); - gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 3)); + gateExitVolume.setCornerTwo(gate.getFace(right, 1).getFace(BlockFace.UP, 2)); if (gateExitVolume.contains(location)) { return true; diff --git a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java index e139e54..4c65353 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarMapper.java @@ -153,6 +153,11 @@ public class WarMapper { if (warConfig.keyExists("defaultScoreCap")) { War.war.setDefaultScoreCap(warConfig.getInt("defaultScoreCap")); } + + // defaultRespawnTimer + if (warConfig.keyExists("defaultRespawnTimer")) { + War.war.setDefaultRespawnTimer(warConfig.getInt("defaultRespawnTimer")); + } // pvpInZonesOnly if (warConfig.keyExists("pvpInZonesOnly")) { @@ -360,6 +365,9 @@ public class WarMapper { // defaultScoreCap warConfig.setInt("defaultScoreCap", War.war.getDefaultScoreCap()); + + // defaultRespawnTimer + warConfig.setInt("defaultRespawnTimer", War.war.getDefaultRespawnTimer()); // pvpInZonesOnly warConfig.setBoolean("pvpInZonesOnly", War.war.isPvpInZonesOnly()); diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java index 6d1be02..e5e95f2 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -196,7 +196,7 @@ public class WarzoneMapper { warzone.setFlagPointsOnly(warzoneConfig.getBoolean("flagPointsOnly")); } - // flagPointsOnly + // flagMustBeHome if (warzoneConfig.containsKey("flagMustBeHome")) { warzone.setFlagMustBeHome(warzoneConfig.getBoolean("flagMustBeHome")); } @@ -210,6 +210,11 @@ public class WarzoneMapper { if (warzoneConfig.containsKey("scoreCap")) { warzone.setScoreCap(warzoneConfig.getInt("scoreCap")); } + + // respawn timer + if (warzoneConfig.containsKey("respawnTimer")) { + warzone.setRespawnTimer(warzoneConfig.getInt("respawnTimer")); + } // blockHeads if (warzoneConfig.containsKey("blockHeads")) { @@ -496,6 +501,9 @@ public class WarzoneMapper { // score cap warzoneConfig.setInt("scoreCap", warzone.getScoreCap()); + + // respawn timer + warzoneConfig.setInt("respawnTimer", warzone.getRespawnTimer()); // blockHeads warzoneConfig.setBoolean("blockHeads", warzone.isBlockHeads());