diff options
author | md_5 <md_5@bigpond.com> | 2012-03-12 10:39:36 +1100 |
---|---|---|
committer | md_5 <md_5@bigpond.com> | 2012-03-12 10:39:36 +1100 |
commit | 78f4820876f42f7b50bf88f64afd45bee939e4e4 (patch) | |
tree | 317cd3bcc63fc9e86a6efbcb5e13a50ed9efbaaf /EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/BlockPlaceCheckListener.java | |
parent | 26409058467e9f34aa65a08df3c68a58129d22ba (diff) | |
download | Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.gz Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.lz Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.tar.xz Essentials-78f4820876f42f7b50bf88f64afd45bee939e4e4.zip |
Initial formatted and slightly tweaked version of @evenprime 's NoCheat. Will be intergrated into the main Essentials as soon as possible
Diffstat (limited to 'EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/BlockPlaceCheckListener.java')
-rw-r--r-- | EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/BlockPlaceCheckListener.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/BlockPlaceCheckListener.java b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/BlockPlaceCheckListener.java new file mode 100644 index 000000000..253982bd1 --- /dev/null +++ b/EssentialsAntiCheat/src/com/earth2me/essentials/anticheat/checks/blockplace/BlockPlaceCheckListener.java @@ -0,0 +1,97 @@ +package com.earth2me.essentials.anticheat.checks.blockplace; + +import java.util.LinkedList; +import java.util.List; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import com.earth2me.essentials.anticheat.EventManager; +import com.earth2me.essentials.anticheat.NoCheat; +import com.earth2me.essentials.anticheat.NoCheatPlayer; +import com.earth2me.essentials.anticheat.config.ConfigurationCacheStore; +import com.earth2me.essentials.anticheat.config.Permissions; + + +/** + * Central location to listen to Block-related events and dispatching them to checks + * + */ +public class BlockPlaceCheckListener implements Listener, EventManager +{ + private final ReachCheck reachCheck; + private final DirectionCheck directionCheck; + private final NoCheat plugin; + + public BlockPlaceCheckListener(NoCheat plugin) + { + + this.plugin = plugin; + + reachCheck = new ReachCheck(plugin); + directionCheck = new DirectionCheck(plugin); + } + + /** + * We listen to BlockPlace events for obvious reasons + * + * @param event the BlockPlace event + */ + @EventHandler(priority = EventPriority.LOWEST) + protected void handleBlockPlaceEvent(BlockPlaceEvent event) + { + + if (event.isCancelled() || event.getBlock() == null || event.getBlockAgainst() == null) + { + return; + } + + boolean cancelled = false; + + final NoCheatPlayer player = plugin.getPlayer(event.getPlayer()); + final BlockPlaceConfig cc = BlockPlaceCheck.getConfig(player); + final BlockPlaceData data = BlockPlaceCheck.getData(player); + + // Remember these locations and put them in a simpler "format" + data.blockPlaced.set(event.getBlock()); + data.blockPlacedAgainst.set(event.getBlockAgainst()); + + // Now do the actual checks + + // First the reach check + if (cc.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH)) + { + cancelled = reachCheck.check(player, data, cc); + } + + // Second the direction check + if (!cancelled && cc.directionCheck && !player.hasPermission(Permissions.BLOCKPLACE_DIRECTION)) + { + cancelled = directionCheck.check(player, data, cc); + } + + // If one of the checks requested to cancel the event, do so + if (cancelled) + { + event.setCancelled(cancelled); + } + } + + public List<String> getActiveChecks(ConfigurationCacheStore cc) + { + LinkedList<String> s = new LinkedList<String>(); + + BlockPlaceConfig bp = BlockPlaceCheck.getConfig(cc); + + if (bp.reachCheck) + { + s.add("blockplace.reach"); + } + if (bp.directionCheck) + { + s.add("blockplace.direction"); + } + + return s; + } +} |