mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-30 20:37:52 +01:00
Bugfixes and code style changes
This commit is contained in:
parent
40f187b55c
commit
17dac93056
@ -26,7 +26,7 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
public boolean check(final NoCheatPlayer player, final BlockBreakData blockbreak, final CCBlockBreak ccblockbreak) {
|
||||
|
||||
final SimpleLocation brokenBlock = blockbreak.brokenBlockLocation;
|
||||
final boolean isInstaBreak = blockbreak.instaBrokeBlockLocation.equals(brokenBlock);
|
||||
final boolean isInstaBreak = blockbreak.instaBrokenBlockLocation.equals(brokenBlock);
|
||||
|
||||
// If the block is instabreak and we don't check instabreak, return
|
||||
if(isInstaBreak && !ccblockbreak.checkinstabreakblocks) {
|
||||
|
@ -10,7 +10,7 @@ public class BlockBreakData extends Data {
|
||||
public double directionVL = 0.0D;
|
||||
|
||||
public long directionLastViolationTime = 0;
|
||||
public final SimpleLocation instaBrokeBlockLocation = new SimpleLocation();
|
||||
public final SimpleLocation instaBrokenBlockLocation = new SimpleLocation();
|
||||
public final SimpleLocation brokenBlockLocation = new SimpleLocation();
|
||||
|
||||
public final ExecutionHistory history = new ExecutionHistory();
|
||||
|
@ -17,12 +17,12 @@ import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
|
||||
public class PlayerManager {
|
||||
|
||||
// Store data between Events
|
||||
private final Map<String, NoCheatPlayer> map;
|
||||
private final Map<String, NoCheatPlayer> players;
|
||||
private final NoCheat plugin;
|
||||
private final List<String> removals;
|
||||
|
||||
public PlayerManager(NoCheat plugin) {
|
||||
this.map = new HashMap<String, NoCheatPlayer>();
|
||||
this.players = new HashMap<String, NoCheatPlayer>();
|
||||
this.removals = new ArrayList<String>(5);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -33,12 +33,12 @@ public class PlayerManager {
|
||||
*/
|
||||
public NoCheatPlayer getPlayer(String playerName) {
|
||||
|
||||
NoCheatPlayer p = this.map.get(playerName);
|
||||
NoCheatPlayer p = this.players.get(playerName);
|
||||
|
||||
if(p == null) {
|
||||
// TODO: Differentiate which player"type" should be created, e.g. based on bukkit version
|
||||
p = new NoCheatPlayerImpl(playerName, plugin, new BaseData());
|
||||
this.map.put(playerName, p);
|
||||
this.players.put(playerName, p);
|
||||
}
|
||||
|
||||
return p;
|
||||
@ -49,7 +49,7 @@ public class PlayerManager {
|
||||
*
|
||||
*/
|
||||
public void clearCriticalData() {
|
||||
for(NoCheatPlayer b : this.map.values()) {
|
||||
for(NoCheatPlayer b : this.players.values()) {
|
||||
b.getData().clearCriticalData();
|
||||
}
|
||||
}
|
||||
@ -62,14 +62,14 @@ public class PlayerManager {
|
||||
synchronized(removals) {
|
||||
long time = System.currentTimeMillis();
|
||||
try {
|
||||
for(Entry<String, NoCheatPlayer> p : this.map.entrySet()) {
|
||||
for(Entry<String, NoCheatPlayer> p : this.players.entrySet()) {
|
||||
if(p.getValue().getData().shouldBeRemoved(time)) {
|
||||
removals.add(p.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
for(String p : removals) {
|
||||
this.map.remove(p);
|
||||
this.players.remove(p);
|
||||
}
|
||||
|
||||
removals.clear();
|
||||
@ -80,7 +80,7 @@ public class PlayerManager {
|
||||
}
|
||||
|
||||
public void clearCriticalData(String playerName) {
|
||||
NoCheatPlayer p = this.map.get(playerName);
|
||||
NoCheatPlayer p = this.players.get(playerName);
|
||||
if(p != null) {
|
||||
p.getData().clearCriticalData();
|
||||
}
|
||||
|
@ -45,50 +45,45 @@ public class BlockBreakEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBlockBreakEvent(BlockBreakEvent event, Priority priority) {
|
||||
protected void handleBlockBreakEvent(final BlockBreakEvent event, final Priority priority) {
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
final CCBlockBreak cc = player.getConfiguration().blockbreak;
|
||||
|
||||
ConfigurationCache c = player.getConfiguration();
|
||||
|
||||
if(!c.blockbreak.check || player.hasPermission(Permissions.BLOCKBREAK)) {
|
||||
if(!cc.check || player.hasPermission(Permissions.BLOCKBREAK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CCBlockBreak cc = player.getConfiguration().blockbreak;
|
||||
BlockBreakData data = player.getData().blockbreak;
|
||||
final BlockBreakData data = player.getData().blockbreak;
|
||||
|
||||
data.brokenBlockLocation.set(event.getBlock());
|
||||
|
||||
for(BlockBreakCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
check.check(player, data, cc);
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
if(cancelled) {
|
||||
if(cancelled)
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBlockDamageEvent(BlockDamageEvent event, Priority priority) {
|
||||
protected void handleBlockDamageEvent(final BlockDamageEvent event, final Priority priority) {
|
||||
|
||||
// Only interested in insta-break events here
|
||||
if(!event.getInstaBreak()) {
|
||||
if(!event.getInstaBreak())
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the player-specific stored data that applies here
|
||||
final BlockBreakData data = plugin.getPlayer(event.getPlayer().getName()).getData().blockbreak;
|
||||
|
||||
// Remember this location. We ignore block breaks in the block-break
|
||||
// direction check that are insta-breaks
|
||||
data.instaBrokeBlockLocation.set(event.getBlock());
|
||||
data.instaBrokenBlockLocation.set(event.getBlock());
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
|
@ -47,14 +47,14 @@ public class BlockPlaceEventManager extends EventManager {
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
final CCBlockPlace cc = player.getConfiguration().blockplace;
|
||||
|
||||
if(!player.getConfiguration().blockplace.check || player.hasPermission(Permissions.BLOCKPLACE)) {
|
||||
if(!cc.check || player.hasPermission(Permissions.BLOCKPLACE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CCBlockPlace cc = player.getConfiguration().blockplace;
|
||||
BlockPlaceData data = player.getData().blockplace;
|
||||
final BlockPlaceData data = player.getData().blockplace;
|
||||
|
||||
data.blockPlaced.set(event.getBlock());
|
||||
data.blockPlacedAgainst.set(event.getBlockAgainst());
|
||||
@ -63,13 +63,12 @@ public class BlockPlaceEventManager extends EventManager {
|
||||
for(BlockPlaceCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
check.check(player, data, cc);
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
if(cancelled) {
|
||||
if(cancelled)
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
|
@ -4,6 +4,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event.Type;
|
||||
@ -11,6 +12,7 @@ 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.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityListener;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
@ -27,6 +29,13 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
|
||||
/**
|
||||
* To make the actual event management easier, this class will handle
|
||||
* most of the repetitive tasks, allow to know the priority of events,
|
||||
* and already filter out events that are cancelled and measure the
|
||||
* time it takes to handle the event.
|
||||
*
|
||||
*/
|
||||
public abstract class EventManager {
|
||||
|
||||
protected NoCheat plugin;
|
||||
@ -46,12 +55,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handleBlockPlaceEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -60,12 +69,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
public void onBlockBreak(final BlockBreakEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handleBlockBreakEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -74,12 +83,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
public void onBlockDamage(final BlockDamageEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handleBlockDamageEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -103,12 +112,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerChatEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -117,12 +126,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerCommandPreprocessEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -131,12 +140,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
public void onPlayerMove(final PlayerMoveEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerMoveEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -145,12 +154,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
public void onPlayerVelocity(final PlayerVelocityEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerVelocityEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -159,12 +168,13 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
public void onPlayerRespawn(final PlayerRespawnEvent event) {
|
||||
// Can't be cancelled
|
||||
// if(ignoreCancelledEvents && event.isCancelled())
|
||||
// return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerRespawnEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -173,12 +183,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||
public void onPlayerPortal(final PlayerPortalEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerPortalEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -187,12 +197,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
public void onPlayerTeleport(final PlayerTeleportEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerTeleportEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -201,12 +211,12 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
public void onPlayerAnimation(final PlayerAnimationEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
final long startTime = System.nanoTime();
|
||||
m.handlePlayerAnimationEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
@ -230,17 +240,30 @@ public abstract class EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
public void onEntityDamage(final EntityDamageEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handleEntityDamageEvent(event, priority);
|
||||
|
||||
/**
|
||||
* Some additional limitations - only interested in direct
|
||||
* attacks executed by actual players
|
||||
*
|
||||
*/
|
||||
if(!(event instanceof EntityDamageByEntityEvent))
|
||||
return;
|
||||
|
||||
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
|
||||
|
||||
if(!(event2.getDamager() instanceof Player))
|
||||
return;
|
||||
|
||||
/** Only now measure time and dispatch event */
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handleEntityDamageEvent(event, priority);
|
||||
final long startTime = System.nanoTime();
|
||||
m.handleEntityDamageByEntityEvent(event2, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handleEntityDamageEvent(event, priority);
|
||||
m.handleEntityDamageByEntityEvent(event2, priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,6 +272,14 @@ public abstract class EventManager {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to register listeners with CraftBukkit
|
||||
*
|
||||
* @param type
|
||||
* @param priority
|
||||
* @param ignoreCancelled
|
||||
* @param performance
|
||||
*/
|
||||
protected void registerListener(Type type, Priority priority, boolean ignoreCancelled, Performance performance) {
|
||||
switch (type.getCategory()) {
|
||||
case BLOCK:
|
||||
@ -269,7 +300,7 @@ public abstract class EventManager {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected void handleEvent(Event event, Priority priority) {
|
||||
protected void handleEvent(final Event event, final Priority priority) {
|
||||
System.out.println("Handling of event " + event.getType() + " not implemented for " + this);
|
||||
}
|
||||
|
||||
@ -277,51 +308,51 @@ public abstract class EventManager {
|
||||
* OVERRIDE THESE IN THE SUBCLASSES, IF YOU LISTEN TO THE RELEVANT EVENT(S)
|
||||
*/
|
||||
|
||||
protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
|
||||
protected void handleBlockPlaceEvent(final BlockPlaceEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handleBlockBreakEvent(BlockBreakEvent event, Priority priority) {
|
||||
protected void handleBlockBreakEvent(final BlockBreakEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handleBlockDamageEvent(BlockDamageEvent event, Priority priority) {
|
||||
protected void handleBlockDamageEvent(final BlockDamageEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handleEntityDamageEvent(EntityDamageEvent event, Priority priority) {
|
||||
protected void handlePlayerCommandPreprocessEvent(final PlayerCommandPreprocessEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event, Priority priority) {
|
||||
protected void handlePlayerChatEvent(final PlayerChatEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerChatEvent(PlayerChatEvent event, Priority priority) {
|
||||
protected void handlePlayerMoveEvent(final PlayerMoveEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
|
||||
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerVelocityEvent(PlayerVelocityEvent event, Priority priority) {
|
||||
protected void handlePlayerRespawnEvent(final PlayerRespawnEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerRespawnEvent(PlayerRespawnEvent event, Priority priority) {
|
||||
protected void handlePlayerPortalEvent(final PlayerPortalEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerPortalEvent(PlayerPortalEvent event, Priority priority) {
|
||||
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerTeleportEvent(PlayerTeleportEvent event, Priority priority) {
|
||||
protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
protected void handlePlayerAnimationEvent(PlayerAnimationEvent event, Priority priority) {
|
||||
protected void handleEntityDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,11 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.server.Entity;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
@ -41,36 +38,35 @@ public class FightEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleEntityDamageEvent(EntityDamageEvent event, Priority priority) {
|
||||
protected void handleEntityDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
|
||||
|
||||
final Entity damagee = ((CraftEntity) event.getEntity()).getHandle();
|
||||
// Our event listener already checked if that cast is valid
|
||||
final Player damager = (Player) event.getDamager();
|
||||
|
||||
// We can cast like crazy here because we ruled out all other
|
||||
// possibilities above
|
||||
final NoCheatPlayer player = plugin.getPlayer(((Player) ((EntityDamageByEntityEvent) event).getDamager()).getName());
|
||||
final FightData data = player.getData().fight;
|
||||
final NoCheatPlayer player = plugin.getPlayer(damager.getName());
|
||||
final CCFight cc = player.getConfiguration().fight;
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.FIGHT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final FightData data = player.getData().fight;
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
data.damagee = damagee;
|
||||
data.damagee = ((CraftEntity) event.getEntity()).getHandle();
|
||||
|
||||
for(FightCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
check.check(player, data, cc);
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
data.damagee = null;
|
||||
|
||||
if(cancelled) {
|
||||
if(cancelled)
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
|
@ -35,30 +35,30 @@ public class PlayerChatEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event, Priority priority) {
|
||||
protected void handlePlayerCommandPreprocessEvent(final PlayerCommandPreprocessEvent event, final Priority priority) {
|
||||
handleEvent((PlayerChatEvent) event, priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerChatEvent(PlayerChatEvent event, Priority priority) {
|
||||
protected void handlePlayerChatEvent(final PlayerChatEvent event, final Priority priority) {
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
||||
if(!player.getConfiguration().chat.check || player.hasPermission(Permissions.CHAT)) {
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
final CCChat cc = player.getConfiguration().chat;
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.CHAT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CCChat cc = player.getConfiguration().chat;
|
||||
ChatData data = player.getData().chat;
|
||||
final ChatData data = player.getData().chat;
|
||||
|
||||
data.message = event.getMessage();
|
||||
|
||||
for(ChatCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
check.check(player, data, cc);
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,6 @@ import cc.co.evenprime.bukkit.nocheat.checks.moving.RunflyCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
@ -39,7 +38,7 @@ public class PlayerMoveEventManager extends EventManager {
|
||||
|
||||
private final List<MovingCheck> checks;
|
||||
|
||||
public PlayerMoveEventManager(final NoCheat plugin) {
|
||||
public PlayerMoveEventManager(NoCheat plugin) {
|
||||
|
||||
super(plugin);
|
||||
|
||||
@ -54,37 +53,37 @@ public class PlayerMoveEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
|
||||
protected void handleBlockPlaceEvent(final BlockPlaceEvent event, final Priority priority) {
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
// Get the player-specific stored data that applies here
|
||||
BaseData data = player.getData();
|
||||
final MovingData data = player.getData().moving;
|
||||
|
||||
Block blockPlaced = event.getBlockPlaced();
|
||||
final Block blockPlaced = event.getBlockPlaced();
|
||||
|
||||
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
|
||||
if(blockPlaced == null || !data.runflySetBackPoint.isSet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
SimpleLocation lblock = new SimpleLocation();
|
||||
final SimpleLocation lblock = new SimpleLocation();
|
||||
lblock.set(blockPlaced);
|
||||
SimpleLocation lplayer = new SimpleLocation();
|
||||
final SimpleLocation lplayer = new SimpleLocation();
|
||||
lplayer.setLocation(player.getPlayer().getLocation());
|
||||
|
||||
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
|
||||
|
||||
int type = CheckUtil.getType(blockPlaced.getTypeId());
|
||||
final int type = CheckUtil.getType(blockPlaced.getTypeId());
|
||||
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
|
||||
if(lblock.y + 1 >= data.moving.runflySetBackPoint.y) {
|
||||
data.moving.runflySetBackPoint.y = (lblock.y + 1);
|
||||
data.moving.jumpPhase = 0;
|
||||
if(lblock.y + 1 >= data.runflySetBackPoint.y) {
|
||||
data.runflySetBackPoint.y = (lblock.y + 1);
|
||||
data.jumpPhase = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
|
||||
protected void handlePlayerMoveEvent(final PlayerMoveEvent event, final Priority priority) {
|
||||
|
||||
// Get the world-specific configuration that applies here
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
@ -141,11 +140,11 @@ public class PlayerMoveEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerVelocityEvent(PlayerVelocityEvent event, Priority priority) {
|
||||
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
|
||||
|
||||
MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
|
||||
final MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
|
||||
|
||||
Vector v = event.getVelocity();
|
||||
final Vector v = event.getVelocity();
|
||||
|
||||
double newVal = v.getY();
|
||||
if(newVal >= 0.0D) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
@ -29,9 +30,9 @@ public class PlayerTeleportEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerTeleportEvent(PlayerTeleportEvent event, Priority priority) {
|
||||
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||
if(priority.equals(Priority.Monitor)) {
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
handleTeleportation(event.getPlayer());
|
||||
} else {
|
||||
// No typo here, I really want to only handle cancelled events
|
||||
if(!event.isCancelled())
|
||||
@ -46,26 +47,25 @@ public class PlayerTeleportEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerPortalEvent(PlayerPortalEvent event, Priority priority) {
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
protected void handlePlayerPortalEvent(final PlayerPortalEvent event, final Priority priority) {
|
||||
handleTeleportation(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerRespawnEvent(PlayerRespawnEvent event, Priority priority) {
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
protected void handlePlayerRespawnEvent(final PlayerRespawnEvent event, final Priority priority) {
|
||||
handleTeleportation(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
|
||||
protected void handlePlayerMoveEvent(final PlayerMoveEvent event, final Priority priority) {
|
||||
// No typo here. I really only handle cancelled events and ignore others
|
||||
if(!event.isCancelled())
|
||||
return;
|
||||
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
handleTeleportation(event.getPlayer());
|
||||
}
|
||||
|
||||
private void handleTeleportation(String playerName) {
|
||||
|
||||
plugin.clearCriticalData(playerName);
|
||||
private void handleTeleportation(final Player player) {
|
||||
plugin.clearCriticalData(player.getName());
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class SwingEventManager extends EventManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerAnimationEvent(PlayerAnimationEvent event, Priority priority) {
|
||||
protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) {
|
||||
plugin.getPlayer(event.getPlayer().getName()).getData().armswung = true;
|
||||
}
|
||||
}
|
||||
|
@ -96,10 +96,10 @@ public class TimedEventManager extends EventManager {
|
||||
}, 0, 1);
|
||||
}
|
||||
|
||||
private void handleEvent(NoCheatPlayer player) {
|
||||
private void handleEvent(final NoCheatPlayer player) {
|
||||
|
||||
TimedData data = player.getData().timed;
|
||||
CCTimed cc = player.getConfiguration().timed;
|
||||
final TimedData data = player.getData().timed;
|
||||
final CCTimed cc = player.getConfiguration().timed;
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.TIMED)) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user