Spawn protection is back. Can't re-enter spawn.

- Players are now technically invincible while in spawn. Closes gh-492.
- More air cleared around warhub tp and moved the warhub sign by one
block.
This commit is contained in:
taoneill 2012-06-20 21:32:44 -04:00
parent b504b5b014
commit 7a90119c97
4 changed files with 112 additions and 46 deletions

View File

@ -173,7 +173,6 @@ public class War extends JavaPlugin {
warzoneDefaultConfig.put(WarzoneConfig.UNBREAKABLE, false);
warzoneDefaultConfig.put(WarzoneConfig.DEATHMESSAGES, true);
teamDefaultConfig.put(TeamConfig.FLAGMUSTBEHOME, true);
teamDefaultConfig.put(TeamConfig.FLAGPOINTSONLY, false);
teamDefaultConfig.put(TeamConfig.FLAGRETURN, FlagReturn.BOTH);
@ -186,7 +185,6 @@ public class War extends JavaPlugin {
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
this.getDefaultInventories().getLoadouts().clear();
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();

View File

@ -42,6 +42,7 @@ import com.tommytony.war.job.DeferredBlockResetsJob;
import com.tommytony.war.spout.SpoutDisplayer;
import com.tommytony.war.structure.Bomb;
import com.tommytony.war.utility.DeferredBlockReset;
import com.tommytony.war.utility.LoadoutSelection;
/**
* Handles Entity-Events
@ -80,7 +81,21 @@ public class WarEntityListener implements Listener {
if ((attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone)
|| (attackerTeam != null && defenderTeam != null && attacker.getEntityId() == defender.getEntityId())) {
// Make sure none of them are respawning
LoadoutSelection defenderLoadoutState = defenderWarzone.getLoadoutSelections().get(d.getName());
if (defenderLoadoutState != null && defenderLoadoutState.isStillInSpawn()) {
War.war.badMsg(a, "The target is still in spawn!");
event.setCancelled(true);
return;
}
LoadoutSelection attackerLoadoutState = attackerWarzone.getLoadoutSelections().get(a.getName());
if (attackerLoadoutState != null && attackerLoadoutState.isStillInSpawn()) {
War.war.badMsg(a, "You can't attack while still in spawn!");
event.setCancelled(true);
return;
}
// Make sure none of them are locked in by respawn timer
if (defenderWarzone.isRespawning(d)) {
War.war.badMsg(a, "The target is currently respawning!");
event.setCancelled(true);
@ -411,40 +426,48 @@ public class WarEntityListener implements Listener {
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
} else {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
Team team = Team.getTeamByPlayerName(player.getName());
if (zone != null && event.getDamage() >= player.getHealth()) {
if (zone.getReallyDeadFighters().contains(player.getName())) {
// don't re-count the death points of an already dead person, make sure they are dead though
// (reason for this is that onEntityDamage sometimes fires more than once for one death)
if (player.getHealth() != 0) {
player.setHealth(0);
}
return;
}
// Detect death, prevent it and respawn the player
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
String deathMessage = "";
String cause = " died";
if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK
|| event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.LIGHTNING) {
cause = " burned to a crisp";
} else if (event.getCause() == DamageCause.DROWNING) {
cause = " drowned";
} else if (event.getCause() == DamageCause.FALL) {
cause = " fell to an untimely death";
}
deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getName() + ChatColor.WHITE + cause;
for (Team team : zone.getTeams()) {
team.teamcast(deathMessage);
}
}
zone.handleDeath(player);
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
// fast respawn, don't really die
if (zone != null && team != null) {
LoadoutSelection playerLoadoutState = zone.getLoadoutSelections().get(player.getName());
if (team.getSpawnVolume().contains(player.getLocation())
&& playerLoadoutState != null && playerLoadoutState.isStillInSpawn()) {
// don't let a player still in spawn get damaged
event.setCancelled(true);
} else if (event.getDamage() >= player.getHealth()) {
if (zone.getReallyDeadFighters().contains(player.getName())) {
// don't re-count the death points of an already dead person, make sure they are dead though
// (reason for this is that onEntityDamage sometimes fires more than once for one death)
if (player.getHealth() != 0) {
player.setHealth(0);
}
return;
}
// Detect death, prevent it and respawn the player
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DEATHMESSAGES)) {
String deathMessage = "";
String cause = " died";
if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK
|| event.getCause() == DamageCause.LAVA || event.getCause() == DamageCause.LIGHTNING) {
cause = " burned to a crisp";
} else if (event.getCause() == DamageCause.DROWNING) {
cause = " drowned";
} else if (event.getCause() == DamageCause.FALL) {
cause = " fell to an untimely death";
}
deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getName() + ChatColor.WHITE + cause;
for (Team teamToMsg : zone.getTeams()) {
teamToMsg.teamcast(deathMessage);
}
}
zone.handleDeath(player);
if (!zone.getWarzoneConfig().getBoolean(WarzoneConfig.REALDEATHS)) {
// fast respawn, don't really die
event.setCancelled(true);
}
}
}
}

View File

@ -247,7 +247,7 @@ public class WarPlayerListener implements Listener {
}
Player player = event.getPlayer();
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
Location playerLoc = event.getTo(); // Don't call again we need same result.
Location previousLocation = latestLocations.get(player.getName());
if (previousLocation != null &&
@ -436,6 +436,7 @@ public class WarPlayerListener implements Listener {
}
}
LoadoutSelection loadoutSelectionState = playerWarzone.getLoadoutSelections().get(player.getName());
if (!playerTeam.getSpawnVolume().contains(playerLoc)) {
if (!playerWarzone.isEnoughPlayers()) {
War.war.badMsg(player, "Can't leave spawn until there's a minimum of " + playerWarzone.getWarzoneConfig().getInt(WarzoneConfig.MINPLAYERS)
@ -446,11 +447,57 @@ public class WarPlayerListener implements Listener {
if (playerWarzone.isRespawning(player)) {
int rt = playerTeam.getTeamConfig().resolveInt(TeamConfig.RESPAWNTIMER);
String isS = "s";
if (rt==1) isS = "";
War.war.badMsg(player, "Can't leave spawn for "+rt+" second"+isS+" after spawning!");
if (rt == 1) {
isS = "";
}
War.war.badMsg(player, "Can't leave spawn for " + rt + " second" + isS + " after spawning!");
event.setTo(playerTeam.getTeamSpawn());
return;
}
} else if (loadoutSelectionState != null && !loadoutSelectionState.isStillInSpawn()) {
// player is in spawn, but has left already: he should NOT be let back in - kick him out gently
int diffZ = playerLoc.getBlockZ() - playerTeam.getTeamSpawn().getBlockZ();
int diffX = playerLoc.getBlockX() - playerTeam.getTeamSpawn().getBlockX();
int finalZ = playerLoc.getBlockZ();
int finalX = playerLoc.getBlockX();
int bumpDistance = 1;
if (diffZ == 0 && diffX == 0) {
// at spawn already, get him moving
finalZ += bumpDistance + 1;
finalX += bumpDistance + 1;
} else if (diffZ > 0 && diffX > 0) {
finalZ += bumpDistance;
finalX += bumpDistance;
} else if (diffZ == 0 && diffX > 0) {
finalX += bumpDistance;
}else if (diffZ < 0 && diffX > 0) {
finalZ -= bumpDistance;
finalX += bumpDistance;
} else if (diffZ < 0 && diffX == 0) {
finalZ -= bumpDistance;
} else if (diffZ > 0 && diffX < 0) {
finalZ -= bumpDistance;
finalX -= bumpDistance;
} else if (diffZ == 0 && diffX < 0) {
finalX -= bumpDistance;
} else if (diffZ > 0 && diffX < 0) {
finalZ += bumpDistance;
finalX -= bumpDistance;
} else if (diffZ > 0 && diffX == 0) {
finalZ += bumpDistance;
}
event.setTo(new Location(playerLoc.getWorld(),
finalX,
playerLoc.getY(),
finalZ,
playerLoc.getYaw(),
playerLoc.getPitch()
));
War.war.badMsg(player, "Can't re-enter spawn!");
return;
}
// Monuments

View File

@ -175,13 +175,11 @@ public class WarHub {
this.volume.setFloorOutlineMaterial(outline, outlineData);
}
// clear minimal path
locationBlock.setType(Material.AIR);
locationBlock.getRelative(BlockFace.UP).setType(Material.AIR);
locationBlock.getRelative(this.getOrientation()).setType(Material.AIR);
locationBlock.getRelative(this.getOrientation()).getRelative(BlockFace.UP).setType(Material.AIR);
locationBlock.getRelative(this.getOrientation()).getRelative(this.getOrientation()).setType(Material.AIR);
locationBlock.getRelative(this.getOrientation()).getRelative(this.getOrientation()).getRelative(BlockFace.UP).setType(Material.AIR);
// clear minimal path around warhub tp
Volume warhubTpVolume = new Volume("warhubtp", this.location.getWorld());
warhubTpVolume.setCornerOne(locationBlock.getRelative(back).getRelative(left));
warhubTpVolume.setCornerTwo(locationBlock.getRelative(front, 2).getRelative(right).getRelative(BlockFace.UP));
warhubTpVolume.setToMaterial(Material.AIR);
// draw gates
Block currentGateBlock = BlockInfo.getBlock(this.location.getWorld(), this.volume.getCornerOne()).getRelative(BlockFace.UP).getRelative(front, hubDepth).getRelative(right, 2);
@ -241,7 +239,7 @@ public class WarHub {
}
// War hub sign
Block signBlock = locationBlock.getRelative(front);
Block signBlock = locationBlock.getRelative(front, 2);
String[] lines = new String[4];
lines[0] = "War hub";