Closes gh-196. Closes gh-295. Closes gh-296. Closes gh-297. Players can't drop items inside zones when nodrops is true. For 1.8, added nohunger setting that prevents food regen and saturation setting (0-20) that controls how fast your food bar starts depleting. 0 saturation means your bar starts depleting right away. Instead of teleporting back to spawn, people that wander out of zone are bumped back in.

This commit is contained in:
taoneill 2011-10-01 13:57:12 -04:00
parent 06427445b7
commit 9f9d6ba7c1
6 changed files with 247 additions and 17 deletions

View File

@ -82,7 +82,10 @@ public class War extends JavaPlugin {
private boolean defaultNoCreatures = false;
private boolean defaultGlassWalls = true;
private boolean defaultPvpInZone = true;
private boolean defaultInstaBreak = false;
private boolean defaultInstaBreak = false;
private boolean defaultNoDrops = false;
private boolean defaultNoHunger = false;
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;
private FlagReturn defaultFlagReturn = FlagReturn.BOTH;
@ -141,6 +144,7 @@ public class War extends JavaPlugin {
pm.registerEvent(Event.Type.ENTITY_COMBUST, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_REGAIN_HEALTH, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.FOOD_LEVEL_CHANGE, this.entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Priority.Normal, this);
@ -165,6 +169,7 @@ public class War extends JavaPlugin {
this.getDeadlyAdjectives().add("fine ");
this.getDeadlyAdjectives().add("precise ");
this.getDeadlyAdjectives().add("brutal ");
this.getDeadlyAdjectives().add("powerful ");
this.getKillerVerbs().clear();
this.getKillerVerbs().add("killed");
@ -357,6 +362,26 @@ public class War extends JavaPlugin {
warzone.setInstaBreak(onOff.equals("on") || onOff.equals("true"));
returnMessage.append(" instabreak set to " + String.valueOf(warzone.isInstaBreak()) + ".");
}
if (namedParams.containsKey("nodrops")) {
String onOff = namedParams.get("nodrops");
warzone.setNoDrops(onOff.equals("on") || onOff.equals("true"));
returnMessage.append(" nodrops set to " + String.valueOf(warzone.isNoDrops()) + ".");
}
if (namedParams.containsKey("nohunger")) {
String onOff = namedParams.get("nohunger");
warzone.setNoHunger(onOff.equals("on") || onOff.equals("true"));
returnMessage.append(" nohunger set to " + String.valueOf(warzone.isNoHunger()) + ".");
}
if (namedParams.containsKey("saturation")) {
int sat = Integer.parseInt(namedParams.get("saturation"));
if (sat > 20) {
sat = 20;
} else if (sat < 0) {
sat = 0;
}
warzone.setSaturation(sat);
returnMessage.append(" saturation set to " + warzone.getSaturation() + ".");
}
if (namedParams.containsKey("minplayers")) {
int val = Integer.parseInt(namedParams.get("minplayers"));
if (val > warzone.getTeamCap()) {
@ -543,6 +568,26 @@ public class War extends JavaPlugin {
this.setDefaultInstaBreak(onOff.equals("on") || onOff.equals("true"));
returnMessage.append(" instabreak set to " + String.valueOf(war.isDefaultInstaBreak()) + ".");
}
if (namedParams.containsKey("nodrops")) {
String onOff = namedParams.get("nodrops");
war.setDefaultNoDrops(onOff.equals("on") || onOff.equals("true"));
returnMessage.append(" nodrops set to " + String.valueOf(war.isDefaultNoDrops()) + ".");
}
if (namedParams.containsKey("nohunger")) {
String onOff = namedParams.get("nohunger");
this.setDefaultNoHunger(onOff.equals("on") || onOff.equals("true"));
returnMessage.append(" nohunger set to " + String.valueOf(this.isDefaultNoHunger()) + ".");
}
if (namedParams.containsKey("saturation")) {
int sat = Integer.parseInt(namedParams.get("saturation"));
if (sat > 20) {
sat = 20;
} else if (sat < 0) {
sat = 0;
}
this.setDefaultSaturation(sat);
returnMessage.append(" saturation set to " + this.getDefaultSaturation() + ".");
}
if (namedParams.containsKey("minplayers")) {
int val = Integer.parseInt(namedParams.get("minplayers"));
if (val > this.getDefaultTeamCap()) {
@ -637,6 +682,9 @@ public class War extends JavaPlugin {
+ " glasswalls:" + String.valueOf(zone.isGlassWalls())
+ " pvpinzone:" + String.valueOf(zone.isPvpInZone())
+ " instabreak:" + String.valueOf(zone.isInstaBreak())
+ " nodrops:" + String.valueOf(zone.isNoDrops())
+ " nohunger:" + String.valueOf(zone.isNoHunger())
+ " saturation:" + zone.getSaturation()
+ " minplayers:" + zone.getMinPlayers()
+ " minteams:" + zone.getMinTeams()
+ " resetonempty:" + String.valueOf(zone.isResetOnEmpty())
@ -666,6 +714,9 @@ public class War extends JavaPlugin {
+ " glasswalls:" + String.valueOf(this.isDefaultGlassWalls())
+ " pvpinzone:" + String.valueOf(this.isDefaultPvpInZone())
+ " instabreak:" + String.valueOf(this.isDefaultInstaBreak())
+ " nodrops:" + String.valueOf(this.isDefaultNoDrops())
+ " nohunger:" + String.valueOf(this.isDefaultNoHunger())
+ " saturation:" + this.getDefaultSaturation()
+ " minplayers:" + this.getDefaultMinPlayers()
+ " minteams:" + this.getDefaultMinTeams()
+ " resetonempty:" + String.valueOf(this.isDefaultResetOnEmpty())
@ -1189,4 +1240,29 @@ public class War extends JavaPlugin {
public void setTntInZonesOnly(boolean tntInZonesOnly) {
this.tntInZonesOnly = tntInZonesOnly;
}
public boolean isDefaultNoDrops() {
return defaultNoDrops;
}
public void setDefaultNoDrops(boolean defaultNoDrops) {
this.defaultNoDrops = defaultNoDrops;
}
public boolean isDefaultNoHunger() {
return defaultNoHunger;
}
public void setDefaultNoHunger(boolean defaultNoHunger) {
this.defaultNoHunger = defaultNoHunger;
}
public int getDefaultSaturation() {
return defaultSaturation;
}
public void setDefaultSaturation(int defaultSaturation) {
this.defaultSaturation = defaultSaturation;
}
}

View File

@ -24,6 +24,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
@ -271,7 +273,6 @@ public class WarEntityListener extends EntityListener {
float middleYeild = (float)(explodedSize - dontExplodeSize) / (float)explodedSize;
float newYeild = middleYeild * event.getYield();
float old = event.getYield();
event.setYield(newYeild);
}
}
@ -315,12 +316,22 @@ public class WarEntityListener extends EntityListener {
// pass pvp-damage
if (event instanceof EntityDamageByEntityEvent) {
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
} else {
// Detect death, prevent it and respawn the player
} else {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null && event.getDamage() >= player.getHealth()) {
// Detect death, prevent it and respawn the player
String deathMessage = "";
deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died";
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.getDisplayName() + ChatColor.WHITE + cause;
for (Team team : zone.getTeams()) {
team.teamcast(deathMessage);
}
@ -376,7 +387,8 @@ public class WarEntityListener extends EntityListener {
*/
@Override
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (!War.war.isLoaded() || event.getRegainReason() != RegainReason.REGEN) {
if (!War.war.isLoaded() || (event.getRegainReason() != RegainReason.REGEN && event.getRegainReason() != RegainReason.EATING)) {
War.war.log("Refused " + event.getRegainReason().toString(), Level.INFO);
return;
}
@ -386,9 +398,27 @@ public class WarEntityListener extends EntityListener {
}
Player player = (Player) entity;
Warzone zone = Warzone.getZoneByLocation(player);
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null) {
event.setCancelled(true);
if (event.getRegainReason() == RegainReason.EATING && zone.isNoHunger()) {
// noHunger setting means you can't auto-heal with full hunger bar (use saturation instead to control how fast you get hungry)
event.setCancelled(true);
} else if (event.getRegainReason() == RegainReason.REGEN) {
// disable peaceful mode regen
event.setCancelled(true);
}
}
}
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (!War.war.isLoaded() || !(event.getEntity() instanceof Player)) {
return;
}
Player player = (Player) event.getEntity();
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null && zone.isNoHunger()){
event.setCancelled(true);
}
}
}

View File

@ -2,11 +2,13 @@ package bukkit.tommytony.war;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.entity.CraftItem;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
@ -73,6 +75,9 @@ public class WarPlayerListener extends PlayerListener {
// a flag thief can't drop his flag
War.war.badMsg(player, "Can't drop items while stealing flag. What are you doing?! Run!");
event.setCancelled(true);
} else if (zone.isNoDrops()) {
War.war.badMsg(player, "Can't drop items in this warzone.");
event.setCancelled(true);
} else {
Item item = event.getItemDrop();
if (item != null) {
@ -325,7 +330,7 @@ public class WarPlayerListener extends PlayerListener {
War.war.getWarHub().resetZoneSign(zone);
}
zone.keepPlayerState(player);
War.war.msg(player, "Your inventory is in storage until exit with '/war leave'.");
War.war.msg(player, "Your inventory is in storage until you exit with '/war leave'.");
zone.respawnPlayer(event, team, player);
for (Team t : zone.getTeams()) {
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
@ -377,9 +382,51 @@ public class WarPlayerListener extends PlayerListener {
if (playerWarzone != null) {
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
List<BlockFace> nearestWalls = playerWarzone.getNearestWalls(playerLoc);
War.war.badMsg(player, "Use /leave (or /war leave) to exit the zone.");
event.setTo(playerTeam.getTeamSpawn());
return;
if(nearestWalls != null && nearestWalls.size() > 0) {
// First, try to bump the player back in
int northSouthMove = 0;
int eastWestMove = 0;
int upDownMove = 0;
int moveDistance = 1;
if (nearestWalls.contains(BlockFace.NORTH)) {
// move south
northSouthMove += moveDistance;
} else if (nearestWalls.contains(BlockFace.SOUTH)) {
// move north
northSouthMove -= moveDistance;
}
if (nearestWalls.contains(BlockFace.EAST)) {
// move west
eastWestMove += moveDistance;
} else if (nearestWalls.contains(BlockFace.WEST)) {
// move east
eastWestMove -= moveDistance;
}
if (nearestWalls.contains(BlockFace.UP)) {
upDownMove -= moveDistance;
} else if (nearestWalls.contains(BlockFace.DOWN)) {
// fell off the map, back to spawn
event.setTo(playerTeam.getTeamSpawn());
return;
}
event.setTo(new Location(playerLoc.getWorld(),
playerLoc.getX() + northSouthMove,
playerLoc.getY() + upDownMove,
playerLoc.getZ() + eastWestMove,
playerLoc.getYaw(),
playerLoc.getPitch()));
return;
} else {
// Otherwise, send him to spawn
event.setTo(playerTeam.getTeamSpawn());
return;
}
}
if (!playerWarzone.isEnoughPlayers() && !playerTeam.getSpawnVolume().contains(playerLoc)) {
@ -390,7 +437,7 @@ public class WarPlayerListener extends PlayerListener {
// Monuments
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
&& this.random.nextInt(77) == 3) { // one chance out of many of getting healed
&& this.random.nextInt(7) == 3) { // one chance out of many of getting healed
int currentHp = player.getHealth();
int newHp = Math.max(20, currentHp + locZone.getMonumentHeal());
@ -485,7 +532,7 @@ public class WarPlayerListener extends PlayerListener {
if (War.war.isLoaded() && event.isSneaking()) {
Warzone playerWarzone = Warzone.getZoneByLocation(event.getPlayer());
Team playerTeam = Team.getTeamByPlayerName(event.getPlayer().getName());
if (playerWarzone != null && playerTeam != null &&playerWarzone.getExtraLoadouts().keySet().size() > 0 && playerTeam.getSpawnVolume().contains(event.getPlayer().getLocation())) {
if (playerWarzone != null && playerTeam != null && playerWarzone.getExtraLoadouts().keySet().size() > 0 && playerTeam.getSpawnVolume().contains(event.getPlayer().getLocation())) {
if (playerWarzone.getNewlyRespawned().keySet().contains(event.getPlayer().getName())) {
Integer currentIndex = playerWarzone.getNewlyRespawned().get(event.getPlayer().getName());
currentIndex = (currentIndex + 1) % (playerWarzone.getExtraLoadouts().keySet().size() + 1);

View File

@ -66,6 +66,9 @@ public class Warzone {
private boolean glassWalls = true;
private boolean pvpInZone = true;
private boolean instaBreak = false;
private boolean noDrops = false;
private boolean noHunger = false;
private int saturation = 10;
private int minPlayers = 1;
private int minTeams = 1;
@ -76,7 +79,6 @@ public class Warzone {
private HashMap<String, PlayerState> deadMenInventories = new HashMap<String, PlayerState>();
private Location rallyPoint;
@SuppressWarnings("unchecked")
public Warzone(World world, String name) {
this.world = world;
@ -99,6 +101,9 @@ public class Warzone {
this.setGlassWalls(War.war.isDefaultGlassWalls());
this.setPvpInZone(War.war.isDefaultPvpInZone());
this.setInstaBreak(War.war.isDefaultInstaBreak());
this.setNoDrops(War.war.isDefaultNoDrops());
this.setNoHunger(War.war.isDefaultNoHunger());
this.setSaturation(War.war.getDefaultSaturation());
this.setMinPlayers(War.war.getDefaultMinPlayers());
this.setMinTeams(War.war.getDefaultMinTeams());
this.setResetOnEmpty(War.war.isDefaultResetOnEmpty());
@ -323,7 +328,7 @@ public class Warzone {
player.setRemainingAir(300);
player.setHealth(20);
player.setFoodLevel(20);
player.setSaturation(20);
player.setSaturation(this.getSaturation());
player.setExhaustion(0);
if (player.getGameMode() == GameMode.CREATIVE) {
player.setGameMode(GameMode.SURVIVAL);
@ -335,7 +340,7 @@ public class Warzone {
LoadoutResetJob job = new LoadoutResetJob(this, team, player);
War.war.getServer().getScheduler().scheduleSyncDelayedTask(War.war, job);
}
public void resetInventory(Team team, Player player) {
this.resetInventory(team, player, this.loadout);
}
@ -1192,4 +1197,28 @@ public class Warzone {
public void setInstaBreak(boolean instaBreak) {
this.instaBreak = instaBreak;
}
public boolean isNoDrops() {
return noDrops;
}
public void setNoDrops(boolean noDrops) {
this.noDrops = noDrops;
}
public boolean isNoHunger() {
return noHunger;
}
public void setNoHunger(boolean noHunger) {
this.noHunger = noHunger;
}
public int getSaturation() {
return this.saturation;
}
public void setSaturation(int saturation) {
this.saturation = saturation;
}
}

View File

@ -221,6 +221,21 @@ public class WarMapper {
War.war.setDefaultInstaBreak(warConfig.getBoolean("defaultInstaBreak"));
}
// defaultNoDrops
if (warConfig.keyExists("defaultNoDrops")) {
War.war.setDefaultNoDrops(warConfig.getBoolean("defaultNoDrops"));
}
// defaultNoHunger
if (warConfig.keyExists("defaultNoHunger")) {
War.war.setDefaultNoHunger(warConfig.getBoolean("defaultNoHunger"));
}
// defaultSaturation
if (warConfig.keyExists("defaultSaturation")) {
War.war.setDefaultSaturation(warConfig.getInt("defaultSaturation"));
}
// defaultMinPlayers
if (warConfig.keyExists("defaultMinPlayers")) {
War.war.setDefaultMinPlayers(warConfig.getInt("defaultMinPlayers"));
@ -374,9 +389,18 @@ public class WarMapper {
// defaultPvpInZone
warConfig.setBoolean("defaultPvpInZone", War.war.isDefaultPvpInZone());
// defaultInstaBreak
warConfig.setBoolean("defaultInstaBreak", War.war.isDefaultInstaBreak());
// defaultNoDrops
warConfig.setBoolean("defaultNoDrops", War.war.isDefaultNoDrops());
// defaultNoHunger
warConfig.setBoolean("defaultNoHunger", War.war.isDefaultNoHunger());
// defaultSaturation
warConfig.setInt("defaultSaturation", War.war.getDefaultSaturation());
// defaultMinPlayers
warConfig.setInt("defaultMinPlayers", War.war.getDefaultMinPlayers());

View File

@ -259,6 +259,21 @@ public class WarzoneMapper {
warzone.setInstaBreak(warzoneConfig.getBoolean("instaBreak"));
}
// noDrops
if (warzoneConfig.containsKey("noDrops")) {
warzone.setNoDrops(warzoneConfig.getBoolean("noDrops"));
}
// noHunger
if (warzoneConfig.containsKey("noHunger")) {
warzone.setNoHunger(warzoneConfig.getBoolean("noHunger"));
}
// saturation
if (warzoneConfig.containsKey("saturation")) {
warzone.setSaturation(warzoneConfig.getInt("saturation"));
}
// minPlayers
if (warzoneConfig.containsKey("minPlayers")) {
warzone.setMinPlayers(warzoneConfig.getInt("minPlayers"));
@ -501,6 +516,15 @@ public class WarzoneMapper {
// instaBreak
warzoneConfig.setBoolean("instaBreak", warzone.isInstaBreak());
// noDrops
warzoneConfig.setBoolean("noDrops", warzone.isNoDrops());
// noHunger
warzoneConfig.setBoolean("noHunger", warzone.isNoHunger());
// saturation
warzoneConfig.setInt("saturation", warzone.getSaturation());
// minPlayers
warzoneConfig.setInt("minPlayers", warzone.getMinPlayers());