mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-08 07:41:23 +01:00
Reorganize some code to make it more obvious and added some comments.
This commit is contained in:
parent
d315e08296
commit
67d1931a65
@ -21,33 +21,29 @@ import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
public abstract class Check {
|
||||
|
||||
private final String name;
|
||||
private final String groupId; // used to bundle information of multiple checks
|
||||
private final String permission;
|
||||
// used to bundle information of multiple checks
|
||||
private final String groupId;
|
||||
private static final CommandSender noCheatCommandSender = new NoCheatCommandSender();
|
||||
protected final NoCheat plugin;
|
||||
|
||||
public Check(NoCheat plugin, String groupId, String name, String permission) {
|
||||
|
||||
public Check(NoCheat plugin, String groupId, String name) {
|
||||
this.plugin = plugin;
|
||||
this.groupId = groupId;
|
||||
this.name = name;
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public final String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute some actions for the specified player
|
||||
*
|
||||
* @param player
|
||||
* @param actions
|
||||
* @return
|
||||
*/
|
||||
protected final boolean executeActions(NoCheatPlayer player, Action[] actions) {
|
||||
|
||||
boolean special = false;
|
||||
|
||||
final long time = System.currentTimeMillis() / 1000;
|
||||
|
||||
final long time = System.currentTimeMillis() / 1000L;
|
||||
final ConfigurationCacheStore cc = player.getConfigurationStore();
|
||||
|
||||
for(Action ac : actions) {
|
||||
@ -67,6 +63,13 @@ public abstract class Check {
|
||||
return special;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect information about the players violations
|
||||
*
|
||||
* @param player
|
||||
* @param id
|
||||
* @param vl
|
||||
*/
|
||||
protected void incrementStatistics(NoCheatPlayer player, Id id, double vl) {
|
||||
player.getDataStore().getStatistics().increment(id, vl);
|
||||
}
|
||||
@ -91,12 +94,21 @@ public abstract class Check {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a parameter for commands or log actions with an actual
|
||||
* value. Individual checks should override this to get their own
|
||||
* parameters handled too.
|
||||
*
|
||||
* @param wildcard
|
||||
* @param player
|
||||
* @return
|
||||
*/
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.PLAYER)
|
||||
return player.getName();
|
||||
else if(wildcard == ParameterName.CHECK)
|
||||
return getName();
|
||||
return name;
|
||||
else if(wildcard == ParameterName.LOCATION) {
|
||||
Location l = player.getPlayer().getLocation();
|
||||
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
@ -10,14 +9,10 @@ public abstract class BlockBreakCheck extends Check {
|
||||
|
||||
private static final String id = "blockbreak";
|
||||
|
||||
public BlockBreakCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, id, name, permission);
|
||||
public BlockBreakCheck(NoCheat plugin, String name) {
|
||||
super(plugin, id, name);
|
||||
}
|
||||
|
||||
public abstract boolean check(NoCheatPlayer player, BlockBreakData data, BlockBreakConfig cc);
|
||||
|
||||
public abstract boolean isEnabled(BlockBreakConfig cc);
|
||||
|
||||
public static BlockBreakData getData(DataStore base) {
|
||||
BlockBreakData data = base.get(id);
|
||||
if(data == null) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -23,16 +22,16 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
*/
|
||||
public class BlockBreakCheckListener implements Listener, EventManager {
|
||||
|
||||
private final List<BlockBreakCheck> checks;
|
||||
private final NoCheat plugin;
|
||||
private final NoswingCheck noswingCheck;
|
||||
private final ReachCheck reachCheck;
|
||||
private final DirectionCheck directionCheck;
|
||||
private final NoCheat plugin;
|
||||
|
||||
public BlockBreakCheckListener(NoCheat plugin) {
|
||||
|
||||
// Three checks exist for this event type
|
||||
this.checks = new ArrayList<BlockBreakCheck>(3);
|
||||
this.checks.add(new NoswingCheck(plugin));
|
||||
this.checks.add(new ReachCheck(plugin));
|
||||
this.checks.add(new DirectionCheck(plugin));
|
||||
noswingCheck = new NoswingCheck(plugin);
|
||||
reachCheck = new ReachCheck(plugin);
|
||||
directionCheck = new DirectionCheck(plugin);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
@ -48,10 +47,6 @@ public class BlockBreakCheckListener implements Listener, EventManager {
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final BlockBreakConfig cc = BlockBreakCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.BLOCKBREAK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockBreakData data = BlockBreakCheck.getData(player.getDataStore());
|
||||
|
||||
data.brokenBlockLocation.set(event.getBlock());
|
||||
@ -64,12 +59,15 @@ public class BlockBreakCheckListener implements Listener, EventManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Go through all "blockbreak" checks
|
||||
for(BlockBreakCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
// Now do the actual checks, if still needed
|
||||
if(cc.noswingCheck && !player.hasPermission(Permissions.BLOCKBREAK_NOSWING)) {
|
||||
cancelled = noswingCheck.check(player, data, cc);
|
||||
}
|
||||
if(!cancelled && cc.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH)) {
|
||||
cancelled = reachCheck.check(player, data, cc);
|
||||
}
|
||||
if(!cancelled && cc.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION)) {
|
||||
cancelled = directionCheck.check(player, data, cc);
|
||||
}
|
||||
|
||||
if(cancelled)
|
||||
@ -117,11 +115,11 @@ public class BlockBreakCheckListener implements Listener, EventManager {
|
||||
|
||||
BlockBreakConfig bb = BlockBreakCheck.getConfig(cc);
|
||||
|
||||
if(bb.check && bb.directionCheck)
|
||||
if(bb.directionCheck)
|
||||
s.add("blockbreak.direction");
|
||||
if(bb.check && bb.reachCheck)
|
||||
if(bb.reachCheck)
|
||||
s.add("blockbreak.reach");
|
||||
if(bb.check && bb.noswingCheck)
|
||||
if(bb.noswingCheck)
|
||||
s.add("blockbreak.noswing");
|
||||
|
||||
return s;
|
||||
|
@ -12,7 +12,6 @@ import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
*/
|
||||
public class BlockBreakConfig implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
public final boolean reachCheck;
|
||||
public final double reachDistance;
|
||||
public final ActionList reachActions;
|
||||
@ -34,8 +33,5 @@ public class BlockBreakConfig implements ConfigItem {
|
||||
directionActions = data.getActionList(ConfPaths.BLOCKBREAK_DIRECTION_ACTIONS);
|
||||
noswingCheck = data.getBoolean(ConfPaths.BLOCKBREAK_NOSWING_CHECK);
|
||||
noswingActions = data.getActionList(ConfPaths.BLOCKBREAK_NOSWING_ACTIONS);
|
||||
|
||||
check = reachCheck || directionCheck || noswingCheck;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
@ -17,7 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
public class DirectionCheck extends BlockBreakCheck {
|
||||
|
||||
public DirectionCheck(NoCheat plugin) {
|
||||
super(plugin, "blockbreak.direction", Permissions.BLOCKBREAK_DIRECTION);
|
||||
super(plugin, "blockbreak.direction");
|
||||
}
|
||||
|
||||
public boolean check(final NoCheatPlayer player, final BlockBreakData data, final BlockBreakConfig ccblockbreak) {
|
||||
@ -65,10 +64,6 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public boolean isEnabled(BlockBreakConfig cc) {
|
||||
return cc.directionCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -4,13 +4,12 @@ import java.util.Locale;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class NoswingCheck extends BlockBreakCheck {
|
||||
|
||||
public NoswingCheck(NoCheat plugin) {
|
||||
super(plugin, "blockbreak.noswing", Permissions.BLOCKBREAK_NOSWING);
|
||||
super(plugin, "blockbreak.noswing");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, BlockBreakData data, BlockBreakConfig cc) {
|
||||
@ -31,10 +30,6 @@ public class NoswingCheck extends BlockBreakCheck {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public boolean isEnabled(BlockBreakConfig cc) {
|
||||
return cc.noswingCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -5,7 +5,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
@ -17,7 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
public class ReachCheck extends BlockBreakCheck {
|
||||
|
||||
public ReachCheck(NoCheat plugin) {
|
||||
super(plugin, "blockbreak.reach", Permissions.BLOCKBREAK_REACH);
|
||||
super(plugin, "blockbreak.reach");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, BlockBreakData data, BlockBreakConfig cc) {
|
||||
@ -44,10 +43,6 @@ public class ReachCheck extends BlockBreakCheck {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
public boolean isEnabled(BlockBreakConfig cc) {
|
||||
return cc.reachCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -16,14 +16,10 @@ public abstract class BlockPlaceCheck extends Check {
|
||||
|
||||
private static final String id = "blockplace";
|
||||
|
||||
public BlockPlaceCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, id, name, permission);
|
||||
public BlockPlaceCheck(NoCheat plugin, String name) {
|
||||
super(plugin, id, name);
|
||||
}
|
||||
|
||||
public abstract boolean check(NoCheatPlayer player, BlockPlaceData data, BlockPlaceConfig cc);
|
||||
|
||||
public abstract boolean isEnabled(BlockPlaceConfig cc);
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
if(wildcard == ParameterName.PLACE_LOCATION) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -20,16 +19,16 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
*/
|
||||
public class BlockPlaceCheckListener implements Listener, EventManager {
|
||||
|
||||
private final List<BlockPlaceCheck> checks;
|
||||
private final NoCheat plugin;
|
||||
private final ReachCheck reachCheck;
|
||||
private final DirectionCheck directionCheck;
|
||||
private final NoCheat plugin;
|
||||
|
||||
public BlockPlaceCheckListener(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
this.checks = new ArrayList<BlockPlaceCheck>(2);
|
||||
this.checks.add(new ReachCheck(plugin));
|
||||
this.checks.add(new DirectionCheck(plugin));
|
||||
reachCheck = new ReachCheck(plugin);
|
||||
directionCheck = new DirectionCheck(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -46,20 +45,17 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final BlockPlaceConfig cc = BlockPlaceCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.BLOCKPLACE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockPlaceData data = BlockPlaceCheck.getData(player.getDataStore());
|
||||
|
||||
data.blockPlaced.set(event.getBlock());
|
||||
data.blockPlacedAgainst.set(event.getBlockAgainst());
|
||||
|
||||
for(BlockPlaceCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
// Now do the actual checks
|
||||
if(cc.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH)) {
|
||||
cancelled = reachCheck.check(player, data, cc);
|
||||
}
|
||||
if(!cancelled && cc.directionCheck && !player.hasPermission(Permissions.BLOCKPLACE_DIRECTION)) {
|
||||
cancelled = directionCheck.check(player, data, cc);
|
||||
}
|
||||
|
||||
if(cancelled)
|
||||
@ -71,8 +67,10 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
|
||||
|
||||
BlockPlaceConfig bp = BlockPlaceCheck.getConfig(cc);
|
||||
|
||||
if(bp.check && bp.reachCheck)
|
||||
if(bp.reachCheck)
|
||||
s.add("blockplace.reach");
|
||||
if(bp.directionCheck)
|
||||
s.add("blockplace.direction");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
*/
|
||||
public class BlockPlaceConfig implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
|
||||
public final boolean reachCheck;
|
||||
public final double reachDistance;
|
||||
public final ActionList reachActions;
|
||||
@ -31,8 +29,5 @@ public class BlockPlaceConfig implements ConfigItem {
|
||||
directionPenaltyTime = data.getInt(ConfPaths.BLOCKPLACE_DIRECTION_PENALTYTIME);
|
||||
directionPrecision = ((double) data.getInt(ConfPaths.BLOCKPLACE_DIRECTION_PRECISION)) / 100D;
|
||||
directionActions = data.getActionList(ConfPaths.BLOCKPLACE_DIRECTION_ACTIONS);
|
||||
|
||||
check = reachCheck || directionCheck;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,13 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class DirectionCheck extends BlockPlaceCheck {
|
||||
|
||||
public DirectionCheck(NoCheat plugin) {
|
||||
super(plugin, "blockplace.direction", Permissions.BLOCKPLACE_DIRECTION);
|
||||
super(plugin, "blockplace.direction");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, BlockPlaceData data, BlockPlaceConfig cc) {
|
||||
@ -84,11 +83,6 @@ public class DirectionCheck extends BlockPlaceCheck {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(BlockPlaceConfig cc) {
|
||||
return cc.directionCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -5,7 +5,6 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
@ -17,7 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
public class ReachCheck extends BlockPlaceCheck {
|
||||
|
||||
public ReachCheck(NoCheat plugin) {
|
||||
super(plugin, "blockplace.reach", Permissions.BLOCKPLACE_REACH);
|
||||
super(plugin, "blockplace.reach");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, BlockPlaceData data, BlockPlaceConfig cc) {
|
||||
@ -44,11 +43,6 @@ public class ReachCheck extends BlockPlaceCheck {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(BlockPlaceConfig cc) {
|
||||
return cc.reachCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -11,14 +11,10 @@ public abstract class ChatCheck extends Check {
|
||||
|
||||
private static final String id = "chat";
|
||||
|
||||
public ChatCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, id, name, permission);
|
||||
public ChatCheck(NoCheat plugin, String name) {
|
||||
super(plugin, id, name);
|
||||
}
|
||||
|
||||
public abstract boolean check(NoCheatPlayer player, ChatData data, ChatConfig cc);
|
||||
|
||||
public abstract boolean isEnabled(ChatConfig cc);
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -16,16 +15,17 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
|
||||
public class ChatCheckListener implements Listener, EventManager {
|
||||
|
||||
private final List<ChatCheck> checks;
|
||||
private final NoCheat plugin;
|
||||
private final SpamCheck spamCheck;
|
||||
private final ColorCheck colorCheck;
|
||||
|
||||
private final NoCheat plugin;
|
||||
|
||||
public ChatCheckListener(NoCheat plugin) {
|
||||
|
||||
this.checks = new ArrayList<ChatCheck>(3);
|
||||
this.checks.add(new SpamCheck(plugin));
|
||||
this.checks.add(new ColorCheck(plugin));
|
||||
|
||||
this.plugin = plugin;
|
||||
|
||||
spamCheck = new SpamCheck(plugin);
|
||||
colorCheck = new ColorCheck(plugin);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
@ -44,19 +44,16 @@ public class ChatCheckListener implements Listener, EventManager {
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final ChatConfig cc = ChatCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.CHAT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ChatData data = ChatCheck.getData(player.getDataStore());
|
||||
|
||||
data.message = event.getMessage();
|
||||
|
||||
for(ChatCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
// Now do the actual checks
|
||||
if(cc.spamCheck && !player.hasPermission(Permissions.CHAT_SPAM)) {
|
||||
cancelled = spamCheck.check(player, data, cc);
|
||||
}
|
||||
if(!cancelled && cc.colorCheck && !player.hasPermission(Permissions.CHAT_COLOR)) {
|
||||
cancelled = colorCheck.check(player, data, cc);
|
||||
}
|
||||
|
||||
if(cancelled) {
|
||||
@ -71,9 +68,9 @@ public class ChatCheckListener implements Listener, EventManager {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
ChatConfig c = ChatCheck.getConfig(cc);
|
||||
if(c.check && c.spamCheck)
|
||||
if(c.spamCheck)
|
||||
s.add("chat.spam");
|
||||
if(c.check && c.colorCheck)
|
||||
if(c.colorCheck)
|
||||
s.add("chat.color");
|
||||
return s;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
|
||||
public class ChatConfig implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
public final boolean spamCheck;
|
||||
public final String[] spamWhitelist;
|
||||
public final int spamTimeframe;
|
||||
@ -29,9 +28,6 @@ public class ChatConfig implements ConfigItem {
|
||||
spamActions = data.getActionList(ConfPaths.CHAT_SPAM_ACTIONS);
|
||||
colorCheck = data.getBoolean(ConfPaths.CHAT_COLOR_CHECK);
|
||||
colorActions = data.getActionList(ConfPaths.CHAT_COLOR_ACTIONS);
|
||||
|
||||
check = spamCheck || colorCheck;
|
||||
|
||||
}
|
||||
|
||||
private String[] splitWhitelist(String string) {
|
||||
|
@ -4,13 +4,12 @@ import java.util.Locale;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class ColorCheck extends ChatCheck {
|
||||
|
||||
public ColorCheck(NoCheat plugin) {
|
||||
super(plugin, "chat.color", Permissions.CHAT_COLOR);
|
||||
super(plugin, "chat.color");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, ChatData data, ChatConfig cc) {
|
||||
@ -31,11 +30,6 @@ public class ColorCheck extends ChatCheck {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(ChatConfig cc) {
|
||||
return cc.colorCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -4,13 +4,12 @@ import java.util.Locale;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class SpamCheck extends ChatCheck {
|
||||
|
||||
public SpamCheck(NoCheat plugin) {
|
||||
super(plugin, "chat.spam", Permissions.CHAT_SPAM);
|
||||
super(plugin, "chat.spam");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, ChatData data, ChatConfig cc) {
|
||||
@ -53,11 +52,6 @@ public class SpamCheck extends ChatCheck {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(ChatConfig cc) {
|
||||
return cc.spamCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -13,9 +13,11 @@ import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
public abstract class FightCheck extends Check {
|
||||
|
||||
private static final String id = "fight";
|
||||
public final String permission;
|
||||
|
||||
public FightCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, id, name, permission);
|
||||
super(plugin, id, name);
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public abstract boolean check(NoCheatPlayer player, FightData data, FightConfig cc);
|
||||
|
@ -71,7 +71,7 @@ public class FightCheckListener implements Listener, EventManager {
|
||||
NoCheatPlayer player = plugin.getPlayer((Player) entity);
|
||||
FightConfig cc = FightCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!godmodeCheck.isEnabled(cc) || player.hasPermission(godmodeCheck.getPermission())) {
|
||||
if(!godmodeCheck.isEnabled(cc) || player.hasPermission(godmodeCheck.permission)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ public class FightCheckListener implements Listener, EventManager {
|
||||
|
||||
for(FightCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.permission)) {
|
||||
cancelled = check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,12 @@ import java.util.Locale;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class DropCheck extends InventoryCheck {
|
||||
|
||||
public DropCheck(NoCheat plugin) {
|
||||
super(plugin, "inventory.drop", Permissions.INVENTORY_DROP);
|
||||
super(plugin, "inventory.drop");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, InventoryData data, InventoryConfig cc) {
|
||||
|
@ -5,13 +5,12 @@ import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class InstantBowCheck extends InventoryCheck {
|
||||
|
||||
public InstantBowCheck(NoCheat plugin) {
|
||||
super(plugin, "inventory.instantbow", Permissions.INVENTORY_INSTANTBOW);
|
||||
super(plugin, "inventory.instantbow");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, EntityShootBowEvent event, InventoryData data, InventoryConfig cc) {
|
||||
|
@ -5,13 +5,12 @@ import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class InstantEatCheck extends InventoryCheck {
|
||||
|
||||
public InstantEatCheck(NoCheat plugin) {
|
||||
super(plugin, "inventory.instanteat", Permissions.INVENTORY_INSTANTEAT);
|
||||
super(plugin, "inventory.instanteat");
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, FoodLevelChangeEvent event, InventoryData data, InventoryConfig cc) {
|
||||
|
@ -9,8 +9,8 @@ public abstract class InventoryCheck extends Check {
|
||||
|
||||
private static final String id = "inventory";
|
||||
|
||||
public InventoryCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, id, name, permission);
|
||||
public InventoryCheck(NoCheat plugin, String name) {
|
||||
super(plugin, id, name);
|
||||
}
|
||||
|
||||
public static InventoryData getData(DataStore base) {
|
||||
|
@ -53,7 +53,7 @@ public class InventoryCheckListener implements Listener, EventManager {
|
||||
boolean cancelled = false;
|
||||
|
||||
// If it should be executed, do it
|
||||
if(cc.dropCheck && !player.hasPermission(dropCheck.getPermission())) {
|
||||
if(cc.dropCheck && !player.hasPermission(Permissions.INVENTORY_DROP)) {
|
||||
cancelled = dropCheck.check(player, data, cc);
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ public class InventoryCheckListener implements Listener, EventManager {
|
||||
final InventoryConfig cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
||||
final InventoryData data = InventoryCheck.getData(player.getDataStore());
|
||||
|
||||
if(cc.eatCheck && !player.hasPermission(instantEatCheck.getPermission())) {
|
||||
if(cc.eatCheck && !player.hasPermission(Permissions.INVENTORY_INSTANTEAT)) {
|
||||
|
||||
boolean cancelled = instantEatCheck.check(player, event, data, cc);
|
||||
event.setCancelled(cancelled);
|
||||
@ -110,7 +110,7 @@ public class InventoryCheckListener implements Listener, EventManager {
|
||||
final NoCheatPlayer player = plugin.getPlayer((Player) event.getEntity());
|
||||
final InventoryConfig cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(cc.bowCheck && !player.hasPermission(instantBowCheck.getPermission())) {
|
||||
if(cc.bowCheck && !player.hasPermission(Permissions.INVENTORY_INSTANTBOW)) {
|
||||
final InventoryData data = InventoryCheck.getData(player.getDataStore());
|
||||
boolean cancelled = instantBowCheck.check(player, event, data, cc);
|
||||
|
||||
|
@ -16,7 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
public class FlyingCheck extends MovingCheck {
|
||||
|
||||
public FlyingCheck(NoCheat plugin) {
|
||||
super(plugin, "moving.flying", null);
|
||||
super(plugin, "moving.flying");
|
||||
}
|
||||
|
||||
private static final double creativeSpeed = 0.60D;
|
||||
@ -125,11 +125,6 @@ public class FlyingCheck extends MovingCheck {
|
||||
return newToLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(MovingConfig moving) {
|
||||
return moving.allowFlying && moving.runflyCheck;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
|
@ -4,7 +4,6 @@ import java.util.Locale;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
@ -23,7 +22,7 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
private final static int packetsPerTimeframe = 22;
|
||||
|
||||
public MorePacketsCheck(NoCheat plugin) {
|
||||
super(plugin, "moving.morepackets", Permissions.MOVING_MOREPACKETS);
|
||||
super(plugin, "moving.morepackets");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,11 +96,6 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
return newToLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(MovingConfig moving) {
|
||||
return moving.morePacketsCheck;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
|
@ -13,20 +13,10 @@ public abstract class MovingCheck extends Check {
|
||||
|
||||
private static final String id = "moving";
|
||||
|
||||
public MovingCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, id, name, permission);
|
||||
public MovingCheck(NoCheat plugin, String name) {
|
||||
super(plugin, id, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new destination location or null
|
||||
*
|
||||
* @param event
|
||||
* @return
|
||||
*/
|
||||
public abstract PreciseLocation check(final NoCheatPlayer player, MovingData data, MovingConfig cc);
|
||||
|
||||
public abstract boolean isEnabled(MovingConfig moving);
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import org.bukkit.Location;
|
||||
@ -23,7 +22,6 @@ import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
/**
|
||||
* The only place that listens to and modifies player_move events if necessary
|
||||
@ -34,51 +32,87 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
*/
|
||||
public class MovingCheckListener implements Listener, EventManager {
|
||||
|
||||
private final List<MovingCheck> checks;
|
||||
private final NoCheat plugin;
|
||||
private final MorePacketsCheck morePacketsCheck;
|
||||
private final FlyingCheck flyingCheck;
|
||||
private final RunningCheck runningCheck;
|
||||
|
||||
private final NoCheat plugin;
|
||||
|
||||
public MovingCheckListener(NoCheat plugin) {
|
||||
|
||||
this.checks = new ArrayList<MovingCheck>(2);
|
||||
|
||||
checks.add(new RunflyCheck(plugin));
|
||||
checks.add(new MorePacketsCheck(plugin));
|
||||
flyingCheck = new FlyingCheck(plugin);
|
||||
runningCheck = new RunningCheck(plugin);
|
||||
morePacketsCheck = new MorePacketsCheck(plugin);
|
||||
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* A workaround for players placing blocks below them getting pushed
|
||||
* off the block by NoCheat.
|
||||
*
|
||||
* It essentially moves the "setbackpoint" to the top of the newly
|
||||
* placed block, therefore tricking NoCheat into thinking the player
|
||||
* was already on top of that block and should be allowed to stay
|
||||
* there
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void blockPlace(final BlockPlaceEvent event) {
|
||||
|
||||
// Block wasn't placed, so we don't care
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
// Get the player-specific stored data that applies here
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
final MovingConfig config = MovingCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
final Block blockPlaced = event.getBlockPlaced();
|
||||
|
||||
if(blockPlaced == null || !data.runflySetBackPoint.isSet()) {
|
||||
// If the player is allowed to fly anyway, the workaround is not needed
|
||||
// It's kind of expensive (looking up block types) therefore it makes
|
||||
// sense to avoid it
|
||||
if(config.allowFlying || !config.runflyCheck || player.hasPermission(Permissions.MOVING_FLYING) || player.hasPermission(Permissions.MOVING_RUNFLY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final SimpleLocation lblock = new SimpleLocation();
|
||||
lblock.set(blockPlaced);
|
||||
final SimpleLocation lplayer = new SimpleLocation();
|
||||
lplayer.setLocation(player.getPlayer().getLocation());
|
||||
// Get the player-specific stored data that applies here
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
|
||||
final Block block = event.getBlockPlaced();
|
||||
|
||||
final int type = CheckUtil.getType(blockPlaced.getTypeId());
|
||||
if(block == null || !data.runflySetBackPoint.isSet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep some results of "expensive calls
|
||||
final Location l = player.getPlayer().getLocation();
|
||||
final int playerX = l.getBlockX();
|
||||
final int playerY = l.getBlockY();
|
||||
final int playerZ = l.getBlockZ();
|
||||
final int blockY = block.getY();
|
||||
|
||||
// Was the block below the player?
|
||||
if(Math.abs(playerX - block.getX()) <= 1 && Math.abs(playerZ - block.getZ()) <= 1 && playerY - blockY >= 0 && playerY - blockY <= 2) {
|
||||
// yes
|
||||
final int type = CheckUtil.getType(block.getTypeId());
|
||||
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
|
||||
if(lblock.y + 1 >= data.runflySetBackPoint.y) {
|
||||
data.runflySetBackPoint.y = (lblock.y + 1);
|
||||
if(blockY + 1 >= data.runflySetBackPoint.y) {
|
||||
data.runflySetBackPoint.y = (blockY + 1);
|
||||
data.jumpPhase = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If a player gets teleported, it may have two reasons. Either
|
||||
* it was NoCheat or another plugin. If it was NoCheat, the target
|
||||
* location should match the "data.teleportTo" value.
|
||||
*
|
||||
* On teleports, reset some movement related data
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void teleport(final PlayerTeleportEvent event) {
|
||||
|
||||
@ -86,20 +120,31 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
// If it was a teleport initialized by NoCheat, do it anyway
|
||||
// even if another plugin said "no"
|
||||
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
||||
event.setCancelled(false);
|
||||
} else {
|
||||
// Only if it wasn't NoCheat, drop data from morepackets check
|
||||
// Only if it wasn't NoCheat, drop data from morepackets check.
|
||||
// If it was NoCheat, we don't want players to exploit the
|
||||
// runfly check teleporting to get rid of the "morepackets"
|
||||
// data.
|
||||
data.clearMorePacketsData();
|
||||
}
|
||||
|
||||
// Always forget runfly specific data
|
||||
// Always drop data from runfly check, as it always loses its validity
|
||||
// after teleports. Always!
|
||||
data.teleportTo.reset();
|
||||
data.clearRunFlyData();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Just for security, if a player switches between worlds, reset the
|
||||
* runfly and morepackets checks.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void worldChange(final PlayerChangedWorldEvent event) {
|
||||
// Maybe this helps with people teleporting through multiverse portals having problems?
|
||||
@ -109,6 +154,12 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
data.clearMorePacketsData();
|
||||
}
|
||||
|
||||
/**
|
||||
* When a player uses a portal, all information related to the
|
||||
* moving checks becomes invalid.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void portal(final PlayerPortalEvent event) {
|
||||
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||
@ -116,6 +167,12 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
data.clearRunFlyData();
|
||||
}
|
||||
|
||||
/**
|
||||
* When a player respawns, all information related to the
|
||||
* moving checks becomes invalid.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void respawn(final PlayerRespawnEvent event) {
|
||||
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||
@ -123,63 +180,75 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
data.clearRunFlyData();
|
||||
}
|
||||
|
||||
/**
|
||||
* When a player moves, he will be checked for various
|
||||
* suspicious behaviour.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void move(final PlayerMoveEvent event) {
|
||||
|
||||
if(event.isCancelled())
|
||||
if(event.isCancelled() || event.getPlayer().isInsideVehicle() || event.getPlayer().isDead())
|
||||
return;
|
||||
// Get the world-specific configuration that applies here
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
|
||||
// Not interested at all in players in vehicles or dead
|
||||
if(event.getPlayer().isInsideVehicle() || player.isDead()) {
|
||||
return;
|
||||
}
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
|
||||
final MovingConfig cc = MovingCheck.getConfig(player.getConfigurationStore());
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
// Various calculations related to velocity estimates
|
||||
updateVelocities(data);
|
||||
// Advance various counters and values that change per movement
|
||||
// tick. They are needed to decide on how fast a player may
|
||||
// move.
|
||||
tickVelocities(data);
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
|
||||
// Remember locations
|
||||
data.from.set(event.getFrom());
|
||||
final Location to = event.getTo();
|
||||
data.to.set(to);
|
||||
|
||||
PreciseLocation newTo = null;
|
||||
|
||||
/** RUNFLY CHECK SECTION **/
|
||||
// If the player isn't handled by runfly checks
|
||||
if(!cc.runflyCheck || player.hasPermission(Permissions.MOVING_RUNFLY)) {
|
||||
// Just because he is allowed now, doesn't mean he will always
|
||||
// be. So forget data about the player related to moving
|
||||
data.clearRunFlyData();
|
||||
} else if(cc.allowFlying || (player.isCreative() && cc.identifyCreativeMode) || player.hasPermission(Permissions.MOVING_FLYING)) {
|
||||
// Only do the limited flying check
|
||||
newTo = flyingCheck.check(player, data, cc);
|
||||
} else {
|
||||
// Go for the full treatment
|
||||
newTo = runningCheck.check(player, data, cc);
|
||||
}
|
||||
|
||||
/** MOREPACKETS CHECK SECTION **/
|
||||
if(!cc.morePacketsCheck || player.hasPermission(Permissions.MOVING_MOREPACKETS)) {
|
||||
data.clearMorePacketsData();
|
||||
return;
|
||||
} else if(newTo != null) {
|
||||
newTo = morePacketsCheck.check(player, data, cc);
|
||||
}
|
||||
|
||||
// Get some data that's needed from this event, to avoid passing the
|
||||
// event itself on to the checks (and risk to
|
||||
// accidentally modifying the event there)
|
||||
|
||||
final Location to = event.getTo();
|
||||
|
||||
data.from.set(event.getFrom());
|
||||
data.to.set(to);
|
||||
|
||||
// This variable will have the modified data of the event (new
|
||||
// "to"-location)
|
||||
PreciseLocation newTo = null;
|
||||
|
||||
for(MovingCheck check : checks) {
|
||||
if(newTo == null && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
newTo = check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
// Did the check(s) decide we need a new "to"-location?
|
||||
// Did one of the check(s) decide we need a new "to"-location?
|
||||
if(newTo != null) {
|
||||
// Compose a new location based on coordinates of "newTo" and
|
||||
// viewing direction of "event.getTo()"
|
||||
event.setTo(new Location(player.getPlayer().getWorld(), newTo.x, newTo.y, newTo.z, to.getYaw(), to.getPitch()));
|
||||
|
||||
// remember where we send the player to
|
||||
data.teleportTo.set(newTo);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVelocities(MovingData data) {
|
||||
/**
|
||||
* Just try to estimate velocities over time
|
||||
* Not very precise, but works good enough most
|
||||
* of the time.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
private void tickVelocities(MovingData data) {
|
||||
|
||||
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
|
||||
if(data.horizVelocityCounter > 0) {
|
||||
@ -200,10 +269,18 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Player got a velocity packet. The server can't keep track
|
||||
* of actual velocity values (by design), so we have to try
|
||||
* and do that ourselves.
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void velocity(final PlayerVelocityEvent event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
|
||||
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||
|
||||
final Vector v = event.getVelocity();
|
||||
@ -228,22 +305,20 @@ public class MovingCheckListener implements Listener, EventManager {
|
||||
|
||||
MovingConfig m = MovingCheck.getConfig(cc);
|
||||
|
||||
if(m.check) {
|
||||
if(m.runflyCheck) {
|
||||
if(m.runflyCheck) {
|
||||
|
||||
if(!m.allowFlying) {
|
||||
s.add("moving.runfly");
|
||||
if(m.sneakingCheck)
|
||||
s.add("moving.sneaking");
|
||||
if(m.nofallCheck)
|
||||
s.add("moving.nofall");
|
||||
} else
|
||||
s.add("moving.flying");
|
||||
if(!m.allowFlying) {
|
||||
s.add("moving.runfly");
|
||||
if(m.sneakingCheck)
|
||||
s.add("moving.sneaking");
|
||||
if(m.nofallCheck)
|
||||
s.add("moving.nofall");
|
||||
} else
|
||||
s.add("moving.flying");
|
||||
|
||||
}
|
||||
if(m.morePacketsCheck)
|
||||
s.add("moving.morepackets");
|
||||
}
|
||||
if(m.morePacketsCheck)
|
||||
s.add("moving.morepackets");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
@ -12,8 +12,6 @@ import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
|
||||
*/
|
||||
public class MovingConfig implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
|
||||
public final boolean runflyCheck;
|
||||
public final boolean identifyCreativeMode;
|
||||
public final double walkingSpeedLimit;
|
||||
@ -70,8 +68,5 @@ public class MovingConfig implements ConfigItem {
|
||||
|
||||
morePacketsCheck = data.getBoolean(ConfPaths.MOVING_MOREPACKETS_CHECK);
|
||||
morePacketsActions = data.getActionList(ConfPaths.MOVING_MOREPACKETS_ACTIONS);
|
||||
|
||||
check = runflyCheck || morePacketsCheck;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class MovingData implements DataItem {
|
||||
|
||||
public int jumpPhase;
|
||||
public double lastJumpAmplifier;
|
||||
public int onIce = 0;
|
||||
public int onIce;
|
||||
|
||||
public final PreciseLocation runflySetBackPoint = new PreciseLocation();
|
||||
|
||||
|
@ -4,8 +4,6 @@ import java.util.Locale;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
@ -16,21 +14,21 @@ import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
public class NoFallCheck extends MovingCheck {
|
||||
|
||||
public NoFallCheck(NoCheat plugin) {
|
||||
super(plugin, "moving.nofall", Permissions.MOVING_NOFALL);
|
||||
super(plugin, "moving.nofall");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate if and how much the player "failed" this check.
|
||||
*
|
||||
*/
|
||||
public PreciseLocation check(NoCheatPlayer player, MovingData data, MovingConfig cc) {
|
||||
public void check(NoCheatPlayer player, MovingData data, MovingConfig cc) {
|
||||
|
||||
// If the player is serverside in creative mode, we have to stop here to
|
||||
// avoid hurting him when he switches back to "normal" mode
|
||||
if(player.isCreative()) {
|
||||
data.fallDistance = 0F;
|
||||
data.lastAddedFallDistance = 0F;
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
// This check is pretty much always a step behind for technical reasons.
|
||||
@ -110,12 +108,7 @@ public class NoFallCheck extends MovingCheck {
|
||||
// Reduce falldamage violation level
|
||||
data.nofallVL *= 0.99D;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(MovingConfig moving) {
|
||||
return moving.nofallCheck;
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,48 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
|
||||
public class RunflyCheck extends MovingCheck {
|
||||
|
||||
private final FlyingCheck flyingCheck;
|
||||
private final RunningCheck runningCheck;
|
||||
|
||||
public RunflyCheck(NoCheat plugin) {
|
||||
// Permission field intentionally left blank here
|
||||
// We check in the actual "check" method, because
|
||||
// we have to do something beside skipping the test
|
||||
super(plugin, "moving.runfly", null);
|
||||
|
||||
flyingCheck = new FlyingCheck(plugin);
|
||||
runningCheck = new RunningCheck(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreciseLocation check(NoCheatPlayer player, MovingData data, MovingConfig cc) {
|
||||
|
||||
if(player.hasPermission(Permissions.MOVING_RUNFLY)) {
|
||||
// If the player doesn't get checked for movement
|
||||
// reset his critical data
|
||||
data.clearRunFlyData();
|
||||
return null;
|
||||
}
|
||||
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.isCreative() && cc.identifyCreativeMode);
|
||||
|
||||
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
|
||||
// If the player is not allowed to fly and not allowed to run
|
||||
|
||||
if(flyAllowed) {
|
||||
return flyingCheck.check(player, data, cc);
|
||||
} else {
|
||||
return runningCheck.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(MovingConfig moving) {
|
||||
return moving.runflyCheck;
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
public RunningCheck(NoCheat plugin) {
|
||||
|
||||
super(plugin, "moving.running", null);
|
||||
super(plugin, "moving.running");
|
||||
|
||||
this.noFallCheck = new NoFallCheck(plugin);
|
||||
}
|
||||
@ -235,10 +235,6 @@ public class RunningCheck extends MovingCheck {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(MovingConfig moving) {
|
||||
return moving.runflyCheck && !moving.allowFlying;
|
||||
}
|
||||
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.CHECK)
|
||||
|
Loading…
Reference in New Issue
Block a user