[Development] An other day of work, wow so much changes: some issues

fixed (some others left), new API introduced, new way of declaring
checks, etc.
This commit is contained in:
NeatMonster 2012-08-08 01:24:31 +02:00
parent 06bd7c294d
commit 113d627329
48 changed files with 1133 additions and 1518 deletions

View File

@ -19,6 +19,7 @@ import fr.neatmonster.nocheatplus.actions.types.LogAction;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
import fr.neatmonster.nocheatplus.players.ExecutionHistory;
import fr.neatmonster.nocheatplus.players.Permissions;
@ -88,41 +89,65 @@ public abstract class Check {
fileLogger = logger;
}
/** The type. */
private final CheckType type;
/**
* Instantiates a new check.
*
* @param type
* the type
*/
public Check(final CheckType type) {
this.type = type;
}
/**
* Execute some actions for the specified player.
*
* @param player
* the player
* @param actionList
* the action list
* @param violationLevel
* the violation level
* @return true, if successful
*/
protected boolean executeActions(final Player player, final ActionList actionList, final double violationLevel) {
boolean special = false;
protected boolean executeActions(final Player player) {
try {
boolean special = false;
// Get the to be executed actions.
final Action[] actions = actionList.getActions(violationLevel);
final Object config = type.getConfig().getDeclaredMethod("getConfig", Player.class).invoke(null, player);
final Object data = type.getData().getDeclaredMethod("getData", Player.class).invoke(null, player);
final ActionList actionList = (ActionList) type.getConfig().getDeclaredField(type.getName() + "Actions")
.get(config);
final double violationLevel = type.getData().getDeclaredField(type.getName() + "VL").getDouble(data);
final long time = System.currentTimeMillis() / 1000L;
// Dispatch the VL processing to the hook manager.
if (NCPHookManager.shouldCancelVLProcessing(type, player))
// One of the hooks has decided to cancel the VL processing, return false.
return false;
for (final Action ac : actions)
if (getHistory(player).executeAction(getClass().getName(), ac, time))
// The execution history said it really is time to execute the action, find out what it is and do what
// is
// needed.
if (ac instanceof LogAction && !player.hasPermission(actionList.permissionSilent))
executeLogAction((LogAction) ac, this, player);
else if (ac instanceof CancelAction)
special = true;
else if (ac instanceof CommandAction)
executeConsoleCommand((CommandAction) ac, this, player);
else if (ac instanceof DummyAction) {
// Do nothing, it's a dummy action after all.
}
// Get the to be executed actions.
final Action[] actions = actionList.getActions(violationLevel);
return special;
final long time = System.currentTimeMillis() / 1000L;
for (final Action ac : actions)
if (getHistory(player).executeAction(getClass().getName(), ac, time))
// The execution history said it really is time to execute the action, find out what it is and do
// what is needed.
if (ac instanceof LogAction && !player.hasPermission(actionList.permissionSilent))
executeLogAction((LogAction) ac, this, player);
else if (ac instanceof CancelAction)
special = true;
else if (ac instanceof CommandAction)
executeConsoleCommand((CommandAction) ac, this, player);
else if (ac instanceof DummyAction) {
// Do nothing, it's a dummy action after all.
}
return special;
} catch (final Exception e) {
e.printStackTrace();
}
return false;
}
/**
@ -192,16 +217,34 @@ public abstract class Check {
return getClass().getSimpleName();
else if (wildcard == ParameterName.PLAYER)
return player.getName();
else
else if (wildcard == ParameterName.VIOLATIONS) {
try {
final Object data = type.getData().getDeclaredMethod("getData", Player.class).invoke(null, player);
return "" + Math.round(type.getData().getDeclaredField(type.getName() + "VL").getDouble(data));
} catch (final Exception e) {
Bukkit.broadcastMessage("getParameter " + type.getName());
e.printStackTrace();
}
return "";
} else
return "The author was lazy and forgot to define " + wildcard + ".";
}
/**
* Returns if the check is enabled or not for the specified player.
* Checks if this check is enabled for the specified player.
*
* @param player
* the player
* @return true, if enabled
* @return true, if is enabled
*/
protected abstract boolean isEnabled(final Player player);
public boolean isEnabled(final Player player) {
try {
final Object config = type.getConfig().getDeclaredMethod("getConfig", Player.class).invoke(null, player);
return !player.hasPermission(type.getPermission())
&& type.getConfig().getDeclaredField(type.getName() + "Check").getBoolean(config);
} catch (final Exception e) {
e.printStackTrace();
}
return false;
}
}

View File

@ -1,80 +0,0 @@
package fr.neatmonster.nocheatplus.checks;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/*
* MM'""""'YMM dP dP MM""""""""`M dP
* M' .mmm. `M 88 88 MM mmmmmmmM 88
* M MMMMMooM 88d888b. .d8888b. .d8888b. 88 .dP M` MMMM dP .dP .d8888b. 88d888b. d8888P
* M MMMMMMMM 88' `88 88ooood8 88' `"" 88888" MM MMMMMMMM 88 d8' 88ooood8 88' `88 88
* M. `MMM' .M 88 88 88. ... 88. ... 88 `8b. MM MMMMMMMM 88 .88' 88. ... 88 88 88
* MM. .dM dP dP `88888P' `88888P' dP `YP MM .M 8888P' `88888P' dP dP dP
* MMMMMMMMMMM MMMMMMMMMMMM
*/
/**
* An event that is triggered by NoCheatPlus' API.
*/
public class CheckEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
/**
* Gets the handler list.
*
* @return the handler list
*/
public static HandlerList getHandlerList() {
return handlers;
}
/** The player who has triggered the check. */
private final Player player;
/** Is the event cancelled? */
private boolean cancel = false;
/**
* Instantiates a new check event.
*
* @param player
* the player
*/
public CheckEvent(final Player player) {
this.player = player;
}
/* (non-Javadoc)
* @see org.bukkit.event.Event#getHandlers()
*/
@Override
public HandlerList getHandlers() {
return handlers;
}
/**
* Gets the player who has triggered the event.
*
* @return the player
*/
public Player getPlayer() {
return player;
}
/* (non-Javadoc)
* @see org.bukkit.event.Cancellable#isCancelled()
*/
@Override
public boolean isCancelled() {
return cancel;
}
/* (non-Javadoc)
* @see org.bukkit.event.Cancellable#setCancelled(boolean)
*/
@Override
public void setCancelled(final boolean cancel) {
this.cancel = cancel;
}
}

View File

@ -0,0 +1,189 @@
package fr.neatmonster.nocheatplus.checks;
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakConfig;
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakData;
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractConfig;
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractData;
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceConfig;
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceData;
import fr.neatmonster.nocheatplus.checks.chat.ChatConfig;
import fr.neatmonster.nocheatplus.checks.chat.ChatData;
import fr.neatmonster.nocheatplus.checks.fight.FightConfig;
import fr.neatmonster.nocheatplus.checks.fight.FightData;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryData;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingData;
import fr.neatmonster.nocheatplus.players.Permissions;
/*
* MM'""""'YMM dP dP M""""""""M
* M' .mmm. `M 88 88 Mmmm mmmM
* M MMMMMooM 88d888b. .d8888b. .d8888b. 88 .dP MMMM MMMM dP dP 88d888b. .d8888b.
* M MMMMMMMM 88' `88 88ooood8 88' `"" 88888" MMMM MMMM 88 88 88' `88 88ooood8
* M. `MMM' .M 88 88 88. ... 88. ... 88 `8b. MMMM MMMM 88. .88 88. .88 88. ...
* MM. .dM dP dP `88888P' `88888P' dP `YP MMMM MMMM `8888P88 88Y888P' `88888P'
* MMMMMMMMMMM MMMMMMMMMM .88 88
* d8888P dP
*/
/**
* Type of checks (containing configuration and data classes, name and permission).
*/
public enum CheckType {
ALL,
BLOCKBREAK(BlockBreakConfig.class, BlockBreakData.class),
BLOCKBREAK_DIRECTION(BLOCKBREAK, "direction", Permissions.BLOCKBREAK_DIRECTION),
BLOCKBREAK_FASTBREAK(BLOCKBREAK, "fastBreak", Permissions.BLOCKBREAK_FASTBREAK),
BLOCKBREAK_NOSWING(BLOCKBREAK, "noSwing", Permissions.BLOCKBREAK_NOSWING),
BLOCKBREAK_REACH(BLOCKBREAK, "reach", Permissions.BLOCKBREAK_REACH),
BLOCKINTERACT(BlockInteractConfig.class, BlockInteractData.class),
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, "direction", Permissions.BLOCKINTERACT_DIRECTION),
BLOCKINTERACT_NOSWING(BLOCKINTERACT, "noSwing", Permissions.BLOCKINTERACT_NOSWING),
BLOCKINTERACT_REACH(BLOCKINTERACT, "reach", Permissions.BLOCKINTERACT_REACH),
BLOCKPLACE(BlockPlaceConfig.class, BlockPlaceData.class),
BLOCKPLACE_DIRECTION(BLOCKPLACE, "direction", Permissions.BLOCKPLACE_DIRECTION),
BLOCKPLACE_FASTPLACE(BLOCKPLACE, "fastPlace", Permissions.BLOCKPLACE_FASTPLACE),
BLOCKPLACE_NOSWING(BLOCKPLACE, "noSwing", Permissions.BLOCKPLACE_NOSWING),
BLOCKPLACE_REACH(BLOCKPLACE, "reach", Permissions.BLOCKBREAK_REACH),
BLOCKPLACE_SPEED(BLOCKPLACE, "speed", Permissions.BLOCKPLACE_SPEED),
CHAT(ChatConfig.class, ChatData.class),
CHAT_ARRIVALS(CHAT, "arrivals", Permissions.CHAT_ARRIVALS),
CHAT_COLOR(CHAT, "color", Permissions.CHAT_COLOR),
CHAT_NOPWNAGE(CHAT, "noPwnage", Permissions.CHAT_NOPWNAGE),
FIGHT(FightConfig.class, FightData.class),
FIGHT_ANGLE(FIGHT, "angle", Permissions.FIGHT_ANGLE),
FIGHT_CRITICAL(FIGHT, "critical", Permissions.FIGHT_CRITICAL),
FIGHT_DIRECTION(FIGHT, "direction", Permissions.FIGHT_DIRECTION),
FIGHT_GODMODE(FIGHT, "godMode", Permissions.FIGHT_GODMODE),
FIGHT_INSTANTHEAL(FIGHT, "instantHeal", Permissions.FIGHT_INSTANTHEAL),
FIGHT_KNOCKBACK(FIGHT, "knockback", Permissions.FIGHT_KNOCKBACK),
FIGHT_NOSWING(FIGHT, "noSwing", Permissions.FIGHT_NOSWING),
FIGHT_REACH(FIGHT, "reach", Permissions.FIGHT_REACH),
FIGHT_SPEED(FIGHT, "speed", Permissions.FIGHT_SPEED),
INVENTORY(InventoryConfig.class, InventoryData.class),
INVENTORY_DROP(INVENTORY, "drop", Permissions.INVENTORY_DROP),
INVENTORY_INSTANTBOW(INVENTORY, "instantBow", Permissions.INVENTORY_INSTANTBOW),
INVENTORY_INSTANTEAT(INVENTORY, "instantEat", Permissions.INVENTORY_INSTANTEAT),
MOVING(MovingConfig.class, MovingData.class),
MOVING_CREATIVEFLY(MOVING, "creativeFly", Permissions.MOVING_CREATIVEFLY),
MOVING_MOREPACKETS(MOVING, "morePackets", Permissions.MOVING_MOREPACKETS),
MOVING_MOREPACKETSVEHICLE(MOVING, "morePacketsVehicle", Permissions.MOVING_MOREPACKETSVEHICLE),
MOVING_NOFALL(MOVING, "noFall", Permissions.MOVING_NOFALL),
MOVING_SURVIVALFLY(MOVING, "survivalFly", Permissions.MOVING_SURVIVALFLY),
UNKNOWN;
/** The group. */
public final CheckType group;
/** The config. */
public final Class<?> config;
/** The data. */
public final Class<?> data;
/** The name. */
public final String name;
/** The permission. */
public final String permission;
/**
* Instantiates a new check type.
*/
private CheckType() {
this(null, null, null, null, null);
}
/**
* Instantiates a new check type.
*
* @param group
* the group
* @param config
* the config class
* @param data
* the data class
* @param name
* the name
* @param permission
* the permission
*/
private CheckType(final CheckType group, final Class<?> config, final Class<?> data, final String name,
final String permission) {
this.group = group;
this.config = config;
this.data = data;
this.name = name;
this.permission = permission;
}
/**
* Instantiates a new check type.
*
* @param group
* the group
* @param name
* the name
* @param permission
* the permission
*/
private CheckType(final CheckType group, final String name, final String permission) {
this(group, group.getConfig(), group.getData(), name, permission);
}
/**
* Instantiates a new check type.
*
* @param config
* the config
* @param data
* the data
*/
private CheckType(final Class<?> config, final Class<?> data) {
this(null, config, data, null, null);
}
/**
* Gets the config class.
*
* @return the config class
*/
public Class<?> getConfig() {
return config;
}
/**
* Gets the data class.
*
* @return the data class
*/
public Class<?> getData() {
return data;
}
/**
* Gets the name.
*
* @return the name
*/
public String getName() {
return name;
}
/**
* Gets the permission.
*
* @return the permission
*/
public String getPermission() {
return permission;
}
}

View File

@ -1,14 +1,11 @@
package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -26,19 +23,10 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
public class Direction extends Check {
/**
* The event triggered by this check.
* Instantiates a new direction check.
*/
public class DirectionEvent extends CheckEvent {
/**
* Instantiates a new direction event.
*
* @param player
* the player
*/
public DirectionEvent(final Player player) {
super(player);
}
public Direction() {
super(CheckType.BLOCKBREAK_DIRECTION);
}
/**
@ -51,7 +39,6 @@ public class Direction extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
boolean cancel = false;
@ -70,37 +57,13 @@ public class Direction extends Check {
// Add the overall violation level of the check.
data.directionVL += distance;
// Dispatch a direction event (API).
final DirectionEvent e = new DirectionEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
cancel = executeActions(player);
} else
// Player did likely nothing wrong, reduce violation counter to reward him.
data.directionVL *= 0.9D;
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockBreakData.getData(player).directionVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION)
&& BlockBreakConfig.getConfig(player).directionCheck;
}
}

View File

@ -1,15 +1,12 @@
package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* MM""""""""`M dP M#"""""""'M dP
@ -25,24 +22,8 @@ import fr.neatmonster.nocheatplus.players.Permissions;
*/
public class FastBreak extends Check {
/**
* The event triggered by this check.
*/
public class FastBreakEvent extends CheckEvent {
/**
* Instantiates a new fast break event.
*
* @param player
* the player
*/
public FastBreakEvent(final Player player) {
super(player);
}
}
/** The minimum time that needs to be elapsed between two block breaks for a player in creative mode. */
private static final long CREATIVE = 145L;
private static final long CREATIVE = 95L;
/** The minimum time that needs to be elapsed between two block breaks for a player in survival mode. */
private static final long SURVIVAL = 45L;
@ -50,6 +31,13 @@ public class FastBreak extends Check {
/** The multiplicative constant used when incrementing the limit. */
private static final int TOLERANCE = 10;
/**
* Instantiates a new fast break check.
*/
public FastBreak() {
super(CheckType.BLOCKBREAK_FASTBREAK);
}
/**
* Checks a player.
*
@ -84,18 +72,14 @@ public class FastBreak extends Check {
// Increment the violation level (but using the original limit).
data.fastBreakVL += Math.max(timeLimit - elapsedTime, 0D);
// Dispatch a new fast break event (API).
final FastBreakEvent e = new FastBreakEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Cancel the event if needed.
cancel = !e.isCancelled() && executeActions(player, cc.fastBreakActions, data.fastBreakVL);
cancel = executeActions(player);
} else
// Remove one from the buffer.
data.fastBreakBuffer--;
} else {
// If the buffer isn't full.
if (data.fastBreakBuffer < data.fastBreakBuffer)
if (data.fastBreakBuffer < cc.fastBreakBuffer)
// Add one to the buffer.
data.fastBreakBuffer++;
@ -108,24 +92,4 @@ public class FastBreak extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockBreakData.getData(player).fastBreakVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKBREAK_FASTBREAK)
&& BlockBreakConfig.getConfig(player).fastBreakCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""""`YM MP""""""`MM oo
@ -24,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class NoSwing extends Check {
/**
* The event triggered by this check.
* Instantiates a new no swing check.
*/
public class NoSwingEvent extends CheckEvent {
/**
* Instantiates a new no swing event.
*
* @param player
* the player
*/
public NoSwingEvent(final Player player) {
super(player);
}
public NoSwing() {
super(CheckType.BLOCKBREAK_NOSWING);
}
/**
@ -47,7 +35,6 @@ public class NoSwing extends Check {
* @return true, if successful
*/
public boolean check(final Player player) {
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
boolean cancel = false;
@ -62,35 +49,11 @@ public class NoSwing extends Check {
// He failed, increase violation level.
data.noSwingVL += 1D;
// Dispatch a no swing event (API).
final NoSwingEvent e = new NoSwingEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.noSwingActions, data.noSwingVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockBreakData.getData(player).noSwingVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKBREAK_NOSWING) && BlockBreakConfig.getConfig(player).noSwingCheck;
}
}

View File

@ -1,13 +1,12 @@
package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -24,25 +23,19 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
*/
public class Reach extends Check {
/** The maximum distance allowed to interact with a block in creative mode. */
public final double CREATIVE_DISTANCE = 5.6D;
/** The maximum distance allowed to interact with a block in survival mode. */
public final double SURVIVAL_DISTANCE = 5.1D;
/**
* The event triggered by this check.
* Instantiates a new reach check.
*/
public class ReachEvent extends CheckEvent {
/**
* Instantiates a new reach event.
*
* @param player
* the player
*/
public ReachEvent(final Player player) {
super(player);
}
public Reach() {
super(CheckType.BLOCKBREAK_REACH);
}
/** The maximum distance allowed to interact with a block. */
public final double DISTANCE = 5D; // TODO: Test with creative mode.
/**
* Checks a player.
*
@ -53,29 +46,28 @@ public class Reach extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockBreakConfig cc = BlockBreakConfig.getConfig(player);
BlockBreakConfig.getConfig(player);
final BlockBreakData data = BlockBreakData.getData(player);
boolean cancel = false;
final double distanceLimit = player.getGameMode() == GameMode.SURVIVAL ? SURVIVAL_DISTANCE : CREATIVE_DISTANCE;
// Distance is calculated from eye location to center of targeted block. If the player is further away from his
// target than allowed, the difference will be assigned to "distance".
final double distance = Math.max(CheckUtils.distance(player, location) - DISTANCE, 0D);
final double distance = CheckUtils.distance(player.getEyeLocation(), location.add(0.5D, 0.5D, 0.5D))
- distanceLimit;
if (distance > 0) {
// He failed, increment violation level.
data.reachVL += distance;
// Dispatch a reach event (API).
final ReachEvent e = new ReachEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Remember how much further than allowed he tried to reach for logging, if necessary.
data.reachDistance = distance + DISTANCE;
data.reachDistance = distance;
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.reachActions, data.reachVL);
cancel = executeActions(player);
} else
// Player passed the check, reward him.
data.reachVL *= 0.9D;
@ -88,19 +80,9 @@ public class Reach extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockBreakData.getData(player).reachVL));
else if (wildcard == ParameterName.REACH_DISTANCE)
if (wildcard == ParameterName.REACH_DISTANCE)
return String.valueOf(Math.round(BlockBreakData.getData(player).reachDistance));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKBREAK_REACH) && BlockBreakConfig.getConfig(player).reachCheck;
}
}

View File

@ -1,14 +1,11 @@
package fr.neatmonster.nocheatplus.checks.blockinteract;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -26,19 +23,10 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
public class Direction extends Check {
/**
* The event triggered by this check.
* Instantiates a new direction check.
*/
public class DirectionEvent extends CheckEvent {
/**
* Instantiates a new direction event.
*
* @param player
* the player
*/
public DirectionEvent(final Player player) {
super(player);
}
public Direction() {
super(CheckType.BLOCKINTERACT_DIRECTION);
}
/**
@ -51,7 +39,7 @@ public class Direction extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockInteractConfig cc = BlockInteractConfig.getConfig(player);
BlockInteractConfig.getConfig(player);
final BlockInteractData data = BlockInteractData.getData(player);
boolean cancel = false;
@ -70,37 +58,13 @@ public class Direction extends Check {
// Add the overall violation level of the check.
data.directionVL += distance;
// Dispatch a direction event (API).
final DirectionEvent e = new DirectionEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
cancel = executeActions(player);
} else
// Player did likely nothing wrong, reduce violation counter to reward him.
data.directionVL *= 0.9D;
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockInteractData.getData(player).directionVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKINTERACT_DIRECTION)
&& BlockInteractConfig.getConfig(player).directionCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.blockinteract;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""""`YM MP""""""`MM oo
@ -24,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class NoSwing extends Check {
/**
* The event triggered by this check.
* Instantiates a new no swing check.
*/
public class NoSwingEvent extends CheckEvent {
/**
* Instantiates a new no swing event.
*
* @param player
* the player
*/
public NoSwingEvent(final Player player) {
super(player);
}
public NoSwing() {
super(CheckType.BLOCKINTERACT_NOSWING);
}
/**
@ -47,7 +35,7 @@ public class NoSwing extends Check {
* @return true, if successful
*/
public boolean check(final Player player) {
final BlockInteractConfig cc = BlockInteractConfig.getConfig(player);
BlockInteractConfig.getConfig(player);
final BlockInteractData data = BlockInteractData.getData(player);
boolean cancel = false;
@ -63,14 +51,9 @@ public class NoSwing extends Check {
// He failed, increase violation level.
data.noSwingVL += 1D;
// Dispatch a no swing event (API).
final NoSwingEvent e = new NoSwingEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we
// should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.noSwingActions, data.noSwingVL);
// should cancel the event.
cancel = executeActions(player);
}
data.noSwingLastTime = System.currentTimeMillis();
@ -78,24 +61,4 @@ public class NoSwing extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockInteractData.getData(player).noSwingVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKINTERACT_NOSWING)
&& BlockInteractConfig.getConfig(player).noSwingCheck;
}
}

View File

@ -1,13 +1,12 @@
package fr.neatmonster.nocheatplus.checks.blockinteract;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -24,25 +23,19 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
*/
public class Reach extends Check {
/** The maximum distance allowed to interact with a block in creative mode. */
public final double CREATIVE_DISTANCE = 5.6D;
/** The maximum distance allowed to interact with a block in survival mode. */
public final double SURVIVAL_DISTANCE = 5.1D;
/**
* The event triggered by this check.
* Instantiates a new reach check.
*/
public class ReachEvent extends CheckEvent {
/**
* Instantiates a new reach event.
*
* @param player
* the player
*/
public ReachEvent(final Player player) {
super(player);
}
public Reach() {
super(CheckType.BLOCKINTERACT_REACH);
}
/** The maximum distance allowed to interact with a block. */
public final double DISTANCE = 5D; // TODO: Test with creative mode.
/**
* Checks a player.
*
@ -53,29 +46,28 @@ public class Reach extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockInteractConfig cc = BlockInteractConfig.getConfig(player);
BlockInteractConfig.getConfig(player);
final BlockInteractData data = BlockInteractData.getData(player);
boolean cancel = false;
final double distanceLimit = player.getGameMode() == GameMode.SURVIVAL ? SURVIVAL_DISTANCE : CREATIVE_DISTANCE;
// Distance is calculated from eye location to center of targeted block. If the player is further away from his
// target than allowed, the difference will be assigned to "distance".
final double distance = Math.max(CheckUtils.distance(player, location) - DISTANCE, 0D);
final double distance = CheckUtils.distance(player.getEyeLocation(), location.add(0.5D, 0.5D, 0.5D))
- distanceLimit;
if (distance > 0) {
// He failed, increment violation level.
data.reachVL += distance;
// Dispatch a reach event (API).
final ReachEvent e = new ReachEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Remember how much further than allowed he tried to reach for logging, if necessary.
data.reachDistance = distance + DISTANCE;
data.reachDistance = distance;
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.reachActions, data.reachVL);
cancel = executeActions(player);
} else
// Player passed the check, reward him.
data.reachVL *= 0.9D;
@ -88,20 +80,9 @@ public class Reach extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockInteractData.getData(player).reachVL));
else if (wildcard == ParameterName.REACH_DISTANCE)
if (wildcard == ParameterName.REACH_DISTANCE)
return String.valueOf(Math.round(BlockInteractData.getData(player).reachDistance));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKINTERACT_REACH)
&& BlockInteractConfig.getConfig(player).reachCheck;
}
}

View File

@ -49,7 +49,7 @@ public class BlockPlaceListener implements Listener {
*/
@EventHandler(
ignoreCancelled = true, priority = EventPriority.LOWEST)
protected void onBlockPlace(final BlockPlaceEvent event) {
public void onBlockPlace(final BlockPlaceEvent event) {
/*
* ____ _ _ ____ _
* | __ )| | ___ ___| | __ | _ \| | __ _ ___ ___
@ -70,8 +70,9 @@ public class BlockPlaceListener implements Listener {
if (fastPlace.isEnabled(player) && fastPlace.check(player, block))
cancelled = true;
// Second, the no swing check.
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player))
// Second, the no swing check (player doesn't swing his arm when placing a lily pad).
if (!cancelled && event.getBlockPlaced().getType() != Material.WATER_LILY && noSwing.isEnabled(player)
&& noSwing.check(player))
cancelled = true;
// Third, the reach check.

View File

@ -1,14 +1,11 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -26,19 +23,10 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
public class Direction extends Check {
/**
* The event triggered by this check.
* Instantiates a new direction check.
*/
public class DirectionEvent extends CheckEvent {
/**
* Instantiates a new direction event.
*
* @param player
* the player
*/
public DirectionEvent(final Player player) {
super(player);
}
public Direction() {
super(CheckType.BLOCKPLACE_DIRECTION);
}
/**
@ -51,7 +39,7 @@ public class Direction extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Location placed, final Location against) {
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
BlockPlaceConfig.getConfig(player);
final BlockPlaceData data = BlockPlaceData.getData(player);
boolean cancel = false;
@ -93,37 +81,13 @@ public class Direction extends Check {
// Add the overall violation level of the check.
data.directionVL += distance;
// Dispatch a direction event (API).
final DirectionEvent e = new DirectionEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
cancel = executeActions(player);
} else
// Player did likely nothing wrong, reduce violation counter to reward him.
data.directionVL *= 0.9D;
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockPlaceData.getData(player).directionVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKPLACE_DIRECTION)
&& BlockPlaceConfig.getConfig(player).directionCheck;
}
}

View File

@ -1,13 +1,10 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
/*
@ -25,19 +22,10 @@ import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
public class FastPlace extends Check {
/**
* The event triggered by this check.
* Instantiates a new fast place check.
*/
public class FastPlaceEvent extends CheckEvent {
/**
* Instantiates a new fast place event.
*
* @param player
* the player
*/
public FastPlaceEvent(final Player player) {
super(player);
}
public FastPlace() {
super(CheckType.BLOCKPLACE_FASTPLACE);
}
/**
@ -62,13 +50,9 @@ public class FastPlace extends Check {
// He failed, increase his violation level.
data.fastPlaceVL += cc.fastPlaceInterval - System.currentTimeMillis() + data.fastPlaceLastTime;
// Distance a fast place event (API).
final FastPlaceEvent e = new FastPlaceEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if
// we should cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.fastPlaceActions, data.fastPlaceVL);
cancel = executeActions(player);
}
data.fastPlaceLastRefused = true;
@ -83,24 +67,4 @@ public class FastPlace extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockPlaceData.getData(player).fastPlaceVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKPLACE_FASTPLACE)
&& BlockPlaceConfig.getConfig(player).fastPlaceCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""""`YM MP""""""`MM oo
@ -24,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class NoSwing extends Check {
/**
* The event triggered by this check.
* Instantiates a new no swing check.
*/
public class NoSwingEvent extends CheckEvent {
/**
* Instantiates a new no swing event.
*
* @param player
* the player
*/
public NoSwingEvent(final Player player) {
super(player);
}
public NoSwing() {
super(CheckType.BLOCKPLACE_NOSWING);
}
/**
@ -47,7 +35,7 @@ public class NoSwing extends Check {
* @return true, if successful
*/
public boolean check(final Player player) {
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
BlockPlaceConfig.getConfig(player);
final BlockPlaceData data = BlockPlaceData.getData(player);
boolean cancel = false;
@ -62,34 +50,11 @@ public class NoSwing extends Check {
// He failed, increase violation level.
data.noSwingVL += 1D;
// Dispatch a no swing event (API).
final NoSwingEvent e = new NoSwingEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.noSwingActions, data.noSwingVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockPlaceData.getData(player).noSwingVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKPLACE_NOSWING) && BlockPlaceConfig.getConfig(player).noSwingCheck;
}
}

View File

@ -1,13 +1,12 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -24,25 +23,19 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
*/
public class Reach extends Check {
/** The maximum distance allowed to interact with a block in creative mode. */
public final double CREATIVE_DISTANCE = 5.6D;
/** The maximum distance allowed to interact with a block in survival mode. */
public final double SURVIVAL_DISTANCE = 5.1D;
/**
* The event triggered by this check.
* Instantiates a new reach check.
*/
public class ReachEvent extends CheckEvent {
/**
* Instantiates a new reach event.
*
* @param player
* the player
*/
public ReachEvent(final Player player) {
super(player);
}
public Reach() {
super(CheckType.BLOCKPLACE_REACH);
}
/** The maximum distance allowed to interact with a block. */
public final double DISTANCE = 5D; // TODO: Test with creative mode.
/**
* Checks a player.
*
@ -53,28 +46,28 @@ public class Reach extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final Location location) {
final BlockPlaceConfig cc = BlockPlaceConfig.getConfig(player);
BlockPlaceConfig.getConfig(player);
final BlockPlaceData data = BlockPlaceData.getData(player);
boolean cancel = false;
final double distanceLimit = player.getGameMode() == GameMode.SURVIVAL ? SURVIVAL_DISTANCE : CREATIVE_DISTANCE;
// Distance is calculated from eye location to center of targeted block. If the player is further away from his
// target than allowed, the difference will be assigned to "distance".
final double distance = Math.max(CheckUtils.distance(player, location) - DISTANCE, 0D);
final double distance = CheckUtils.distance(player.getEyeLocation(), location.add(0.5D, 0.5D, 0.5D))
- distanceLimit;
if (distance > 0) {
// He failed, increment violation level.
data.reachVL += distance;
// Dispatch a reach event (API).
final ReachEvent e = new ReachEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Remember how much further than allowed he tried to reach for logging, if necessary.
data.reachDistance = distance + DISTANCE;
data.reachDistance = distance;
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.reachActions, data.reachVL);
cancel = executeActions(player);
} else
// Player passed the check, reward him.
data.reachVL *= 0.9D;
@ -87,19 +80,9 @@ public class Reach extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockPlaceData.getData(player).reachVL));
else if (wildcard == ParameterName.REACH_DISTANCE)
if (wildcard == ParameterName.REACH_DISTANCE)
return String.valueOf(Math.round(BlockPlaceData.getData(player).reachDistance));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKPLACE_REACH) && BlockPlaceConfig.getConfig(player).reachCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* MP""""""`MM dP
@ -24,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class Speed extends Check {
/**
* The event triggered by this check.
* Instantiates a new speed check.
*/
public class SpeedEvent extends CheckEvent {
/**
* Instantiates a new speed event.
*
* @param player
* the player
*/
public SpeedEvent(final Player player) {
super(player);
}
public Speed() {
super(CheckType.BLOCKPLACE_SPEED);
}
/**
@ -58,13 +46,9 @@ public class Speed extends Check {
// He failed, increase this violation level.
data.speedVL += cc.speedInterval - System.currentTimeMillis() + data.speedLastTime;
// Dispatch a speed event (API).
final SpeedEvent e = new SpeedEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we
// should cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.speedActions, data.speedVL);
cancel = executeActions(player);
}
data.speedLastRefused = true;
@ -79,23 +63,4 @@ public class Speed extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(BlockPlaceData.getData(player).speedVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.BLOCKPLACE_SPEED) && BlockPlaceConfig.getConfig(player).speedCheck;
}
}

View File

@ -5,14 +5,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* MMP"""""""MM oo dP
@ -28,25 +25,16 @@ import fr.neatmonster.nocheatplus.players.Permissions;
*/
public class Arrivals extends Check {
/**
* The event triggered by this check.
*/
public class ArrivalsEvent extends CheckEvent {
/**
* Instantiates a new arrivals event.
*
* @param player
* the player
*/
public ArrivalsEvent(final Player player) {
super(player);
}
}
/** The map containing the time and the name of the player, every time that one of them joins. */
private final Map<Long, String> joins = new HashMap<Long, String>();
/**
* Instantiates a new arrivals check.
*/
public Arrivals() {
super(CheckType.CHAT_ARRIVALS);
}
/**
* Checks a player.
*
@ -76,34 +64,10 @@ public class Arrivals extends Check {
// Add the new data.
joins.put(System.currentTimeMillis(), player.getName());
if (joins.size() > cc.arrivalsJoinsLimit) {
// Dispatch an arrivals event (API).
final ArrivalsEvent e = new ArrivalsEvent(player);
Bukkit.getPluginManager().callEvent(e);
if (joins.size() > cc.arrivalsJoinsLimit)
// Find out if we should cancel the event or not.
cancel = !e.isCancelled() && executeActions(player, cc.arrivalsActions, 0);
}
cancel = executeActions(player);
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return "0";
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.CHAT_ARRIVALS) && ChatConfig.getConfig(player).arrivalsCheck;
}
}

View File

@ -37,6 +37,7 @@ public class ChatData {
}
// Violation levels.
public double arrivalsVL;
public double colorVL;
public double noPwnageVL;

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.chat;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* MM'""""'YMM dP
@ -23,19 +20,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class Color extends Check {
/**
* The event triggered by this check.
* Instantiates a new color check.
*/
public class ColorEvent extends CheckEvent {
/**
* Instantiates a new color event.
*
* @param player
* the player
*/
public ColorEvent(final Player player) {
super(player);
}
public Color() {
super(CheckType.CHAT_COLOR);
}
/**
@ -48,7 +36,7 @@ public class Color extends Check {
* @return the string
*/
public String check(final Player player, final String message) {
final ChatConfig cc = ChatConfig.getConfig(player);
ChatConfig.getConfig(player);
final ChatData data = ChatData.getData(player);
// If the message contains colors...
@ -56,35 +44,12 @@ public class Color extends Check {
// Increment the violation level of the player.
data.colorVL++;
// Dispatch a color event (API).
final ColorEvent e = new ColorEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Find out if we need to remove the colors or not.
if (!e.isCancelled() && executeActions(player, cc.colorActions, data.colorVL))
if (executeActions(player))
// Remove color codes.
message.replaceAll("\302\247.", "").replaceAll("\247.", "");
}
return message;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(ChatData.getData(player).colorVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.CHAT_COLOR) && ChatConfig.getConfig(player).colorCheck;
}
}

View File

@ -9,10 +9,8 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerEvent;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -30,22 +28,6 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
*/
public class NoPwnage extends Check {
/**
* The event triggered by this check.
*/
public class NoPwnageEvent extends CheckEvent {
/**
* Instantiates a new no pwnage event.
*
* @param player
* the player
*/
public NoPwnageEvent(final Player player) {
super(player);
}
}
/** The last message which caused ban said. */
private String lastBanCausingMessage;
@ -58,12 +40,15 @@ public class NoPwnage extends Check {
/** The time it was when the last message was said. */
private long lastGlobalMessageTime;
/** The random number generator. */
private final Random random = new Random();
/**
* Instantiates a new no pwnage check.
*/
public NoPwnage() {
super(CheckType.CHAT_NOPWNAGE);
for (final Player player : Bukkit.getOnlinePlayers())
ChatData.getData(player).noPwnageLastLocation = player.getLocation();
}
@ -93,15 +78,9 @@ public class NoPwnage extends Check {
player.sendMessage(replaceColors(cc.noPwnageReloginWarningMessage));
data.noPwnageReloginWarningTime = now;
data.noPwnageReloginWarnings++;
} else if (now - data.noPwnageReloginWarningTime < cc.noPwnageReloginWarningTimeout) {
// Dispatch a no pwnage event (API).
final NoPwnageEvent e = new NoPwnageEvent(player);
Bukkit.getPluginManager().callEvent(e);
} else if (now - data.noPwnageReloginWarningTime < cc.noPwnageReloginWarningTimeout)
// Find out if we need to ban the player or not.
if (!e.isCancelled())
cancel = executeActions(player, cc.noPwnageActions, data.noPwnageVL);
}
cancel = executeActions_(player);
}
// Store his location and some other data.
@ -145,16 +124,9 @@ public class NoPwnage extends Check {
player.sendMessage(replaceColors(cc.noPwnageCaptchaSuccess));
} else {
// Does he failed too much times?
if (data.noPwnageCaptchTries > cc.noPwnageCaptchaTries) {
// Dispatch a no pwnage event (API).
final NoPwnageEvent e = new NoPwnageEvent(player);
Bukkit.getPluginManager().callEvent(e);
if (data.noPwnageCaptchTries > cc.noPwnageCaptchaTries)
// Find out if we need to ban the player or not.
if (!e.isCancelled())
cancel = executeActions(player, cc.noPwnageActions, data.noPwnageVL);
}
cancel = executeActions_(player);
// Increment his tries number counter.
data.noPwnageCaptchTries++;
@ -250,13 +222,8 @@ public class NoPwnage extends Check {
else if (event instanceof PlayerCommandPreprocessEvent)
((PlayerCommandPreprocessEvent) event).setCancelled(true);
// Dispatch a no pwnage event (API).
final NoPwnageEvent e = new NoPwnageEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Find out if we need to ban the player or not.
if (!e.isCancelled())
cancel = executeActions(player, cc.noPwnageActions, data.noPwnageVL);
cancel = executeActions_(player);
}
// Store the message and some other data.
@ -269,12 +236,15 @@ public class NoPwnage extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#executeActions(org.bukkit.entity.Player, fr.neatmonster.nocheatplus.actions.types.ActionList, double)
/**
* Execute actions.
*
* @param player
* the player
* @return true, if successful
*/
@Override
protected boolean executeActions(final Player player, final ActionList actionList, final double violationLevel) {
if (super.executeActions(player, actionList, violationLevel)) {
private boolean executeActions_(final Player player) {
if (super.executeActions(player)) {
ChatData.getData(player).clearNoPwnageData();
return true;
}
@ -286,19 +256,9 @@ public class NoPwnage extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(ChatData.getData(player).noPwnageVL));
else if (wildcard == ParameterName.IP)
if (wildcard == ParameterName.IP)
return player.getAddress().toString().substring(1).split(":")[0];
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.CHAT_NOPWNAGE) && ChatConfig.getConfig(player).noPwnageCheck;
}
}

View File

@ -2,14 +2,11 @@ package fr.neatmonster.nocheatplus.checks.fight;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
/*
@ -30,19 +27,10 @@ import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
public class Angle extends Check {
/**
* The event triggered by this check.
* Instantiates a new angle check.
*/
public class AngleEvent extends CheckEvent {
/**
* Instantiates a new angle event.
*
* @param player
* the player
*/
public AngleEvent(final Player player) {
super(player);
}
public Angle() {
super(CheckType.FIGHT_ANGLE);
}
/**
@ -128,36 +116,13 @@ public class Angle extends Check {
// If it hasn't, increment the violation level.
data.angleVL += violation;
// Dispatch a angle event (API).
final AngleEvent e = new AngleEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.angleActions, data.angleVL);
cancel = executeActions(player);
} else
// Reward the player by lowering his violation level.
data.angleVL *= 0.98D;
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).angleVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_ANGLE) && FightConfig.getConfig(player).angleCheck;
}
}

View File

@ -1,13 +1,10 @@
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
@ -26,19 +23,10 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
public class Critical extends Check {
/**
* The event triggered by this check.
* Instantiates a new critical check.
*/
public class CriticalEvent extends CheckEvent {
/**
* Instantiates a new critical event.
*
* @param player
* the player
*/
public CriticalEvent(final Player player) {
super(player);
}
public Critical() {
super(CheckType.FIGHT_CRITICAL);
}
/**
@ -77,34 +65,11 @@ public class Critical extends Check {
// Increment the violation level.
data.criticalVL += delta;
// Dispatch a critical event (API).
final CriticalEvent e = new CriticalEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we
// should cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.criticalActions, data.criticalVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).criticalVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_CRITICAL) && FightConfig.getConfig(player).criticalCheck;
}
}

View File

@ -4,15 +4,12 @@ import net.minecraft.server.Entity;
import net.minecraft.server.EntityComplex;
import net.minecraft.server.EntityComplexPart;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
/*
@ -30,19 +27,10 @@ import fr.neatmonster.nocheatplus.utilities.CheckUtils;
public class Direction extends Check {
/**
* The event triggered by this check.
* Instantiates a new direction check.
*/
public class DirectionEvent extends CheckEvent {
/**
* Instantiates a new direction event.
*
* @param player
* the player
*/
public DirectionEvent(final Player player) {
super(player);
}
public Direction() {
super(CheckType.FIGHT_DIRECTION);
}
/**
@ -85,13 +73,9 @@ public class Direction extends Check {
// Add the overall violation level of the check.
data.directionVL += distance;
// Dispatch a direction event (API)
final DirectionEvent e = new DirectionEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
cancel = executeActions(player);
if (cancel)
// If we should cancel, remember the current time too.
@ -113,23 +97,4 @@ public class Direction extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).directionVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_DIRECTION) && FightConfig.getConfig(player).directionCheck;
}
}

View File

@ -14,7 +14,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.players.Permissions;
/*
* MM""""""""`M oo dP dP M""MMMMMMMM oo dP
@ -98,7 +98,7 @@ public class FightListener implements Listener {
if (!cancelled && speed.isEnabled(player) && speed.check(player))
cancelled = true;
if (!cancelled && !MovingConfig.getConfig(player).survivalFlyAllowFastBlocking && player.isBlocking())
if (!cancelled && player.isBlocking() && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_BLOCKING))
cancelled = true;
// One of the checks requested the event to be cancelled, so do it.

View File

@ -7,10 +7,8 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* MM'"""""`MM dP M"""""`'"""`YM dP
@ -27,19 +25,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class GodMode extends Check {
/**
* The event triggered by this check.
* Instantiates a new god mode check.
*/
public class GodModeEvent extends CheckEvent {
/**
* Instantiates a new god mode event.
*
* @param player
* the player
*/
public GodModeEvent(final Player player) {
super(player);
}
public GodMode() {
super(CheckType.FIGHT_GODMODE);
}
/**
@ -50,7 +39,7 @@ public class GodMode extends Check {
* @return true, if successful
*/
public boolean check(final Player player) {
final FightConfig cc = FightConfig.getConfig(player);
FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
boolean cancel = false;
@ -73,13 +62,9 @@ public class GodMode extends Check {
// No, that means we can increase his violation level.
data.godModeVL -= data.godModeBuffer;
// Dispatch a god mode event (API).
final GodModeEvent e = new GodModeEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if
// we should cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.godModeActions, data.godModeVL);
cancel = executeActions(player);
}
} else {
// Give some new points, once a second.
@ -134,23 +119,4 @@ public class GodMode extends Check {
}, 30);
} catch (final Exception e) {}
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).godModeVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_GODMODE) && FightConfig.getConfig(player).godModeCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M""M dP dP M""MMMMM""MM dP
@ -23,19 +20,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class InstantHeal extends Check {
/**
* The event triggered by this check.
* Instantiates a new instant heal check.
*/
public class InstantHealEvent extends CheckEvent {
/**
* Instantiates a new instant heal event.
*
* @param player
* the player
*/
public InstantHealEvent(final Player player) {
super(player);
}
public InstantHeal() {
super(CheckType.FIGHT_INSTANTHEAL);
}
/**
@ -46,7 +34,7 @@ public class InstantHeal extends Check {
* @return true, if successful
*/
public boolean check(final Player player) {
final FightConfig cc = FightConfig.getConfig(player);
FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
boolean cancel = false;
@ -67,13 +55,9 @@ public class InstantHeal extends Check {
// Reset the buffer.
data.instantHealBuffer = 0L;
// Dispatch an instant heal event (API).
final InstantHealEvent e = new InstantHealEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.instantHealActions, data.instantHealVL);
cancel = executeActions(player);
} else
// Decrease the violation level.
data.instantHealVL *= 0.9D;
@ -88,23 +72,4 @@ public class InstantHeal extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).instantHealVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_INSTANTHEAL) && FightConfig.getConfig(player).instantHealCheck;
}
}

View File

@ -1,13 +1,10 @@
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
/*
@ -25,19 +22,10 @@ import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
public class Knockback extends Check {
/**
* The event triggered by this check.
* Instantiates a new knockback check.
*/
public class KnockbackEvent extends CheckEvent {
/**
* Instantiates a new knockback event.
*
* @param player
* the player
*/
public KnockbackEvent(final Player player) {
super(player);
}
public Knockback() {
super(CheckType.FIGHT_KNOCKBACK);
}
/**
@ -66,34 +54,11 @@ public class Knockback extends Check {
// Increment the violation level
data.knockbackVL += cc.knockbackInterval - System.currentTimeMillis() + data.knockbackSprintTime;
// Dispatch a knockback event (API).
final KnockbackEvent e = new KnockbackEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.knockbackActions, data.knockbackVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).knockbackVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_KNOCKBACK) && FightConfig.getConfig(player).knockbackCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""""`YM MP""""""`MM oo
@ -24,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class NoSwing extends Check {
/**
* The event triggered by this check.
* Instantiates a new no swing check.
*/
public class NoSwingEvent extends CheckEvent {
/**
* Instantiates a new no swing event.
*
* @param player
* the player
*/
public NoSwingEvent(final Player player) {
super(player);
}
public NoSwing() {
super(CheckType.FIGHT_NOSWING);
}
/**
@ -47,7 +35,7 @@ public class NoSwing extends Check {
* @return true, if successful
*/
public boolean check(final Player player) {
final FightConfig cc = FightConfig.getConfig(player);
FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
boolean cancel = false;
@ -61,34 +49,11 @@ public class NoSwing extends Check {
// No, increase his violation level.
data.noSwingVL += 1D;
// Dispatch a no swing event (API).
final NoSwingEvent e = new NoSwingEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.noSwingActions, data.noSwingVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).noSwingVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_NOSWING) && FightConfig.getConfig(player).noSwingCheck;
}
}

View File

@ -2,14 +2,11 @@ package fr.neatmonster.nocheatplus.checks.fight;
import net.minecraft.server.Entity;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
@ -27,25 +24,19 @@ import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
*/
public class Reach extends Check {
/** The maximum distance allowed to interact with an entity in creative mode. */
public final double CREATIVE_DISTANCE = 6D;
/** The maximum distance allowed to interact with an entity in survival mode. */
public final double SURVIVAL_DISTANCE = 3.6D;
/**
* The event triggered by this check.
* Instantiates a new reach check.
*/
public class ReachEvent extends CheckEvent {
/**
* Instantiates a new reach event.
*
* @param player
* the player
*/
public ReachEvent(final Player player) {
super(player);
}
public Reach() {
super(CheckType.FIGHT_REACH);
}
/** The maximum distance allowed to interact with an entity. */
public final double DISTANCE = 4D; // TODO: Needs testing.
/**
* Checks a player.
*
@ -61,28 +52,22 @@ public class Reach extends Check {
boolean cancel = false;
final Location minimum = new Location(player.getWorld(), damaged.boundingBox.a, damaged.boundingBox.b,
damaged.boundingBox.c);
final Location maximum = new Location(player.getWorld(), damaged.boundingBox.d, damaged.boundingBox.e,
damaged.boundingBox.f);
final Location location = minimum.add(maximum).multiply(0.5D);
final double distanceLimit = player.getGameMode() == GameMode.SURVIVAL ? SURVIVAL_DISTANCE : CREATIVE_DISTANCE;
// Distance is calculated from eye location to center of targeted. If the player is further away from his target
// than allowed, the difference will be assigned to "distance".
final double distance = Math.max(CheckUtils.distance(player, location) - DISTANCE, 0D);
final double distance = CheckUtils.distance(player.getEyeLocation(), damaged.getBukkitEntity().getLocation()
.add(0D, damaged.getHeadHeight(), 0D))
- distanceLimit;
if (distance > 0) {
// He failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
if (!LagMeasureTask.skipCheck())
data.reachVL += distance;
// Dispatch a reach event (API).
final ReachEvent e = new ReachEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.reachActions, data.reachVL);
cancel = executeActions(player);
if (cancel)
// If we should cancel, remember the current time too.
@ -104,23 +89,4 @@ public class Reach extends Check {
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).reachVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_REACH) && FightConfig.getConfig(player).reachCheck;
}
}

View File

@ -1,12 +1,10 @@
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
/*
@ -25,19 +23,10 @@ import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
public class Speed extends Check {
/**
* The event triggered by this check.
* Instantiates a new speed check.
*/
public class SpeedEvent extends CheckEvent {
/**
* Instantiates a new speed event.
*
* @param player
* the player
*/
public SpeedEvent(final Player player) {
super(player);
}
public Speed() {
super(CheckType.FIGHT_SPEED);
}
/**
@ -69,13 +58,9 @@ public class Speed extends Check {
if (!LagMeasureTask.skipCheck())
data.speedVL += 1;
// Dispatch a speed event (API).
final SpeedEvent e = new SpeedEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.speedActions, data.speedVL);
cancel = executeActions(player);
}
return cancel;
@ -86,19 +71,9 @@ public class Speed extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(FightData.getData(player).speedVL));
else if (wildcard == ParameterName.LIMIT)
if (wildcard == ParameterName.LIMIT)
return String.valueOf(Math.round(FightConfig.getConfig(player).speedLimit));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.FIGHT_SPEED) && FightConfig.getConfig(player).speedCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M""""""'YMM
@ -24,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class Drop extends Check {
/**
* The event triggered by this check.
* Instantiates a new drop check.
*/
public class DropEvent extends CheckEvent {
/**
* Instantiates a new drop event.
*
* @param player
* the player
*/
public DropEvent(final Player player) {
super(player);
}
public Drop() {
super(CheckType.INVENTORY_DROP);
}
/**
@ -70,34 +58,11 @@ public class Drop extends Check {
// Set his violation level.
data.dropVL = data.dropCount - cc.dropLimit;
// Dispatch a drop event (API).
final DropEvent e = new DropEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.dropActions, data.dropVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(InventoryData.getData(player).dropVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.INVENTORY_DROP) && InventoryConfig.getConfig(player).dropCheck;
}
}

View File

@ -1,12 +1,9 @@
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M""M dP dP M#"""""""'M
@ -23,19 +20,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class InstantBow extends Check {
/**
* The event triggered by this check.
* Instantiates a new instant bow check.
*/
public class InstantBowEvent extends CheckEvent {
/**
* Instantiates a new instant bow event.
*
* @param player
* the player
*/
public InstantBowEvent(final Player player) {
super(player);
}
public InstantBow() {
super(CheckType.INVENTORY_INSTANTBOW);
}
/**
@ -48,7 +36,7 @@ public class InstantBow extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final float force) {
final InventoryConfig cc = InventoryConfig.getConfig(player);
InventoryConfig.getConfig(player);
final InventoryData data = InventoryData.getData(player);
boolean cancel = false;
@ -66,35 +54,11 @@ public class InstantBow extends Check {
// Player was too fast, increase his violation level.
data.instantBowVL += (expectedTimeWhenStringDrawn - System.currentTimeMillis()) / 100D;
// Dispatch an instant bow event (API).
final InstantBowEvent e = new InstantBowEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the
// violation level and find out if we should cancel the event
cancel = !e.isCancelled() && executeActions(player, cc.instantBowActions, data.instantBowVL);
cancel = executeActions(player);
}
return cancel;
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(InventoryData.getData(player).instantBowVL));
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.INVENTORY_INSTANTBOW)
&& InventoryConfig.getConfig(player).instantBowCheck;
}
}

View File

@ -1,12 +1,10 @@
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M""M dP dP MM""""""""`M dP
@ -23,19 +21,10 @@ import fr.neatmonster.nocheatplus.players.Permissions;
public class InstantEat extends Check {
/**
* The event triggered by this check.
* Instantiates a new instant eat check.
*/
public class InstantEatEvent extends CheckEvent {
/**
* Instantiates a new instant eat event.
*
* @param player
* the player
*/
public InstantEatEvent(final Player player) {
super(player);
}
public InstantEat() {
super(CheckType.INVENTORY_INSTANTEAT);
}
/**
@ -48,7 +37,7 @@ public class InstantEat extends Check {
* @return true, if successful
*/
public boolean check(final Player player, final int level) {
final InventoryConfig cc = InventoryConfig.getConfig(player);
InventoryConfig.getConfig(player);
final InventoryData data = InventoryData.getData(player);
boolean cancel = false;
@ -70,13 +59,9 @@ public class InstantEat extends Check {
// Player was too fast, increase his violation level.
data.instantEatVL += (expectedTimeWhenEatingFinished - System.currentTimeMillis()) / 100D;
// Dispatch an instant eat event (API).
final InstantEatEvent e = new InstantEatEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
cancel = !e.isCancelled() && executeActions(player, cc.instantEatActions, data.instantEatVL);
cancel = executeActions(player);
}
return cancel;
@ -87,20 +72,9 @@ public class InstantEat extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(InventoryData.getData(player).instantEatVL));
else if (wildcard == ParameterName.FOOD)
if (wildcard == ParameterName.FOOD)
return InventoryData.getData(player).instantEatFood.toString();
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.INVENTORY_INSTANTEAT)
&& InventoryConfig.getConfig(player).instantEatCheck;
}
}

View File

@ -5,15 +5,13 @@ import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
/*
@ -31,21 +29,6 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
* aren't allowed to fly, and therefore have tighter rules to obey.
*/
public class CreativeFly extends Check {
/**
* The event triggered by this check.
*/
public class CreativeFlyEvent extends CheckEvent {
/**
* Instantiates a new creative fly event.
*
* @param player
* the player
*/
public CreativeFlyEvent(final Player player) {
super(player);
}
}
/** The horizontal speed in creative mode. */
private static final double HORIZONTAL_SPEED = 0.6D;
@ -53,6 +36,13 @@ public class CreativeFly extends Check {
/** The vertical speed in creative mode. */
private static final double VERTICAL_SPEED = 1D;
/**
* Instantiates a new creative fly check.
*/
public CreativeFly() {
super(CheckType.MOVING_CREATIVEFLY);
}
/**
* Checks a player.
*
@ -140,17 +130,12 @@ public class CreativeFly extends Check {
// Increment violation level.
data.creativeFlyVL += result;
// Dispatch a creative fly event (API).
final CreativeFlyEvent e = new CreativeFlyEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we
// should
// cancel the event.
if (!e.isCancelled() && executeActions(player, cc.creativeFlyActions, data.creativeFlyVL))
if (executeActions(player))
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()"
// to
// allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
// to allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(),
data.setBack.getZ(), to.getYaw(), to.getPitch());
} else
@ -173,9 +158,7 @@ public class CreativeFly extends Check {
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
final MovingData data = MovingData.getData(player);
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(data.creativeFlyVL));
else if (wildcard == ParameterName.LOCATION_FROM)
if (wildcard == ParameterName.LOCATION_FROM)
return String.format(Locale.US, "%.2f, %.2f, %.2f", data.from.getX(), data.from.getY(), data.from.getZ());
else if (wildcard == ParameterName.LOCATION_TO)
return String.format(Locale.US, "%.2f, %.2f, %.2f", data.to.getX(), data.to.getY(), data.to.getZ());
@ -184,12 +167,4 @@ public class CreativeFly extends Check {
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.MOVING_CREATIVEFLY) && MovingConfig.getConfig(player).creativeFlyCheck;
}
}

View File

@ -1,13 +1,11 @@
package fr.neatmonster.nocheatplus.checks.moving;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
/*
@ -29,22 +27,6 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
*/
public class MorePackets extends Check {
/**
* The event triggered by this check.
*/
public class MorePacketsEvent extends CheckEvent {
/**
* Instantiates a new more packets event.
*
* @param player
* the player
*/
public MorePacketsEvent(final Player player) {
super(player);
}
}
/**
* The usual number of packets per timeframe.
*
@ -52,6 +34,13 @@ public class MorePackets extends Check {
*/
private final static int packetsPerTimeframe = 22;
/**
* Instantiates a new more packets check.
*/
public MorePackets() {
super(CheckType.MOVING_MOREPACKETS);
}
/**
* Checks a player.
*
@ -69,7 +58,7 @@ public class MorePackets extends Check {
* @return the location
*/
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
final MovingConfig cc = MovingConfig.getConfig(player);
MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
Location newTo = null;
@ -89,13 +78,9 @@ public class MorePackets extends Check {
// Increment violation level.
data.morePacketsVL = -data.morePacketsBuffer;
// Dispatch a more packets event (API).
final MorePacketsEvent e = new MorePacketsEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
if (!e.isCancelled() && executeActions(player, cc.morePacketsActions, data.morePacketsVL))
if (executeActions(player))
newTo = data.teleported = data.morePacketsSetback;
}
@ -138,19 +123,9 @@ public class MorePackets extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(MovingData.getData(player).morePacketsVL));
else if (wildcard == ParameterName.PACKETS)
if (wildcard == ParameterName.PACKETS)
return String.valueOf(MovingData.getData(player).morePacketsPackets);
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.MOVING_MOREPACKETS) && MovingConfig.getConfig(player).morePacketsCheck;
}
}

View File

@ -1,13 +1,11 @@
package fr.neatmonster.nocheatplus.checks.moving;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""`'"""`YM MM"""""""`YM dP dP
@ -31,22 +29,6 @@ import fr.neatmonster.nocheatplus.players.Permissions;
*/
public class MorePacketsVehicle extends Check {
/**
* The event triggered by this check.
*/
public class MorePacketsVehicleEvent extends CheckEvent {
/**
* Instantiates a new more packets vehicle event.
*
* @param player
* the player
*/
public MorePacketsVehicleEvent(final Player player) {
super(player);
}
}
/**
* The usual number of packets per timeframe.
*
@ -54,6 +36,13 @@ public class MorePacketsVehicle extends Check {
*/
private final static int packetsPerTimeframe = 22;
/**
* Instantiates a new more packet vehicle check.
*/
public MorePacketsVehicle() {
super(CheckType.MOVING_MOREPACKETSVEHICLE);
}
/**
* Checks a player.
*
@ -68,7 +57,7 @@ public class MorePacketsVehicle extends Check {
* @return the location
*/
public Location check(final Player player, final Location from, final Location to) {
final MovingConfig cc = MovingConfig.getConfig(player);
MovingConfig.getConfig(player);
final MovingData data = MovingData.getData(player);
Location newTo = null;
@ -88,13 +77,9 @@ public class MorePacketsVehicle extends Check {
// Increment violation level.
data.morePacketsVehicleVL = -data.morePacketsVehicleBuffer;
// Dispatch a more packets vehicle event (API).
final MorePacketsVehicleEvent e = new MorePacketsVehicleEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
if (!e.isCancelled() && executeActions(player, cc.morePacketsVehicleActions, data.morePacketsVehicleVL))
if (executeActions(player))
newTo = data.morePacketsVehicleSetback;
}
@ -137,20 +122,9 @@ public class MorePacketsVehicle extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(MovingData.getData(player).morePacketsVehicleVL));
else if (wildcard == ParameterName.PACKETS)
if (wildcard == ParameterName.PACKETS)
return String.valueOf(MovingData.getData(player).morePacketsVehiclePackets);
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.MOVING_MOREPACKETSVEHICLE)
&& MovingConfig.getConfig(player).morePacketsVehicleCheck;
}
}

View File

@ -67,8 +67,6 @@ public class MovingConfig {
public final ActionList noFallActions;
public final boolean survivalFlyCheck;
public final boolean survivalFlyAllowFastBlocking;
public final boolean survivalFlyAllowFastSneaking;
public final int survivalFlyBlockingSpeed;
public final int survivalFlyCobWebSpeed;
public final int survivalFlyLadderSpeed;
@ -105,8 +103,6 @@ public class MovingConfig {
noFallActions = data.getActionList(ConfPaths.MOVING_NOFALL_ACTIONS, Permissions.MOVING_NOFALL);
survivalFlyCheck = data.getBoolean(ConfPaths.MOVING_SURVIVALFLY_CHECK);
survivalFlyAllowFastBlocking = data.getBoolean(ConfPaths.MOVING_SURVIVALFLY_ALLOWFASTBLOCKING);
survivalFlyAllowFastSneaking = data.getBoolean(ConfPaths.MOVING_SURVIVALFLY_ALLOWFASTSNEAKING);
// Default values are specified here because this settings aren't showed by default into the configuration file.
survivalFlyBlockingSpeed = data.getInt(ConfPaths.MOVING_SURVIVALFLY_BLOCKINGSPEED, 100);
survivalFlyCobWebSpeed = data.getInt(ConfPaths.MOVING_SURVIVALFLY_COBWEBSPEED, 100);

View File

@ -76,10 +76,11 @@ public class MovingData {
public float noFallLastAddedDistance;
// Data of the survival fly check.
public int survivalFlyJumpPhase;
public int survivalFlyOnIce;
public long survivalFlyInLavaSince;
public long survivalFlyInWaterSince;
public int survivalFlyJumpPhase;
public double[] survivalFlyLastDistances = new double[] {0D, 0D};
public int survivalFlyOnIce;
public long survivalFlyOnLadderSince;
// Locations shared between all checks.

View File

@ -111,7 +111,7 @@ public class MovingListener implements Listener {
final MovingData data = MovingData.getData(player);
final int blockY = event.getBlock().getY();
if (isLiquid(event.getBlockAgainst().getType()))
if (isLiquid(event.getBlockAgainst().getType()) && event.getBlock().getType() != Material.WATER_LILY)
// The block was placed against a liquid block, cancel its placement.
event.setCancelled(true);
else if ((creativeFly.isEnabled(player) || survivalFly.isEnabled(player)) && event.getBlock() != null

View File

@ -2,15 +2,13 @@ package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
/*
@ -28,19 +26,10 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
public class NoFall extends Check {
/**
* The event triggered by this check.
* Instantiates a new no fall check.
*/
public class NoFallEvent extends CheckEvent {
/**
* Instantiates a new no fall event.
*
* @param player
* the player
*/
public NoFallEvent(final Player player) {
super(player);
}
public NoFall() {
super(CheckType.MOVING_NOFALL);
}
/**
@ -78,13 +67,9 @@ public class NoFall extends Check {
// Increment violation level.
data.noFallVL += player.getFallDistance();
// Dispatch a no fall event (API).
final NoFallEvent e = new NoFallEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
if (!e.isCancelled() && executeActions(player, cc.noFallActions, data.noFallVL))
if (executeActions(player))
// Deal fall damages to the player.
((CraftPlayer) player).getHandle().b(0D, true);
data.noFallDistance = 0F;
@ -104,13 +89,9 @@ public class NoFall extends Check {
// Increment violation level.
data.noFallVL += difference;
// Dispatch a no fall event (API).
final NoFallEvent e = new NoFallEvent(player);
Bukkit.getPluginManager().callEvent(e);
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event. If "cancelled", the fall damage gets dealt in a way that's visible to other plugins.
if (!e.isCancelled() && executeActions(player, cc.noFallActions, data.noFallVL))
if (executeActions(player))
// Increase the fall distance a bit. :)
player.setFallDistance(data.noFallDistance + difference);
data.noFallDistance = 0F;
@ -123,7 +104,7 @@ public class NoFall extends Check {
// feeling.
if (from.getY() > to.getY()) {
final float deltaY = (float) (from.getY() - to.getY());
data.noFallDistance += deltaY;
data.noFallDistance += deltaY * 0.75F; // Magic number. :)
if (deltaY > 1F) {
data.noFallLastAddedDistance = deltaY;
@ -133,6 +114,9 @@ public class NoFall extends Check {
} else
data.noFallLastAddedDistance = 0F;
if (to.isOnGround())
data.noFallDistance = 0F;
// Reduce violation level.
data.noFallVL *= 0.95D;
}
@ -143,19 +127,9 @@ public class NoFall extends Check {
*/
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(MovingData.getData(player).noFallVL));
else if (wildcard == ParameterName.FALL_DISTANCE)
if (wildcard == ParameterName.FALL_DISTANCE)
return String.format(Locale.US, "%.2f", MovingData.getData(player).noFallDistance);
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.MOVING_NOFALL) && MovingConfig.getConfig(player).noFallCheck;
}
}

View File

@ -5,14 +5,13 @@ import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckEvent;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.players.Permissions;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
@ -33,22 +32,6 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
*/
public class SurvivalFly extends Check {
/**
* The event triggered by this check.
*/
public class SurvivalFlyEvent extends CheckEvent {
/**
* Instantiates a new survival fly event.
*
* @param player
* the player
*/
public SurvivalFlyEvent(final Player player) {
super(player);
}
}
/** The common margin of error for some speeds. */
private static final double MARGIN = 0.001D;
@ -115,6 +98,13 @@ public class SurvivalFly extends Check {
/** The no fall check. */
private final NoFall noFall = new NoFall();
/**
* Instantiates a new survival fly check.
*/
public SurvivalFly() {
super(CheckType.MOVING_SURVIVALFLY);
}
/**
* Checks a player.
*
@ -157,9 +147,9 @@ public class SurvivalFly extends Check {
else if (from.isOnSoulSand() && to.isOnSoulSand() && sprinting) {
hAllowedDistance = cc.survivalFlySoulSandSpeed / 100D * SOULSAND_SPRINTING_MOVE;
useBuffer = false;
} else if (player.isSneaking())
} else if (player.isSneaking() && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_SNEAKING))
hAllowedDistance = cc.survivalFlySneakingSpeed / 100D * SNEAKING_MOVE;
else if (player.isBlocking())
else if (player.isBlocking() && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_BLOCKING))
hAllowedDistance = cc.survivalFlyBlockingSpeed / 100D * BLOCKING_MOVE;
else if (from.isInWater() && to.isInWater())
hAllowedDistance = cc.survivalFlyWaterSpeed / 100D * WATER_MOVE;
@ -262,8 +252,17 @@ public class SurvivalFly extends Check {
vDistanceAboveLimit = cc.survivalFlyLadderSpeed / 100D * -LADDER_DESCEND - vDistance;
} else {
vDistance = to.getY() - data.setBack.getY();
if (vDistance <= 0D)
if (data.survivalFlyLastDistances[0] < data.survivalFlyLastDistances[1]
&& vDistance > data.survivalFlyLastDistances[0] && data.survivalFlyJumpPhase >= 7
&& data.survivalFlyJumpPhase <= 8) {
data.survivalFlyJumpPhase = 0;
data.noFallDistance = 0f;
} else if (vDistance <= 0D)
data.survivalFlyJumpPhase = 0;
data.survivalFlyLastDistances[1] = data.survivalFlyLastDistances[0];
data.survivalFlyLastDistances[0] = vDistance;
double vAllowedDistance = (data.verticalFreedom + 1.35D) * data.jumpAmplifier;
if (data.survivalFlyJumpPhase > JUMP_PHASE + data.jumpAmplifier)
@ -273,10 +272,9 @@ public class SurvivalFly extends Check {
}
// Handle slabs placed into a liquid.
if (from.isInLiquid()
&& to.isInLiquid()
&& (to.isOnGround() && to.getY() - from.getY() == 0.5D || !from.isOnGround() && to.isOnGround() || from
.isOnGround() && !to.isOnGround()))
if ((to.isOnGround() && to.getY() - from.getY() == 0.5D || !from.isOnGround() && to.isOnGround() || from
.isOnGround() && !to.isOnGround())
&& from.isInLiquid() && to.isInLiquid())
vDistanceAboveLimit = 0D;
if (from.isOnGround() || to.isOnGround())
@ -294,13 +292,9 @@ public class SurvivalFly extends Check {
// Increment violation counter.
data.survivalFlyVL += result;
// Dispatch a survival fly event (API).
final SurvivalFlyEvent e = new SurvivalFlyEvent(player);
Bukkit.getPluginManager().callEvent(e);
// If the other plugins haven't decided to cancel the execution of the actions, then do it. If one of the
// actions was a cancel, cancel it.
if (!e.isCancelled() && executeActions(player, cc.survivalFlyActions, data.survivalFlyVL))
if (executeActions(player))
// Compose a new location based on coordinates of "newTo" and viewing direction of "event.getTo()" to
// allow the player to look somewhere else despite getting pulled back by NoCheatPlus.
return new Location(player.getWorld(), data.setBack.getX(), data.setBack.getY(), data.setBack.getZ(),
@ -348,9 +342,7 @@ public class SurvivalFly extends Check {
@Override
public String getParameter(final ParameterName wildcard, final Player player) {
final MovingData data = MovingData.getData(player);
if (wildcard == ParameterName.VIOLATIONS)
return String.valueOf(Math.round(data.survivalFlyVL));
else if (wildcard == ParameterName.LOCATION_FROM)
if (wildcard == ParameterName.LOCATION_FROM)
return String.format(Locale.US, "%.2f, %.2f, %.2f", data.from.getX(), data.from.getY(), data.from.getZ());
else if (wildcard == ParameterName.LOCATION_TO)
return String.format(Locale.US, "%.2f, %.2f, %.2f", data.to.getX(), data.to.getY(), data.to.getZ());
@ -359,12 +351,4 @@ public class SurvivalFly extends Check {
else
return super.getParameter(wildcard, player);
}
/* (non-Javadoc)
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
*/
@Override
protected boolean isEnabled(final Player player) {
return !player.hasPermission(Permissions.MOVING_SURVIVALFLY) && MovingConfig.getConfig(player).survivalFlyCheck;
}
}

View File

@ -324,8 +324,6 @@ public abstract class ConfPaths {
private static final String MOVING_SURVIVALFLY = MOVING + "survivalfly.";
public static final String MOVING_SURVIVALFLY_CHECK = MOVING_SURVIVALFLY + "active";
public static final String MOVING_SURVIVALFLY_ALLOWFASTSNEAKING = MOVING_SURVIVALFLY + "allowfastsneaking";
public static final String MOVING_SURVIVALFLY_ALLOWFASTBLOCKING = MOVING_SURVIVALFLY + "allowfastblocking";
public static final String MOVING_SURVIVALFLY_BLOCKINGSPEED = MOVING_SURVIVALFLY + "blockingspeed";
public static final String MOVING_SURVIVALFLY_COBWEBSPEED = MOVING_SURVIVALFLY + "cobwebspeed";
public static final String MOVING_SURVIVALFLY_LAVASPEED = MOVING_SURVIVALFLY + "lavaspeed";

View File

@ -63,7 +63,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.BLOCKBREAK_FASTBREAK_BUFFER, 5);
set(ConfPaths.BLOCKBREAK_FASTBREAK_EXPERIMENTAL, true);
set(ConfPaths.BLOCKBREAK_FASTBREAK_INTERVAL, 100);
set(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, "cancel vl>100 log:fastinteract:3:5:cif cancel");
set(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, "cancel vl>100 log:fastbreak:3:5:cif cancel");
set(ConfPaths.BLOCKBREAK_NOSWING_CHECK, true);
set(ConfPaths.BLOCKBREAK_NOSWING_ACTIONS, "log:noswing:3:2:if cancel");
@ -280,8 +280,6 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.MOVING_NOFALL_ACTIONS, "log:nofall:0:5:cif cancel");
set(ConfPaths.MOVING_SURVIVALFLY_CHECK, true);
set(ConfPaths.MOVING_SURVIVALFLY_ALLOWFASTBLOCKING, false);
set(ConfPaths.MOVING_SURVIVALFLY_ALLOWFASTSNEAKING, false);
// The settings aren't enabled by default. Simply write them yourself in the configuration file.
// set(ConfPaths.MOVING_SURVIVALFLY_BLOCKINGSPEED, 100);
// set(ConfPaths.MOVING_SURVIVALFLY_COBWEBSPEED, 100);
@ -313,6 +311,7 @@ public class DefaultConfig extends ConfigFile {
set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end);
set(ConfPaths.STRINGS + ".breach", start
+ "tried to interact with a block over distance [reachdistance] block(s)" + end);
set(ConfPaths.STRINGS + ".color", start + "sent colored chat message" + end);
set(ConfPaths.STRINGS + ".critical", start + "tried to do a critical hit but wasn't technically jumping" + end);
set(ConfPaths.STRINGS + ".drop", start + "tried to drop more items than allowed" + end);
set(ConfPaths.STRINGS + ".fastbreak", start + "tried to break too much blocks" + end);

View File

@ -0,0 +1,28 @@
package fr.neatmonster.nocheatplus.hooks;
/*
* MMP"""""""MM dP dP dP
* M' .mmmm MM 88 88 88
* M `M 88d888b. .d8888b. d8888P 88d888b. .d8888b. .d8888b. d8888P
* M MMMMM MM 88' `88 Y8ooooo. 88 88' `88 88' `88 88' `"" 88
* M MMMMM MM 88. .88 88 88 88 88. .88 88. ... 88
* M MMMMM MM 88Y8888' `88888P' dP dP `88888P8 `88888P' dP
* MMMMMMMMMMMM
*
* M"""""""`YM MM'""""'YMM MM"""""""`YM M""MMMMM""MM dP
* M mmmm. M M' .mmm. `M MM mmmmm M M MMMMM MM 88
* M MMMMM M M MMMMMooM M' .M M `M .d8888b. .d8888b. 88 .dP
* M MMMMM M M MMMMMMMM MM MMMMMMMM M MMMMM MM 88' `88 88' `88 88888"
* M MMMMM M M. `MMM' .M MM MMMMMMMM M MMMMM MM 88. .88 88. .88 88 `8b.
* M MMMMM M MM. .dM MM MMMMMMMM M MMMMM MM `88888P' `88888P' dP `YP
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMM
*/
/**
* Extend this class for maximum future compatibility.<br>
*
* Especially the onCheckFailure method might get extended with check specific arguments, this class will provide
* compatibility with older method signatures, where possible.
*
* @author asofold
*/
public abstract class AbstractNCPHook implements NCPHook {}

View File

@ -0,0 +1,52 @@
package fr.neatmonster.nocheatplus.hooks;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""""`YM MM'""""'YMM MM"""""""`YM M""MMMMM""MM dP
* M mmmm. M M' .mmm. `M MM mmmmm M M MMMMM MM 88
* M MMMMM M M MMMMMooM M' .M M `M .d8888b. .d8888b. 88 .dP
* M MMMMM M M MMMMMMMM MM MMMMMMMM M MMMMM MM 88' `88 88' `88 88888"
* M MMMMM M M. `MMM' .M MM MMMMMMMM M MMMMM MM 88. .88 88. .88 88 `8b.
* M MMMMM M MM. .dM MM MMMMMMMM M MMMMM MM `88888P' `88888P' dP `YP
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMM
*/
/**
* Compatibility hooks have to implement this.
*
* @author asofold
*/
public interface NCPHook {
/**
* For logging purposes.
*
* @return the hook name
*/
public String getHookName();
/**
* For logging purposes.
*
* @return the hook version
*/
public String getHookVersion();
/**
* This is called on failure of a check.<br>
*
* This is the minimal interface, it might later be extended by specific information like (target) locations and VL,
* but with this a lot is possible already (see CNCP).<br>
*
* See AbstractNCPHook for future compatibility questions.
*
* @param checkType
* the check that failed.
* @param player
* the player that failed the check.
* @return if to cancel the check failure processing.
*/
public boolean onCheckFailure(CheckType checkType, Player player);
}

View File

@ -0,0 +1,405 @@
package fr.neatmonster.nocheatplus.hooks;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.CheckType;
/*
* M"""""""`YM MM'""""'YMM MM"""""""`YM M""MMMMM""MM dP
* M mmmm. M M' .mmm. `M MM mmmmm M M MMMMM MM 88
* M MMMMM M M MMMMMooM M' .M M `M .d8888b. .d8888b. 88 .dP
* M MMMMM M M MMMMMMMM MM MMMMMMMM M MMMMM MM 88' `88 88' `88 88888"
* M MMMMM M M. `MMM' .M MM MMMMMMMM M MMMMM MM 88. .88 88. .88 88 `8b.
* M MMMMM M MM. .dM MM MMMMMMMM M MMMMM MM `88888P' `88888P' dP `YP
* MMMMMMMMMMM MMMMMMMMMMM MMMMMMMMMMMM MMMMMMMMMMMM
*
* M"""""`'"""`YM
* M mm. mm. M
* M MMM MMM M .d8888b. 88d888b. .d8888b. .d8888b. .d8888b. 88d888b.
* M MMM MMM M 88' `88 88' `88 88' `88 88' `88 88ooood8 88' `88
* M MMM MMM M 88. .88 88 88 88. .88 88. .88 88. ... 88
* M MMM MMM M `88888P8 dP dP `88888P8 `8888P88 `88888P' dP
* MMMMMMMMMMMMMM .88
* d8888P
*/
/**
* After-check-failure hook manager integrated into NoCheatPlus.
*
* @author asofold
*/
public final class NCPHookManager {
/** Ids given to hooks. */
private static int maxHookId = 0;
/** Hook id to hook. */
private final static Map<Integer, NCPHook> allHooks = new HashMap<Integer, NCPHook>();
/** Mapping the check types to the hooks. */
private static final Map<CheckType, List<NCPHook>> hooksByChecks = new HashMap<CheckType, List<NCPHook>>();
/**
* Register a hook for a specific check type (all, group, or an individual check).
*
* @param checkType
* the check type
* @param hook
* the hook
* @return an id to identify the hook, will return the existing id if the hook was already present somewhere
*/
public static Integer addHook(final CheckType checkType, final NCPHook hook) {
final Integer hookId = getId(hook);
addToMappings(checkType, hook);
logHookAdded(hook);
return hookId;
}
/**
* Register a hook for several individual checks ids (all, group, or an individual checks).
*
* @param checkTypes
* array of check types to register the hook for. If you pass null this hook will be registered for all
* checks
* @param hook
* the hook
* @return the hook id
*/
public static Integer addHook(CheckType[] checkTypes, final NCPHook hook) {
if (checkTypes == null)
checkTypes = new CheckType[] {CheckType.ALL};
final Integer hookId = getId(hook);
for (final CheckType checkType : checkTypes)
addToMappings(checkType, hook);
logHookAdded(hook);
return hookId;
}
/**
* Add to the mapping for given check type (only).
*
* @param checkType
* the check type
* @param hook
* the hook
*/
private static void addToMapping(final CheckType checkType, final NCPHook hook) {
List<NCPHook> hooks = hooksByChecks.get(checkType);
if (hooks == null) {
hooks = new ArrayList<NCPHook>();
hooks.add(hook);
hooksByChecks.put(checkType, hooks);
} else if (!hooks.contains(hook))
hooks.add(hook);
}
/**
* Add hook to the hooksByChecks mappings, for the check type and if present, group type. Assumes that the hook
* already has been registered in the allHooks map.
*
* @param checkType
* the check type
* @param hook
* the hook
*/
private static void addToMappings(final CheckType checkType, final NCPHook hook) {
addToMapping(checkType, hook);
if (checkType.group != null)
addToMapping(checkType.group, hook);
}
/**
* Call the hooks for the specified check type and player.
*
* @param checkType
* the check type
* @param player
* the player
* @param hooks
* the hooks
* @return true, if a hook as decided to cancel the VL processing
*/
private static final boolean applyHooks(final CheckType checkType, final Player player, final List<NCPHook> hooks) {
for (int i = 0; i < hooks.size(); i++) {
final NCPHook hook = hooks.get(i);
try {
if (hook.onCheckFailure(checkType, player))
return true;
} catch (final Throwable t) {
// TODO: maybe distinguish some exceptions here (interrupted ?).
logHookFailure(checkType, player, hook, t);
}
}
return false;
}
/**
* Get a collection of all hooks.
*
* @return all the hooks
*/
public static Collection<NCPHook> getAllHooks() {
final List<NCPHook> hooks = new LinkedList<NCPHook>();
hooks.addAll(allHooks.values());
return hooks;
}
/**
* Get the hook description.
*
* @param hook
* the hook
* @return the hook description
*/
private static final String getHookDescription(final NCPHook hook) {
return hook.getHookName() + " [" + hook.getHookVersion() + "]";
}
/**
* Get hooks by their hook name.
*
* @param hookName
* case sensitive (exact match)
* @return the collection of NCP hooks matching the hook name
*/
public static Collection<NCPHook> getHooksByName(final String hookName) {
final List<NCPHook> hooks = new LinkedList<NCPHook>();
for (final Integer refId : allHooks.keySet()) {
final NCPHook hook = allHooks.get(refId);
if (hook.getHookName().equals(hookName) && !hooks.contains(hook))
hooks.add(hook);
}
return hooks;
}
/**
* For registration purposes only.
*
* @param hook
* the hook
* @return unique id associated with that hook (returns an existing id if hook is already present)
*/
private static Integer getId(final NCPHook hook) {
if (hook == null)
// Just in case.
throw new NullPointerException("Hooks must not be null.");
Integer id = null;
for (final Integer refId : allHooks.keySet())
if (hook == allHooks.get(refId)) {
id = refId;
break;
}
if (id == null) {
id = getNewHookId();
allHooks.put(id, hook);
}
return id;
}
/**
* Gets the new hook id.
*
* @return the new hook id
*/
private static Integer getNewHookId() {
maxHookId++;
return maxHookId;
}
/**
* Log that a hook was added.
*
* @param hook
* the hook
*/
private static final void logHookAdded(final NCPHook hook) {
Bukkit.getLogger().info("[NoCheatPlus] Added hook: " + getHookDescription(hook) + ".");
}
/**
* Log that a hook failed.
*
* @param checkType
* the check type
* @param player
* the player
* @param hook
* the hook
* @param throwable
* the throwable
*/
private static final void logHookFailure(final CheckType checkType, final Player player, final NCPHook hook,
final Throwable t) {
// TODO: Might accumulate failure rate and only log every so and so seconds or disable hook if spamming (leads
// to NCP spam though)?
final StringBuilder builder = new StringBuilder(1024);
builder.append("[NoCheatPlus] Hook " + getHookDescription(hook) + " encountered an unexpected exception:\n");
builder.append("Processing: ");
if (checkType.group != null)
builder.append("Group " + checkType.group + " ");
builder.append("Check " + checkType);
builder.append(" Player " + player.getName());
builder.append("\n");
builder.append("Exception (" + t.getClass().getSimpleName() + "): " + t.getMessage() + "\n");
for (final StackTraceElement el : t.getStackTrace())
builder.append(el.toString());
Bukkit.getLogger().severe(builder.toString());
}
/**
* Log that a hook was removed.
*
* @param hook
* the hook
*/
private static final void logHookRemoved(final NCPHook hook) {
Bukkit.getLogger().info("[NoCheatPlus] Removed hook: " + getHookDescription(hook) + ".");
}
/**
* Removes all the hooks.
*
* @return the collection
*/
public static Collection<NCPHook> removeAllHooks() {
final Collection<NCPHook> hooks = getAllHooks();
for (final NCPHook hook : hooks)
removeHook(hook);
return hooks;
}
/**
* Remove from internal mappings, both allHooks and hooksByChecks.
*
* @param hook
* the hook
* @param hookId
* the hook id
*/
private static void removeFromMappings(final NCPHook hook, final Integer hookId) {
allHooks.remove(hookId);
final List<CheckType> rem = new LinkedList<CheckType>();
for (final CheckType checkId : hooksByChecks.keySet()) {
final List<NCPHook> hooks = hooksByChecks.get(checkId);
if (hooks.remove(hook))
if (hooks.isEmpty())
rem.add(checkId);
}
for (final CheckType checkId : rem)
hooksByChecks.remove(checkId);
}
/**
* Remove a hook by its hook id (returned on adding hooks).
*
* @param hookId
* if present, null otherwise
* @return the NCP hook
*/
public static NCPHook removeHook(final Integer hookId) {
final NCPHook hook = allHooks.get(hookId);
if (hook == null)
return null;
removeFromMappings(hook, hookId);
logHookRemoved(hook);
return hook;
}
/**
* Remove a hook.
*
* @param hook
* the hook
* @return hook id if present, null otherwise
*/
public static Integer removeHook(final NCPHook hook) {
Integer hookId = null;
for (final Integer refId : allHooks.keySet())
if (hook == allHooks.get(refId)) {
hookId = refId;
break;
}
if (hookId == null)
return null;
removeFromMappings(hook, hookId);
logHookRemoved(hook);
return hookId;
}
/**
* Remove a collection of hooks.
*
* @param hooks
* the hooks
* @return a set of the removed hooks ids
*/
public static Set<Integer> removeHooks(final Collection<NCPHook> hooks) {
final Set<Integer> ids = new HashSet<Integer>();
for (final NCPHook hook : hooks) {
final Integer id = removeHook(hook);
if (id != null)
ids.add(id);
}
return ids;
}
/**
* Remove hooks by their name (case sensitive, exact match).
*
* @param hookName
* the hook name
* @return the collection of NCP hooks removed
*/
public static Collection<NCPHook> removeHooks(final String hookName) {
final Collection<NCPHook> hooks = getHooksByName(hookName);
if (hooks.isEmpty())
return null;
removeHooks(hooks);
return hooks;
}
/**
* This is called by checks when players fail them.
*
* @param checkType
* the check type
* @param player
* the player that fails the check
* @return if we should cancel the VL processing
*/
public static final boolean shouldCancelVLProcessing(final CheckType checkType, final Player player) {
// Checks for hooks registered for all events, only for the group and specifically for the check.
// A paradigm could be to return true as soon as one hook has returned true.
// Check specific.
final List<NCPHook> hooksCheck = hooksByChecks.get(checkType);
if (hooksCheck != null)
if (applyHooks(checkType, player, hooksCheck))
return true;
// Group specific.
if (checkType.group != null) {
final List<NCPHook> hooksGroup = hooksByChecks.get(checkType);
if (hooksCheck != null)
if (applyHooks(checkType, player, hooksGroup))
return true;
}
// General (all).
final List<NCPHook> hooksAll = hooksByChecks.get(CheckType.ALL);
if (hooksAll != null)
if (applyHooks(checkType, player, hooksAll))
return true;
return false;
}
}

View File

@ -13,7 +13,7 @@ package fr.neatmonster.nocheatplus.players;
* The various permission nodes used by NoCheatPlus.
*/
public class Permissions {
private static final String NOCHEATPLUS = "nocheatplus";
private static final String NOCHEATPLUS = "nocheatplus";
/*
* e Y8b 888 ,e, ,e, d8 d8 ,e,
@ -22,10 +22,10 @@ public class Permissions {
* d888888888b Y888 888 888 888 888 888 888 888 888 Y88D 888 888 ,ee 888 888 888 Y888 888P 888 888
* d8888888b Y8b "88 888 888 888 888 888 888 888 888 d,dP 888 888 "88 888 888 888 "88 88" 888 888
*/
private static final String ADMINISTRATION = NOCHEATPLUS + ".admin";
public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify";
public static final String ADMINISTRATION_PLUGINS = ADMINISTRATION + ".plugins";
public static final String ADMINISTRATION_RELOAD = ADMINISTRATION + ".reload";
private static final String ADMINISTRATION = NOCHEATPLUS + ".admin";
public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify";
public static final String ADMINISTRATION_PLUGINS = ADMINISTRATION + ".plugins";
public static final String ADMINISTRATION_RELOAD = ADMINISTRATION + ".reload";
/*
* e e 888 ,e, dP,e, ,e, d8 ,e,
@ -34,36 +34,36 @@ public class Permissions {
* d8b Y8b Y8b Y888 888P Y888 888 888 888 888 Y888 , ,ee 888 888 888 Y888 888P 888 888 Y88D
* d888b Y8b Y8b "88 88" "88 888 888 888 888 "88,e8' "88 888 888 888 "88 88" 888 888 d,dP
*/
private static final String MODS = NOCHEATPLUS + ".mods";
private static final String MODS = NOCHEATPLUS + ".mods";
private static final String CJB = MODS + ".cjb";
public static final String CJB_FLY = CJB + ".fly";
public static final String CJB_XRAY = CJB + ".xray";
public static final String CJB_RADAR = CJB + ".radar";
private static final String CJB = MODS + ".cjb";
public static final String CJB_FLY = CJB + ".fly";
public static final String CJB_XRAY = CJB + ".xray";
public static final String CJB_RADAR = CJB + ".radar";
private static final String MINECRAFTAUTOMAP = MODS + ".minecraftautomap";
public static final String MINECRAFTAUTOMAP_ORES = MINECRAFTAUTOMAP + ".ores";
public static final String MINECRAFTAUTOMAP_CAVE = MINECRAFTAUTOMAP + ".cave";
public static final String MINECRAFTAUTOMAP_RADAR = MINECRAFTAUTOMAP + ".radar";
private static final String MINECRAFTAUTOMAP = MODS + ".minecraftautomap";
public static final String MINECRAFTAUTOMAP_ORES = MINECRAFTAUTOMAP + ".ores";
public static final String MINECRAFTAUTOMAP_CAVE = MINECRAFTAUTOMAP + ".cave";
public static final String MINECRAFTAUTOMAP_RADAR = MINECRAFTAUTOMAP + ".radar";
private static final String REI = MODS + ".rei";
public static final String REI_CAVE = REI + ".cave";
public static final String REI_RADAR = REI + ".radar";
private static final String REI = MODS + ".rei";
public static final String REI_CAVE = REI + ".cave";
public static final String REI_RADAR = REI + ".radar";
private static final String SMARTMOVING = MODS + ".smartmoving";
public static final String SMARTMOVING_CLIMBING = SMARTMOVING + ".climbing";
public static final String SMARTMOVING_SWIMMING = SMARTMOVING + ".swimming";
public static final String SMARTMOVING_CRAWLING = SMARTMOVING + ".crawling";
public static final String SMARTMOVING_SLIDING = SMARTMOVING + ".sliding";
public static final String SMARTMOVING_JUMPING = SMARTMOVING + ".jumping";
public static final String SMARTMOVING_FLYING = SMARTMOVING + ".flying";
private static final String SMARTMOVING = MODS + ".smartmoving";
public static final String SMARTMOVING_CLIMBING = SMARTMOVING + ".climbing";
public static final String SMARTMOVING_SWIMMING = SMARTMOVING + ".swimming";
public static final String SMARTMOVING_CRAWLING = SMARTMOVING + ".crawling";
public static final String SMARTMOVING_SLIDING = SMARTMOVING + ".sliding";
public static final String SMARTMOVING_JUMPING = SMARTMOVING + ".jumping";
public static final String SMARTMOVING_FLYING = SMARTMOVING + ".flying";
private static final String ZOMBE = MODS + ".zombe";
public static final String ZOMBE_FLY = ZOMBE + ".fly";
public static final String ZOMBE_NOCLIP = ZOMBE + ".noclip";
public static final String ZOMBE_CHEAT = ZOMBE + ".cheat";
private static final String ZOMBE = MODS + ".zombe";
public static final String ZOMBE_FLY = ZOMBE + ".fly";
public static final String ZOMBE_NOCLIP = ZOMBE + ".noclip";
public static final String ZOMBE_CHEAT = ZOMBE + ".cheat";
private static final String CHECKS = NOCHEATPLUS + ".checks";
private static final String CHECKS = NOCHEATPLUS + ".checks";
/*
* 888 88b, 888 888 888 88b, 888
@ -72,11 +72,11 @@ public class Permissions {
* 888 88b, 888 Y888 888P Y888 , 888 b 888 88b, 888 888 , ,ee 888 888 b
* 888 88P' 888 "88 88" "88,e8' 888 8b 888 88P' 888 "YeeP" "88 888 888 8b
*/
private static final String BLOCKBREAK = CHECKS + ".blockbreak";
public static final String BLOCKBREAK_DIRECTION = BLOCKBREAK + ".direction";
public static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + ".fastbreak";
public static final String BLOCKBREAK_NOSWING = BLOCKBREAK + ".noswing";
public static final String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";
private static final String BLOCKBREAK = CHECKS + ".blockbreak";
public static final String BLOCKBREAK_DIRECTION = BLOCKBREAK + ".direction";
public static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + ".fastbreak";
public static final String BLOCKBREAK_NOSWING = BLOCKBREAK + ".noswing";
public static final String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";
/*
* 888 88b, 888 888 888 d8 d8
@ -85,10 +85,10 @@ public class Permissions {
* 888 88b, 888 Y888 888P Y888 , 888 b 888 888 888 888 888 , 888 ,ee 888 Y888 , 888
* 888 88P' 888 "88 88" "88,e8' 888 8b 888 888 888 888 "YeeP" 888 "88 888 "88,e8' 888
*/
private static final String BLOCKINTERACT = CHECKS + ".blockinteract";
public static final String BLOCKINTERACT_DIRECTION = BLOCKINTERACT + ".direction";
public static final String BLOCKINTERACT_NOSWING = BLOCKINTERACT + ".noswing";
public static final String BLOCKINTERACT_REACH = BLOCKINTERACT + ".reach";
private static final String BLOCKINTERACT = CHECKS + ".blockinteract";
public static final String BLOCKINTERACT_DIRECTION = BLOCKINTERACT + ".direction";
public static final String BLOCKINTERACT_NOSWING = BLOCKINTERACT + ".noswing";
public static final String BLOCKINTERACT_REACH = BLOCKINTERACT + ".reach";
/*
* 888 88b, 888 888 888 88e 888
@ -97,12 +97,12 @@ public class Permissions {
* 888 88b, 888 Y888 888P Y888 , 888 b 888 888 ,ee 888 Y888 , 888 ,
* 888 88P' 888 "88 88" "88,e8' 888 8b 888 888 "88 888 "88,e8' "YeeP"
*/
private static final String BLOCKPLACE = CHECKS + ".blockplace";
public static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + ".direction";
public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + ".fastplace";
public static final String BLOCKPLACE_NOSWING = BLOCKPLACE + ".noswing";
public static final String BLOCKPLACE_REACH = BLOCKPLACE + ".reach";
public static final String BLOCKPLACE_SPEED = BLOCKPLACE + ".speed";
private static final String BLOCKPLACE = CHECKS + ".blockplace";
public static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + ".direction";
public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + ".fastplace";
public static final String BLOCKPLACE_NOSWING = BLOCKPLACE + ".noswing";
public static final String BLOCKPLACE_REACH = BLOCKPLACE + ".reach";
public static final String BLOCKPLACE_SPEED = BLOCKPLACE + ".speed";
/*
* e88'Y88 888 d8
@ -111,10 +111,10 @@ public class Permissions {
* Y888 ,d 888 888 ,ee 888 888
* "88,d88 888 888 "88 888 888
*/
private static final String CHAT = CHECKS + ".chat";
public static final String CHAT_ARRIVALS = CHAT + ".arrivals";
public static final String CHAT_COLOR = CHAT + ".color";
public static final String CHAT_NOPWNAGE = CHAT + ".nopwnage";
private static final String CHAT = CHECKS + ".chat";
public static final String CHAT_ARRIVALS = CHAT + ".arrivals";
public static final String CHAT_COLOR = CHAT + ".color";
public static final String CHAT_NOPWNAGE = CHAT + ".nopwnage";
/*
* 888'Y88 ,e, 888 d8
@ -125,16 +125,16 @@ public class Permissions {
* , 88P
* "8",P"
*/
private static final String FIGHT = CHECKS + ".fight";
public static final String FIGHT_ANGLE = FIGHT + ".angle";
public static final String FIGHT_CRITICAL = FIGHT + ".critical";
public static final String FIGHT_DIRECTION = FIGHT + ".direction";
public static final String FIGHT_GODMODE = FIGHT + ".godmode";
public static final String FIGHT_INSTANTHEAL = FIGHT + ".instantheal";
public static final String FIGHT_KNOCKBACK = FIGHT + ".knockback";
public static final String FIGHT_NOSWING = FIGHT + ".noswing";
public static final String FIGHT_REACH = FIGHT + ".reach";
public static final String FIGHT_SPEED = FIGHT + ".speed";
private static final String FIGHT = CHECKS + ".fight";
public static final String FIGHT_ANGLE = FIGHT + ".angle";
public static final String FIGHT_CRITICAL = FIGHT + ".critical";
public static final String FIGHT_DIRECTION = FIGHT + ".direction";
public static final String FIGHT_GODMODE = FIGHT + ".godmode";
public static final String FIGHT_INSTANTHEAL = FIGHT + ".instantheal";
public static final String FIGHT_KNOCKBACK = FIGHT + ".knockback";
public static final String FIGHT_NOSWING = FIGHT + ".noswing";
public static final String FIGHT_REACH = FIGHT + ".reach";
public static final String FIGHT_SPEED = FIGHT + ".speed";
/*
* 888 d8
@ -145,10 +145,10 @@ public class Permissions {
* 888
* 888
*/
private static final String INVENTORY = CHECKS + ".inventory";
public static final String INVENTORY_DROP = INVENTORY + ".drop";
public static final String INVENTORY_INSTANTBOW = INVENTORY + ".instantbow";
public static final String INVENTORY_INSTANTEAT = INVENTORY + ".instanteat";
private static final String INVENTORY = CHECKS + ".inventory";
public static final String INVENTORY_DROP = INVENTORY + ".drop";
public static final String INVENTORY_INSTANTBOW = INVENTORY + ".instantbow";
public static final String INVENTORY_INSTANTEAT = INVENTORY + ".instanteat";
/*
* e e ,e,
@ -159,11 +159,13 @@ public class Permissions {
* , 88P
* "8",P"
*/
private static final String MOVING = CHECKS + ".moving";
public static final String MOVING_BOATSANYWHERE = MOVING + ".boatsanywhere";
public static final String MOVING_CREATIVEFLY = MOVING + ".creativefly";
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";
public static final String MOVING_MOREPACKETSVEHICLE = MOVING + ".morepacketsvehicle";
public static final String MOVING_NOFALL = MOVING + ".nofall";
public static final String MOVING_SURVIVALFLY = MOVING + ".survivalfly";
private static final String MOVING = CHECKS + ".moving";
public static final String MOVING_BOATSANYWHERE = MOVING + ".boatsanywhere";
public static final String MOVING_CREATIVEFLY = MOVING + ".creativefly";
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";
public static final String MOVING_MOREPACKETSVEHICLE = MOVING + ".morepacketsvehicle";
public static final String MOVING_NOFALL = MOVING + ".nofall";
public static final String MOVING_SURVIVALFLY = MOVING + ".survivalfly";
public static final String MOVING_SURVIVALFLY_BLOCKING = MOVING_SURVIVALFLY + ".blocking";
public static final String MOVING_SURVIVALFLY_SNEAKING = MOVING_SURVIVALFLY + ".sneaking";
}

View File

@ -61,30 +61,18 @@ public class CheckUtils {
}
/**
* Calculates the distance between the player and the intersection of the player's line of sight with the targeted
* block.
* Calculate the distance between two location, because for Bukkit distance is the distance squared and
* distanceSquared is the distance non-squared.
*
* @param player
* the player
* @param location
* the location
* @param location1
* the location1
* @param location2
* the location2
* @return the double
*/
public static double distance(final Player player, final Location location) {
final Location eyes = player.getEyeLocation();
final Vector directionUnit = eyes.getDirection().normalize();
final double xMin = (location.getX() - eyes.getX()) / directionUnit.getX();
final double xMax = (location.getX() + 1D - eyes.getX()) / directionUnit.getX();
final double yMin = (location.getY() - eyes.getY()) / directionUnit.getY();
final double yMax = (location.getY() + 1D - eyes.getY()) * directionUnit.getY();
final double zMin = (location.getZ() - eyes.getZ()) / directionUnit.getZ();
final double zMax = (location.getZ() + 1D - eyes.getZ()) / directionUnit.getZ();
final double min = Math.max(Math.max(Math.min(xMin, xMax), Math.min(yMin, yMax)), Math.min(zMin, zMax));
final double max = Math.min(Math.min(Math.max(xMin, xMax), Math.max(yMin, yMax)), Math.max(zMin, zMax));
if (max < 0D || min > max)
return max;
else
return min;
public static double distance(final Location location1, final Location location2) {
return Math.sqrt(Math.pow(location2.getX() - location1.getX(), 2)
+ Math.pow(location2.getY() - location1.getY(), 2) + Math.pow(location2.getZ() - location1.getZ(), 2));
}
/**