Jail update, jailed people can't attack other players.

This commit is contained in:
KHobbits 2012-04-05 03:22:49 +01:00
parent e7d1cb8bb6
commit 10cb4c03b7

View File

@ -9,12 +9,16 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; 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.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
@ -38,10 +42,8 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
{ {
enabled = true; enabled = true;
final PluginManager pluginManager = ess.getServer().getPluginManager(); final PluginManager pluginManager = ess.getServer().getPluginManager();
final JailBlockListener blockListener = new JailBlockListener(); final JailListener blockListener = new JailListener();
final JailPlayerListener playerListener = new JailPlayerListener();
pluginManager.registerEvents(blockListener, ess); pluginManager.registerEvents(blockListener, ess);
pluginManager.registerEvents(playerListener, ess);
} }
@Override @Override
@ -179,7 +181,7 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
} }
private class JailBlockListener implements Listener private class JailListener implements Listener
{ {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(final BlockBreakEvent event) public void onBlockBreak(final BlockBreakEvent event)
@ -210,11 +212,22 @@ public class Jails extends AsyncStorageObjectHolder<com.earth2me.essentials.sett
event.setCancelled(true); event.setCancelled(true);
} }
} }
}
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityDamageByEntity(final EntityDamageByEntityEvent event)
{
if (event.getCause() != DamageCause.ENTITY_ATTACK || event.getEntity().getType() != EntityType.PLAYER)
{
return;
}
final Entity damager = event.getDamager();
final User user = ess.getUser(damager);
if (user.isJailed())
{
event.setCancelled(true);
}
}
private class JailPlayerListener implements Listener
{
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerInteract(final PlayerInteractEvent event) public void onPlayerInteract(final PlayerInteractEvent event)
{ {