Update to new Bukkit Event system

Also remove leftover TNT exploit prevention code which I missed earlier
This commit is contained in:
Brettflan 2012-01-28 04:37:55 -06:00
parent 84e137049e
commit fc04e0a446
6 changed files with 54 additions and 120 deletions

View File

@ -11,7 +11,6 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.plugin.Plugin;
@ -104,41 +103,14 @@ public class P extends MPlugin
{
Worldguard.init(this);
}
// Player Events
this.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, Event.Priority.Highest);
this.registerEvent(Event.Type.PLAYER_CHAT, this.chatEarlyListener, Event.Priority.Lowest);
this.registerEvent(Event.Type.PLAYER_INTERACT, this.playerListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PLAYER_JOIN, this.playerListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PLAYER_QUIT, this.playerListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PLAYER_RESPAWN, this.playerListener, Event.Priority.High);
this.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this.playerListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this.playerListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PLAYER_KICK, this.playerListener, Event.Priority.Normal);
// Entity Events
this.registerEvent(Event.Type.ENDERMAN_PICKUP, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.ENDERMAN_PLACE, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.ENTITY_DEATH, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.ENTITY_DAMAGE, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PAINTING_BREAK, this.entityListener, Event.Priority.Normal);
this.registerEvent(Event.Type.PAINTING_PLACE, this.entityListener, Event.Priority.Normal);
// Block Events
this.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Event.Priority.Normal);
this.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Event.Priority.Normal);
this.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal);
this.registerEvent(Event.Type.BLOCK_PISTON_EXTEND, this.blockListener, Event.Priority.Normal);
this.registerEvent(Event.Type.BLOCK_PISTON_RETRACT, this.blockListener, Event.Priority.Normal);
// Server Events
this.registerEvent(Event.Type.PLUGIN_ENABLE, this.serverListener, Event.Priority.Monitor);
this.registerEvent(Event.Type.PLUGIN_DISABLE, this.serverListener, Event.Priority.Monitor);
// Register Event Handlers
getServer().getPluginManager().registerEvents(playerListener, this);
getServer().getPluginManager().registerEvents(chatEarlyListener, this);
getServer().getPluginManager().registerEvents(entityListener, this);
getServer().getPluginManager().registerEvents(blockListener, this);
getServer().getPluginManager().registerEvents(serverListener, this);
postEnable();
}

View File

@ -4,9 +4,11 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent;
@ -22,7 +24,7 @@ import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
public class FactionsBlockListener extends BlockListener
public class FactionsBlockListener implements Listener
{
public P p;
public FactionsBlockListener(P p)
@ -30,7 +32,7 @@ public class FactionsBlockListener extends BlockListener
this.p = p;
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled()) return;
@ -45,17 +47,10 @@ public class FactionsBlockListener extends BlockListener
if ( ! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false))
{
event.setCancelled(true);
Material handItem = event.getPlayer().getItemInHand().getType();
if (handItem == Material.TNT || handItem == Material.REDSTONE_TORCH_ON)
{
Faction targetFaction = Board.getFactionAt(new FLocation(event.getBlock()));
FactionsEntityListener.trackPotentialExplosionExploit(event.getPlayer().getName(), targetFaction, handItem, event.getBlock().getLocation());
}
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockBreak(BlockBreakEvent event)
{
if (event.isCancelled()) return;
@ -66,7 +61,7 @@ public class FactionsBlockListener extends BlockListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockDamage(BlockDamageEvent event)
{
if (event.isCancelled()) return;
@ -77,7 +72,7 @@ public class FactionsBlockListener extends BlockListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
if (event.isCancelled()) return;
@ -102,7 +97,7 @@ public class FactionsBlockListener extends BlockListener
*/
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPistonRetract(BlockPistonRetractEvent event)
{
// if not a sticky piston, retraction should be fine

View File

@ -4,8 +4,10 @@ import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerListener;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
@ -17,7 +19,7 @@ import com.massivecraft.factions.struct.Relation;
// this is an addtional PlayerListener for handling slashless command usage and faction chat, to be set at low priority so Factions gets to them first
public class FactionsChatEarlyListener extends PlayerListener
public class FactionsChatEarlyListener implements Listener
{
public P p;
public FactionsChatEarlyListener(P p)
@ -25,7 +27,7 @@ public class FactionsChatEarlyListener extends PlayerListener
this.p = p;
}
@Override
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(PlayerChatEvent event)
{
if (event.isCancelled()) return;

View File

@ -1,17 +1,16 @@
package com.massivecraft.factions.listeners;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Creeper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EndermanPickupEvent;
import org.bukkit.event.entity.EndermanPlaceEvent;
@ -19,9 +18,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.painting.PaintingBreakEvent;
import org.bukkit.event.painting.PaintingPlaceEvent;
@ -37,7 +34,7 @@ import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.util.MiscUtil;
public class FactionsEntityListener extends EntityListener
public class FactionsEntityListener implements Listener
{
public P p;
public FactionsEntityListener(P p)
@ -45,9 +42,7 @@ public class FactionsEntityListener extends EntityListener
this.p = p;
}
private static ArrayList<PotentialExplosionExploit> exploitExplosions = new ArrayList<PotentialExplosionExploit>();
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDeath(EntityDeathEvent event)
{
Entity entity = event.getEntity();
@ -97,7 +92,7 @@ public class FactionsEntityListener extends EntityListener
* I can always hurt enemies.
* I can hurt neutrals as long as they are outside their own territory.
*/
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDamage(EntityDamageEvent event)
{
if ( event.isCancelled()) return;
@ -117,7 +112,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityExplode(EntityExplodeEvent event)
{
if ( event.isCancelled()) return;
@ -361,7 +356,7 @@ public class FactionsEntityListener extends EntityListener
return true;
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onCreatureSpawn(CreatureSpawnEvent event)
{
if (event.isCancelled() || event.getLocation() == null)
@ -375,7 +370,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityTarget(EntityTargetEvent event)
{
if (event.isCancelled()) return;
@ -400,7 +395,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPaintingBreak(PaintingBreakEvent event)
{
if (event.isCancelled()) return;
@ -422,7 +417,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPaintingPlace(PaintingPlaceEvent event)
{
if (event.isCancelled()) return;
@ -433,7 +428,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEndermanPickup(EndermanPickupEvent event)
{
if (event.isCancelled()) return;
@ -444,7 +439,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEndermanPlace(EndermanPlaceEvent event)
{
if (event.isCancelled()) return;
@ -500,38 +495,4 @@ public class FactionsEntityListener extends EntityListener
return false;
}
/**
* Since the Bukkit team still don't seem to be in any hurry to fix the problem after at least half a year,
* we'll track potential explosion exploits ourselves and try to prevent them
* For reference, canceled TNT placement next to redstone power is bugged and triggers a free explosion
* Same thing happens for canceled redstone torch placement next to existing TNT
* https://bukkit.atlassian.net/browse/BUKKIT-89
*/
public static void trackPotentialExplosionExploit(String playerName, Faction faction, Material item, Location location)
{
exploitExplosions.add(new PotentialExplosionExploit(playerName, faction, item, location));
}
public static class PotentialExplosionExploit
{
public String playerName;
public Faction faction;
public Material item;
public long timeMillis;
public int X;
public int Z;
public PotentialExplosionExploit(String playerName, Faction faction, Material item, Location location)
{
this.playerName = playerName;
this.faction = faction;
this.item = item;
this.timeMillis = System.currentTimeMillis();
this.X = location.getBlockX();
this.Z = location.getBlockZ();
}
}
}

View File

@ -10,6 +10,9 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
@ -17,7 +20,6 @@ import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
@ -40,7 +42,7 @@ import java.util.logging.Level;
public class FactionsPlayerListener extends PlayerListener
public class FactionsPlayerListener implements Listener
{
public P p;
public FactionsPlayerListener(P p)
@ -48,7 +50,7 @@ public class FactionsPlayerListener extends PlayerListener
this.p = p;
}
@Override
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(PlayerChatEvent event)
{
if (event.isCancelled()) return;
@ -143,7 +145,7 @@ public class FactionsPlayerListener extends PlayerListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerJoin(PlayerJoinEvent event)
{
// Make sure that all online players do have a fplayer.
@ -159,7 +161,7 @@ public class FactionsPlayerListener extends PlayerListener
SpoutFeatures.updateAppearancesShortly(event.getPlayer());
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerQuit(PlayerQuitEvent event)
{
// Make sure player's power is up to date when they log off.
@ -173,7 +175,7 @@ public class FactionsPlayerListener extends PlayerListener
SpoutFeatures.playerDisconnect(me);
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event)
{
Player player = event.getPlayer();
@ -302,7 +304,7 @@ public class FactionsPlayerListener extends PlayerListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event)
{
if (event.isCancelled()) return;
@ -477,7 +479,7 @@ public class FactionsPlayerListener extends PlayerListener
return true;
}
@Override
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event)
{
FPlayer me = FPlayers.i.get(event.getPlayer());
@ -503,7 +505,7 @@ public class FactionsPlayerListener extends PlayerListener
// For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected),
// but these separate bucket events below always fire without fail
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event)
{
if (event.isCancelled()) return;
@ -517,7 +519,7 @@ public class FactionsPlayerListener extends PlayerListener
return;
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerBucketFill(PlayerBucketFillEvent event)
{
if (event.isCancelled()) return;
@ -628,7 +630,7 @@ public class FactionsPlayerListener extends PlayerListener
return false;
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerKick(PlayerKickEvent event)
{
if (event.isCancelled()) return;

View File

@ -1,7 +1,9 @@
package com.massivecraft.factions.listeners;
import org.bukkit.plugin.Plugin;
import org.bukkit.event.server.ServerListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.event.server.PluginEnableEvent;
@ -9,7 +11,7 @@ import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.SpoutFeatures;
public class FactionsServerListener extends ServerListener
public class FactionsServerListener implements Listener
{
public P p;
public FactionsServerListener(P p)
@ -17,7 +19,7 @@ public class FactionsServerListener extends ServerListener
this.p = p;
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event)
{
String name = event.getPlugin().getDescription().getName();
@ -27,7 +29,7 @@ public class FactionsServerListener extends ServerListener
}
}
@Override
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event)
{
Plugin plug = event.getPlugin();