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:56 -06:00
parent 1dc5a0f226
commit fb92fb7c68
6 changed files with 56 additions and 124 deletions

View File

@ -11,7 +11,6 @@ import org.bukkit.Location;
import org.bukkit.Material;
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;
@ -110,41 +109,12 @@ 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);
this.registerEvent(Event.Type.BLOCK_SPREAD, this.blockListener, Event.Priority.Normal);
this.registerEvent(Event.Type.BLOCK_BURN, 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,10 +4,12 @@ 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.BlockBurnEvent;
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;
@ -24,7 +26,7 @@ import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm;
public class FactionsBlockListener extends BlockListener
public class FactionsBlockListener implements Listener
{
public P p;
public FactionsBlockListener(P p)
@ -32,7 +34,7 @@ public class FactionsBlockListener extends BlockListener
this.p = p;
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockSpread(BlockSpreadEvent event)
{
if (event.isCancelled()) return;
@ -44,7 +46,7 @@ public class FactionsBlockListener extends BlockListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockBurn(BlockBurnEvent event)
{
if (event.isCancelled()) return;
@ -78,7 +80,7 @@ public class FactionsBlockListener extends BlockListener
return FPerm.BUILD.has(me, loc, true);
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.isCancelled()) return;
@ -94,17 +96,10 @@ public class FactionsBlockListener extends BlockListener
if ( ! playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "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;
@ -115,7 +110,7 @@ public class FactionsBlockListener extends BlockListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockDamage(BlockDamageEvent event)
{
if (event.isCancelled()) return;
@ -127,7 +122,7 @@ public class FactionsBlockListener extends BlockListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onBlockPistonExtend(BlockPistonExtendEvent event)
{
if (event.isCancelled()) return;
@ -152,7 +147,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.Rel;
// 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,16 +1,15 @@
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.block.Block;
import org.bukkit.entity.Entity;
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;
@ -18,9 +17,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.Rel;
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();
@ -73,7 +68,7 @@ public class FactionsEntityListener extends EntityListener
fplayer.msg("<i>Your power is now <h>"+fplayer.getPowerRounded()+" / "+fplayer.getPowerMaxRounded());
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityDamage(EntityDamageEvent event)
{
if ( event.isCancelled()) return;
@ -94,7 +89,7 @@ public class FactionsEntityListener extends EntityListener
}*/
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityExplode(EntityExplodeEvent event)
{
if ( event.isCancelled()) return;
@ -228,7 +223,7 @@ public class FactionsEntityListener extends EntityListener
return true;
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onCreatureSpawn(CreatureSpawnEvent event)
{
if (event.isCancelled()) return;
@ -243,7 +238,7 @@ public class FactionsEntityListener extends EntityListener
event.setCancelled(true);
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEntityTarget(EntityTargetEvent event)
{
if (event.isCancelled()) return;
@ -263,7 +258,7 @@ public class FactionsEntityListener extends EntityListener
event.setCancelled(true);
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPaintingBreak(PaintingBreakEvent event)
{
if (event.isCancelled()) return;
@ -285,7 +280,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPaintingPlace(PaintingPlaceEvent event)
{
if (event.isCancelled()) return;
@ -296,7 +291,7 @@ public class FactionsEntityListener extends EntityListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEndermanPickup(EndermanPickupEvent event)
{
if (event.isCancelled()) return;
@ -309,7 +304,7 @@ public class FactionsEntityListener extends EntityListener
event.setCancelled(true);
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onEndermanPlace(EndermanPlaceEvent event)
{
if (event.isCancelled()) return;
@ -321,38 +316,4 @@ public class FactionsEntityListener extends EntityListener
event.setCancelled(true);
}
/**
* 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;
@ -37,7 +39,7 @@ import java.util.logging.Level;
public class FactionsPlayerListener extends PlayerListener
public class FactionsPlayerListener implements Listener
{
public P p;
public FactionsPlayerListener(P p)
@ -45,7 +47,7 @@ public class FactionsPlayerListener extends PlayerListener
this.p = p;
}
@Override
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(PlayerChatEvent event)
{
if (event.isCancelled()) return;
@ -140,7 +142,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.
@ -156,7 +158,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.
@ -165,7 +167,7 @@ public class FactionsPlayerListener extends PlayerListener
SpoutFeatures.playerDisconnect(me);
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerMove(PlayerMoveEvent event)
{
// Did we change block?
@ -205,7 +207,7 @@ public class FactionsPlayerListener extends PlayerListener
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerInteract(PlayerInteractEvent event)
{
if (event.isCancelled()) return;
@ -279,7 +281,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());
@ -305,7 +307,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;
@ -319,7 +321,7 @@ public class FactionsPlayerListener extends PlayerListener
return;
}
}
@Override
@EventHandler(priority = EventPriority.NORMAL)
public void onPlayerBucketFill(PlayerBucketFillEvent event)
{
if (event.isCancelled()) return;
@ -425,7 +427,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();