Closes #746. OnEntityCombust event handler was firing for non-fire events and cancelling regular damage events for players within spawn.

- This fixes players being able to profit from spawn damage protection even if they already left the spawn once
This commit is contained in:
taoneill 2014-01-26 17:14:57 -05:00
parent 5146a7c9c8
commit b17e38cfd2
4 changed files with 34 additions and 11 deletions

View File

@ -724,6 +724,7 @@ public class Team {
return true; return true;
} }
} }
return false; return false;
} }

View File

@ -3,6 +3,7 @@ package com.tommytony.war.event;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.logging.Level;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -18,6 +19,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -122,6 +124,7 @@ public class WarEntityListener implements Listener {
if (d.getHealth() != 0) { if (d.getHealth() != 0) {
d.setHealth(0); d.setHealth(0);
} }
return; return;
} }
@ -233,6 +236,7 @@ public class WarEntityListener implements Listener {
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) { if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEPVPMESSAGE)) {
War.war.badMsg(a, "pvp.outside.permission"); War.war.badMsg(a, "pvp.outside.permission");
} }
event.setCancelled(true); // global pvp is off event.setCancelled(true); // global pvp is off
} else { } else {
if (attackerTeam == null) { if (attackerTeam == null) {
@ -246,6 +250,7 @@ public class WarEntityListener implements Listener {
} else if (attackerWarzone != defenderWarzone) { } else if (attackerWarzone != defenderWarzone) {
War.war.badMsg(a, "pvp.target.otherzone"); War.war.badMsg(a, "pvp.target.otherzone");
} }
event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
} }
} else if (defender instanceof Player) { } else if (defender instanceof Player) {
@ -264,6 +269,7 @@ public class WarEntityListener implements Listener {
if (d.getHealth() != 0) { if (d.getHealth() != 0) {
d.setHealth(0); d.setHealth(0);
} }
return; return;
} }
@ -373,18 +379,22 @@ public class WarEntityListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityDamage(final EntityDamageEvent event) { public void onEntityDamage(final EntityDamageEvent event) {
if (!War.war.isLoaded()) { if (!War.war.isLoaded()) {
return; return;
} }
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (!(entity instanceof Player)) { if (!(entity instanceof Player)) {
return; return;
} }
Player player = (Player) entity; Player player = (Player) entity;
// prevent godmode // prevent godmode
if (Warzone.getZoneByPlayerName(player.getName()) != null) { Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null) {
event.setCancelled(false); event.setCancelled(false);
} }
@ -392,7 +402,6 @@ public class WarEntityListener implements Listener {
if (event instanceof EntityDamageByEntityEvent) { if (event instanceof EntityDamageByEntityEvent) {
this.handlerAttackDefend((EntityDamageByEntityEvent) event); this.handlerAttackDefend((EntityDamageByEntityEvent) event);
} else { } else {
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
Team team = Team.getTeamByPlayerName(player.getName()); Team team = Team.getTeamByPlayerName(player.getName());
if (zone != null && team != null) { if (zone != null && team != null) {
@ -439,18 +448,29 @@ public class WarEntityListener implements Listener {
} }
@EventHandler @EventHandler
// TODO Remove due to deletion of cantreenterspawnjob public void onEntityCombust(final EntityCombustEvent event) {
public void onEntityCombust(final EntityDamageEvent event) {
if (!War.war.isLoaded()) { if (!War.war.isLoaded()) {
return; return;
} }
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player) entity; Player player = (Player) entity;
Team team = Team.getTeamByPlayerName(player.getName()); Team team = Team.getTeamByPlayerName(player.getName());
if (team != null && team.isSpawnLocation(player.getLocation())) { Warzone zone = Warzone.getZoneByPlayerName(player.getName());
LoadoutSelection playerLoadoutState = null;
if (zone != null) {
playerLoadoutState = zone.getLoadoutSelections().get(player.getName());
}
if (team != null
&& zone != null
&& team.isSpawnLocation(player.getLocation())
&& playerLoadoutState != null
&& playerLoadoutState.isStillInSpawn()) {
// smother out the fire that didn't burn out when you respawned // smother out the fire that didn't burn out when you respawned
// Stop fire // Stop fire (but not if you came back to spawn after leaving it a first time)
player.setFireTicks(0); player.setFireTicks(0);
event.setCancelled(true); event.setCancelled(true);
} }

View File

@ -230,6 +230,7 @@ public class WarPlayerListener implements Listener {
// another player. // another player.
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1, 0);
} }
if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST && !zone.getWarzoneConfig().getBoolean(WarzoneConfig.ALLOWENDER)) { if (zone != null && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.ENDER_CHEST && !zone.getWarzoneConfig().getBoolean(WarzoneConfig.ALLOWENDER)) {
event.setCancelled(true); event.setCancelled(true);
War.war.badMsg(player, "use.ender"); War.war.badMsg(player, "use.ender");
@ -275,7 +276,6 @@ public class WarPlayerListener implements Listener {
} }
} }
} }
} }
@EventHandler @EventHandler

View File

@ -1,5 +1,7 @@
package com.tommytony.war.utility; package com.tommytony.war.utility;
import com.tommytony.war.War;
public class LoadoutSelection { public class LoadoutSelection {
private boolean stillInSpawn; private boolean stillInSpawn;