[API] Added an API to change the settings per player

[General] Some parts of the code have been rewritten, packages have been
renamed ('me' to 'fr') and the instructions have been fixed
This commit is contained in:
NeatMonster 2012-04-26 23:36:43 +02:00
parent ef738e3b11
commit e48069e73f
104 changed files with 1899 additions and 2471 deletions

View File

@ -13,7 +13,8 @@
won't use. They'll be implicitly taken from the master "config.yml" file.
3) If you have files named "config.txt", "default_actions.txt" or "actions.txt"
please delete them. They are no longer used by NoCheatPlus and serve no purpose anymore.
please delete them. They are no longer used by NoCheatPlus and serve no
purpose anymore.
4) Never change the amount of white-spaces in front of options in the config
file "config.yml". It will break the configuration.
@ -30,7 +31,8 @@
(read on to learn in detail on how to define/modify actions)
cancel: The effects of the action "cancel" depend on the check that it is used
for. Usually it means to prevent something from happening, e.g. stop an attack or prevent sending of a chat message.
for. Usually it means to prevent something from happening, e.g. stop
an attack or prevent sending of a chat message.
log: Create and show/log a message. Log messages can be customized in how
often, when and where they are registered/shown.
@ -60,10 +62,12 @@
2) The "log" action is a string of the form "log:string:delay:repeat:target".
log: is simply used to let NoCheatPlus know it is a log action. Don't
remove it from the action, or NoCheatPlus will not know what it is and how to handle it.
remove it from the action, or NoCheatPlus will not know what it is
and how to handle it.
string: is the message that will be logged. Because there is so little space
here, you only give a name here and define the actual log message in the "strings" section of the config file.
here, you only give a name here and define the actual log message in
the "strings" section of the config file.
delay: a number declaring how many times that action initially has to be
executed before it really leads to logging a message. Use this for
@ -86,7 +90,8 @@
3) The "cmd" action is a string of the form "cmd:string:delay:repeat".
cmd: is simply used to let NoCheatPlus know it is a command action. Don't
remove it from the action, or NoCheatPlus will not know what it is and how to handle it.
remove it from the action, or NoCheatPlus will not know what it is
and how to handle it.
string: is the command that will be issued. Because there is so little space
here, you only give a name here and define the actual command in the
@ -106,7 +111,8 @@
4) The "vl>" isn't really an action. It limits all actions that are written
afterwards to be only executed if the players violation level has reached
at least the given value. This allows to define layers of actions and handle
repeated or severe failing of checks different. For example the spam check will only kick players if they reach a certain violation level (vl).
repeated or severe failing of checks different. For example the spam check
will only kick players if they reach a certain violation level (vl).
################################################################################
@ -116,9 +122,9 @@
################################################################################
NoCheatPlus only supports "SuperPerms", CraftBukkits official permission framework.
You'll need to use a permissions plugin that supports "SuperPerms" to use it
with NoCheatPlus. Here are some I know of:
NoCheatPlus only supports "SuperPerms", CraftBukkits official permission
framework. You'll need to use a permissions plugin that supports "SuperPerms"
to use it with NoCheatPlus. Here are some I know of:
- bPermissions;
- PermissionsEx;
@ -142,10 +148,13 @@
The player gets access to some of the "/nocheatplus" commands.
- nocheatplus.admin.reload
In combination with "nocheatplus.admin.commands", the player gets access to the "/nocheatplus reload" command, which will cause NoCheatPlus to reread its config files.
In combination with "nocheatplus.admin.commands", the player gets access to
the "/nocheatplus reload" command, which will cause NoCheatPlus to reread
its config files.
- nocheatplus.admin.plugins
Give this permissions to the players you want to be able to see the plugins your server is using.
Give this permissions to the players you want to be able to see the plugins
your server is using.
--------------------------------------------------------------------------------
@ -176,7 +185,8 @@
- nocheatplus.checks.moving.swimming
Allows the player to swim as fast as he is allowed to walk. Normally a
player swims slower than he walks and NoCheatPlus prevents faster movement in water.
player swims slower than he walks and NoCheatPlus prevents faster movement
in water.
- nocheatplus.checks.moving.sneaking
Allows the player to sneak faster than he is allowed to walk. Normally a
@ -208,13 +218,13 @@
- nocheatplus.checks.moving.morepacketsvehicle
Allows players to make a lot more movements (while being in a vehicule) than
normally possible. Doing more movements will result in faster overall movement speed and causes the server to spent a lot of additional time for processing these movements.
normally possible. Doing more movements will result in faster overall
movement speed and causes the server to spent a lot of additional time for
processing these movements.
- nocheatplus.checks.moving.waterwalk
Allows players to walk on water (by using a griefing client). This functionality is also called Jesus mode.
- nocheatplus.checks.moving.unpushable
Allows players to be unpushable (they can't be pushed by an other player).
Allows players to walk on water (by using a griefing client). This
functionality is also called Jesus mode.
- nocheatplus.checks.moving.boatonground
Allows players to place boats on the ground (and not only on the water).
@ -257,7 +267,9 @@
to level up very quickly or to crash the server by spawning too much mobs.
- nocheatplus.checks.blockplace.autosign
Allows the player to place multiple signs with the same text. This is usually used by griefers to place quickly a lot of signs with their signature.
Allows the player to place multiple signs with the same text. This is
usually used by griefers to place quickly a lot of signs with their
signature.
--------------------- INVENTORY Permissions for CHECKS -------------------------
@ -382,7 +394,8 @@
---------------------- Things to know about Permissions ------------------------
--------------------------------------------------------------------------------
NoCheatPlus defines "parent" nodes for all permissions already for you. That means you can use one of the following:
NoCheatPlus defines "parent" nodes for all permissions already for you. That
means you can use one of the following:
- nocheatplus
- nocheatplus.admin
@ -431,7 +444,8 @@
-------------------------------- LOGGING Section -------------------------------
--------------------------------------------------------------------------------
Everything that in general has to do with controlling NoCheatPluss logging can be found at this part of the config.yml.
Everything that in general has to do with controlling NoCheatPluss logging can
be found at this part of the config.yml.
active:
@ -447,7 +461,8 @@
filename:
The name of the logfile that NoCheatPlus will use to log its messages. The
default name is "nocheatplus.log", but you can use a different one if you want to.
default name is "nocheatplus.log", but you can use a different one if you
want to.
file:
@ -457,16 +472,21 @@
console:
Should the server console be used to display messages. Set to false if you
don't want NoCheatPlus to show messages related to checks in the console. Error messages may still get displayed there though.
don't want NoCheatPlus to show messages related to checks in the console.
Error messages may still get displayed there though.
ingamechat:
Should NoCheatPlus display messages in the ingame chat? Set to false if you
don't want NoCheatPlus to show messages ingame. The messages will only be seen by players with the permission node "nocheatplus.admin.chatlog" or if you don't use a permissions plugin, by players who are OP.
don't want NoCheatPlus to show messages ingame. The messages will only be
seen by players with the permission node "nocheatplus.admin.chatlog" or if
you don't use a permissions plugin, by players who are OP.
showactivechecks:
Should NoCheatPlus display lists of checks that are enabled for each world. Set to true if you are unsure that your (multiworld) setup of the config files is done correctly.
Should NoCheatPlus display lists of checks that are enabled for each world.
Set to true if you are unsure that your (multiworld) setup of the config
files is done correctly.
debugmessages:
@ -483,7 +503,8 @@
allowclientmods:
Allow all your players to use all the client mods (Zombe, CJB, Rei's Minimap, Minecraft AutoMap and Smart Moving).
Allow all your players to use all the client mods (Zombe, CJB, Rei's
Minimap, Minecraft AutoMap and Smart Moving).
opbyconsoleonly:
@ -500,7 +521,9 @@
-------------------------------- CHECKS Section --------------------------------
--------------------------------------------------------------------------------
Everything that in has to do with the various checks that NoCheatPlus runs on the players. Use these to specify what will be done, how it will be done and what happens if somebody fails checks.
Everything that in has to do with the various checks that NoCheatPlus runs on
the players. Use these to specify what will be done, how it will be done and
what happens if somebody fails checks.
----------------------------- INVENTORY Subsection -----------------------------
@ -551,7 +574,8 @@
this check the time difference between how long it took the player to
fire an arrow and how long NoCheatPlus thinks he should have taken, in
1/10 seconds. Therefore a VL of 10 would mean that the player shot an
arrow 1 second faster than NoCheatPlus expected. The VL gets increased with every failed check and slowly decreased for every passed check.
arrow 1 second faster than NoCheatPlus expected. The VL gets increased
with every failed check and slowly decreased for every passed check.
3) INSTANTEAT:
@ -568,7 +592,8 @@
this check the time difference between how long it took the player to
eat his food and how long NoCheatPlus thinks he should have taken, in
1/10 seconds. Therefore a VL of 10 would mean that the player ate his
food 1 second faster than NoCheatPlus expected. The VL gets increased with every failed check and slowly decreased for every passed check.
food 1 second faster than NoCheatPlus expected. The VL gets increased
with every failed check and slowly decreased for every passed check.
------------------------------ MOVING Subsection -------------------------------
@ -591,7 +616,8 @@
How fast should the player be allowed to walk. Default is "100",
meaning 100% of normal walking speed. You will not see this option in
your config.yml file, because normally you shouldn't have to change the
walking speed of players at all (NoCheatPlus knows when players sprint, use Swiftness potions etc and will already adapt the speed based on that
walking speed of players at all (NoCheatPlus knows when players sprint,
use Swiftness potions etc and will already adapt the speed based on that
data).
sneakspeed:
@ -604,7 +630,11 @@
blockspeed:
How fast should the player be allowed to move while blocking. Default is
"100" meaning 100% of normal blocking speed. You will not see this option in your config.yml file, because normally you shouldn't have to change the blocking speed of player at all (NoCheatPlus knows when players block, use Swiftness potions etc and will already adapt the speed based on that data).
"100" meaning 100% of normal blocking speed. You will not see this
option in your config.yml file, because normally you shouldn't have to
change the blocking speed of player at all (NoCheatPlus knows when
players block, use Swiftness potions etc and will already adapt the
speed based on that data).
swimspeed:
How fast should the player be allowed to swim. Default is "100",
@ -618,11 +648,18 @@
How fast should the player be allowed to sprint. Default is "100",
meaning 100% of normal sprinting speed. You will not see this option in
your config.yml file, because normally you shouldn't have to change the
sprinting speed of players at all (NoCheatPlus knows when players sprint, use Swiftness potions etc and will already adapt the speed based on that data).
sprinting speed of players at all (NoCheatPlus knows when players
sprint, use Swiftness potions etc and will already adapt the speed based
on that data).
cobwebspeed:
How fast should the player be allowed to move while being into cobweb.
Default is "100" meaning 100% of normal speed while being into cobweb. You will not see this option in your config.yml file, because normally you shouldn't have to change the speed while being into cobweb of players at all (NoCheatPlus knows when players are in cobweb, use Swiftness potions etc and will already adapt the speed based on that data).
Default is "100" meaning 100% of normal speed while being into cobweb.
You will not see this option in your config.yml file, because normally
you shouldn't have to change the speed while being into cobweb of
players at all (NoCheatPlus knows when players are in cobweb, use
Swiftness potions etc and will already adapt the speed based on that
data).
maxcooldown:
How much time the player can spend in the air if his velocity has been
@ -643,7 +680,8 @@
What should happen when a player sneaks/swims/walks/runs faster than
normally allowed or is flying. Default is to log messages (depending on
how severe the cheating is) and teleport the player to the last known
legitimate location on ground that NoCheatPlus can remember for that player ("cancel" the movement).
legitimate location on ground that NoCheatPlus can remember for that
player ("cancel" the movement).
checknofall:
Should players be checked for a common type of "nofall" hack, that
@ -699,7 +737,8 @@
What should happen if a player flies faster/higher than defined here?
Default is to log messages and to prevent the player from moving
("cancel" his last movement). The Violation Level (VL) of this check
is the distance that the player went beyond what NoCheatPlus allowed him. The VL increases with every failed check and slowly decreases for
is the distance that the player went beyond what NoCheatPlus allowed
him. The VL increases with every failed check and slowly decreases for
every passed check.
2) MOREPACKETS:
@ -762,17 +801,12 @@
actions:
What should happen if a player is considered to be cheating by walking
on water. Default is to log messages and to prevent the player from moving ("cancel" his last movement). The Violation Level (VL) of this check is the distance between the player and the surface or how far away he is from the normal position if a player climbing a block. The VL increases with every failed check and slowly decreases for every passed check.
5) UNPUSHABLE:
This check is designed to prevent players from being unpushable. It'll handle "pushs" server-side instead of letting the client calculates them for the server.
active:
Should players be checked for this kind of cheating. If you are not
interested in players that cheat that way, set this to false. It is a
good idea to have this active, because players won't be able to stay on
a block and to do not fall when pushed by other players.
on water. Default is to log messages and to prevent the player from
moving ("cancel" his last movement). The Violation Level (VL) of this
check is the distance between the player and the surface or how far away
he is from the normal position if a player climbing a block. The VL
increases with every failed check and slowly decreases for every passed
check.
---------------------------- BLOCKBREAK Subsection -----------------------------
@ -781,7 +815,10 @@
1) FASTBREAK:
This check will prevent players from breaking blocks too quickly by checking the interval of time elapsed since they've broken their last block. This should prevent players from using the features called "Smasher", "Click Nuker" and "Creative Nuker" of their griefing client.
This check will prevent players from breaking blocks too quickly by
checking the interval of time elapsed since they've broken their last
block. This should prevent players from using the features called
"Smasher", "Click Nuker" and "Creative Nuker" of their griefing client.
active:
Should players be checked for this behaviour.
@ -809,7 +846,10 @@
What should happen if the player is considered to cheat this way. The
default is to prevent him from breaking the block ("cancel" breaking)
and on repeated offenses to log messages about it. The Violation Level
(VL) is the distance in Blocks between the reach distance that NoCheatPlus allowed and what the player actually tried to use. The VL increases with every failed attempt to break a block out of reach, and decreases with every successful attempt.
(VL) is the distance in Blocks between the reach distance that NoCheatPlus
allowed and what the player actually tried to use. The VL increases with
every failed attempt to break a block out of reach, and decreases with
every successful attempt.
3) DIRECTION:
@ -821,7 +861,8 @@
Should players get checked for this type of hack.
precision:
How strict should NoCheatPlus be when comparing the players line of view with the broken block location. The value represents (roughly) the
How strict should NoCheatPlus be when comparing the players line of view
with the broken block location. The value represents (roughly) the
amount of 1/100 blocks that the player is allowed to look past the to
be broken block. 50 (0.5 blocks) seems a good default value.
@ -892,7 +933,10 @@
What should happen if the player is considered to cheat this way. The
default is to prevent him from placing the block ("cancel" placing)
and on repeated offenses to log messages about it. The Violation Level
(VL) is the distance in Blocks between the reach distance that NoCheatPlus allowed and what the player actually tried to use. The VL increases with every failed attempt to place a block out of reach, and decreases with every successful attempt.
(VL) is the distance in Blocks between the reach distance that
NoCheatPlus allowed and what the player actually tried to use. The VL
increases with every failed attempt to place a block out of reach, and
decreases with every successful attempt.
3) DIRECTION:
@ -903,7 +947,8 @@
Should players get checked for this type of hack.
precision:
How strict should NoCheatPlus be when comparing the players line of view with the placed block location. The value represents (roughly) the
How strict should NoCheatPlus be when comparing the players line of view
with the placed block location. The value represents (roughly) the
amount of 1/100 blocks that the player is allowed to look past the to
be placed block. 75 (0.75 blocks) seems a good default value.
@ -938,7 +983,18 @@
What should happen if a player fails this check. Default is to prevent
the placing of the block ("cancel" it) and after repeated/more severe
offenses to log a message and kick the player. The Violation Level (VL)
for this check is the interval elapsed subtracted to the interval defined in the configuration's file; It increases with every failure and decreases with every successfully thrown projectile.
for this check is the interval elapsed subtracted to the interval
defined in the configuration's file; It increases with every failure and
decreases with every successfully thrown projectile.
5) FASTSIGN
Players using custom clients are able to spam the server with signs
containing the text they have chosen.
exclusions:
If the first line of the sign is included into this list, the sign won't
be checked.
------------------------------- CHAT Subsection --------------------------------
@ -952,45 +1008,59 @@
1) NOPWNAGE:
The instructions for this check comes directly from NoPwnage's instructions
file. You can find the project at http://dev.bukkit.org/server-mods/nopwnage/.
file. You can find the project at http://dev.bukkit.org/server-mods/
nopwnage/.
warnPlayers:
Should a player that reaches the "warnLevel" get a text message telling
him that he is under suspicion of being a bot.
warnOthers:
Should all players get warned when a player gets banned for spambot-like activity?
Should all players get warned when a player gets banned for spambot-like
activity?
warnLevel:
How much suspicion must a message earn to issue a warning for the player?
How much suspicion must a message earn to issue a warning for the
player?
warnTimeout:
After what time (in ms) should a player be considered "unwarned" again.
banLevel:
How much suspicion must a message earn to execute the "commands" (usually ban the player). If warnings for players are enabled and the player hasn't been warned yet, he'll get warned instead.
How much suspicion must a message earn to execute the "commands"
(usually ban the player). If warnings for players are enabled and the
player hasn't been warned yet, he'll get warned instead.
move.enabled:
move.weightbonus:
move.weightmalus:
move.timeout:
NoPwnage will check if a player moved within the "timeout" timeframe. If
he did move, the suspicion will be reduced by the "weightbonus" value. If he did not move, the suspicion will be increased by "weightmalus" value.
he did move, the suspicion will be reduced by the "weightbonus" value.
If he did not move, the suspicion will be increased by "weightmalus"
value.
Only used if "enabled".
messageRepeat.enabled:
messageRepeat.weight:
messageRepeat.timeout:
NoPwnage will check if a player repeats his messages within the "timeout" timeframe. Even if the message is a bit different, it will be counted as being a repetition. The suspicion is increased by "weight" and for each additional repetition by "weight/2". This means that multiple repetitions will increase suspicion, but not as much as the first repetition.
NoPwnage will check if a player repeats his messages within the
"timeout" timeframe. Even if the message is a bit different, it will be
counted as being a repetition. The suspicion is increased by "weight"
and for each additional repetition by "weight/2". This means that
multiple repetitions will increase suspicion, but not as much as the
first repetition.
Only used if "enabled".
messageSpeed.enabled:
messageSpeed.weight:
messageSpeed.timeout:
NoPwnage will check if a player sends messages too fast. If a message is
sent within "timout" ms after the previous message, increase suspicion by "weight". For each additional message that is sent within "timeout",
sent within "timout" ms after the previous message, increase suspicion
by "weight". For each additional message that is sent within "timeout",
the suspicion is increased by "weight/2". This means that multiple
too fast sent messages in a row will increase suspicion, but not as much as the first.
too fast sent messages in a row will increase suspicion, but not as much
as the first.
Only used if "enabled".
messageFirst.enabled:
@ -1005,13 +1075,18 @@
globalMessageRepeat.timeout:
NoPwnage will check if a player repeats a message that has been sent by
another player just before, within "timeout". If he does, suspicion will
be increased by "weight" and for each additional repetition by "weight/2", independent of by which player. This means that multiple repetitions will increase suspicion, but not as much as the first repetition.
be increased by "weight" and for each additional repetition by
"weight/2", independent of by which player. This means that multiple
repetitions will increase suspicion, but not as much as the first
repetition.
Only used if "enabled".
bannedMessageRepeat.enabled:
bannedMessageRepeat.weight:
bannedMessageRepeat.timeout:
NoPwnage will remember the last message that caused someone to get banned. If a player repeats that message within "timeout" ms, the suspicion will be increased by "weight".
NoPwnage will remember the last message that caused someone to get
banned. If a player repeats that message within "timeout" ms, the
suspicion will be increased by "weight".
Only used if "enabled".
relog.enabled:
@ -1020,13 +1095,18 @@
relog.timeout:
NoPwnage will remember the time when a player leaves the server. If he
returns within "time" ms, he will get warned. If he has been warned
"warnings" times already, the "commands" will be executed for him. Warnings get removed if the time of the last warning was more than "timeout" ms ago.
"warnings" times already, the "commands" will be executed for him.
Warnings get removed if the time of the last warning was more than
"timeout" ms ago.
actions:
NoPwnage allows you to decide what should happen when a player reaches
"banLevel" or relogged too fast. The default is to kick him and ban IP and name. You'll also get a log message to console stating how exactly he reached the "banLevel" (how much suspicion was added by each check).
"banLevel" or relogged too fast. The default is to kick him and ban IP
and name. You'll also get a log message to console stating how exactly
he reached the "banLevel" (how much suspicion was added by each check).
"[player]" and "[ip]" wildcards will be replaced by the actual data during execution.
"[player]" and "[ip]" wildcards will be replaced by the actual data
during execution.
captcha.enabled:
Should players that get to "banlevel" be presented with a captcha first
@ -1037,7 +1117,10 @@
[captcha] will be replaced with the actual captcha.
tries:
How many attempts will a player have to give the correct answer. A failed attempt will display the question again. Be generous here, as players may not be fast enough to read the question the first few times or be otherwise distracted.
How many attempts will a player have to give the correct answer. A
failed attempt will display the question again. Be generous here, as
players may not be fast enough to read the question the first few times
or be otherwise distracted.
length:
How many characters should the captcha have.
@ -1105,7 +1188,8 @@
Should players get checked for this type of hack.
precision:
How strict should NoCheatPlus be when comparing the players line of view with the his target's location. The value represents (roughly) the
How strict should NoCheatPlus be when comparing the players line of view
with the his target's location. The value represents (roughly) the
amount of 1/100 blocks that the player is allowed to look past the to
be attacked entity. 75 (0.75 blocks) seems a good default value.
@ -1166,7 +1250,10 @@
What should happen if the player is considered to cheat this way. The
default is to prevent him from attacking the target ("cancel" attack)
and on repeated offenses to log messages about it. The Violation Level
(VL) is the distance in Blocks between the reach distance that NoCheatPlus allowed and what the player actually tried to use. The VL increases with every failed attempt to attack enemies out of reach, and decreases with every successful attempt.
(VL) is the distance in Blocks between the reach distance that
NoCheatPlus allowed and what the player actually tried to use. The VL
increases with every failed attempt to attack enemies out of reach, and
decreases with every successful attempt.
4) SPEED:
@ -1293,7 +1380,9 @@
best effort approach.
- NoCheatPlus may make mistakes. Don't see everything NoCheatPlus says or does
as indisputable fact that somebody cheated. It's not possible to be 100% sure if somebody is cheating or not, NoCheatPlus will try to be right most of the time.
as indisputable fact that somebody cheated. It's not possible to be 100% sure
if somebody is cheating or not, NoCheatPlus will try to be right most of the
time.
Thank you for reading this file. It took hours to write it, so it's nice that
people actually take a look at it. ;)

View File

@ -6,7 +6,7 @@ author: NeatMonster
authors: [Evenprime, Juliui]
website: ${project.url}
main: me.neatmonster.nocheatplus.NoCheatPlus
main: ${project.groupId}.${project.artifactId}
commands:
nocheatplus:
@ -59,8 +59,6 @@ permissions:
description: Allow a player to send more vehicule-move-event-packets than normal, causing him to move faster than normal
nocheatplus.checks.moving.waterwalk:
description: Allow a player to walk on the water
nocheatplus.checks.moving.unpushable:
description: Allow a player to be unpushable by the other players
nocheatplus.checks.moving.boatonground:
description: Allow a player to place a boat on the ground (not only on the water)
nocheatplus.checks.moving.respawntrick:

View File

@ -4,12 +4,12 @@
<!-- Informations -->
<name>NoCheatPlus</name>
<version>3.5.8</version>
<version>3.5.9</version>
<description>Detect and fight the exploitation of various flaws/bugs in Minecraft.</description>
<url>http://dev.bukkit.org/server-mods/nocheatplus</url>
<groupId>me.neatmonster.nocheatplus</groupId>
<artifactId>nocheatplus</artifactId>
<groupId>fr.neatmonster.nocheatplus</groupId>
<artifactId>NoCheatPlus</artifactId>
<packaging>jar</packaging>
<!-- License -->
@ -42,7 +42,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>craftbukkit</artifactId>
<version>1.2.5-R1.1</version>
<version>1.2.5-R1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>

View File

@ -1,33 +1,35 @@
package me.neatmonster.nocheatplus.command;
package fr.neatmonster.nocheatplus;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.chat.ChatCheck;
import me.neatmonster.nocheatplus.checks.chat.ChatConfig;
import me.neatmonster.nocheatplus.config.Permissions;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Handle all NoCheatPlus related commands in a common place
*/
public class CommandHandler {
public class CommandHandler implements CommandExecutor {
private final List<Permission> perms;
public CommandHandler(final NoCheatPlus plugin) {
public CommandHandler() {
// Make a copy to allow sorting
perms = new LinkedList<Permission>(plugin.getDescription().getPermissions());
perms = new LinkedList<Permission>(NoCheatPlus.instance.getDescription().getPermissions());
// Sort NoCheats permission by name and parent-child relation with
// a custom sorting method
@ -53,51 +55,10 @@ public class CommandHandler {
});
}
/**
* Handle a command that is directed at NoCheatPlus
*
* @param plugin
* @param sender
* @param command
* @param label
* @param args
* @return
*/
public boolean handleCommand(final NoCheatPlus plugin, final CommandSender sender, final Command command,
final String label, final String[] args) {
if (sender instanceof Player) {
final NoCheatPlusPlayer player = plugin.getPlayer((Player) sender);
final ChatConfig cc = ChatCheck.getConfig(player);
// Hide NoCheatPlus's commands if the player doesn't have the required permission
if (cc.protectPlugins && !sender.hasPermission("nocheatplus.admin.commands")) {
sender.sendMessage("Unknown command. Type \"help\" for help.");
return true;
}
}
boolean result = false;
// Not our command, how did it get here?
if (!command.getName().equalsIgnoreCase("nocheatplus") || args.length == 0)
result = false;
else if (args[0].equalsIgnoreCase("permlist") && args.length >= 2)
// permlist command was used
result = handlePermlistCommand(plugin, sender, args);
else if (args[0].equalsIgnoreCase("reload"))
// reload command was used
result = handleReloadCommand(plugin, sender);
else if (args[0].equalsIgnoreCase("playerinfo") && args.length >= 2)
// playerinfo command was used
result = handlePlayerInfoCommand(plugin, sender, args);
return result;
}
private boolean handlePermlistCommand(final NoCheatPlus plugin, final CommandSender sender, final String[] args) {
private boolean handlePermlistCommand(final CommandSender sender, final String[] args) {
// Get the player by name
final Player player = plugin.getServer().getPlayerExact(args[1]);
final Player player = Bukkit.getServer().getPlayerExact(args[1]);
if (player == null) {
sender.sendMessage("Unknown player: " + args[1]);
return true;
@ -116,9 +77,11 @@ public class CommandHandler {
return true;
}
private boolean handlePlayerInfoCommand(final NoCheatPlus plugin, final CommandSender sender, final String[] args) {
private boolean handlePlayerInfoCommand(final CommandSender sender, final String[] args) {
final Map<String, Object> map = plugin.getPlayerData(args[1]);
final Player player = Bukkit.getPlayer(args[1]);
final Map<String, Object> map = player == null ? new HashMap<String, Object>() : NCPPlayer.getPlayer(player)
.collectData();
String filter = "";
if (args.length > 2)
@ -131,16 +94,53 @@ public class CommandHandler {
return true;
}
private boolean handleReloadCommand(final NoCheatPlus plugin, final CommandSender sender) {
private boolean handleReloadCommand(final CommandSender sender) {
// Players need a special permission for this
if (!(sender instanceof Player) || sender.hasPermission(Permissions.ADMIN_RELOAD)) {
sender.sendMessage("[NoCheatPlus] Reloading configuration");
plugin.reloadConfiguration();
ConfigManager.cleanup();
ConfigManager.init();
sender.sendMessage("[NoCheatPlus] Configuration reloaded");
} else
sender.sendMessage("You lack the " + Permissions.ADMIN_RELOAD + " permission to use 'reload'");
return true;
}
/**
* Handle a command that is directed at NoCheatPlus
*/
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String commandLabel,
final String[] args) {
if (sender instanceof Player) {
final String worldName = ((Player) sender).getWorld().getName();
final boolean protectPlugins = ConfigManager.getConfigFile(worldName).getBoolean(
ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);
// Hide NoCheatPlus's commands if the player doesn't have the required permission
if (protectPlugins && !sender.hasPermission("nocheatplus.admin.commands")) {
sender.sendMessage("Unknown command. Type \"help\" for help.");
return true;
}
}
boolean result = false;
// Not our command, how did it get here?
if (!command.getName().equalsIgnoreCase("nocheatplus") || args.length == 0)
result = false;
else if (args[0].equalsIgnoreCase("permlist") && args.length >= 2)
// permlist command was used
result = handlePermlistCommand(sender, args);
else if (args[0].equalsIgnoreCase("reload"))
// reload command was used
result = handleReloadCommand(sender);
else if (args[0].equalsIgnoreCase("playerinfo") && args.length >= 2)
// playerinfo command was used
result = handlePlayerInfoCommand(sender, args);
return result;
}
}

View File

@ -1,29 +1,10 @@
package me.neatmonster.nocheatplus;
package fr.neatmonster.nocheatplus;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import me.neatmonster.nocheatplus.checks.WorkaroundsListener;
import me.neatmonster.nocheatplus.checks.blockbreak.BlockBreakCheckListener;
import me.neatmonster.nocheatplus.checks.blockplace.BlockPlaceCheckListener;
import me.neatmonster.nocheatplus.checks.chat.ChatCheckListener;
import me.neatmonster.nocheatplus.checks.fight.FightCheckListener;
import me.neatmonster.nocheatplus.checks.inventory.InventoryCheckListener;
import me.neatmonster.nocheatplus.checks.moving.MovingCheckListener;
import me.neatmonster.nocheatplus.command.CommandHandler;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.ConfigurationManager;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.PlayerManager;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -32,77 +13,60 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
/**
*
* NoCheatPlus
*
* Check various player events for their plausibility and log/deny them/react to
* them based on configuration
*/
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.checks.WorkaroundsListener;
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener;
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceListener;
import fr.neatmonster.nocheatplus.checks.chat.ChatListener;
import fr.neatmonster.nocheatplus.checks.fight.FightListener;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.utilities.Colors;
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
import fr.neatmonster.nocheatplus.utilities.LogEvent;
public class NoCheatPlus extends JavaPlugin implements Listener {
public enum Check {
BLOCKBREAK("blockbreak"),
BLOCKPLACE("blockplace"),
CHAT("chat"),
FIGHT("fight"),
INVENTORY("inventory"),
MOVING("moving");
private ConfigurationManager conf;
private CommandHandler commandHandler;
private PlayerManager players;
private final String group;
private List<EventManager> eventManagers;
private LagMeasureTask lagMeasureTask;
private Logger fileLogger;
public NoCheatPlus() {
private Check(final String group) {
this.group = group;
}
private String getGroup() {
return group;
}
}
/**
* Call this periodically to walk over the stored data map and remove
* old/unused entries
*
*/
public void cleanDataMap() {
players.cleanDataMap();
public static NoCheatPlus instance = null;
public static CheckConfig getConfig(final Player player, final Check check) {
return NCPPlayer.getPlayer(player).getConfig(check.getGroup());
}
public ConfigurationCacheStore getConfig(final Player player) {
if (player != null)
return getConfig(player.getWorld());
else
return conf.getConfigurationCacheForWorld(null);
public static boolean skipCheck() {
return instance.lagMeasureTask == null ? false : instance.lagMeasureTask.skipCheck();
}
public ConfigurationCacheStore getConfig(final World world) {
if (world != null)
return conf.getConfigurationCacheForWorld(world.getName());
else
return conf.getConfigurationCacheForWorld(null);
}
public NoCheatPlusPlayer getPlayer(final Player player) {
return players.getPlayer(player);
}
/**
* An interface method usable by other plugins to collect information about
* a player. It will include the plugin version, two timestamps (beginning
* and end of data collection for that player), and various data from
* checks)
*
* @param playerName
* a player name
* @return A newly created map of identifiers and corresponding values
*/
public Map<String, Object> getPlayerData(final String playerName) {
final Map<String, Object> map = players.getPlayerData(playerName);
map.put("nocheatplus.version", getDescription().getVersion());
return map;
}
private CommandHandler commandHandler;
private Logger fileLogger;
private LagMeasureTask lagMeasureTask;
private List<Listener> listeners;
@EventHandler(
priority = EventPriority.MONITOR)
public void logEvent(final NoCheatPlusLogEvent event) {
public void logEvent(final LogEvent event) {
if (event.toConsole())
// Console logs are not colored
System.out.println(Colors.removeColors(event.getPrefix() + event.getMessage()));
@ -116,13 +80,6 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
fileLogger.info(Colors.removeColors(event.getMessage()));
}
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
final boolean result = commandHandler.handleCommand(this, sender, command, label, args);
return result;
}
@Override
public void onDisable() {
@ -133,10 +90,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
lagMeasureTask = null;
}
if (conf != null) {
conf.cleanup();
conf = null;
}
ConfigManager.cleanup();
// Just to be sure nothing gets left out
getServer().getScheduler().cancelTasks(this);
@ -148,37 +102,37 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
@Override
public void onEnable() {
instance = this;
// Then set up in memory per player data storage
players = new PlayerManager(this);
commandHandler = new CommandHandler(this);
commandHandler = new CommandHandler();
// Then read the configuration files
conf = new ConfigurationManager(this, getDataFolder());
ConfigManager.init();
eventManagers = new ArrayList<EventManager>(8); // Big enough
listeners = new ArrayList<Listener>();
// Then set up the event listeners
eventManagers.add(new MovingCheckListener(this));
eventManagers.add(new WorkaroundsListener());
eventManagers.add(new ChatCheckListener(this));
eventManagers.add(new BlockBreakCheckListener(this));
eventManagers.add(new BlockPlaceCheckListener(this));
eventManagers.add(new FightCheckListener(this));
eventManagers.add(new InventoryCheckListener(this));
listeners.add(new WorkaroundsListener());
listeners.add(new BlockBreakListener());
listeners.add(new BlockPlaceListener());
listeners.add(new ChatListener());
listeners.add(new FightListener());
listeners.add(new InventoryListener());
listeners.add(new MovingListener());
// Then set up a task to monitor server lag
if (lagMeasureTask == null) {
lagMeasureTask = new LagMeasureTask(this);
lagMeasureTask = new LagMeasureTask();
lagMeasureTask.start();
}
// register all listeners
for (final EventManager eventManager : eventManagers)
Bukkit.getPluginManager().registerEvents(eventManager, this);
for (final Listener listener : listeners)
Bukkit.getPluginManager().registerEvents(listener, this);
Bukkit.getPluginManager().registerEvents(this, this);
NoCheatPlusConfiguration.writeInstructions(this);
getCommand("nocheatplus").setExecutor(commandHandler);
ConfigManager.writeInstructions();
// Tell the server admin that we finished loading NoCheatPlus now
System.out.println("[NoCheatPlus] version [" + getDescription().getVersion() + "] is enabled.");
@ -188,7 +142,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
if (getConfig(player).getConfiguration().getBoolean(ConfPaths.MISCELLANEOUS_ALLOWCLIENTMODS))
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.MISCELLANEOUS_ALLOWCLIENTMODS))
return;
String message = "";
// Disable Zombe's fly mod
@ -245,19 +199,7 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
player.sendMessage(message);
}
public void reloadConfiguration() {
conf.cleanup();
conf = new ConfigurationManager(this, getDataFolder());
players.cleanDataMap();
}
public void setFileLogger(final Logger logger) {
fileLogger = logger;
}
public boolean skipCheck() {
if (lagMeasureTask != null)
return lagMeasureTask.skipCheck();
return false;
}
}

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.actions;
package fr.neatmonster.nocheatplus.actions;
/**
* An action gets executed as the result of a failed check. If it 'really' gets

View File

@ -1,16 +1,15 @@
package me.neatmonster.nocheatplus.config;
package fr.neatmonster.nocheatplus.actions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.neatmonster.nocheatplus.actions.Action;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.actions.types.ConsolecommandAction;
import me.neatmonster.nocheatplus.actions.types.DummyAction;
import me.neatmonster.nocheatplus.actions.types.LogAction;
import me.neatmonster.nocheatplus.actions.types.SpecialAction;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.actions.types.ConsolecommandAction;
import fr.neatmonster.nocheatplus.actions.types.DummyAction;
import fr.neatmonster.nocheatplus.actions.types.LogAction;
import fr.neatmonster.nocheatplus.actions.types.SpecialAction;
/**
* Helps with creating Actions out of text string definitions

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.actions;
package fr.neatmonster.nocheatplus.actions;
/**
* Some wildcards that are used in commands and log messages

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.actions.types;
package fr.neatmonster.nocheatplus.actions.types;
import java.util.ArrayList;
import java.util.Collections;
@ -6,7 +6,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import me.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.Action;
/**
* A list of actions, that associates actions to tresholds. It allows to

View File

@ -1,11 +1,11 @@
package me.neatmonster.nocheatplus.actions.types;
package fr.neatmonster.nocheatplus.actions.types;
import java.util.ArrayList;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.Action;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Action with parameters is used to
@ -30,7 +30,7 @@ public abstract class ActionWithParameters extends Action {
* @return
*/
protected String getMessage(final NoCheatPlusPlayer player, final Check check) {
protected String getMessage(final NCPPlayer player, final Check check) {
final StringBuilder log = new StringBuilder(100); // Should be big enough most
// of the time

View File

@ -1,7 +1,7 @@
package me.neatmonster.nocheatplus.actions.types;
package fr.neatmonster.nocheatplus.actions.types;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Execute a command by imitating an admin typing the command directly into the
@ -26,7 +26,7 @@ public class ConsolecommandAction extends ActionWithParameters {
* The check that is used to fill in missing data
* @return The complete, ready to use, command
*/
public String getCommand(final NoCheatPlusPlayer player, final Check check) {
public String getCommand(final NCPPlayer player, final Check check) {
return super.getMessage(player, check);
}

View File

@ -1,6 +1,6 @@
package me.neatmonster.nocheatplus.actions.types;
package fr.neatmonster.nocheatplus.actions.types;
import me.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.Action;
/**
* If an action can't be parsed correctly, at least keep it

View File

@ -1,7 +1,7 @@
package me.neatmonster.nocheatplus.actions.types;
package fr.neatmonster.nocheatplus.actions.types;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Print a log message to various locations
@ -33,7 +33,7 @@ public class LogAction extends ActionWithParameters {
* The check that is used as a source for the log message
* @return
*/
public String getLogMessage(final NoCheatPlusPlayer player, final Check check) {
public String getLogMessage(final NCPPlayer player, final Check check) {
return super.getMessage(player, check);
}

View File

@ -1,6 +1,6 @@
package me.neatmonster.nocheatplus.actions.types;
package fr.neatmonster.nocheatplus.actions.types;
import me.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.Action;
/**
* Do something check-specific. Usually that is to cancel the event, undo

View File

@ -0,0 +1,172 @@
package fr.neatmonster.nocheatplus.checks;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandException;
import fr.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.actions.types.ConsolecommandAction;
import fr.neatmonster.nocheatplus.actions.types.DummyAction;
import fr.neatmonster.nocheatplus.actions.types.LogAction;
import fr.neatmonster.nocheatplus.actions.types.SpecialAction;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.LogEvent;
public abstract class Check {
private static final Map<String, Check> checks = new HashMap<String, Check>();
public static CheckConfig newConfig(final String group, final String worldName) {
if (checks.containsKey(group))
return checks.get(group).newConfig(worldName);
return null;
}
public static CheckData newData(final String group) {
if (checks.containsKey(group))
return checks.get(group).newData();
return null;
}
private final String name;
private final Class<? extends CheckConfig> configClass;
private final Class<? extends CheckData> dataClass;
public Check(final String name, final Class<? extends CheckConfig> configClass,
final Class<? extends CheckData> dataClass) {
this.name = name;
this.configClass = configClass;
this.dataClass = dataClass;
checks.put(getGroup(), this);
}
/**
* Execute some actions for the specified player
*
* @param player
* @param actions
* @return
*/
protected boolean executeActions(final NCPPlayer player, final ActionList actionList, final double violationLevel) {
boolean special = false;
// Get the to be executed actions
final Action[] actions = actionList.getActions(violationLevel);
final long time = System.currentTimeMillis() / 1000L;
for (final Action ac : actions)
if (player.getExecutionHistory().executeAction(getGroup(), ac, time))
// The executionHistory 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 SpecialAction)
special = true;
else if (ac instanceof ConsolecommandAction)
executeConsoleCommand((ConsolecommandAction) ac, this, player);
else if (ac instanceof DummyAction) {
// nothing - it's a "DummyAction" after all
}
return special;
}
private void executeConsoleCommand(final ConsolecommandAction action, final Check check, final NCPPlayer player) {
final String command = action.getCommand(player, check);
try {
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} catch (final CommandException e) {
System.out.println("[NoCheatPlus] failed to execute the command '" + command + "': " + e.getMessage()
+ ", please check if everything is setup correct.");
} catch (final Exception e) {
// I don't care in this case, your problem if your command fails.
}
}
private void executeLogAction(final LogAction l, final Check check, final NCPPlayer player) {
final ConfigFile configurationFile = ConfigManager.getConfigFile();
if (!configurationFile.getBoolean(ConfPaths.LOGGING_ACTIVE))
return;
// Fire one of our custom "Log" Events
Bukkit.getServer()
.getPluginManager()
.callEvent(
new LogEvent(configurationFile.getString(ConfPaths.LOGGING_PREFIX), l.getLogMessage(player,
check), configurationFile.getBoolean(ConfPaths.LOGGING_LOGTOCONSOLE) && l.toConsole(),
configurationFile.getBoolean(ConfPaths.LOGGING_LOGTOINGAMECHAT) && l.toChat(),
configurationFile.getBoolean(ConfPaths.LOGGING_LOGTOFILE) && l.toFile()));
}
public String getGroup() {
return name.contains(".") ? name.split("\\.")[0] : name;
}
/**
* 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(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.PLAYER)
return player.getName();
else if (wildcard == ParameterName.CHECK)
return name;
else if (wildcard == ParameterName.LOCATION) {
final Location l = player.getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
} else if (wildcard == ParameterName.WORLD)
return player.getWorld().getName();
else
return "the Author was lazy and forgot to define " + wildcard + ".";
}
/**
* Collect information about the players violations
*
* @param player
* @param id
* @param vl
*/
protected void incrementStatistics(final NCPPlayer player, final Id id, final double vl) {
player.getStatistics().increment(id, vl);
}
public CheckConfig newConfig(final String worldName) {
try {
return configClass.getConstructor(ConfigFile.class).newInstance(ConfigManager.getConfFile(worldName));
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
public CheckData newData() {
try {
return dataClass.getConstructor().newInstance();
} catch (final Exception e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -0,0 +1,3 @@
package fr.neatmonster.nocheatplus.checks;
public abstract class CheckConfig {}

View File

@ -0,0 +1,3 @@
package fr.neatmonster.nocheatplus.checks;
public abstract class CheckData {}

View File

@ -0,0 +1,21 @@
package fr.neatmonster.nocheatplus.checks;
import org.bukkit.event.Listener;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
public abstract class CheckListener implements Listener {
private final String group;
public CheckListener(final String group) {
this.group = group;
}
public CheckConfig getConfig(final NCPPlayer player) {
return player.getConfig(group);
}
public CheckData getData(final NCPPlayer player) {
return player.getData(group);
}
}

View File

@ -1,7 +1,5 @@
package me.neatmonster.nocheatplus.checks;
package fr.neatmonster.nocheatplus.checks;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import net.minecraft.server.Block;
import org.bukkit.Location;
@ -11,12 +9,15 @@ import org.bukkit.block.BlockFace;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* Some stuff that's used by different checks or just too complex to keep
* in other places
*
*/
public class CheckUtil {
public class CheckUtils {
private static final double magic = 0.45D;
@ -114,11 +115,11 @@ public class CheckUtil {
* Check if a player looks at a target of a specific size, with a specific
* precision value (roughly)
*/
public static double directionCheck(final NoCheatPlusPlayer player, final double targetX, final double targetY,
public static double directionCheck(final NCPPlayer player, final double targetX, final double targetY,
final double targetZ, final double targetWidth, final double targetHeight, final double precision) {
// Eye location of the player
final Location eyes = player.getPlayer().getEyeLocation();
final Location eyes = player.getBukkitPlayer().getEyeLocation();
final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2)
+ Math.pow(eyes.getZ() - targetZ, 2));
@ -323,10 +324,10 @@ public class CheckUtil {
* @param limit
* @return
*/
public static double reachCheck(final NoCheatPlusPlayer player, final double targetX, final double targetY,
public static double reachCheck(final NCPPlayer player, final double targetX, final double targetY,
final double targetZ, final double limit) {
final Location eyes = player.getPlayer().getEyeLocation();
final Location eyes = player.getBukkitPlayer().getEyeLocation();
final double distance = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2)
+ Math.pow(eyes.getZ() - targetZ, 2));

View File

@ -1,10 +1,4 @@
package me.neatmonster.nocheatplus.checks;
import java.util.Collections;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
package fr.neatmonster.nocheatplus.checks;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -17,14 +11,7 @@ import org.bukkit.event.player.PlayerToggleSprintEvent;
* to relevant checks
*
*/
public class WorkaroundsListener implements Listener, EventManager {
public WorkaroundsListener() {}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
return Collections.emptyList();
}
public class WorkaroundsListener implements Listener {
@EventHandler(
priority = EventPriority.HIGHEST)

View File

@ -0,0 +1,24 @@
package fr.neatmonster.nocheatplus.checks.blockbreak;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Abstract base class for BlockBreakChecks.
*/
public abstract class BlockBreakCheck extends Check {
public BlockBreakCheck(final String name) {
super("blockbreak." + name, BlockBreakConfig.class, BlockBreakData.class);
}
public abstract boolean check(final NCPPlayer player, final Object... args);
public BlockBreakConfig getConfig(final NCPPlayer player) {
return (BlockBreakConfig) player.getConfig(this);
}
public BlockBreakData getData(final NCPPlayer player) {
return (BlockBreakData) player.getData(this);
}
}

View File

@ -1,10 +1,10 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import me.neatmonster.nocheatplus.ConfigItem;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Configurations specific for the "BlockBreak" checks
@ -12,7 +12,7 @@ import me.neatmonster.nocheatplus.config.Permissions;
* it's own, it will use the "global" version
*
*/
public class BlockBreakConfig implements ConfigItem {
public class BlockBreakConfig extends CheckConfig {
public final boolean fastBreakCheck;
public final int fastBreakIntervalSurvival;
@ -31,7 +31,7 @@ public class BlockBreakConfig implements ConfigItem {
public final boolean noswingCheck;
public final ActionList noswingActions;
public BlockBreakConfig(final NoCheatPlusConfiguration data) {
public BlockBreakConfig(final ConfigFile data) {
fastBreakCheck = data.getBoolean(ConfPaths.BLOCKBREAK_FASTBREAK_CHECK);
fastBreakIntervalSurvival = data.getInt(ConfPaths.BLOCKBREAK_FASTBREAK_INTERVALSURVIVAL);

View File

@ -1,13 +1,13 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import me.neatmonster.nocheatplus.DataItem;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import fr.neatmonster.nocheatplus.checks.CheckData;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* Player specific data for the blockbreak checks
*
*/
public class BlockBreakData implements DataItem {
public class BlockBreakData extends CheckData {
// Keep track of violation levels for the three checks
public double fastBreakVL = 0.0D;

View File

@ -1,43 +1,35 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
import java.util.LinkedList;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.Permissions;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Central location to listen to events that are
* relevant for the blockbreak checks
*
*/
public class BlockBreakCheckListener implements Listener, EventManager {
public class BlockBreakListener extends CheckListener {
private final FastBreakCheck fastBreakCheck;
private final NoswingCheck noswingCheck;
private final ReachCheck reachCheck;
private final DirectionCheck directionCheck;
private final NoCheatPlus plugin;
public BlockBreakCheckListener(final NoCheatPlus plugin) {
public BlockBreakListener() {
super("blockbreak");
fastBreakCheck = new FastBreakCheck(plugin);
noswingCheck = new NoswingCheck(plugin);
reachCheck = new ReachCheck(plugin);
directionCheck = new DirectionCheck(plugin);
this.plugin = plugin;
fastBreakCheck = new FastBreakCheck();
noswingCheck = new NoswingCheck();
reachCheck = new ReachCheck();
directionCheck = new DirectionCheck();
}
/**
@ -52,7 +44,7 @@ public class BlockBreakCheckListener implements Listener, EventManager {
priority = EventPriority.MONITOR)
public void armSwing(final PlayerAnimationEvent event) {
// Just set a flag to true when the arm was swung
BlockBreakCheck.getData(plugin.getPlayer(event.getPlayer())).armswung = true;
((BlockBreakData) getData(NCPPlayer.getPlayer(event.getPlayer()))).armswung = true;
}
/**
@ -64,13 +56,12 @@ public class BlockBreakCheckListener implements Listener, EventManager {
@EventHandler(
ignoreCancelled = true, priority = EventPriority.LOWEST)
public void blockBreak(final BlockBreakEvent event) {
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final BlockBreakConfig cc = (BlockBreakConfig) getConfig(player);
final BlockBreakData data = (BlockBreakData) getData(player);
boolean cancelled = false;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final BlockBreakConfig cc = BlockBreakCheck.getConfig(player);
final BlockBreakData data = BlockBreakCheck.getData(player);
// Remember the location of the block that will be broken
data.brokenBlockLocation.set(event.getBlock());
@ -88,20 +79,20 @@ public class BlockBreakCheckListener implements Listener, EventManager {
// First FastPlace: Has the player broken blocks too quickly?
if (cc.fastBreakCheck && !player.hasPermission(Permissions.BLOCKBREAK_FASTBREAK))
cancelled = fastBreakCheck.check(player, data, cc);
cancelled = fastBreakCheck.check(player);
// Second NoSwing: Did the arm of the player move before breaking this
// block?
if (!cancelled && cc.noswingCheck && !player.hasPermission(Permissions.BLOCKBREAK_NOSWING))
cancelled = noswingCheck.check(player, data, cc);
cancelled = noswingCheck.check(player);
// Third Reach: Is the block really in reach distance
if (!cancelled && cc.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH))
cancelled = reachCheck.check(player, data, cc);
cancelled = reachCheck.check(player);
// Forth Direction: Did the player look at the block at all
if (!cancelled && cc.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION))
cancelled = directionCheck.check(player, data, cc);
cancelled = directionCheck.check(player);
// At least one check failed and demanded to cancel the event
if (cancelled)
@ -118,16 +109,14 @@ public class BlockBreakCheckListener implements Listener, EventManager {
@EventHandler(
ignoreCancelled = true, priority = EventPriority.MONITOR)
public void blockHit(final BlockDamageEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final BlockBreakData data = BlockBreakCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final BlockBreakData data = (BlockBreakData) getData(player);
// Only interested in insta-break events here
if (event.getInstaBreak())
// Remember this location. We handle insta-breaks slightly
// different in some of the blockbreak checks.
data.instaBrokenBlockLocation.set(event.getBlock());
}
/**
@ -145,28 +134,11 @@ public class BlockBreakCheckListener implements Listener, EventManager {
if (event.getClickedBlock() == null)
return;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final BlockBreakData data = BlockBreakCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final BlockBreakData data = (BlockBreakData) getData(player);
// Remember this location. Only blockbreakevents for this specific
// block will be handled at all
data.lastDamagedBlock.set(event.getClickedBlock());
}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
final LinkedList<String> s = new LinkedList<String>();
final BlockBreakConfig bb = BlockBreakCheck.getConfig(cc);
if (bb.fastBreakCheck)
s.add("blockbreak.fastbreak");
if (bb.directionCheck)
s.add("blockbreak.direction");
if (bb.reachCheck)
s.add("blockbreak.reach");
if (bb.noswingCheck)
s.add("blockbreak.noswing");
return s;
}
}

View File

@ -1,13 +1,12 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* The DirectionCheck will find out if a player tried to interact with something
@ -16,21 +15,25 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class DirectionCheck extends BlockBreakCheck {
public DirectionCheck(final NoCheatPlus plugin) {
super(plugin, "blockbreak.direction");
public DirectionCheck() {
super("direction");
}
public boolean check(final NoCheatPlusPlayer player, final BlockBreakData data, final BlockBreakConfig ccblockbreak) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final BlockBreakConfig cc = getConfig(player);
final BlockBreakData data = getData(player);
final SimpleLocation brokenBlock = data.brokenBlockLocation;
boolean cancel = false;
// How far "off" is the player with his aim. We calculate from the
// players eye location and view direction to the center of the target
// block. If the line of sight is more too far off, "off" will be
// bigger than 0
double off = CheckUtil.directionCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D, brokenBlock.z + 0.5D,
1D, 1D, ccblockbreak.directionPrecision);
double off = CheckUtils.directionCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D,
brokenBlock.z + 0.5D, 1D, 1D, cc.directionPrecision);
final long time = System.currentTimeMillis();
@ -53,7 +56,7 @@ public class DirectionCheck extends BlockBreakCheck {
// Execute whatever actions are associated with this check and the
// violation level and find out if we should cancel the event
cancel = executeActions(player, ccblockbreak.directionActions, data.directionVL);
cancel = executeActions(player, cc.directionActions, data.directionVL);
if (cancel)
// if we should cancel, remember the current time too
@ -61,7 +64,7 @@ public class DirectionCheck extends BlockBreakCheck {
}
// If the player is still in penalty time, cancel the event anyway
if (data.directionLastViolationTime + ccblockbreak.directionPenaltyTime > time) {
if (data.directionLastViolationTime + cc.directionPenaltyTime > time) {
// A saveguard to avoid people getting stuck in penalty time
// indefinitely in case the system time of the server gets changed
if (data.directionLastViolationTime > time)
@ -75,7 +78,7 @@ public class DirectionCheck extends BlockBreakCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).directionVL);

View File

@ -1,29 +1,32 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.GameMode;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* A check used to verify if the player isn't placing his blocks too quickly
*
*/
public class FastBreakCheck extends BlockBreakCheck {
public FastBreakCheck(final NoCheatPlus plugin) {
super(plugin, "blockbreak.fastbreak");
public FastBreakCheck() {
super("fastbreak");
}
public boolean check(final NoCheatPlusPlayer player, final BlockBreakData data, final BlockBreakConfig cc) {
@Override
public boolean check(final fr.neatmonster.nocheatplus.players.NCPPlayer player, final Object... args) {
final BlockBreakConfig cc = getConfig(player);
final BlockBreakData data = getData(player);
// Get the minimum break time for the player's game mode
int breakTime = cc.fastBreakIntervalSurvival;
if (player.getPlayer().getGameMode() == GameMode.CREATIVE)
if (player.getBukkitPlayer().getGameMode() == GameMode.CREATIVE)
breakTime = cc.fastBreakIntervalCreative;
// Elapsed time since the previous block was broken
@ -33,7 +36,7 @@ public class FastBreakCheck extends BlockBreakCheck {
// Has the player broken the blocks too quickly
if (data.lastBreakTime != 0 && elapsedTime < breakTime) {
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
if (data.previousRefused) {
// He failed, increase vl and statistics
data.fastBreakVL += breakTime - elapsedTime;
@ -53,11 +56,10 @@ public class FastBreakCheck extends BlockBreakCheck {
data.lastBreakTime = System.currentTimeMillis();
return cancel;
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).fastBreakVL);

View File

@ -1,11 +1,10 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* We require that the player moves his arm between blockbreaks, this is
@ -14,11 +13,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class NoswingCheck extends BlockBreakCheck {
public NoswingCheck(final NoCheatPlus plugin) {
super(plugin, "blockbreak.noswing");
public NoswingCheck() {
super("noswing");
}
public boolean check(final NoCheatPlusPlayer player, final BlockBreakData data, final BlockBreakConfig cc) {
@Override
public boolean check(final fr.neatmonster.nocheatplus.players.NCPPlayer player, final Object... args) {
final BlockBreakConfig cc = getConfig(player);
final BlockBreakData data = getData(player);
boolean cancel = false;
@ -42,12 +44,11 @@ public class NoswingCheck extends BlockBreakCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).noswingVL);
else
return super.getParameter(wildcard, player);
}
}

View File

@ -1,13 +1,14 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
package fr.neatmonster.nocheatplus.checks.blockbreak;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.GameMode;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* The reach check will find out if a player interacts with something that's
@ -16,11 +17,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class ReachCheck extends BlockBreakCheck {
public ReachCheck(final NoCheatPlus plugin) {
super(plugin, "blockbreak.reach");
public ReachCheck() {
super("reach");
}
public boolean check(final NoCheatPlusPlayer player, final BlockBreakData data, final BlockBreakConfig cc) {
@Override
public boolean check(final fr.neatmonster.nocheatplus.players.NCPPlayer player, final Object... args) {
final BlockBreakConfig cc = getConfig(player);
final BlockBreakData data = getData(player);
boolean cancel = false;
@ -29,8 +33,9 @@ public class ReachCheck extends BlockBreakCheck {
// 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 = CheckUtil.reachCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D,
brokenBlock.z + 0.5D, player.isCreative() ? cc.reachDistance + 2 : cc.reachDistance);
final double distance = CheckUtils.reachCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D,
brokenBlock.z + 0.5D,
player.getBukkitPlayer().getGameMode() == GameMode.CREATIVE ? cc.reachDistance + 2 : cc.reachDistance);
if (distance <= 0D)
// Player passed the check, reward him
@ -53,7 +58,7 @@ public class ReachCheck extends BlockBreakCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).reachVL);

View File

@ -0,0 +1,51 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import java.util.Locale;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* Abstract base class for BlockPlace checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class BlockPlaceCheck extends Check {
public BlockPlaceCheck(final String name) {
super("blockplace." + name, BlockPlaceConfig.class, BlockPlaceData.class);
}
public abstract boolean check(final NCPPlayer player, final Object... args);
public BlockPlaceConfig getConfig(final NCPPlayer player) {
return (BlockPlaceConfig) player.getConfig(this);
}
public BlockPlaceData getData(final NCPPlayer player) {
return (BlockPlaceData) player.getData(this);
}
@Override
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.PLACE_LOCATION) {
final SimpleLocation l = getData(player).blockPlaced;
if (l.isSet())
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
else
return "null";
}
else if (wildcard == ParameterName.PLACE_AGAINST) {
final SimpleLocation l = getData(player).blockPlacedAgainst;
if (l.isSet())
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
else
return "null";
}
else
return super.getParameter(wildcard, player);
}
}

View File

@ -0,0 +1,62 @@
package fr.neatmonster.nocheatplus.checks.blockplace;
import java.util.ArrayList;
import java.util.List;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Configurations specific for the "BlockPlace" checks
* Every world gets one of these assigned to it, or if a world doesn't get
* it's own, it will use the "global" version
*
*/
public class BlockPlaceConfig extends CheckConfig {
public final boolean fastPlaceCheck;
public final int fastPlaceInterval;
public final ActionList fastPlaceActions;
public final boolean reachCheck;
public final double reachDistance;
public final ActionList reachActions;
public final boolean directionCheck;
public final ActionList directionActions;
public final long directionPenaltyTime;
public final double directionPrecision;
public final boolean projectileCheck;
public final int projectileInterval;
public final ActionList projectileActions;
public final List<String> fastSignExclusions = new ArrayList<String>();
public BlockPlaceConfig(final ConfigFile data) {
fastPlaceCheck = data.getBoolean(ConfPaths.BLOCKPLACE_FASTPLACE_CHECK);
fastPlaceInterval = data.getInt(ConfPaths.BLOCKPLACE_FASTPLACE_INTERVAL);
fastPlaceActions = data.getActionList(ConfPaths.BLOCKPLACE_FASTPLACE_ACTIONS, Permissions.BLOCKPLACE_FASTPLACE);
reachCheck = data.getBoolean(ConfPaths.BLOCKPLACE_REACH_CHECK);
reachDistance = 535D / 100D;
reachActions = data.getActionList(ConfPaths.BLOCKPLACE_REACH_ACTIONS, Permissions.BLOCKPLACE_REACH);
directionCheck = data.getBoolean(ConfPaths.BLOCKPLACE_DIRECTION_CHECK);
directionPenaltyTime = data.getInt(ConfPaths.BLOCKPLACE_DIRECTION_PENALTYTIME);
directionPrecision = data.getInt(ConfPaths.BLOCKPLACE_DIRECTION_PRECISION) / 100D;
directionActions = data.getActionList(ConfPaths.BLOCKPLACE_DIRECTION_ACTIONS, Permissions.BLOCKPLACE_DIRECTION);
projectileCheck = data.getBoolean(ConfPaths.BLOCKPLACE_PROJECTILE_CHECK);
projectileInterval = data.getInt(ConfPaths.BLOCKPLACE_PROJECTILE_INTERVAL);
projectileActions = data.getActionList(ConfPaths.BLOCKPLACE_PROJECTILE_ACTIONS,
Permissions.BLOCKPLACE_PROJECTILE);
for (final String exclusion : data.getStringList(ConfPaths.BLOCKPLACE_FASTSIGN_EXCLUSIONS))
data.getStringList(ConfPaths.BLOCKPLACE_FASTSIGN_EXCLUSIONS).add(exclusion.toLowerCase());
}
}

View File

@ -1,13 +1,13 @@
package me.neatmonster.nocheatplus.checks.blockplace;
package fr.neatmonster.nocheatplus.checks.blockplace;
import me.neatmonster.nocheatplus.DataItem;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import fr.neatmonster.nocheatplus.checks.CheckData;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* Player specific data for the blockbreak checks
*
*/
public class BlockPlaceData implements DataItem {
public class BlockPlaceData extends CheckData {
// Keep track of violation levels for the two checks
public double fastPlaceVL = 0.0D;

View File

@ -1,64 +1,38 @@
package me.neatmonster.nocheatplus.checks.blockplace;
import java.util.LinkedList;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.Permissions;
package fr.neatmonster.nocheatplus.checks.blockplace;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Central location to listen to Block-related events and dispatching them to
* checks
*
*/
public class BlockPlaceCheckListener implements Listener, EventManager {
public class BlockPlaceListener extends CheckListener {
private final FastPlaceCheck fastPlaceCheck;
private final ReachCheck reachCheck;
private final DirectionCheck directionCheck;
private final ProjectileCheck projectileCheck;
private final NoCheatPlus plugin;
public BlockPlaceCheckListener(final NoCheatPlus plugin) {
public BlockPlaceListener() {
super("blockplace");
this.plugin = plugin;
fastPlaceCheck = new FastPlaceCheck(plugin);
reachCheck = new ReachCheck(plugin);
directionCheck = new DirectionCheck(plugin);
projectileCheck = new ProjectileCheck(plugin);
}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
final LinkedList<String> s = new LinkedList<String>();
final BlockPlaceConfig bp = BlockPlaceCheck.getConfig(cc);
if (bp.fastPlaceCheck)
s.add("blockplace.fastplace");
if (bp.reachCheck)
s.add("blockplace.reach");
if (bp.directionCheck)
s.add("blockplace.direction");
if (bp.projectileCheck)
s.add("blockplace.projectileCheck");
return s;
fastPlaceCheck = new FastPlaceCheck();
reachCheck = new ReachCheck();
directionCheck = new DirectionCheck();
projectileCheck = new ProjectileCheck();
}
/**
@ -74,11 +48,11 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
if (event.getBlock() == null || event.getBlockAgainst() == null)
return;
boolean cancelled = false;
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final BlockPlaceConfig cc = (BlockPlaceConfig) getConfig(player);
final BlockPlaceData data = (BlockPlaceData) getData(player);
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final BlockPlaceConfig cc = BlockPlaceCheck.getConfig(player);
final BlockPlaceData data = BlockPlaceCheck.getData(player);
boolean cancelled = false;
// Remember these locations and put them in a simpler "format"
data.blockPlaced.set(event.getBlock());
@ -88,15 +62,15 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
// First the fastplace check
if (cc.fastPlaceCheck && !player.hasPermission(Permissions.BLOCKPLACE_FASTPLACE))
cancelled = fastPlaceCheck.check(player, data, cc);
cancelled = fastPlaceCheck.check(player);
// Second the reach check
if (!cancelled && cc.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH))
cancelled = reachCheck.check(player, data, cc);
cancelled = reachCheck.check(player);
// Third the direction check
if (!cancelled && cc.directionCheck && !player.hasPermission(Permissions.BLOCKPLACE_DIRECTION))
cancelled = directionCheck.check(player, data, cc);
cancelled = directionCheck.check(player);
// If one of the checks requested to cancel the event, do so
if (cancelled)
@ -112,13 +86,12 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
|| event.getPlayer().getItemInHand().getType() != Material.MONSTER_EGG)
return;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final BlockPlaceConfig cc = BlockPlaceCheck.getConfig(player);
final BlockPlaceData data = BlockPlaceCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final BlockPlaceConfig cc = (BlockPlaceConfig) getConfig(player);
// Do the actual check
if (cc.projectileCheck && !player.hasPermission(Permissions.BLOCKPLACE_PROJECTILE)
&& projectileCheck.check(player, data, cc))
&& projectileCheck.check(player))
// If the check is positive, cancel the event
event.setCancelled(true);
}
@ -146,13 +119,12 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
return;
}
final NoCheatPlusPlayer player = plugin.getPlayer((Player) event.getEntity().getShooter());
final BlockPlaceConfig cc = BlockPlaceCheck.getConfig(player);
final BlockPlaceData data = BlockPlaceCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer((Player) event.getEntity().getShooter());
final BlockPlaceConfig cc = (BlockPlaceConfig) getConfig(player);
// Do the actual check
if (cc.projectileCheck && !player.hasPermission(Permissions.BLOCKPLACE_PROJECTILE)
&& projectileCheck.check(player, data, cc))
&& projectileCheck.check(player))
// If the check is positive, cancel the event
event.setCancelled(true);
}
@ -168,12 +140,15 @@ public class BlockPlaceCheckListener implements Listener, EventManager {
ignoreCancelled = true, priority = EventPriority.LOWEST)
public void sign(final SignChangeEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final BlockPlaceData data = BlockPlaceCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final BlockPlaceConfig cc = (BlockPlaceConfig) getConfig(player);
final BlockPlaceData data = (BlockPlaceData) getData(player);
// Check if the sign's content is empty
// if is the first line is whitelisted
if (event.getLine(0).length() + event.getLine(1).length() + event.getLine(2).length()
+ event.getLine(3).length() == 0)
+ event.getLine(3).length() == 0
|| cc.fastSignExclusions.contains(event.getLine(0).toLowerCase()))
return;
// Check if the text is the same

View File

@ -1,16 +1,15 @@
package me.neatmonster.nocheatplus.checks.blockplace;
package fr.neatmonster.nocheatplus.checks.blockplace;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.Location;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* The DirectionCheck will find out if a player tried to interact with something
* that's not in his field of view.
@ -18,11 +17,14 @@ import org.bukkit.Location;
*/
public class DirectionCheck extends BlockPlaceCheck {
public DirectionCheck(final NoCheatPlus plugin) {
super(plugin, "blockplace.direction");
public DirectionCheck() {
super("direction");
}
public boolean check(final NoCheatPlusPlayer player, final BlockPlaceData data, final BlockPlaceConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final BlockPlaceConfig cc = getConfig(player);
final BlockPlaceData data = getData(player);
boolean cancel = false;
@ -33,7 +35,7 @@ public class DirectionCheck extends BlockPlaceCheck {
// players eye location and view direction to the center of the target
// block. If the line of sight is more too far off, "off" will be
// bigger than 0
double off = CheckUtil.directionCheck(player, blockPlacedAgainst.x + 0.5D, blockPlacedAgainst.y + 0.5D,
double off = CheckUtils.directionCheck(player, blockPlacedAgainst.x + 0.5D, blockPlacedAgainst.y + 0.5D,
blockPlacedAgainst.z + 0.5D, 1D, 1D, cc.directionPrecision);
// now check if the player is looking at the block from the correct side
@ -41,7 +43,7 @@ public class DirectionCheck extends BlockPlaceCheck {
// Find out against which face the player tried to build, and if he
// stood on the correct side of it
final Location eyes = player.getPlayer().getEyeLocation();
final Location eyes = player.getBukkitPlayer().getEyeLocation();
if (blockPlaced.x > blockPlacedAgainst.x)
off2 = blockPlacedAgainst.x + 0.5D - eyes.getX();
else if (blockPlaced.x < blockPlacedAgainst.x)
@ -95,7 +97,7 @@ public class DirectionCheck extends BlockPlaceCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).directionVL);

View File

@ -1,11 +1,11 @@
package me.neatmonster.nocheatplus.checks.blockplace;
package fr.neatmonster.nocheatplus.checks.blockplace;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* A check used to verify if the player isn't breaking his blocks too quickly
@ -13,17 +13,20 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class FastPlaceCheck extends BlockPlaceCheck {
public FastPlaceCheck(final NoCheatPlus plugin) {
super(plugin, "blockplace.fastplace");
public FastPlaceCheck() {
super("fastplace");
}
public boolean check(final NoCheatPlusPlayer player, final BlockPlaceData data, final BlockPlaceConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final BlockPlaceConfig cc = getConfig(player);
final BlockPlaceData data = getData(player);
boolean cancel = false;
// Has the player placed blocks too quickly
if (data.lastPlaceTime != 0 && System.currentTimeMillis() - data.lastPlaceTime < cc.fastPlaceInterval) {
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
if (data.previousRefused) {
// He failed, increase vl and statistics
data.fastPlaceVL += cc.fastPlaceInterval - System.currentTimeMillis() + data.lastPlaceTime;
@ -45,11 +48,10 @@ public class FastPlaceCheck extends BlockPlaceCheck {
data.lastPlaceTime = System.currentTimeMillis();
return cancel;
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).fastPlaceVL);

View File

@ -1,11 +1,10 @@
package me.neatmonster.nocheatplus.checks.blockplace;
package fr.neatmonster.nocheatplus.checks.blockplace;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* A check used to verify if the player isn't throwing projectiles too quickly
@ -13,11 +12,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class ProjectileCheck extends BlockPlaceCheck {
public ProjectileCheck(final NoCheatPlus plugin) {
super(plugin, "blockplace.projectile");
public ProjectileCheck() {
super("projectile");
}
public boolean check(final NoCheatPlusPlayer player, final BlockPlaceData data, final BlockPlaceConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final BlockPlaceConfig cc = getConfig(player);
final BlockPlaceData data = getData(player);
boolean cancel = false;
@ -48,7 +50,7 @@ public class ProjectileCheck extends BlockPlaceCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).projectileVL);

View File

@ -1,13 +1,14 @@
package me.neatmonster.nocheatplus.checks.blockplace;
package fr.neatmonster.nocheatplus.checks.blockplace;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.GameMode;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* The reach check will find out if a player interacts with something that's
@ -16,11 +17,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class ReachCheck extends BlockPlaceCheck {
public ReachCheck(final NoCheatPlus plugin) {
super(plugin, "blockplace.reach");
public ReachCheck() {
super("reach");
}
public boolean check(final NoCheatPlusPlayer player, final BlockPlaceData data, final BlockPlaceConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final BlockPlaceConfig cc = getConfig(player);
final BlockPlaceData data = getData(player);
boolean cancel = false;
@ -29,8 +33,9 @@ public class ReachCheck extends BlockPlaceCheck {
// 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 = CheckUtil.reachCheck(player, placedAgainstBlock.x + 0.5D, placedAgainstBlock.y + 0.5D,
placedAgainstBlock.z + 0.5D, player.isCreative() ? cc.reachDistance + 2 : cc.reachDistance);
final double distance = CheckUtils.reachCheck(player, placedAgainstBlock.x + 0.5D, placedAgainstBlock.y + 0.5D,
placedAgainstBlock.z + 0.5D,
player.getBukkitPlayer().getGameMode() == GameMode.CREATIVE ? cc.reachDistance + 2 : cc.reachDistance);
if (distance <= 0D)
// Player passed the check, reward him
@ -53,7 +58,7 @@ public class ReachCheck extends BlockPlaceCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).reachVL);

View File

@ -1,9 +1,8 @@
package me.neatmonster.nocheatplus.checks.chat;
package fr.neatmonster.nocheatplus.checks.chat;
import java.util.Arrays;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* A check used to limit the number of new players allowed to join in a specified time frame
@ -19,11 +18,13 @@ public class ArrivalsLimitCheck extends ChatCheck {
private long[] joinsTimes = null;
private String[] joinsPlayers = null;
public ArrivalsLimitCheck(final NoCheatPlus plugin) {
super(plugin, "chat.arrivalslimit");
public ArrivalsLimitCheck() {
super("arrivalslimit");
}
public boolean check(final NoCheatPlusPlayer player, final ChatData data, final ChatConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final ChatConfig cc = getConfig(player);
// Initialize the joins array
if (joinsTimes == null)

View File

@ -0,0 +1,36 @@
package fr.neatmonster.nocheatplus.checks.chat;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Abstract base class for Chat checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class ChatCheck extends Check {
public ChatCheck(final String name) {
super("chat." + name, ChatConfig.class, ChatData.class);
}
public abstract boolean check(final NCPPlayer player, final Object... args);
public ChatConfig getConfig(final NCPPlayer player) {
return (ChatConfig) player.getConfig(this);
}
public ChatData getData(final NCPPlayer player) {
return (ChatData) player.getData(this);
}
@Override
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.TEXT)
// Filter colors from the players message when logging
return getData(player).message.replaceAll("\302\247.", "").replaceAll("\247.", "");
else
return super.getParameter(wildcard, player);
}
}

View File

@ -1,10 +1,10 @@
package me.neatmonster.nocheatplus.checks.chat;
package fr.neatmonster.nocheatplus.checks.chat;
import me.neatmonster.nocheatplus.ConfigItem;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Configurations specific for the "Chat" checks
@ -12,7 +12,7 @@ import me.neatmonster.nocheatplus.config.Permissions;
* it's own, it will use the "global" version
*
*/
public class ChatConfig implements ConfigItem {
public class ChatConfig extends CheckConfig {
public final boolean opByConsoleOnly;
public final boolean protectPlugins;
@ -71,7 +71,7 @@ public class ChatConfig implements ConfigItem {
public final boolean colorCheck;
public final ActionList colorActions;
public ChatConfig(final NoCheatPlusConfiguration data) {
public ChatConfig(final ConfigFile data) {
opByConsoleOnly = data.getBoolean(ConfPaths.MISCELLANEOUS_OPBYCONSOLEONLY);
protectPlugins = data.getBoolean(ConfPaths.MISCELLANEOUS_PROTECTPLUGINS);

View File

@ -1,13 +1,13 @@
package me.neatmonster.nocheatplus.checks.chat;
package fr.neatmonster.nocheatplus.checks.chat;
import me.neatmonster.nocheatplus.DataItem;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import fr.neatmonster.nocheatplus.checks.CheckData;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* Player specific data for the chat checks
*
*/
public class ChatData implements DataItem {
public class ChatData extends CheckData {
// Keep track of the violation levels for the check
public int colorVL;

View File

@ -1,45 +1,37 @@
package me.neatmonster.nocheatplus.checks.chat;
package fr.neatmonster.nocheatplus.checks.chat;
import java.lang.management.ManagementFactory;
import java.util.LinkedList;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.Permissions;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Central location to listen to events that are
* relevant for the chat checks
*
*/
public class ChatCheckListener implements Listener, EventManager {
public class ChatListener extends CheckListener {
private final NoPwnageCheck noPwnageCheck;
private final ArrivalsLimitCheck arrivalsLimitCheck;
private final ColorCheck colorCheck;
private final NoCheatPlus plugin;
public ChatListener() {
super("chat");
public ChatCheckListener(final NoCheatPlus plugin) {
this.plugin = plugin;
noPwnageCheck = new NoPwnageCheck(plugin);
arrivalsLimitCheck = new ArrivalsLimitCheck(plugin);
colorCheck = new ColorCheck(plugin);
noPwnageCheck = new NoPwnageCheck();
arrivalsLimitCheck = new ArrivalsLimitCheck();
colorCheck = new ColorCheck();
}
@ -55,9 +47,9 @@ public class ChatCheckListener implements Listener, EventManager {
boolean cancelled = false;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final ChatConfig cc = ChatCheck.getConfig(player);
final ChatData data = ChatCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final ChatConfig cc = (ChatConfig) getConfig(player);
final ChatData data = (ChatData) getData(player);
// Remember the original message
data.message = event.getMessage();
@ -72,11 +64,11 @@ public class ChatCheckListener implements Listener, EventManager {
// First the nopwnage check
if (cc.noPwnageCheck && !player.hasPermission(Permissions.CHAT_NOPWNAGE))
cancelled = noPwnageCheck.check(player, data, cc);
cancelled = noPwnageCheck.check(player);
// Second the color check
if (!cancelled && cc.colorCheck && !player.hasPermission(Permissions.CHAT_COLOR))
cancelled = colorCheck.check(player, data, cc);
cancelled = colorCheck.check(player);
// If one of the checks requested the event to be cancelled, do it
if (cancelled)
@ -98,8 +90,8 @@ public class ChatCheckListener implements Listener, EventManager {
priority = EventPriority.LOWEST)
public void commandPreprocess(final PlayerCommandPreprocessEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final ChatConfig cc = ChatCheck.getConfig(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final ChatConfig cc = (ChatConfig) getConfig(player);
final String command = event.getMessage().split(" ")[0].substring(1).toLowerCase();
@ -130,20 +122,6 @@ public class ChatCheckListener implements Listener, EventManager {
chat(event);
}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
final LinkedList<String> s = new LinkedList<String>();
final ChatConfig c = ChatCheck.getConfig(cc);
if (c.noPwnageCheck)
s.add("chat.nopwnage");
if (c.arrivalsLimitCheck)
s.add("chat.arrivalscheck");
if (c.colorCheck)
s.add("chat.color");
return s;
}
/**
* We listen to PlayerJoin events for the nopwnage check
*
@ -154,9 +132,9 @@ public class ChatCheckListener implements Listener, EventManager {
priority = EventPriority.LOWEST)
public void join(final PlayerJoinEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final ChatConfig cc = ChatCheck.getConfig(player);
final ChatData data = ChatCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final ChatConfig cc = (ChatConfig) getConfig(player);
final ChatData data = (ChatData) getData(player);
// Check if the join is valid
if (cc.noPwnageCheck && !player.hasPermission(Permissions.CHAT_NOPWNAGE))
@ -177,9 +155,9 @@ public class ChatCheckListener implements Listener, EventManager {
if (System.currentTimeMillis() - ManagementFactory.getRuntimeMXBean().getStartTime() < 120000L)
return;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final ChatConfig cc = ChatCheck.getConfig(player);
final ChatData data = ChatCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final ChatConfig cc = (ChatConfig) getConfig(player);
final ChatData data = (ChatData) getData(player);
// Only check new players, not the regular players
if (System.currentTimeMillis() - event.getPlayer().getFirstPlayed() > cc.arrivalsLimitNewTime)

View File

@ -1,19 +1,21 @@
package me.neatmonster.nocheatplus.checks.chat;
package fr.neatmonster.nocheatplus.checks.chat;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
public class ColorCheck extends ChatCheck {
public ColorCheck(final NoCheatPlus plugin) {
super(plugin, "chat.color");
public ColorCheck() {
super("color");
}
public boolean check(final NoCheatPlusPlayer player, final ChatData data, final ChatConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final ChatConfig cc = getConfig(player);
final ChatData data = getData(player);
if (data.message.contains("\247")) {
@ -31,7 +33,7 @@ public class ColorCheck extends ChatCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", getData(player).colorVL);

View File

@ -1,17 +1,18 @@
package me.neatmonster.nocheatplus.checks.chat;
package fr.neatmonster.nocheatplus.checks.chat;
import java.util.Random;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.data.SimpleLocation;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.utilities.Colors;
import fr.neatmonster.nocheatplus.utilities.locations.SimpleLocation;
/**
* A check used to verify if players aren't spam bots
*
@ -25,21 +26,24 @@ public class NoPwnageCheck extends ChatCheck {
private final Random random = new Random();
public NoPwnageCheck(final NoCheatPlus plugin) {
super(plugin, "chat.nopwnage");
public NoPwnageCheck() {
super("nopwnage");
// Store the players' location
for (final Player player : Bukkit.getOnlinePlayers()) {
final ChatData data = ChatCheck.getData(plugin.getPlayer(player));
final ChatData data = getData(NCPPlayer.getPlayer(player));
data.location.setLocation(player.getLocation());
}
}
public boolean check(final NoCheatPlusPlayer player, final ChatData data, final ChatConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final ChatConfig cc = getConfig(player);
final ChatData data = getData(player);
boolean cancel = false;
if (data.commandsHaveBeenRun || !player.getPlayer().isOnline())
if (data.commandsHaveBeenRun || !player.getBukkitPlayer().isOnline())
return false;
// Player is supposed to fill out a captcha
@ -49,15 +53,16 @@ public class NoPwnageCheck extends ChatCheck {
if (cc.noPwnageCaptchaCheck && data.captchaStarted) {
// Correct answer?
if (data.message.equals(data.captchaAnswer))
if (data.message.equals(data.captchaAnswer)) {
data.captchaDone = true;
else {
player.sendMessage(ChatColor.GREEN + "OK, it sounds like you're not a spambot.");
} else {
// Display the question again
player.sendMessage(data.captchaQuestion);
// He failed too much times
if (data.captchaTries > cc.noPwnageCaptchaTries)
if (player.getPlayer().isOnline())
if (player.getBukkitPlayer().isOnline())
// Execute the commands, it's a spambot
runCommands(player, "failed captcha", data, cc);
@ -70,7 +75,7 @@ public class NoPwnageCheck extends ChatCheck {
// Do some pre-testing for the next check
final long now = System.currentTimeMillis();
final SimpleLocation location = new SimpleLocation();
location.setLocation(player.getPlayer().getLocation());
location.setLocation(player.getLocation());
double suspicion = 0;
@ -145,7 +150,7 @@ public class NoPwnageCheck extends ChatCheck {
+ "' to continue sending messages/commands.";
cancel = true;
player.sendMessage(data.captchaQuestion);
} else if (player.getPlayer().isOnline()) {
} else if (player.getBukkitPlayer().isOnline()) {
// Execute the commands, it's a spambot
lastBanCausingMessage = data.message;
lastBanCausingMessageTime = now;
@ -185,7 +190,7 @@ public class NoPwnageCheck extends ChatCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.REASON)
return getData(player).reason;
@ -195,7 +200,7 @@ public class NoPwnageCheck extends ChatCheck {
return super.getParameter(wildcard, player);
}
public void handleJoin(final NoCheatPlusPlayer player, final ChatData data, final ChatConfig cc) {
public void handleJoin(final NCPPlayer player, final ChatData data, final ChatConfig cc) {
final long now = System.currentTimeMillis();
// Relog check (cf. documentation)
@ -204,8 +209,8 @@ public class NoPwnageCheck extends ChatCheck {
data.relogWarnings = 0;
if (data.relogWarnings < cc.noPwnageRelogWarnings) {
player.sendMessage(player.getConfigurationStore().getConfiguration()
.getString(ConfPaths.LOGGING_PREFIX)
player.sendMessage(Colors.replaceColors(ConfigManager.getConfigFile().getString(
ConfPaths.LOGGING_PREFIX))
+ ChatColor.DARK_RED
+ "You relogged really fast! If you keep doing that, you're going to be banned.");
data.lastRelogWarningTime = now;
@ -217,7 +222,7 @@ public class NoPwnageCheck extends ChatCheck {
// Remember his location
final SimpleLocation location = new SimpleLocation();
location.setLocation(player.getPlayer().getLocation());
location.setLocation(player.getLocation());
data.setLocation(location);
data.joinTime = now;
@ -259,12 +264,11 @@ public class NoPwnageCheck extends ChatCheck {
* @param cc
* The ChatConfig
*/
private void runCommands(final NoCheatPlusPlayer player, final String reason, final ChatData data,
final ChatConfig cc) {
private void runCommands(final NCPPlayer player, final String reason, final ChatData data, final ChatConfig cc) {
data.reason = reason;
data.ip = player.getPlayer().getAddress().toString().substring(1).split(":")[0];
data.ip = player.getBukkitPlayer().getAddress().toString().substring(1).split(":")[0];
if (player.getPlayer().isOnline()) {
if (player.getBukkitPlayer().isOnline()) {
data.commandsHaveBeenRun = true;
executeActions(player, cc.noPwnageActions, 0);
}
@ -334,10 +338,10 @@ public class NoPwnageCheck extends ChatCheck {
* @param player
* The Player
*/
private void warnOthers(final NoCheatPlusPlayer player) {
plugin.getServer().broadcastMessage(
private void warnOthers(final NCPPlayer player) {
Bukkit.getServer().broadcastMessage(
ChatColor.YELLOW + player.getName() + ChatColor.DARK_RED + " has set off the autoban!");
plugin.getServer().broadcastMessage(
Bukkit.getServer().broadcastMessage(
ChatColor.DARK_RED + " Please do not say anything similar to what the user said!");
}
@ -347,10 +351,9 @@ public class NoPwnageCheck extends ChatCheck {
* @param player
* The Player
*/
private void warnPlayer(final NoCheatPlusPlayer player) {
player.sendMessage(player.getConfigurationStore().getConfiguration().getString(ConfPaths.LOGGING_PREFIX)
+ ChatColor.DARK_RED + "Our system has detected unusual bot activities coming from you.");
player.sendMessage(ChatColor.DARK_RED
+ "Please be careful with what you say. DON'T repeat what you just said either, unless you want to be banned.");
private void warnPlayer(final NCPPlayer player) {
player.sendMessage(Colors.replaceColors(ConfigManager.getConfigFile().getString(ConfPaths.LOGGING_PREFIX))
+ ChatColor.DARK_RED
+ "Our system has detected unusual bot activities coming from you. Please be careful with what you say. DON'T repeat what you just said either, unless you want to be banned.");
}
}

View File

@ -1,28 +1,31 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Material;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
public class CriticalCheck extends FightCheck {
public CriticalCheck(final NoCheatPlus plugin) {
super(plugin, "fight.critical", Permissions.FIGHT_CRITICAL);
public CriticalCheck() {
super("critical", Permissions.FIGHT_CRITICAL);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancel = false;
@ -43,7 +46,7 @@ public class CriticalCheck extends FightCheck {
location.y = entity.locY;
location.z = entity.locZ;
// Check if the entity is in water
final boolean isInWater = CheckUtil.isLiquid(CheckUtil.evaluateLocation(data.damager.getWorld(), location));
final boolean isInWater = CheckUtils.isLiquid(CheckUtils.evaluateLocation(data.damager.getWorld(), location));
// Check the hit was a critical hit or not (fallDistance > 0, entity in
// the air, not on ladder, not in water and no blindness effect)
@ -62,7 +65,7 @@ public class CriticalCheck extends FightCheck {
: 0D + deltaVelocity > 0D ? deltaVelocity : 0D;
// Player failed the check, but this is influenced by lag,
// so don't do it if there was lag
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
// Increment the violation level
data.criticalVL += delta;
// Increment the statisctics of the player
@ -77,7 +80,7 @@ public class CriticalCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", getData(player).criticalVL);

View File

@ -1,16 +1,16 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityComplex;
import net.minecraft.server.EntityComplexPart;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The DirectionCheck will find out if a player tried to interact with something
@ -19,12 +19,14 @@ import net.minecraft.server.EntityComplexPart;
*/
public class DirectionCheck extends FightCheck {
public DirectionCheck(final NoCheatPlus plugin) {
super(plugin, "fight.direction", Permissions.FIGHT_DIRECTION);
public DirectionCheck() {
super("direction", Permissions.FIGHT_DIRECTION);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancel = false;
@ -48,8 +50,8 @@ public class DirectionCheck extends FightCheck {
// players eye location and view direction to the center of the target
// entity. If the line of sight is more too far off, "off" will be
// bigger than 0
final double off = CheckUtil.directionCheck(player, entity.locX, entity.locY + height / 2D, entity.locZ, width,
height, cc.directionPrecision);
final double off = CheckUtils.directionCheck(player, entity.locX, entity.locY + height / 2D, entity.locZ,
width, height, cc.directionPrecision);
if (off < 0.1D)
// Player did probably nothing wrong
@ -59,7 +61,7 @@ public class DirectionCheck extends FightCheck {
// Player failed the check
// Increment violation counter and statistics, but only if there
// wasn't serious lag
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
final double sqrt = Math.sqrt(off);
data.directionVL += sqrt;
incrementStatistics(player, Id.FI_DIRECTION, sqrt);
@ -89,7 +91,7 @@ public class DirectionCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).directionVL);

View File

@ -0,0 +1,31 @@
package fr.neatmonster.nocheatplus.checks.fight;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Abstract base class for Fight checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class FightCheck extends Check {
public final String permission;
public FightCheck(final String name, final String permission) {
super("fight." + name, FightConfig.class, FightData.class);
this.permission = permission;
}
public abstract boolean check(final NCPPlayer player, final Object... args);
public FightConfig getConfig(final NCPPlayer player) {
return (FightConfig) player.getConfig(this);
}
public FightData getData(final NCPPlayer player) {
return (FightData) player.getData(this);
}
public abstract boolean isEnabled(final FightConfig cc);
}

View File

@ -1,10 +1,10 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import me.neatmonster.nocheatplus.ConfigItem;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Configurations specific for the "Fight" checks
@ -12,7 +12,7 @@ import me.neatmonster.nocheatplus.config.Permissions;
* it's own, it will use the "global" version
*
*/
public class FightConfig implements ConfigItem {
public class FightConfig extends CheckConfig {
public final boolean directionCheck;
public final double directionPrecision;
@ -46,7 +46,7 @@ public class FightConfig implements ConfigItem {
public final double criticalVelocity;
public final ActionList criticalActions;
public FightConfig(final NoCheatPlusConfiguration data) {
public FightConfig(final ConfigFile data) {
directionCheck = data.getBoolean(ConfPaths.FIGHT_DIRECTION_CHECK);
directionPrecision = data.getInt(ConfPaths.FIGHT_DIRECTION_PRECISION) / 100D;

View File

@ -1,15 +1,16 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import me.neatmonster.nocheatplus.DataItem;
import net.minecraft.server.Entity;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.CheckData;
/**
* Player specific data for the fight checks
*
*/
public class FightData implements DataItem {
public class FightData extends CheckData {
// Keep track of the violation levels of the checks
public double directionVL;

View File

@ -1,24 +1,14 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.moving.MovingCheck;
import me.neatmonster.nocheatplus.checks.moving.MovingConfig;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.Permissions;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
@ -28,33 +18,37 @@ import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Central location to listen to events that are
* relevant for the fight checks
*
*/
public class FightCheckListener implements Listener, EventManager {
public class FightListener extends CheckListener {
private final List<FightCheck> checks = new ArrayList<FightCheck>(5);
private final GodmodeCheck godmodeCheck;
private final InstanthealCheck instanthealCheck;
private final NoCheatPlus plugin;
public FightCheckListener(final NoCheatPlus plugin) {
public FightListener() {
super("fight");
// Keep these in a list, because they can be executed in a bundle
checks.add(new SpeedCheck(plugin));
checks.add(new NoswingCheck(plugin));
checks.add(new DirectionCheck(plugin));
checks.add(new ReachCheck(plugin));
checks.add(new KnockbackCheck(plugin));
checks.add(new CriticalCheck(plugin));
checks.add(new SpeedCheck());
checks.add(new NoswingCheck());
checks.add(new DirectionCheck());
checks.add(new ReachCheck());
checks.add(new KnockbackCheck());
checks.add(new CriticalCheck());
godmodeCheck = new GodmodeCheck(plugin);
instanthealCheck = new InstanthealCheck(plugin);
this.plugin = plugin;
godmodeCheck = new GodmodeCheck();
instanthealCheck = new InstanthealCheck();
}
/**
@ -67,7 +61,7 @@ public class FightCheckListener implements Listener, EventManager {
priority = EventPriority.MONITOR)
protected void armSwing(final PlayerAnimationEvent event) {
// Set a flag telling us that the arm has been swung
FightCheck.getData(plugin.getPlayer(event.getPlayer())).armswung = true;
((FightData) getData(NCPPlayer.getPlayer(event.getPlayer()))).armswung = true;
}
/**
@ -81,10 +75,8 @@ public class FightCheckListener implements Listener, EventManager {
*/
private void customDamage(final EntityDamageByEntityEvent event) {
final Player damager = (Player) event.getDamager();
final NoCheatPlusPlayer player = plugin.getPlayer(damager);
final FightData data = FightCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer((Player) event.getDamager());
final FightData data = (FightData) getData(player);
// Skip the next damage event, because it is with high probability
// something from the Heroes plugin
@ -147,47 +139,20 @@ public class FightCheckListener implements Listener, EventManager {
if (!(entity instanceof Player) || entity.isDead())
return;
final NoCheatPlusPlayer player = plugin.getPlayer((Player) entity);
final FightConfig cc = FightCheck.getConfig(player);
final NCPPlayer player = NCPPlayer.getPlayer((Player) entity);
final FightConfig cc = (FightConfig) getConfig(player);
if (!godmodeCheck.isEnabled(cc) || player.hasPermission(godmodeCheck.permission))
return;
final FightData data = FightCheck.getData(player);
// Run the godmode check on the attacked player
final boolean cancelled = godmodeCheck.check(plugin.getPlayer((Player) entity), data, cc);
final boolean cancelled = godmodeCheck.check(NCPPlayer.getPlayer((Player) entity));
// It requested to "cancel" the players invulnerability, so set his
// noDamageTicks to 0
if (cancelled)
// Remove the invulnerability from the player
player.getPlayer().setNoDamageTicks(0);
}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
final LinkedList<String> s = new LinkedList<String>();
final FightConfig f = FightCheck.getConfig(cc);
if (f.directionCheck)
s.add("fight.direction");
if (f.noswingCheck)
s.add("fight.noswing");
if (f.reachCheck)
s.add("fight.reach");
if (f.speedCheck)
s.add("fight.speed");
if (f.godmodeCheck)
s.add("fight.godmode");
if (f.instanthealCheck)
s.add("fight.instantHeal");
if (f.knockbackCheck)
s.add("fight.knockback");
if (f.criticalCheck)
s.add("fight.critical");
return s;
player.getBukkitPlayer().setNoDamageTicks(0);
}
/**
@ -200,10 +165,9 @@ public class FightCheckListener implements Listener, EventManager {
private void normalDamage(final EntityDamageByEntityEvent event) {
final Player damager = (Player) event.getDamager();
final NoCheatPlusPlayer player = plugin.getPlayer(damager);
final FightConfig cc = FightCheck.getConfig(player);
final FightData data = FightCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(damager);
final FightConfig cc = (FightConfig) getConfig(player);
final FightData data = (FightData) getData(player);
// For some reason we decided to skip this event anyway
if (data.skipNext) {
@ -223,10 +187,11 @@ public class FightCheckListener implements Listener, EventManager {
for (final FightCheck check : checks)
// If it should be executed, do it
if (!cancelled && check.isEnabled(cc) && !player.hasPermission(check.permission))
cancelled = check.check(player, data, cc);
cancelled = check.check(player);
final MovingConfig movingCc = MovingCheck.getConfig(player);
if (!cancelled && movingCc.blockingCheck && player.getPlayer().isBlocking())
final boolean blockingCheck = !ConfigManager.getConfFile(player.getWorld().getName()).getBoolean(
ConfPaths.MOVING_RUNFLY_ALLOWFASTBLOCKING);
if (!cancelled && blockingCheck && player.getBukkitPlayer().isBlocking())
cancelled = true;
// Forget the attacked entity (to allow garbage collecting, etc.)
@ -256,15 +221,13 @@ public class FightCheckListener implements Listener, EventManager {
boolean cancelled = false;
final NoCheatPlusPlayer player = plugin.getPlayer((Player) event.getEntity());
final FightConfig config = FightCheck.getConfig(player);
final NCPPlayer player = NCPPlayer.getPlayer((Player) event.getEntity());
final FightConfig config = (FightConfig) getConfig(player);
if (!instanthealCheck.isEnabled(config) || player.hasPermission(instanthealCheck.permission))
return;
final FightData data = FightCheck.getData(player);
cancelled = instanthealCheck.check(player, data, config);
cancelled = instanthealCheck.check(player);
if (cancelled)
event.setCancelled(true);
@ -281,14 +244,14 @@ public class FightCheckListener implements Listener, EventManager {
ignoreCancelled = true, priority = EventPriority.LOWEST)
public void sprint(final PlayerToggleSprintEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final FightConfig cc = FightCheck.getConfig(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final FightConfig cc = (FightConfig) getConfig(player);
if (!cc.knockbackCheck || player.hasPermission(Permissions.FIGHT_KNOCKBACK))
return;
// Store when the player has started sprinting
final FightData data = FightCheck.getData(player);
final FightData data = (FightData) getData(player);
data.sprint = System.currentTimeMillis();
}
}

View File

@ -1,17 +1,18 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics;
import net.minecraft.server.EntityPlayer;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics;
/**
* The Godmode Check will find out if a player tried to stay invulnerable after
* being hit or after dying
@ -19,12 +20,14 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
*/
public class GodmodeCheck extends FightCheck {
public GodmodeCheck(final NoCheatPlus plugin) {
super(plugin, "fight.godmode", Permissions.FIGHT_GODMODE);
public GodmodeCheck() {
super("godmode", Permissions.FIGHT_GODMODE);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancelled = false;
@ -35,11 +38,11 @@ public class GodmodeCheck extends FightCheck {
data.godmodeLastDamageTime = time;
// How old is the player now?
final int age = player.getTicksLived();
final int age = player.getBukkitPlayer().getTicksLived();
// How much older did he get?
final int ageDiff = Math.max(0, age - data.godmodeLastAge);
// Is he invulnerable?
final int nodamageTicks = player.getPlayer().getNoDamageTicks();
final int nodamageTicks = player.getBukkitPlayer().getNoDamageTicks();
if (nodamageTicks > 0 && ageDiff < 15) {
// He is invulnerable and didn't age fast enough, that costs
@ -91,7 +94,7 @@ public class GodmodeCheck extends FightCheck {
final EntityPlayer entity = player.getHandle();
// Schedule a task to be executed in roughly 1.5 seconds
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
Bukkit.getScheduler().scheduleSyncDelayedTask(NoCheatPlus.instance, new Runnable() {
@Override
public void run() {
@ -99,7 +102,7 @@ public class GodmodeCheck extends FightCheck {
// Check again if the player should be dead, and
// if the game didn't mark him as dead
if (entity.getHealth() <= 0 && !entity.dead) {
// Artifically "kill" him
// Artificially "kill" him
entity.deathTicks = 19;
entity.a(true);
}
@ -110,7 +113,7 @@ public class GodmodeCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).godmodeVL);

View File

@ -1,12 +1,11 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics;
/**
* The instantheal Check should find out if a player tried to artificially
@ -15,12 +14,14 @@ import me.neatmonster.nocheatplus.data.Statistics;
*/
public class InstanthealCheck extends FightCheck {
public InstanthealCheck(final NoCheatPlus plugin) {
super(plugin, "fight.instantheal", Permissions.FIGHT_INSTANTHEAL);
public InstanthealCheck() {
super("instantheal", Permissions.FIGHT_INSTANTHEAL);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... check) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancelled = false;
@ -63,7 +64,7 @@ public class InstanthealCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).instanthealVL);

View File

@ -1,12 +1,12 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* A check used to verify if players aren't knockbacking other players when it's not technically possible
@ -14,12 +14,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class KnockbackCheck extends FightCheck {
public KnockbackCheck(final NoCheatPlus plugin) {
super(plugin, "fight.knockback", Permissions.FIGHT_KNOCKBACK);
public KnockbackCheck() {
super("knockback", Permissions.FIGHT_KNOCKBACK);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancel = false;
@ -28,7 +30,7 @@ public class KnockbackCheck extends FightCheck {
// Player failed the check, but this is influenced by lag,
// so don't do it if there was lag
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
// The violation level if the difference between the regular and the elapsed time
final long delta = cc.knockbackInterval - System.currentTimeMillis() + data.sprint;
// Increment the violation level
@ -46,7 +48,7 @@ public class KnockbackCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).knockbackVL);

View File

@ -1,12 +1,11 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* We require that the player moves his arm between attacks, this is
@ -15,12 +14,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class NoswingCheck extends FightCheck {
public NoswingCheck(final NoCheatPlus plugin) {
super(plugin, "fight.noswing", Permissions.FIGHT_NOSWING);
public NoswingCheck() {
super("noswing", Permissions.FIGHT_NOSWING);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancel = false;
@ -43,7 +44,7 @@ public class NoswingCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).noswingVL);

View File

@ -1,16 +1,16 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityComplex;
import net.minecraft.server.EntityComplexPart;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The reach check will find out if a player interacts with something that's
@ -19,12 +19,14 @@ import net.minecraft.server.EntityComplexPart;
*/
public class ReachCheck extends FightCheck {
public ReachCheck(final NoCheatPlus plugin) {
super(plugin, "fight.reach", Permissions.FIGHT_REACH);
public ReachCheck() {
super("reach", Permissions.FIGHT_REACH);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancel = false;
@ -41,7 +43,7 @@ public class ReachCheck extends FightCheck {
// 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 off = CheckUtil.reachCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, cc.reachLimit);
final double off = CheckUtils.reachCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, cc.reachLimit);
if (off < 0.1D)
// Player did probably nothing wrong
@ -51,7 +53,7 @@ public class ReachCheck extends FightCheck {
// Player failed the check
// Increment violation counter and statistics
// This is influenced by lag, so don't do it if there was lag
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
final double sqrt = Math.sqrt(off);
data.reachVL += sqrt;
incrementStatistics(player, Id.FI_REACH, sqrt);
@ -81,7 +83,7 @@ public class ReachCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).reachVL);

View File

@ -1,12 +1,12 @@
package me.neatmonster.nocheatplus.checks.fight;
package fr.neatmonster.nocheatplus.checks.fight;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The speed check will find out if a player interacts with something that's
@ -15,12 +15,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class SpeedCheck extends FightCheck {
public SpeedCheck(final NoCheatPlus plugin) {
super(plugin, "fight.speed", Permissions.FIGHT_SPEED);
public SpeedCheck() {
super("speed", Permissions.FIGHT_SPEED);
}
@Override
public boolean check(final NoCheatPlusPlayer player, final FightData data, final FightConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final FightConfig cc = getConfig(player);
final FightData data = getData(player);
boolean cancel = false;
@ -39,7 +41,7 @@ public class SpeedCheck extends FightCheck {
// too many attacks
if (data.speedAttackCount > cc.speedAttackLimit) {
// if there was lag, don't count it towards statistics and vl
if (!plugin.skipCheck()) {
if (!NoCheatPlus.skipCheck()) {
data.speedVL += 1;
incrementStatistics(player, Id.FI_SPEED, 1);
}
@ -53,12 +55,12 @@ public class SpeedCheck extends FightCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", getData(player).speedVL);
else if (wildcard == ParameterName.LIMIT)
return String.format(Locale.US, "%d", getConfig(player.getConfigurationStore()).speedAttackLimit);
return String.format(Locale.US, "%d", getConfig(player).speedAttackLimit);
else
return super.getParameter(wildcard, player);
}

View File

@ -1,11 +1,10 @@
package me.neatmonster.nocheatplus.checks.inventory;
package fr.neatmonster.nocheatplus.checks.inventory;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The DropCheck will find out if a player drops too many items within a short
@ -14,11 +13,14 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class DropCheck extends InventoryCheck {
public DropCheck(final NoCheatPlus plugin) {
super(plugin, "inventory.drop");
public DropCheck() {
super("drop");
}
public boolean check(final NoCheatPlusPlayer player, final InventoryData data, final InventoryConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final InventoryConfig cc = getConfig(player);
final InventoryData data = getData(player);
boolean cancel = false;
@ -51,7 +53,7 @@ public class DropCheck extends InventoryCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", getData(player).dropVL);

View File

@ -1,26 +1,28 @@
package me.neatmonster.nocheatplus.checks.inventory;
package fr.neatmonster.nocheatplus.checks.inventory;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.event.entity.EntityShootBowEvent;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The InstantBowCheck will find out if a player pulled the string of his bow
* too fast
*/
public class InstantBowCheck extends InventoryCheck {
public InstantBowCheck(final NoCheatPlus plugin) {
super(plugin, "inventory.instantbow");
public InstantBowCheck() {
super("instantbow");
}
public boolean check(final NoCheatPlusPlayer player, final EntityShootBowEvent event, final InventoryData data,
final InventoryConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final InventoryConfig cc = getConfig(player);
final InventoryData data = getData(player);
final EntityShootBowEvent event = (EntityShootBowEvent) args[0];
boolean cancelled = false;
@ -53,7 +55,7 @@ public class InstantBowCheck extends InventoryCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", getData(player).instantBowVL);

View File

@ -1,28 +1,30 @@
package me.neatmonster.nocheatplus.checks.inventory;
package fr.neatmonster.nocheatplus.checks.inventory;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The InstantEatCheck will find out if a player eats his food too fast
*/
public class InstantEatCheck extends InventoryCheck {
public InstantEatCheck(final NoCheatPlus plugin) {
super(plugin, "inventory.instanteat");
public InstantEatCheck() {
super("instanteat");
}
public boolean check(final NoCheatPlusPlayer player, final FoodLevelChangeEvent event, final InventoryData data,
final InventoryConfig cc) {
@Override
public boolean check(final NCPPlayer player, final Object... args) {
final InventoryConfig cc = getConfig(player);
final InventoryData data = getData(player);
final FoodLevelChangeEvent event = (FoodLevelChangeEvent) args[0];
// Hunger level change seems to not be the result of eating
if (data.foodMaterial == null || event.getFoodLevel() <= player.getPlayer().getFoodLevel())
if (data.foodMaterial == null || event.getFoodLevel() <= player.getBukkitPlayer().getFoodLevel())
return false;
boolean cancelled = false;
@ -52,7 +54,7 @@ public class InstantEatCheck extends InventoryCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).instantEatVL);

View File

@ -0,0 +1,25 @@
package fr.neatmonster.nocheatplus.checks.inventory;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
/**
* Abstract base class for Inventory checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class InventoryCheck extends Check {
public InventoryCheck(final String name) {
super("inventory." + name, InventoryConfig.class, InventoryData.class);
}
public abstract boolean check(final NCPPlayer player, final Object... args);
public InventoryConfig getConfig(final NCPPlayer player) {
return (InventoryConfig) player.getConfig(this);
}
public InventoryData getData(final NCPPlayer player) {
return (InventoryData) player.getData(this);
}
}

View File

@ -1,10 +1,10 @@
package me.neatmonster.nocheatplus.checks.inventory;
package fr.neatmonster.nocheatplus.checks.inventory;
import me.neatmonster.nocheatplus.ConfigItem;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Configurations specific for the "Inventory" checks
@ -12,7 +12,7 @@ import me.neatmonster.nocheatplus.config.Permissions;
* it's own, it will use the "global" version
*
*/
public class InventoryConfig implements ConfigItem {
public class InventoryConfig extends CheckConfig {
public final boolean dropCheck;
public final long dropTimeFrame;
@ -25,7 +25,7 @@ public class InventoryConfig implements ConfigItem {
public final boolean eatCheck;
public final ActionList eatActions;
public InventoryConfig(final NoCheatPlusConfiguration data) {
public InventoryConfig(final ConfigFile data) {
dropCheck = data.getBoolean(ConfPaths.INVENTORY_DROP_CHECK);
dropTimeFrame = data.getInt(ConfPaths.INVENTORY_DROP_TIMEFRAME) * 1000;

View File

@ -1,14 +1,14 @@
package me.neatmonster.nocheatplus.checks.inventory;
import me.neatmonster.nocheatplus.DataItem;
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.Material;
import fr.neatmonster.nocheatplus.checks.CheckData;
/**
* Player specific data for the inventory checks
*
*/
public class InventoryData implements DataItem {
public class InventoryData extends CheckData {
// Keep track of the violation levels of the three checks
public int dropVL;
@ -19,7 +19,7 @@ public class InventoryData implements DataItem {
public long dropLastTime;
public int dropCount;
// Times when bow shootinhg and eating started
// Times when bow shooting and eating started
public long lastBowInteractTime;
public long lastEatInteractTime;

View File

@ -1,46 +1,37 @@
package me.neatmonster.nocheatplus.checks.inventory;
import java.util.LinkedList;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.Permissions;
package fr.neatmonster.nocheatplus.checks.inventory;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Central location to listen to events that are
* relevant for the inventory checks
*
*/
public class InventoryCheckListener implements Listener, EventManager {
public class InventoryListener extends CheckListener {
private final DropCheck dropCheck;
private final InstantBowCheck instantBowCheck;
private final InstantEatCheck instantEatCheck;
private final NoCheatPlus plugin;
public InventoryListener() {
super("inventory");
public InventoryCheckListener(final NoCheatPlus plugin) {
dropCheck = new DropCheck(plugin);
instantBowCheck = new InstantBowCheck(plugin);
instantEatCheck = new InstantEatCheck(plugin);
this.plugin = plugin;
dropCheck = new DropCheck();
instantBowCheck = new InstantBowCheck();
instantEatCheck = new InstantEatCheck();
}
/**
@ -54,15 +45,15 @@ public class InventoryCheckListener implements Listener, EventManager {
public void bowfired(final EntityShootBowEvent event) {
// Only if a player shot the arrow
if (event.getEntity() instanceof Player) {
final NoCheatPlusPlayer player = plugin.getPlayer((Player) event.getEntity());
final InventoryConfig cc = InventoryCheck.getConfig(player);
final NCPPlayer player = NCPPlayer.getPlayer((Player) event.getEntity());
final InventoryConfig cc = (InventoryConfig) getConfig(player);
// Only if he should get checked
if (cc.bowCheck && !player.hasPermission(Permissions.INVENTORY_INSTANTBOW)) {
final InventoryData data = InventoryCheck.getData(player);
final boolean cancelled = instantBowCheck.check(player, event, data, cc);
getData(player);
final boolean cancelled = instantBowCheck.check(player, event);
// The check requested the bowshooting to get cancelled
// The check requested the bowshooting turo get cancelled
event.setCancelled(cancelled);
}
}
@ -80,14 +71,14 @@ public class InventoryCheckListener implements Listener, EventManager {
public void foodchanged(final FoodLevelChangeEvent event) {
// Only if a player ate food
if (event.getEntity() instanceof Player) {
final NoCheatPlusPlayer player = plugin.getPlayer((Player) event.getEntity());
final InventoryConfig cc = InventoryCheck.getConfig(player);
final InventoryData data = InventoryCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer((Player) event.getEntity());
final InventoryConfig cc = (InventoryConfig) getConfig(player);
final InventoryData data = (InventoryData) getData(player);
// Only if he should get checked
if (cc.eatCheck && !player.hasPermission(Permissions.INVENTORY_INSTANTEAT)) {
final boolean cancelled = instantEatCheck.check(player, event, data, cc);
final boolean cancelled = instantEatCheck.check(player, event);
// The check requested the foodlevelchange to get cancelled
event.setCancelled(cancelled);
@ -96,21 +87,6 @@ public class InventoryCheckListener implements Listener, EventManager {
// Forget the food material, as the info is no longer needed
data.foodMaterial = null;
}
}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
final LinkedList<String> s = new LinkedList<String>();
final InventoryConfig i = InventoryCheck.getConfig(cc);
if (i.dropCheck)
s.add("inventory.dropCheck");
if (i.bowCheck)
s.add("inventory.instantbow");
if (i.eatCheck)
s.add("inventory.instanteat");
return s;
}
/**
@ -128,13 +104,13 @@ public class InventoryCheckListener implements Listener, EventManager {
boolean cancelled = false;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final InventoryConfig cc = InventoryCheck.getConfig(player);
final InventoryData data = InventoryCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final InventoryConfig cc = (InventoryConfig) getConfig(player);
getData(player);
// If it should be executed, do it
if (cc.dropCheck && !player.hasPermission(Permissions.INVENTORY_DROP))
cancelled = dropCheck.check(player, data, cc);
cancelled = dropCheck.check(player);
if (cancelled) {
// Cancelling drop events is not save (in certain circumstances
@ -161,14 +137,14 @@ public class InventoryCheckListener implements Listener, EventManager {
|| !(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK))
return;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final InventoryData data = InventoryCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final InventoryData data = (InventoryData) getData(player);
if (event.getItem().getType() == Material.BOW)
// It was a bow, the player starts to pull the string
// Remember this time
data.lastBowInteractTime = System.currentTimeMillis();
else if (CheckUtil.isFood(event.getItem())) {
else if (CheckUtils.isFood(event.getItem())) {
// It was food, the player starts to eat some food
// Remember this time and the type of food
data.foodMaterial = event.getItem().getType();

View File

@ -1,12 +1,11 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* A check designed for people that are allowed to fly. The complement to
@ -20,11 +19,13 @@ public class FlyingCheck extends MovingCheck {
// mode
private static final double creativeSpeed = 0.60D;
public FlyingCheck(final NoCheatPlus plugin) {
super(plugin, "moving.flying");
public FlyingCheck() {
super("flying");
}
public PreciseLocation check(final NoCheatPlusPlayer player, final MovingData data, final MovingConfig ccmoving) {
public PreciseLocation check(final NCPPlayer player, final Object... args) {
final MovingConfig cc = getConfig(player);
final MovingData data = getData(player);
// The setBack is the location that players may get teleported to when
// they fail the check
@ -42,7 +43,7 @@ public class FlyingCheck extends MovingCheck {
// Before doing anything, do a basic height check to determine if
// players are flying too high
final int maxheight = ccmoving.flyingHeightLimit + player.getPlayer().getWorld().getMaxHeight();
final int maxheight = cc.flyingHeightLimit + player.getWorld().getMaxHeight();
if (to.y - data.vertFreedom > maxheight) {
newToLocation = new PreciseLocation();
@ -64,8 +65,8 @@ public class FlyingCheck extends MovingCheck {
double result = 0;
// In case of creative game mode give at least 0.60 speed limit horizontal
double speedLimitHorizontal = player.isCreative() ? Math
.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
double speedLimitHorizontal = player.canFly() ? Math.max(creativeSpeed, cc.flyingSpeedLimitHorizontal)
: cc.flyingSpeedLimitHorizontal;
// If the player is affected by potion of swiftness
speedLimitHorizontal *= player.getSpeedAmplifier();
@ -73,7 +74,7 @@ public class FlyingCheck extends MovingCheck {
// Finally, determine how far the player went beyond the set limits
resultHoriz = Math.max(0.0D, horizontalDistance - data.horizFreedom - speedLimitHorizontal);
final boolean sprinting = player.isSprinting();
final boolean sprinting = player.getBukkitPlayer().isSprinting();
data.bunnyhopdelay--;
@ -95,7 +96,7 @@ public class FlyingCheck extends MovingCheck {
if (jumpAmplifier > data.lastJumpAmplifier)
data.lastJumpAmplifier = jumpAmplifier;
final double speedLimitVertical = ccmoving.flyingSpeedLimitVertical * data.lastJumpAmplifier;
final double speedLimitVertical = cc.flyingSpeedLimitVertical * data.lastJumpAmplifier;
if (data.from.y >= data.to.y && data.lastJumpAmplifier > 0)
data.lastJumpAmplifier--;
@ -118,7 +119,7 @@ public class FlyingCheck extends MovingCheck {
// Execute whatever actions are associated with this check and the
// violation level and find out if we should cancel the event
final boolean cancel = executeActions(player, ccmoving.flyingActions, data.runflyVL);
final boolean cancel = executeActions(player, cc.flyingActions, data.runflyVL);
// Was one of the actions a cancel? Then really do it
if (cancel)
@ -136,7 +137,7 @@ public class FlyingCheck extends MovingCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).runflyVL);

View File

@ -1,12 +1,11 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* The morePacketsCheck (previously called SpeedhackCheck) will try to identify
@ -23,8 +22,8 @@ public class MorePacketsCheck extends MovingCheck {
// 20 would be for perfect internet connections, 22 is good enough
private final static int packetsPerTimeframe = 22;
public MorePacketsCheck(final NoCheatPlus plugin) {
super(plugin, "moving.morepackets");
public MorePacketsCheck() {
super("morepackets");
}
/**
@ -36,7 +35,9 @@ public class MorePacketsCheck extends MovingCheck {
* 5. If there was a long pause (maybe lag), limit may be up to 100
*
*/
public PreciseLocation check(final NoCheatPlusPlayer player, final MovingData data, final MovingConfig cc) {
public PreciseLocation check(final NCPPlayer player, final Object... args) {
final MovingConfig cc = getConfig(player);
final MovingData data = getData(player);
PreciseLocation newToLocation = null;
@ -93,7 +94,7 @@ public class MorePacketsCheck extends MovingCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).morePacketsVL);

View File

@ -1,11 +1,10 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* The morePacketsVehiculeCheck will try to identify players that send more than
@ -21,8 +20,8 @@ public class MorePacketsVehicleCheck extends MovingCheck {
// 20 would be for perfect internet connections, 22 is good enough
private final static int packetsPerTimeframe = 22;
public MorePacketsVehicleCheck(final NoCheatPlus plugin) {
super(plugin, "moving.morepacketsvehicle");
public MorePacketsVehicleCheck() {
super("morepacketsvehicle");
}
/**
@ -34,7 +33,9 @@ public class MorePacketsVehicleCheck extends MovingCheck {
* 5. If there was a long pause (maybe lag), limit may be up to 100
*
*/
public boolean check(final NoCheatPlusPlayer player, final MovingData data, final MovingConfig cc) {
public boolean check(final NCPPlayer player, final Object... args) {
final MovingConfig cc = getConfig(player);
final MovingData data = getData(player);
boolean cancel = false;
@ -81,7 +82,7 @@ public class MorePacketsVehicleCheck extends MovingCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).morePacketsVehicleVL);

View File

@ -0,0 +1,44 @@
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* Abstract base class for Moving checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class MovingCheck extends Check {
public MovingCheck(final String name) {
super("moving." + name, MovingConfig.class, MovingData.class);
}
public MovingConfig getConfig(final NCPPlayer player) {
return (MovingConfig) player.getConfig(this);
}
public MovingData getData(final NCPPlayer player) {
return (MovingData) player.getData(this);
}
@Override
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.LOCATION) {
final PreciseLocation from = getData(player).from;
return String.format(Locale.US, "%.2f,%.2f,%.2f", from.x, from.y, from.z);
} else if (wildcard == ParameterName.MOVEDISTANCE) {
final PreciseLocation from = getData(player).from;
final PreciseLocation to = getData(player).to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x - from.x, to.y - from.y, to.z - from.z);
} else if (wildcard == ParameterName.LOCATION_TO) {
final PreciseLocation to = getData(player).to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
} else
return super.getParameter(wildcard, player);
}
}

View File

@ -1,17 +1,17 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import me.neatmonster.nocheatplus.ConfigItem;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
/**
* Configurations specific for the Move Checks. Every world gets one of these
* assigned to it.
*
*/
public class MovingConfig implements ConfigItem {
public class MovingConfig extends CheckConfig {
public final boolean runflyCheck;
public final double jumpheight;
@ -48,11 +48,9 @@ public class MovingConfig implements ConfigItem {
public final boolean waterWalkCheck;
public final ActionList waterWalkActions;
public final boolean unpushableCheck;
public final int flyingHeightLimit;
public MovingConfig(final NoCheatPlusConfiguration data) {
public MovingConfig(final ConfigFile data) {
identifyCreativeMode = data.getBoolean(ConfPaths.MOVING_RUNFLY_FLYING_ALLOWINCREATIVE);
@ -98,7 +96,5 @@ public class MovingConfig implements ConfigItem {
waterWalkCheck = data.getBoolean(ConfPaths.MOVING_WATERWALK_CHECK);
waterWalkActions = data.getActionList(ConfPaths.MOVING_WATERWALK_ACTIONS, Permissions.MOVING_WATERWALK);
unpushableCheck = data.getBoolean(ConfPaths.MOVING_UNPUSHABLE_CHECK);
}
}

View File

@ -1,15 +1,15 @@
package me.neatmonster.nocheatplus.checks.moving;
import me.neatmonster.nocheatplus.DataItem;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
package fr.neatmonster.nocheatplus.checks.moving;
import org.bukkit.Location;
import fr.neatmonster.nocheatplus.checks.CheckData;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* Player specific data for the moving check group
*/
public class MovingData implements DataItem {
public class MovingData extends CheckData {
// Keep track of the violation levels of the checks
public double runflyVL;

View File

@ -1,26 +1,11 @@
package me.neatmonster.nocheatplus.checks.moving;
import java.util.LinkedList;
import java.util.List;
import me.neatmonster.nocheatplus.EventManager;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityLiving;
package fr.neatmonster.nocheatplus.checks.moving;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
@ -36,12 +21,18 @@ import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* Central location to listen to events that are
* relevant for the moving checks
*
*/
public class MovingCheckListener implements Listener, EventManager {
public class MovingListener extends CheckListener {
private final MorePacketsCheck morePacketsCheck;
private final MorePacketsVehicleCheck morePacketsVehicleCheck;
@ -49,17 +40,14 @@ public class MovingCheckListener implements Listener, EventManager {
private final RunningCheck runningCheck;
private final WaterWalkCheck waterWalkCheck;
private final NoCheatPlus plugin;
public MovingListener() {
super("moving");
public MovingCheckListener(final NoCheatPlus plugin) {
flyingCheck = new FlyingCheck(plugin);
runningCheck = new RunningCheck(plugin);
morePacketsCheck = new MorePacketsCheck(plugin);
morePacketsVehicleCheck = new MorePacketsVehicleCheck(plugin);
waterWalkCheck = new WaterWalkCheck(plugin);
this.plugin = plugin;
flyingCheck = new FlyingCheck();
runningCheck = new RunningCheck();
morePacketsCheck = new MorePacketsCheck();
morePacketsVehicleCheck = new MorePacketsVehicleCheck();
waterWalkCheck = new WaterWalkCheck();
}
/**
@ -78,8 +66,8 @@ public class MovingCheckListener implements Listener, EventManager {
ignoreCancelled = true, priority = EventPriority.MONITOR)
public void blockPlace(final BlockPlaceEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final MovingConfig config = MovingCheck.getConfig(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final MovingConfig config = (MovingConfig) getConfig(player);
// 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
@ -89,7 +77,7 @@ public class MovingCheckListener implements Listener, EventManager {
return;
// Get the player-specific stored data that applies here
final MovingData data = MovingCheck.getData(player);
final MovingData data = (MovingData) getData(player);
final Block block = event.getBlockPlaced();
@ -97,7 +85,7 @@ public class MovingCheckListener implements Listener, EventManager {
return;
// Keep some results of "expensive calls
final Location l = player.getPlayer().getLocation();
final Location l = player.getLocation();
final int playerX = l.getBlockX();
final int playerY = l.getBlockY();
final int playerZ = l.getBlockZ();
@ -107,8 +95,8 @@ public class MovingCheckListener implements Listener, EventManager {
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))
final int type = CheckUtils.getType(block.getTypeId());
if (CheckUtils.isSolid(type) || CheckUtils.isLiquid(type))
if (blockY + 1 >= data.runflySetBackPoint.y) {
data.runflySetBackPoint.y = blockY + 1;
data.jumpPhase = 0;
@ -136,72 +124,6 @@ public class MovingCheckListener implements Listener, EventManager {
event.setCancelled(true);
}
private Location collide(final Player collider, final Player collided, final PreciseLocation to) {
// Calculate some distances
double moveX = collider.getLocation().getX() - collided.getLocation().getX();
double moveZ = collider.getLocation().getZ() - collided.getLocation().getZ();
double move = Math.max(Math.abs(moveX), Math.abs(moveZ));
// If the two players are close enough
if (move >= 0.0099999997764825821D) {
// Calculate the move
move = Math.sqrt(move);
moveX /= move;
moveZ /= move;
double moveInv = 1D / move;
if (moveInv > 1D)
moveInv = 1D;
// More magic numbers...
moveX *= moveInv * 0.05000000074505806D;
moveZ *= moveInv * 0.05000000074505806D;
// Teleport the collided player to his new location
// if he hasn't the required permission
if (!collided.hasPermission(Permissions.MOVING_UNPUSHABLE))
((CraftPlayer) collided).getHandle().move(-moveX, 0, -moveZ);
// Same for the collider, check his permissions
if (!collider.hasPermission(Permissions.MOVING_UNPUSHABLE)) {
final Entity entity = ((CraftPlayer) collider).getHandle();
entity.setPosition(to.x, to.y, to.z);
entity.move(moveX, 0, moveZ);
return new Location(collider.getWorld(), entity.locX, entity.locY, entity.locZ, entity.yaw,
entity.pitch);
}
}
return null;
}
@Override
public List<String> getActiveChecks(final ConfigurationCacheStore cc) {
final LinkedList<String> s = new LinkedList<String>();
final MovingConfig m = MovingCheck.getConfig(cc);
if (m.runflyCheck)
if (!m.allowFlying) {
s.add("moving.runfly");
if (m.sneakingCheck)
s.add("moving.sneaking");
if (m.blockingCheck)
s.add("moving.blocking");
if (m.nofallCheck)
s.add("moving.nofall");
if (m.waterWalkCheck)
s.add("moving.waterwalk");
} else
s.add("moving.flying");
if (m.morePacketsCheck)
s.add("moving.morepackets");
if (m.morePacketsVehicleCheck)
s.add("moving.morepacketsvehicle");
return s;
}
/**
* This event handler is used to prevent the player from quickly
* disconnecting/reconnecting in order to cancel his fall damages.
@ -213,11 +135,11 @@ public class MovingCheckListener implements Listener, EventManager {
ignoreCancelled = true, priority = EventPriority.MONITOR)
public void join(final PlayerJoinEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final MovingData data = MovingCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final MovingData data = (MovingData) getData(player);
// If the player has joined in the air and a safe location is defined...
if (player.getPlayer().getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR
if (player.getLocation().add(0, -1, 0).getBlock().getType() == Material.AIR
&& data.lastSafeLocations[0] != null)
// ...then teleport him to this location
event.getPlayer().teleport(data.lastSafeLocations[0]);
@ -245,10 +167,9 @@ public class MovingCheckListener implements Listener, EventManager {
|| event.getFrom().distanceSquared(event.getTo()) > 400)
return;
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final MovingConfig cc = MovingCheck.getConfig(player);
final MovingData data = MovingCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final MovingConfig cc = (MovingConfig) getConfig(player);
final MovingData data = (MovingData) getData(player);
// Advance various counters and values that change per movement
// tick. They are needed to decide on how fast a player may
@ -267,10 +188,10 @@ public class MovingCheckListener implements Listener, EventManager {
}
// Check if the player is on/in the ground
final int toType = CheckUtil.evaluateLocation(event.getPlayer().getWorld(), data.to);
final int toType = CheckUtils.evaluateLocation(event.getPlayer().getWorld(), data.to);
if (data.velocityChanged
&& (System.currentTimeMillis() - data.velocityChangedSince > 500L
&& (CheckUtil.isOnGround(toType) || CheckUtil.isInGround(toType)) || cc.maxCooldown != -1
&& (CheckUtils.isOnGround(toType) || CheckUtils.isInGround(toType)) || cc.maxCooldown != -1
&& System.currentTimeMillis() - data.velocityChangedSince > cc.maxCooldown)) {
data.velocityChanged = false;
data.velocityChangedSince = 0L;
@ -284,54 +205,32 @@ public class MovingCheckListener implements Listener, EventManager {
// 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
else if (cc.allowFlying || player.canFly() && cc.identifyCreativeMode
|| player.hasPermission(Permissions.MOVING_FLYING))
// Only do the limited flying check
newTo = flyingCheck.check(player, data, cc);
newTo = flyingCheck.check(player);
else
// Go for the full treatment
newTo = runningCheck.check(player, data, cc);
newTo = runningCheck.check(player);
/** WATERWALK CHECK SECTION **/
if (newTo == null && cc.waterWalkCheck && !cc.allowFlying && (!player.isCreative() || !cc.identifyCreativeMode)
if (newTo == null && cc.waterWalkCheck && !cc.allowFlying && (!player.canFly() || !cc.identifyCreativeMode)
&& (!cc.runflyCheck || !player.hasPermission(Permissions.MOVING_FLYING))
&& !player.hasPermission(Permissions.MOVING_WATERWALK))
newTo = waterWalkCheck.check(player, data, cc);
newTo = waterWalkCheck.check(player);
/** MOREPACKETS CHECK SECTION **/
if (!cc.morePacketsCheck || player.hasPermission(Permissions.MOVING_MOREPACKETS))
data.clearMorePacketsData();
else if (newTo == null)
newTo = morePacketsCheck.check(player, data, cc);
/** UNPUSHABLE CHECK SECTION **/
if (newTo == null && cc.unpushableCheck) {
final EntityLiving entity = ((CraftPlayer) event.getPlayer()).getHandle();
// List of the entities the player is colliding with
final List<?> collisions = entity.world.getEntities(entity,
entity.boundingBox.grow(0.20000000298023224D, 0.0D, 0.20000000298023224D));
for (int i = 0; i < collisions.size(); i++) {
final Entity collidedEntity = (Entity) collisions.get(i);
// Check if the entity is a player
if (collidedEntity.getBukkitEntity() instanceof Player) {
final Location toLoc = collide(event.getPlayer(), (Player) collidedEntity.getBukkitEntity(),
data.to);
if (toLoc != null)
event.setTo(toLoc);
}
}
}
newTo = morePacketsCheck.check(player);
// 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()" to allow the player to
// look somewhere else despite getting pulled back by NoCheatPlus
event.setTo(new Location(player.getPlayer().getWorld(), newTo.x, newTo.y, newTo.z, to.getYaw(), to
.getPitch()));
event.setTo(new Location(player.getWorld(), newTo.x, newTo.y, newTo.z, to.getYaw(), to.getPitch()));
// remember where we send the player to
data.teleportTo.set(newTo);
@ -347,7 +246,7 @@ public class MovingCheckListener implements Listener, EventManager {
@EventHandler(
priority = EventPriority.MONITOR)
public void portal(final PlayerPortalEvent event) {
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()));
final MovingData data = (MovingData) getData(NCPPlayer.getPlayer(event.getPlayer()));
data.clearMorePacketsData();
data.clearRunFlyData();
}
@ -380,7 +279,7 @@ public class MovingCheckListener implements Listener, EventManager {
@EventHandler(
priority = EventPriority.MONITOR)
public void respawn(final PlayerRespawnEvent event) {
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()));
final MovingData data = (MovingData) getData(NCPPlayer.getPlayer(event.getPlayer()));
data.clearMorePacketsData();
data.clearRunFlyData();
}
@ -399,8 +298,8 @@ public class MovingCheckListener implements Listener, EventManager {
priority = EventPriority.HIGHEST)
public void teleport(final PlayerTeleportEvent event) {
final NoCheatPlusPlayer player = plugin.getPlayer(event.getPlayer());
final MovingData data = MovingCheck.getData(player);
final NCPPlayer player = NCPPlayer.getPlayer(event.getPlayer());
final MovingData data = (MovingData) getData(player);
// If it was a teleport initialized by NoCheatPlus, do it anyway
// even if another plugin said "no"
@ -466,10 +365,10 @@ public class MovingCheckListener implements Listener, EventManager {
|| event.getFrom().distanceSquared(event.getTo()) > 400)
return;
final NoCheatPlusPlayer player = plugin.getPlayer((Player) event.getVehicle().getPassenger());
final NCPPlayer player = NCPPlayer.getPlayer((Player) event.getVehicle().getPassenger());
final MovingConfig cc = MovingCheck.getConfig(player);
final MovingData data = MovingCheck.getData(player);
final MovingConfig cc = (MovingConfig) getConfig(player);
final MovingData data = (MovingData) getData(player);
// Remember locations
data.fromVehicle.set(event.getFrom());
@ -477,7 +376,7 @@ public class MovingCheckListener implements Listener, EventManager {
data.toVehicle.set(to);
if (cc.morePacketsVehicleCheck && !player.hasPermission(Permissions.MOVING_MOREPACKETSVEHICLE)
&& morePacketsVehicleCheck.check(player, data, cc)) {
&& morePacketsVehicleCheck.check(player)) {
// Drop the usual items
event.getVehicle().getWorld()
.dropItemNaturally(event.getVehicle().getLocation(), new ItemStack(Material.WOOD, 3));
@ -503,7 +402,7 @@ public class MovingCheckListener implements Listener, EventManager {
ignoreCancelled = true, priority = EventPriority.MONITOR)
public void velocity(final PlayerVelocityEvent event) {
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()));
final MovingData data = (MovingData) getData(NCPPlayer.getPlayer(event.getPlayer()));
// Remeber that a plugin changed the player's velocity
data.velocityChanged = true;
@ -538,7 +437,7 @@ public class MovingCheckListener implements Listener, EventManager {
priority = EventPriority.MONITOR)
public void worldChange(final PlayerChangedWorldEvent event) {
// Maybe this helps with people teleporting through multiverse portals having problems?
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()));
final MovingData data = (MovingData) getData(NCPPlayer.getPlayer(event.getPlayer()));
data.teleportTo.reset();
data.clearRunFlyData();
data.clearMorePacketsData();

View File

@ -1,12 +1,11 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
/**
* A check to see if people cheat by tricking the server to not deal them
@ -15,27 +14,29 @@ import me.neatmonster.nocheatplus.data.Statistics.Id;
*/
public class NoFallCheck extends MovingCheck {
public NoFallCheck(final NoCheatPlus plugin) {
super(plugin, "moving.nofall");
public NoFallCheck() {
super("nofall");
}
/**
* Calculate if and how much the player "failed" this check.
*
*/
public void check(final NoCheatPlusPlayer player, final MovingData data, final MovingConfig cc) {
public void check(final NCPPlayer player, final Object... args) {
final MovingConfig cc = getConfig(player);
final MovingData data = getData(player);
// 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()) {
if (player.canFly()) {
data.fallDistance = 0F;
data.lastAddedFallDistance = 0F;
return;
}
// If the player is in unclimbable vines, do not do the check
if (CheckUtil.isVine(CheckUtil.evaluateLocation(player.getPlayer().getWorld(), data.from))
|| CheckUtil.isVine(CheckUtil.evaluateLocation(player.getPlayer().getWorld(), data.to))) {
if (CheckUtils.isVine(CheckUtils.evaluateLocation(player.getWorld(), data.from))
|| CheckUtils.isVine(CheckUtils.evaluateLocation(player.getWorld(), data.to))) {
data.fallDistance = 0F;
data.lastAddedFallDistance = 0F;
return;
@ -47,8 +48,8 @@ public class NoFallCheck extends MovingCheck {
data.fallDistance = 0F;
if (cc.nofallaggressive && data.fromOnOrInGround && data.toOnOrInGround && data.from.y <= data.to.y
&& player.getPlayer().getFallDistance() > 3.0F) {
data.fallDistance = player.getPlayer().getFallDistance();
&& player.getBukkitPlayer().getFallDistance() > 3.0F) {
data.fallDistance = player.getBukkitPlayer().getFallDistance();
data.nofallVL += data.fallDistance;
incrementStatistics(player, Id.MOV_NOFALL, data.fallDistance);
@ -62,14 +63,15 @@ public class NoFallCheck extends MovingCheck {
// If we increased fall height before for no good reason, reduce now by
// the same amount
if (player.getPlayer().getFallDistance() > data.lastAddedFallDistance)
player.getPlayer().setFallDistance(player.getPlayer().getFallDistance() - data.lastAddedFallDistance);
if (player.getBukkitPlayer().getFallDistance() > data.lastAddedFallDistance)
player.getBukkitPlayer().setFallDistance(
player.getBukkitPlayer().getFallDistance() - data.lastAddedFallDistance);
data.lastAddedFallDistance = 0;
// We want to know if the fallDistance recorded by the game is smaller
// than the fall distance recorded by the plugin
final float difference = data.fallDistance - player.getPlayer().getFallDistance();
final float difference = data.fallDistance - player.getBukkitPlayer().getFallDistance();
if (difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallVL += difference;
@ -85,7 +87,7 @@ public class NoFallCheck extends MovingCheck {
// Increase the fall distance a bit :)
final float totalDistance = data.fallDistance + difference * (cc.nofallMultiplier - 1.0F);
player.getPlayer().setFallDistance(totalDistance);
player.getBukkitPlayer().setFallDistance(totalDistance);
}
data.fallDistance = 0F;
@ -110,7 +112,7 @@ public class NoFallCheck extends MovingCheck {
if (dist > 1.0F) {
data.lastAddedFallDistance = dist;
player.getPlayer().setFallDistance(player.getPlayer().getFallDistance() + dist);
player.getBukkitPlayer().setFallDistance(player.getBukkitPlayer().getFallDistance() + dist);
} else
data.lastAddedFallDistance = 0.0F;
} else
@ -123,7 +125,7 @@ public class NoFallCheck extends MovingCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).nofallVL);

View File

@ -1,19 +1,18 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.config.Permissions;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.players.informations.Permissions;
import fr.neatmonster.nocheatplus.players.informations.Statistics.Id;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* The counterpart to the FlyingCheck. People that are not allowed to fly
* get checked by this. It will try to identify when they are jumping, check if
@ -31,14 +30,16 @@ public class RunningCheck extends MovingCheck {
private final NoFallCheck noFallCheck;
public RunningCheck(final NoCheatPlus plugin) {
public RunningCheck() {
super(plugin, "moving.running");
super("running");
noFallCheck = new NoFallCheck(plugin);
noFallCheck = new NoFallCheck();
}
public PreciseLocation check(final NoCheatPlusPlayer player, final MovingData data, final MovingConfig cc) {
public PreciseLocation check(final NCPPlayer player, final Object... args) {
final MovingConfig cc = getConfig(player);
final MovingData data = getData(player);
// Some shortcuts:
final PreciseLocation setBack = data.runflySetBackPoint;
@ -54,19 +55,19 @@ public class RunningCheck extends MovingCheck {
setBack.set(from);
// To know if a player "is on ground" is useful
final int fromType = CheckUtil.evaluateLocation(player.getPlayer().getWorld(), from);
final int toType = CheckUtil.evaluateLocation(player.getPlayer().getWorld(), to);
final int fromType = CheckUtils.evaluateLocation(player.getWorld(), from);
final int toType = CheckUtils.evaluateLocation(player.getWorld(), to);
final boolean fromOnGround = CheckUtil.isOnGround(fromType);
final boolean fromInGround = CheckUtil.isInGround(fromType);
final boolean toOnGround = CheckUtil.isOnGround(toType);
final boolean toInGround = CheckUtil.isInGround(toType);
final boolean fromOnGround = CheckUtils.isOnGround(fromType);
final boolean fromInGround = CheckUtils.isInGround(fromType);
final boolean toOnGround = CheckUtils.isOnGround(toType);
final boolean toInGround = CheckUtils.isInGround(toType);
PreciseLocation newToLocation = null;
final double resultHoriz = Math.max(
0.0D,
checkHorizontal(player, data, CheckUtil.isLiquid(fromType) && CheckUtil.isLiquid(toType),
checkHorizontal(player, data, CheckUtils.isLiquid(fromType) && CheckUtils.isLiquid(toType),
horizontalDistance, cc));
final double resultVert = Math.max(0.0D, checkVertical(player, data, fromOnGround, toOnGround, cc));
@ -96,7 +97,7 @@ public class RunningCheck extends MovingCheck {
data.jumpPhase = 0;
}
} else if (toInGround && from.y >= to.y || CheckUtil.isLiquid(toType)) {
} else if (toInGround && from.y >= to.y || CheckUtils.isLiquid(toType)) {
// Yes, if the player moved down "into" the ground or into liquid
setBack.set(to);
setBack.y = Math.ceil(setBack.y);
@ -128,7 +129,7 @@ public class RunningCheck extends MovingCheck {
* Calculate how much the player failed this check
*
*/
private double checkHorizontal(final NoCheatPlusPlayer player, final MovingData data, final boolean isSwimming,
private double checkHorizontal(final NCPPlayer player, final MovingData data, final boolean isSwimming,
final double totalDistance, final MovingConfig cc) {
// How much further did the player move than expected??
@ -136,26 +137,27 @@ public class RunningCheck extends MovingCheck {
// A player is considered sprinting if the flag is set and if he has
// enough food level (configurable)
final boolean sprinting = player.isSprinting() && player.getPlayer().getFoodLevel() > 5;
final boolean sprinting = player.getBukkitPlayer().isSprinting() && player.getBukkitPlayer().getFoodLevel() > 5;
double limit = 0.0D;
Id statisticsCategory = null;
// Player on ice? Give him higher max speed
final Block b = player.getPlayer().getLocation().getBlock();
final Block b = player.getLocation().getBlock();
if (b.getType() == Material.ICE || b.getRelative(0, -1, 0).getType() == Material.ICE)
data.onIce = 20;
else if (data.onIce > 0)
data.onIce--;
if (cc.blockingCheck && player.getPlayer().isBlocking() && !player.hasPermission(Permissions.MOVING_BLOCKING)) {
if (cc.blockingCheck && player.getBukkitPlayer().isBlocking()
&& !player.hasPermission(Permissions.MOVING_BLOCKING)) {
limit = cc.blockingSpeedLimit;
statisticsCategory = Id.MOV_BLOCKING;
if (cc.sneakingCheck && player.getPlayer().isSneaking()
if (cc.sneakingCheck && player.getBukkitPlayer().isSneaking()
&& !player.hasPermission(Permissions.MOVING_SNEAKING))
limit = Math.min(cc.sneakingSpeedLimit, cc.blockingSpeedLimit);
} else if (cc.sneakingCheck && player.getPlayer().isSneaking()
} else if (cc.sneakingCheck && player.getBukkitPlayer().isSneaking()
&& !player.hasPermission(Permissions.MOVING_SNEAKING)) {
limit = cc.sneakingSpeedLimit;
statisticsCategory = Id.MOV_SNEAKING;
@ -174,9 +176,9 @@ public class RunningCheck extends MovingCheck {
limit *= 2.5D;
// If the player is in web, we need a fixed limit
final World world = player.getPlayer().getWorld();
if (CheckUtil.isWeb(CheckUtil.evaluateLocation(world, data.from))
&& CheckUtil.isWeb(CheckUtil.evaluateLocation(world, data.to))
final World world = player.getWorld();
if (CheckUtils.isWeb(CheckUtils.evaluateLocation(world, data.from))
&& CheckUtils.isWeb(CheckUtils.evaluateLocation(world, data.to))
&& !player.hasPermission(Permissions.MOVING_COBWEB)) {
limit = cc.cobWebHoriSpeedLimit;
statisticsCategory = Id.MOV_COBWEB;
@ -218,7 +220,7 @@ public class RunningCheck extends MovingCheck {
* Calculate if and how much the player "failed" this check.
*
*/
private double checkVertical(final NoCheatPlusPlayer player, final MovingData data, final boolean fromOnGround,
private double checkVertical(final NCPPlayer player, final MovingData data, final boolean fromOnGround,
final boolean toOnGround, final MovingConfig cc) {
// How much higher did the player move than expected??
@ -237,9 +239,9 @@ public class RunningCheck extends MovingCheck {
limit -= (data.jumpPhase - jumpingLimit) * 0.15D;
// Check if the player is in web and check his move
final World world = player.getPlayer().getWorld();
if (CheckUtil.isWeb(CheckUtil.evaluateLocation(world, data.from))
&& CheckUtil.isWeb(CheckUtil.evaluateLocation(world, data.to))
final World world = player.getWorld();
if (CheckUtils.isWeb(CheckUtils.evaluateLocation(world, data.from))
&& CheckUtils.isWeb(CheckUtils.evaluateLocation(world, data.to))
&& Math.abs(data.to.y - data.from.y) > cc.cobWebVertSpeedLimit)
distanceAboveLimit = Math.abs(data.to.y - data.from.y - cc.cobWebVertSpeedLimit);
@ -256,7 +258,7 @@ public class RunningCheck extends MovingCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.CHECK)
// Workaround for something until I find a better way to do it

View File

@ -1,29 +1,31 @@
package me.neatmonster.nocheatplus.checks.moving;
package fr.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.CheckUtil;
import me.neatmonster.nocheatplus.data.PreciseLocation;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.CheckUtils;
import fr.neatmonster.nocheatplus.players.NCPPlayer;
import fr.neatmonster.nocheatplus.utilities.locations.PreciseLocation;
/**
* This check is used to verify that players aren't walking on water
*
*/
public class WaterWalkCheck extends MovingCheck {
public WaterWalkCheck(final NoCheatPlus plugin) {
super(plugin, "moving.waterwalk");
public WaterWalkCheck() {
super("waterwalk");
}
public PreciseLocation check(final NoCheatPlusPlayer player, final MovingData data, final MovingConfig cc) {
public PreciseLocation check(final NCPPlayer player, final Object... args) {
final MovingConfig cc = getConfig(player);
final MovingData data = getData(player);
// Some shortcuts:
final PreciseLocation to = data.to;
final PreciseLocation from = data.from;
@ -42,17 +44,17 @@ public class WaterWalkCheck extends MovingCheck {
fromAbove.z = from.z;
// To know if a player "is in water" is useful
final int fromType = CheckUtil.evaluateLocation(player.getPlayer().getWorld(), from);
final int toType = CheckUtil.evaluateLocation(player.getPlayer().getWorld(), to);
final int upType = CheckUtil.evaluateLocation(player.getPlayer().getWorld(), up);
final int fromType = CheckUtils.evaluateLocation(player.getWorld(), from);
final int toType = CheckUtils.evaluateLocation(player.getWorld(), to);
final int upType = CheckUtils.evaluateLocation(player.getWorld(), up);
final boolean fromLiquid = CheckUtil.isLiquid(fromType);
final boolean toLiquid = CheckUtil.isLiquid(toType);
final boolean upLiquid = CheckUtil.isLiquid(upType);
final boolean fromLiquid = CheckUtils.isLiquid(fromType);
final boolean toLiquid = CheckUtils.isLiquid(toType);
final boolean upLiquid = CheckUtils.isLiquid(upType);
final boolean toAboveSolid = CheckUtil.isSolid(CheckUtil.getType(new Location(player.getPlayer().getWorld(),
toAbove.x, toAbove.y, toAbove.z).getBlock().getTypeId()));
final boolean fromAboveSolid = CheckUtil.isSolid(CheckUtil.getType(new Location(player.getPlayer().getWorld(),
final boolean toAboveSolid = CheckUtils.isSolid(CheckUtils.getType(new Location(player.getWorld(), toAbove.x,
toAbove.y, toAbove.z).getBlock().getTypeId()));
final boolean fromAboveSolid = CheckUtils.isSolid(CheckUtils.getType(new Location(player.getWorld(),
fromAbove.x, fromAbove.y, fromAbove.z).getBlock().getTypeId()));
boolean aboveSolid = toAboveSolid || fromAboveSolid;
final boolean save = aboveSolid;
@ -61,7 +63,7 @@ public class WaterWalkCheck extends MovingCheck {
aboveSolid = true;
data.rotateWaterWalkData(save);
final Block fromBlock = new Location(player.getPlayer().getWorld(), from.x, from.y, from.z).getBlock();
final Block fromBlock = new Location(player.getWorld(), from.x, from.y, from.z).getBlock();
// Handle the issue with water streams
boolean waterStreamsFix = false;
@ -125,7 +127,7 @@ public class WaterWalkCheck extends MovingCheck {
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
public String getParameter(final ParameterName wildcard, final NCPPlayer player) {
if (wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player).waterWalkVL);

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.config;
package fr.neatmonster.nocheatplus.config;
/**
* Paths for the configuration options
@ -86,9 +86,6 @@ public abstract class ConfPaths {
public static final String MOVING_WATERWALK_CHECK = MOVING_WATERWALK + "active";
public static final String MOVING_WATERWALK_ACTIONS = MOVING_WATERWALK + "actions";
private static final String MOVING_UNPUSHABLE = MOVING + "unpushable.";
public static final String MOVING_UNPUSHABLE_CHECK = MOVING_UNPUSHABLE + "active";
private static final String BLOCKBREAK = CHECKS + "blockbreak.";
private static final String BLOCKBREAK_FASTBREAK = BLOCKBREAK + "fastbreak.";
@ -133,6 +130,9 @@ public abstract class ConfPaths {
public static final String BLOCKPLACE_PROJECTILE_INTERVAL = BLOCKPLACE_PROJECTILE + "interval";
public static final String BLOCKPLACE_PROJECTILE_ACTIONS = BLOCKPLACE_PROJECTILE + "actions";
private static final String BLOCKPLACE_FASTSIGN = BLOCKPLACE + "fastsign.";
public static final String BLOCKPLACE_FASTSIGN_EXCLUSIONS = BLOCKPLACE_FASTSIGN + "exclusions";
private static final String CHAT = CHECKS + "chat.";
private static final String CHAT_NOPWNAGE = CHAT + "nopwnage.";

View File

@ -1,35 +1,16 @@
package me.neatmonster.nocheatplus.config;
package fr.neatmonster.nocheatplus.config;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.actions.Action;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.yaml.snakeyaml.DumperOptions;
public class NoCheatPlusConfiguration extends YamlConfiguration {
import fr.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.ActionFactory;
import fr.neatmonster.nocheatplus.actions.types.ActionList;
public static void writeInstructions(final NoCheatPlus plugin) {
try {
final InputStream is = plugin.getResource("Instructions.txt");
final FileOutputStream fos = new FileOutputStream(new File(plugin.getDataFolder(), "Intructions.txt"));
final byte[] buffer = new byte[64 * 1024];
int length = 0;
while ((length = is.read(buffer)) != -1)
fos.write(buffer, 0, length);
fos.flush();
fos.close();
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
public class ConfigFile extends YamlConfiguration {
private ActionFactory factory;
@ -87,4 +68,4 @@ public class NoCheatPlusConfiguration extends YamlConfiguration {
set(path, string.toString().trim());
}
}
}

View File

@ -0,0 +1,156 @@
package fr.neatmonster.nocheatplus.config;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.utilities.LogFileFormatter;
public class ConfigManager {
private static final Map<String, ConfigFile> worldsMap = new HashMap<String, ConfigFile>();
private static FileHandler fileHandler;
public static void cleanup() {
fileHandler.flush();
fileHandler.close();
final Logger logger = Logger.getLogger("NoCheatPlus");
logger.removeHandler(fileHandler);
fileHandler = null;
}
public static ConfigFile getConfFile(final String worldName) {
if (worldsMap.containsKey(worldName))
return worldsMap.get(worldName);
return worldsMap.get(null);
}
public static ConfigFile getConfigFile() {
return worldsMap.get(null);
}
public static ConfigFile getConfigFile(final String worldName) {
if (worldsMap.containsKey(worldName))
return worldsMap.get(worldName);
return getConfigFile();
}
public static void init() {
// First try to obtain and parse the global config file
final File rootFolder = NoCheatPlus.instance.getDataFolder();
final ConfigFile root = new ConfigFile();
root.setDefaults(new DefaultConfig());
root.options().copyDefaults(true);
root.options().copyHeader(true);
final File globalConfigFile = new File(rootFolder, "config.yml");
if (globalConfigFile.exists())
try {
root.load(globalConfigFile);
} catch (final Exception e) {
e.printStackTrace();
}
try {
root.save(globalConfigFile);
} catch (final Exception e) {
e.printStackTrace();
}
root.regenerateActionLists();
// Create a corresponding ConfigurationByPlayer and
// put the global configuration in the worlds map
worldsMap.put(null, root);
// Setup the file logger used by the plugin
final Logger logger = Logger.getAnonymousLogger();
logger.setLevel(Level.INFO);
// Ignore parent's settings
logger.setUseParentHandlers(false);
for (final Handler h : logger.getHandlers())
logger.removeHandler(h);
if (fileHandler != null) {
fileHandler.close();
logger.removeHandler(fileHandler);
fileHandler = null;
}
final File logFile = new File(rootFolder, root.getString(ConfPaths.LOGGING_FILENAME));
try {
try {
logFile.getParentFile().mkdirs();
} catch (final Exception e) {
e.printStackTrace();
}
fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new LogFileFormatter());
logger.addHandler(fileHandler);
} catch (final Exception e) {
e.printStackTrace();
}
NoCheatPlus.instance.setFileLogger(logger);
// Try to find world-specific config files
final HashMap<String, File> worldFiles = new HashMap<String, File>();
if (rootFolder.isDirectory())
for (final File file : rootFolder.listFiles())
if (file.isFile()) {
final String filename = file.getName();
if (filename.matches(".+_config.yml$")) {
// Get the first part = world name
final String worldname = filename.substring(0, filename.length() - 10);
worldFiles.put(worldname, file);
}
}
for (final Entry<String, File> worldEntry : worldFiles.entrySet()) {
final File worldConfigFile = worldEntry.getValue();
final ConfigFile world = new ConfigFile();
world.setDefaults(root);
try {
world.load(worldConfigFile);
worldsMap.put(worldEntry.getKey(), world);
// write the config file back to disk immediately
world.save(worldConfigFile);
} catch (final Exception e) {
System.out.println("NoCheatPlus: Couldn't load world-specific config for " + worldEntry.getKey());
e.printStackTrace();
}
world.regenerateActionLists();
}
}
public static void writeInstructions() {
try {
final InputStream is = NoCheatPlus.instance.getResource("Instructions.txt");
final FileOutputStream fos = new FileOutputStream(new File(NoCheatPlus.instance.getDataFolder(),
"Intructions.txt"));
final byte[] buffer = new byte[64 * 1024];
int length = 0;
while ((length = is.read(buffer)) != -1)
fos.write(buffer, 0, length);
fos.flush();
fos.close();
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,4 +1,6 @@
package me.neatmonster.nocheatplus.config;
package fr.neatmonster.nocheatplus.config;
import java.util.Arrays;
/**
* These are the default settings for NoCheatPlus. They will be used
@ -6,9 +8,9 @@ package me.neatmonster.nocheatplus.config;
* config.yml file
*
*/
public class DefaultConfiguration extends NoCheatPlusConfiguration {
public class DefaultConfig extends ConfigFile {
public DefaultConfiguration() {
public DefaultConfig() {
super();
@ -75,8 +77,6 @@ public class DefaultConfiguration extends NoCheatPlusConfiguration {
set(ConfPaths.MOVING_WATERWALK_ACTIONS,
"log:waterwalk:3:5:f cancel vl>100 log:waterwalk:0:5:if cancel vl>400 log:waterwalk:0:5:cif cancel");
set(ConfPaths.MOVING_UNPUSHABLE_CHECK, false);
/*** BLOCKBREAK ***/
set(ConfPaths.BLOCKBREAK_FASTBREAK_CHECK, true);
@ -116,6 +116,11 @@ public class DefaultConfiguration extends NoCheatPlusConfiguration {
set(ConfPaths.BLOCKPLACE_PROJECTILE_ACTIONS,
"cancel vl>150 log:bpprojectile:3:5:if cancel vl>1000 log:bpprojectile:3:5:cif cancel vl>4000 log:bpprojectile:3:5:cif cancel cmd:kick");
set(ConfPaths.BLOCKPLACE_FASTSIGN_EXCLUSIONS,
Arrays.asList(new String[] {"[public]", "[private]", "[protection]", "[mail]", "[free]", "[kit]",
"[disposal]", "[heal]", "[time]", "[weather]", "[warp]", "[spawnmob]", "[enchant]", "[trade]",
"[buy]", "[sell]", "[balance]"}));
/*** CHAT ***/
set(ConfPaths.CHAT_NOPWNAGE_CHECK, true);

View File

@ -0,0 +1,160 @@
package fr.neatmonster.nocheatplus.players;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckConfig;
import fr.neatmonster.nocheatplus.checks.CheckData;
import fr.neatmonster.nocheatplus.players.informations.ExecutionHistory;
import fr.neatmonster.nocheatplus.players.informations.Statistics;
public class NCPPlayer {
public class ConfigByCheck {
private final String worldName;
private final Map<String, CheckConfig> configMap = new HashMap<String, CheckConfig>();
public ConfigByCheck(final String worldName) {
this.worldName = worldName;
}
public CheckConfig getConfig(final String group) {
if (!configMap.containsKey(group))
configMap.put(group, Check.newConfig(group, worldName));
return configMap.get(group);
}
}
private static final Map<String, NCPPlayer> players = new HashMap<String, NCPPlayer>();
public static NCPPlayer getPlayer(final Player bukkitPlayer) {
if (!players.containsKey(bukkitPlayer.getName()))
players.put(bukkitPlayer.getName(), new NCPPlayer(bukkitPlayer));
NCPPlayer player = players.get(bukkitPlayer.getName());
if (player.getBukkitPlayer() != bukkitPlayer)
players.put(bukkitPlayer.getName(), player = new NCPPlayer(bukkitPlayer));
return player;
}
private final String name;
private Player bukkitPlayer;
private final Map<String, ConfigByCheck> configMap = new HashMap<String, ConfigByCheck>();
private final Map<String, CheckData> dataMap = new HashMap<String, CheckData>();
private final ExecutionHistory history = new ExecutionHistory();
private final Statistics statistics = new Statistics();
public NCPPlayer(final Player bukkitPlayer) {
name = bukkitPlayer.getName();
this.bukkitPlayer = bukkitPlayer;
}
public boolean canFly() {
return bukkitPlayer.getGameMode() == GameMode.CREATIVE || bukkitPlayer.getAllowFlight();
}
public Map<String, Object> collectData() {
final Map<String, Object> map = statistics.get();
map.put("nocheatplus.version", NoCheatPlus.instance.getDescription().getVersion());
return map;
}
public void dealFallDamage() {
final EntityPlayer p = ((CraftPlayer) bukkitPlayer).getHandle();
p.b(0D, true);
}
public Player getBukkitPlayer() {
return bukkitPlayer;
}
public CheckConfig getConfig(final Check check) {
return getConfig(check.getGroup());
}
public CheckConfig getConfig(final String group) {
final String worldName = getWorld().getName();
if (!configMap.containsKey(worldName))
configMap.put(worldName, new ConfigByCheck(worldName));
return configMap.get(worldName).getConfig(group);
}
public CheckData getData(final Check check) {
return getData(check.getGroup());
}
public CheckData getData(final String group) {
if (!dataMap.containsKey(group))
dataMap.put(group, Check.newData(group));
return dataMap.get(group);
}
public ExecutionHistory getExecutionHistory() {
return history;
}
public float getJumpAmplifier() {
final EntityPlayer ep = ((CraftPlayer) bukkitPlayer).getHandle();
if (ep.hasEffect(MobEffectList.JUMP)) {
final int amp = ep.getEffect(MobEffectList.JUMP).getAmplifier();
// Very rough estimates only
if (amp > 20)
return 1.5F * (ep.getEffect(MobEffectList.JUMP).getAmplifier() + 1);
else
return 1.2F * (ep.getEffect(MobEffectList.JUMP).getAmplifier() + 1);
} else
return 1.0F;
}
public Location getLocation() {
return bukkitPlayer.getLocation();
}
public String getName() {
return name;
}
public float getSpeedAmplifier() {
final EntityPlayer ep = ((CraftPlayer) bukkitPlayer).getHandle();
if (ep.hasEffect(MobEffectList.FASTER_MOVEMENT))
// Taken directly from Minecraft code, should work
return 1.0F + 0.2F * (ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
else
return 1.0F;
}
public Statistics getStatistics() {
return statistics;
}
public World getWorld() {
return bukkitPlayer.getWorld();
}
public boolean hasPermission(final String permission) {
return bukkitPlayer.hasPermission(permission);
}
public void refresh() {
bukkitPlayer = Bukkit.getPlayer(name);
}
public void sendMessage(final String message) {
bukkitPlayer.sendMessage(message);
}
}

View File

@ -1,9 +1,9 @@
package me.neatmonster.nocheatplus.data;
package fr.neatmonster.nocheatplus.players.informations;
import java.util.HashMap;
import java.util.Map;
import me.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.Action;
/**
* Store amount of action executions for last 60 seconds

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.config;
package fr.neatmonster.nocheatplus.players.informations;
/**
* The various permission nodes used by NoCheatPlus
@ -62,7 +62,6 @@ public class Permissions {
public static final String MOVING_MOREPACKETS = MOVING + ".morepackets";
public static final String MOVING_MOREPACKETSVEHICLE = MOVING + ".morepacketsvehicle";
public static final String MOVING_WATERWALK = MOVING + ".waterwalk";
public static final String MOVING_UNPUSHABLE = MOVING + ".unpushable";
public static final String MOVING_RESPAWNTRICK = MOVING + ".respawntrick";
public static final String MOVING_BOATONGROUND = MOVING + ".boatonground";

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.data;
package fr.neatmonster.nocheatplus.players.informations;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus;
package fr.neatmonster.nocheatplus.utilities;
import org.bukkit.ChatColor;

View File

@ -1,6 +1,10 @@
package me.neatmonster.nocheatplus;
package fr.neatmonster.nocheatplus.utilities;
import org.bukkit.World;
import org.bukkit.Bukkit;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;
/**
* A task running in the background that measures tick time vs. real time
@ -8,22 +12,16 @@ import org.bukkit.World;
*/
public class LagMeasureTask implements Runnable {
private int ingameseconds = 1;
private long lastIngamesecondTime = System.currentTimeMillis();
private long lastIngamesecondDuration = 2000L;
private boolean skipCheck = false;
private int lagMeasureTaskId = -1;
private final NoCheatPlus plugin;
public LagMeasureTask(final NoCheatPlus plugin) {
this.plugin = plugin;
}
// private int ingameseconds = 1;
private long lastIngamesecondTime = System.currentTimeMillis();
private long lastIngamesecondDuration = 2000L;
private boolean skipCheck = false;
private int lagMeasureTaskId = -1;
public void cancel() {
if (lagMeasureTaskId != -1) {
try {
plugin.getServer().getScheduler().cancelTask(lagMeasureTaskId);
Bukkit.getServer().getScheduler().cancelTask(lagMeasureTaskId);
} catch (final Exception e) {
System.out.println("NoCheatPlus: Couldn't cancel LagMeasureTask: " + e.getMessage());
}
@ -40,7 +38,7 @@ public class LagMeasureTask implements Runnable {
// this second
skipCheck = lastIngamesecondDuration > 2000;
if (plugin.getConfig((World) null).logging.debugmessages)
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_DEBUGMESSAGES))
if (oldStatus != skipCheck && skipCheck)
System.out.println("[NoCheatPlus] detected server lag, some checks will not work.");
else if (oldStatus != skipCheck && !skipCheck)
@ -54,11 +52,11 @@ public class LagMeasureTask implements Runnable {
lastIngamesecondDuration = 3600000; // top limit of 1
// hour per "second"
lastIngamesecondTime = time;
ingameseconds++;
// ingameseconds++;
// Check if some data is outdated now and let it be removed
if (ingameseconds % 62 == 0)
plugin.cleanDataMap();
// if (ingameseconds % 62 == 0)
// NoCheatPlus.cleanDataMap();
} catch (final Exception e) {
// Just prevent this thread from dying for whatever reason
}
@ -71,6 +69,7 @@ public class LagMeasureTask implements Runnable {
public void start() {
// start measuring with a delay of 10 seconds
lagMeasureTaskId = plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this, 20, 20);
lagMeasureTaskId = Bukkit.getServer().getScheduler()
.scheduleSyncRepeatingTask(NoCheatPlus.instance, this, 20, 20);
}
}

View File

@ -1,9 +1,9 @@
package me.neatmonster.nocheatplus;
package fr.neatmonster.nocheatplus.utilities;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class NoCheatPlusLogEvent extends Event {
public class LogEvent extends Event {
private static final HandlerList handlers = new HandlerList();
@ -16,8 +16,8 @@ public class NoCheatPlusLogEvent extends Event {
private boolean toConsole, toChat, toFile;
public NoCheatPlusLogEvent(final String prefix, final String message, final boolean toConsole,
final boolean toChat, final boolean toFile) {
public LogEvent(final String prefix, final String message, final boolean toConsole, final boolean toChat,
final boolean toFile) {
this.prefix = prefix;
this.message = message;
this.toConsole = toConsole;

View File

@ -0,0 +1,37 @@
package fr.neatmonster.nocheatplus.utilities;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class LogFileFormatter extends Formatter {
private final SimpleDateFormat date;
public LogFileFormatter() {
date = new SimpleDateFormat("yy.MM.dd HH:mm:ss");
}
@Override
public String format(final LogRecord record) {
final StringBuilder builder = new StringBuilder();
final Throwable ex = record.getThrown();
builder.append(date.format(record.getMillis()));
builder.append(" [");
builder.append(record.getLevel().getLocalizedName().toUpperCase());
builder.append("] ");
builder.append(record.getMessage());
builder.append('\n');
if (ex != null) {
final StringWriter writer = new StringWriter();
ex.printStackTrace(new PrintWriter(writer));
builder.append(writer);
}
return builder.toString();
}
}

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.data;
package fr.neatmonster.nocheatplus.utilities.locations;
import org.bukkit.Location;

View File

@ -1,4 +1,4 @@
package me.neatmonster.nocheatplus.data;
package fr.neatmonster.nocheatplus.utilities.locations;
import org.bukkit.Location;
import org.bukkit.block.Block;

View File

@ -1,5 +0,0 @@
package me.neatmonster.nocheatplus;
public interface ConfigItem {
}

View File

@ -1,8 +0,0 @@
package me.neatmonster.nocheatplus;
/**
*
* Every class that is extending this has to implement an empty Constructor()
*
*/
public interface DataItem {}

View File

@ -1,20 +0,0 @@
package me.neatmonster.nocheatplus;
import java.util.List;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import org.bukkit.event.Listener;
public interface EventManager extends Listener {
/**
* Used for debug output, if checks are activated for the world-specific
* config that is given as a parameter
*
* @param cc
* The config
* @return A list of active/enabled checks
*/
public List<String> getActiveChecks(ConfigurationCacheStore cc);
}

View File

@ -1,39 +0,0 @@
package me.neatmonster.nocheatplus;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
import me.neatmonster.nocheatplus.data.ExecutionHistory;
import org.bukkit.entity.Player;
public interface NoCheatPlusPlayer {
public void dealFallDamage();
public ConfigurationCacheStore getConfigurationStore();
public DataStore getDataStore();
public ExecutionHistory getExecutionHistory();
public float getJumpAmplifier();
public String getName();
public Player getPlayer();
public float getSpeedAmplifier();
public int getTicksLived();
public boolean hasPermission(String permission);
public boolean isCreative();
public boolean isDead();
public boolean isSprinting();
public void sendMessage(String message);
}

View File

@ -1,136 +0,0 @@
package me.neatmonster.nocheatplus;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
import me.neatmonster.nocheatplus.data.ExecutionHistory;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.GameMode;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class NoCheatPlusPlayerImpl implements NoCheatPlusPlayer {
private Player player;
private final NoCheatPlus plugin;
private final DataStore data;
private ConfigurationCacheStore config;
private long lastUsedTime;
private final ExecutionHistory history;
public NoCheatPlusPlayerImpl(final Player player, final NoCheatPlus plugin) {
this.player = player;
this.plugin = plugin;
data = new DataStore();
history = new ExecutionHistory();
lastUsedTime = System.currentTimeMillis();
}
@Override
public void dealFallDamage() {
final EntityPlayer p = ((CraftPlayer) player).getHandle();
p.b(0D, true);
}
@Override
public ConfigurationCacheStore getConfigurationStore() {
return config;
}
@Override
public DataStore getDataStore() {
return data;
}
@Override
public ExecutionHistory getExecutionHistory() {
return history;
}
@Override
public float getJumpAmplifier() {
final EntityPlayer ep = ((CraftPlayer) player).getHandle();
if (ep.hasEffect(MobEffectList.JUMP)) {
final int amp = ep.getEffect(MobEffectList.JUMP).getAmplifier();
// Very rough estimates only
if (amp > 20)
return 1.5F * (ep.getEffect(MobEffectList.JUMP).getAmplifier() + 1);
else
return 1.2F * (ep.getEffect(MobEffectList.JUMP).getAmplifier() + 1);
} else
return 1.0F;
}
@Override
public String getName() {
return player.getName();
}
@Override
public Player getPlayer() {
return player;
}
@Override
public float getSpeedAmplifier() {
final EntityPlayer ep = ((CraftPlayer) player).getHandle();
if (ep.hasEffect(MobEffectList.FASTER_MOVEMENT))
// Taken directly from Minecraft code, should work
return 1.0F + 0.2F * (ep.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
else
return 1.0F;
}
@Override
public int getTicksLived() {
return player.getTicksLived();
}
@Override
public boolean hasPermission(final String permission) {
if (permission == null)
// System.out.println("NoCheatPlus: Warning, asked for null permission");
return false;
return player.hasPermission(permission);
}
@Override
public boolean isCreative() {
return player.getGameMode() == GameMode.CREATIVE || player.getAllowFlight();
}
@Override
public boolean isDead() {
return player.getHealth() <= 0 || player.isDead();
}
@Override
public boolean isSprinting() {
return player.isSprinting();
}
public void refresh(final Player player) {
this.player = player;
config = plugin.getConfig(player);
}
@Override
public void sendMessage(final String message) {
player.sendMessage(message);
}
public void setLastUsedTime(final long currentTimeInMilliseconds) {
lastUsedTime = currentTimeInMilliseconds;
}
public boolean shouldBeRemoved(final long currentTimeInMilliseconds) {
if (lastUsedTime > currentTimeInMilliseconds)
// Should never happen, but if it does, fix it somewhat
lastUsedTime = currentTimeInMilliseconds;
return lastUsedTime + 60000L < currentTimeInMilliseconds;
}
}

View File

@ -1,139 +0,0 @@
package me.neatmonster.nocheatplus.checks;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusLogEvent;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.Action;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.actions.types.ConsolecommandAction;
import me.neatmonster.nocheatplus.actions.types.DummyAction;
import me.neatmonster.nocheatplus.actions.types.LogAction;
import me.neatmonster.nocheatplus.actions.types.SpecialAction;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.Statistics.Id;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandException;
/**
* The abstract Check class, providing some basic functionality
*
*/
public abstract class Check {
private final String name;
// used to bundle information of multiple checks
private final String groupId;
protected final NoCheatPlus plugin;
public Check(final NoCheatPlus plugin, final String groupId, final String name) {
this.plugin = plugin;
this.groupId = groupId;
this.name = name;
}
/**
* Execute some actions for the specified player
*
* @param player
* @param actions
* @return
*/
protected boolean executeActions(final NoCheatPlusPlayer player, final ActionList actionList,
final double violationLevel) {
boolean special = false;
// Get the to be executed actions
final Action[] actions = actionList.getActions(violationLevel);
final long time = System.currentTimeMillis() / 1000L;
// The configuration will be needed too
final ConfigurationCacheStore cc = player.getConfigurationStore();
for (final Action ac : actions)
if (player.getExecutionHistory().executeAction(groupId, ac, time))
// The executionHistory 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, cc);
else if (ac instanceof SpecialAction)
special = true;
else if (ac instanceof ConsolecommandAction)
executeConsoleCommand((ConsolecommandAction) ac, this, player, cc);
else if (ac instanceof DummyAction) {
// nothing - it's a "DummyAction" after all
}
return special;
}
private void executeConsoleCommand(final ConsolecommandAction action, final Check check,
final NoCheatPlusPlayer player, final ConfigurationCacheStore cc) {
final String command = action.getCommand(player, check);
try {
plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command);
} catch (final CommandException e) {
System.out.println("[NoCheatPlus] failed to execute the command '" + command + "': " + e.getMessage()
+ ", please check if everything is setup correct.");
} catch (final Exception e) {
// I don't care in this case, your problem if your command fails
}
}
private void executeLogAction(final LogAction l, final Check check, final NoCheatPlusPlayer player,
final ConfigurationCacheStore cc) {
if (!cc.logging.active)
return;
// Fire one of our custom "Log" Events
Bukkit.getServer()
.getPluginManager()
.callEvent(
new NoCheatPlusLogEvent(cc.logging.prefix, l.getLogMessage(player, check), cc.logging.toConsole
&& l.toConsole(), cc.logging.toChat && l.toChat(), cc.logging.toFile && l.toFile()));
}
/**
* 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(final ParameterName wildcard, final NoCheatPlusPlayer player) {
if (wildcard == ParameterName.PLAYER)
return player.getName();
else if (wildcard == ParameterName.CHECK)
return name;
else if (wildcard == ParameterName.LOCATION) {
final Location l = player.getPlayer().getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
} else if (wildcard == ParameterName.WORLD)
return player.getPlayer().getWorld().getName();
else
return "the Author was lazy and forgot to define " + wildcard + ".";
}
/**
* Collect information about the players violations
*
* @param player
* @param id
* @param vl
*/
protected void incrementStatistics(final NoCheatPlusPlayer player, final Id id, final double vl) {
player.getDataStore().getStatistics().increment(id, vl);
}
}

View File

@ -1,58 +0,0 @@
package me.neatmonster.nocheatplus.checks.blockbreak;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.Check;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
/**
* Abstract base class for BlockBreakChecks. Provides some static convenience
* methods for retrieving data and config objects for players
*
*/
public abstract class BlockBreakCheck extends Check {
private static final String id = "blockbreak";
public static BlockBreakConfig getConfig(final ConfigurationCacheStore cache) {
BlockBreakConfig config = cache.get(id);
if (config == null) {
config = new BlockBreakConfig(cache.getConfiguration());
cache.set(id, config);
}
return config;
}
/**
* Get the BlockBreakConfig object that belongs to the world that the player
* currently resides in.
*
* @param player
* @return
*/
public static BlockBreakConfig getConfig(final NoCheatPlusPlayer player) {
return getConfig(player.getConfigurationStore());
}
/**
* Get the "BlockBreakData" object that belongs to the player. Will ensure
* that such a object exists and if not, create one
*
* @param player
* @return
*/
public static BlockBreakData getData(final NoCheatPlusPlayer player) {
final DataStore base = player.getDataStore();
BlockBreakData data = base.get(id);
if (data == null) {
data = new BlockBreakData();
base.set(id, data);
}
return data;
}
public BlockBreakCheck(final NoCheatPlus plugin, final String name) {
super(plugin, id, name);
}
}

View File

@ -1,83 +0,0 @@
package me.neatmonster.nocheatplus.checks.blockplace;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.Check;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
import me.neatmonster.nocheatplus.data.SimpleLocation;
/**
* Abstract base class for BlockPlace checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class BlockPlaceCheck extends Check {
private static final String id = "blockplace";
public static BlockPlaceConfig getConfig(final ConfigurationCacheStore cache) {
BlockPlaceConfig config = cache.get(id);
if (config == null) {
config = new BlockPlaceConfig(cache.getConfiguration());
cache.set(id, config);
}
return config;
}
/**
* Get the BlockPlaceConfig object that belongs to the world that the player
* currently resides in.
*
* @param player
* @return
*/
public static BlockPlaceConfig getConfig(final NoCheatPlusPlayer player) {
return getConfig(player.getConfigurationStore());
}
/**
* Get the "BlockPlaceData" object that belongs to the player. Will ensure
* that such a object exists and if not, create one
*
* @param player
* @return
*/
public static BlockPlaceData getData(final NoCheatPlusPlayer player) {
final DataStore base = player.getDataStore();
BlockPlaceData data = base.get(id);
if (data == null) {
data = new BlockPlaceData();
base.set(id, data);
}
return data;
}
public BlockPlaceCheck(final NoCheatPlus plugin, final String name) {
super(plugin, id, name);
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
if (wildcard == ParameterName.PLACE_LOCATION) {
final SimpleLocation l = getData(player).blockPlaced;
if (l.isSet())
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
else
return "null";
}
else if (wildcard == ParameterName.PLACE_AGAINST) {
final SimpleLocation l = getData(player).blockPlacedAgainst;
if (l.isSet())
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
else
return "null";
}
else
return super.getParameter(wildcard, player);
}
}

View File

@ -1,54 +0,0 @@
package me.neatmonster.nocheatplus.checks.blockplace;
import me.neatmonster.nocheatplus.ConfigItem;
import me.neatmonster.nocheatplus.actions.types.ActionList;
import me.neatmonster.nocheatplus.config.ConfPaths;
import me.neatmonster.nocheatplus.config.NoCheatPlusConfiguration;
import me.neatmonster.nocheatplus.config.Permissions;
/**
* Configurations specific for the "BlockPlace" checks
* Every world gets one of these assigned to it, or if a world doesn't get
* it's own, it will use the "global" version
*
*/
public class BlockPlaceConfig implements ConfigItem {
public final boolean fastPlaceCheck;
public final int fastPlaceInterval;
public final ActionList fastPlaceActions;
public final boolean reachCheck;
public final double reachDistance;
public final ActionList reachActions;
public final boolean directionCheck;
public final ActionList directionActions;
public final long directionPenaltyTime;
public final double directionPrecision;
public final boolean projectileCheck;
public final int projectileInterval;
public final ActionList projectileActions;
public BlockPlaceConfig(final NoCheatPlusConfiguration data) {
fastPlaceCheck = data.getBoolean(ConfPaths.BLOCKPLACE_FASTPLACE_CHECK);
fastPlaceInterval = data.getInt(ConfPaths.BLOCKPLACE_FASTPLACE_INTERVAL);
fastPlaceActions = data.getActionList(ConfPaths.BLOCKPLACE_FASTPLACE_ACTIONS, Permissions.BLOCKPLACE_FASTPLACE);
reachCheck = data.getBoolean(ConfPaths.BLOCKPLACE_REACH_CHECK);
reachDistance = 535D / 100D;
reachActions = data.getActionList(ConfPaths.BLOCKPLACE_REACH_ACTIONS, Permissions.BLOCKPLACE_REACH);
directionCheck = data.getBoolean(ConfPaths.BLOCKPLACE_DIRECTION_CHECK);
directionPenaltyTime = data.getInt(ConfPaths.BLOCKPLACE_DIRECTION_PENALTYTIME);
directionPrecision = data.getInt(ConfPaths.BLOCKPLACE_DIRECTION_PRECISION) / 100D;
directionActions = data.getActionList(ConfPaths.BLOCKPLACE_DIRECTION_ACTIONS, Permissions.BLOCKPLACE_DIRECTION);
projectileCheck = data.getBoolean(ConfPaths.BLOCKPLACE_PROJECTILE_CHECK);
projectileInterval = data.getInt(ConfPaths.BLOCKPLACE_PROJECTILE_INTERVAL);
projectileActions = data.getActionList(ConfPaths.BLOCKPLACE_PROJECTILE_ACTIONS,
Permissions.BLOCKPLACE_PROJECTILE);
}
}

View File

@ -1,68 +0,0 @@
package me.neatmonster.nocheatplus.checks.chat;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.Check;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
/**
* Abstract base class for Chat checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class ChatCheck extends Check {
private static final String id = "chat";
public static ChatConfig getConfig(final ConfigurationCacheStore cache) {
ChatConfig config = cache.get(id);
if (config == null) {
config = new ChatConfig(cache.getConfiguration());
cache.set(id, config);
}
return config;
}
/**
* Get the ChatConfig object that belongs to the world that the player
* currently resides in.
*
* @param player
* @return
*/
public static ChatConfig getConfig(final NoCheatPlusPlayer player) {
return getConfig(player.getConfigurationStore());
}
/**
* Get the "ChatData" object that belongs to the player. Will ensure
* that such a object exists and if not, create one
*
* @param player
* @return
*/
public static ChatData getData(final NoCheatPlusPlayer player) {
final DataStore base = player.getDataStore();
ChatData data = base.get(id);
if (data == null) {
data = new ChatData();
base.set(id, data);
}
return data;
}
public ChatCheck(final NoCheatPlus plugin, final String name) {
super(plugin, id, name);
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
if (wildcard == ParameterName.TEXT)
// Filter colors from the players message when logging
return getData(player).message.replaceAll("\302\247.", "").replaceAll("\247.", "");
else
return super.getParameter(wildcard, player);
}
}

View File

@ -1,64 +0,0 @@
package me.neatmonster.nocheatplus.checks.fight;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.Check;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
/**
* Abstract base class for Fight checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class FightCheck extends Check {
private static final String id = "fight";
public static FightConfig getConfig(final ConfigurationCacheStore cache) {
FightConfig config = cache.get(id);
if (config == null) {
config = new FightConfig(cache.getConfiguration());
cache.set(id, config);
}
return config;
}
/**
* Get the FightConfig object that belongs to the world that the player
* currently resides in.
*
* @param player
* @return
*/
public static FightConfig getConfig(final NoCheatPlusPlayer player) {
return getConfig(player.getConfigurationStore());
}
/**
* Get the "FightData" object that belongs to the player. Will ensure
* that such a object exists and if not, create one
*
* @param player
* @return
*/
public static FightData getData(final NoCheatPlusPlayer player) {
final DataStore base = player.getDataStore();
FightData data = base.get(id);
if (data == null) {
data = new FightData();
base.set(id, data);
}
return data;
}
public final String permission;
public FightCheck(final NoCheatPlus plugin, final String name, final String permission) {
super(plugin, id, name);
this.permission = permission;
}
public abstract boolean check(NoCheatPlusPlayer player, FightData data, FightConfig cc);
public abstract boolean isEnabled(FightConfig cc);
}

View File

@ -1,57 +0,0 @@
package me.neatmonster.nocheatplus.checks.inventory;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.checks.Check;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
/**
* Abstract base class for Inventory checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class InventoryCheck extends Check {
private static final String id = "inventory";
public static InventoryConfig getConfig(final ConfigurationCacheStore cache) {
InventoryConfig config = cache.get(id);
if (config == null) {
config = new InventoryConfig(cache.getConfiguration());
cache.set(id, config);
}
return config;
}
/**
* Get the InventoryConfig object that belongs to the world that the player
* currently resides in.
*
* @param player
* @return
*/
public static InventoryConfig getConfig(final NoCheatPlusPlayer player) {
return getConfig(player.getConfigurationStore());
}
/**
* Get the "InventoryData" object that belongs to the player. Will ensure
* that such a object exists and if not, create one
*
* @param player
* @return
*/
public static InventoryData getData(final NoCheatPlusPlayer player) {
final DataStore base = player.getDataStore();
InventoryData data = base.get(id);
if (data == null) {
data = new InventoryData();
base.set(id, data);
}
return data;
}
public InventoryCheck(final NoCheatPlus plugin, final String name) {
super(plugin, id, name);
}
}

View File

@ -1,79 +0,0 @@
package me.neatmonster.nocheatplus.checks.moving;
import java.util.Locale;
import me.neatmonster.nocheatplus.NoCheatPlus;
import me.neatmonster.nocheatplus.NoCheatPlusPlayer;
import me.neatmonster.nocheatplus.actions.ParameterName;
import me.neatmonster.nocheatplus.checks.Check;
import me.neatmonster.nocheatplus.config.ConfigurationCacheStore;
import me.neatmonster.nocheatplus.data.DataStore;
import me.neatmonster.nocheatplus.data.PreciseLocation;
/**
* Abstract base class for Moving checks, provides some convenience
* methods for access to data and config that's relevant to this checktype
*/
public abstract class MovingCheck extends Check {
private static final String id = "moving";
public static MovingConfig getConfig(final ConfigurationCacheStore cache) {
MovingConfig config = cache.get(id);
if (config == null) {
config = new MovingConfig(cache.getConfiguration());
cache.set(id, config);
}
return config;
}
/**
* Get the MovingConfig object that belongs to the world that the player
* currently resides in.
*
* @param player
* @return
*/
public static MovingConfig getConfig(final NoCheatPlusPlayer player) {
return getConfig(player.getConfigurationStore());
}
/**
* Get the "MovingData" object that belongs to the player. Will ensure
* that such a object exists and if not, create one
*
* @param player
* @return
*/
public static MovingData getData(final NoCheatPlusPlayer player) {
final DataStore base = player.getDataStore();
MovingData data = base.get(id);
if (data == null) {
data = new MovingData();
base.set(id, data);
}
return data;
}
public MovingCheck(final NoCheatPlus plugin, final String name) {
super(plugin, id, name);
}
@Override
public String getParameter(final ParameterName wildcard, final NoCheatPlusPlayer player) {
if (wildcard == ParameterName.LOCATION) {
final PreciseLocation from = getData(player).from;
return String.format(Locale.US, "%.2f,%.2f,%.2f", from.x, from.y, from.z);
} else if (wildcard == ParameterName.MOVEDISTANCE) {
final PreciseLocation from = getData(player).from;
final PreciseLocation to = getData(player).to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x - from.x, to.y - from.y, to.z - from.z);
} else if (wildcard == ParameterName.LOCATION_TO) {
final PreciseLocation to = getData(player).to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
} else
return super.getParameter(wildcard, player);
}
}

View File

@ -1,45 +0,0 @@
package me.neatmonster.nocheatplus.config;
import java.util.HashMap;
import java.util.Map;
import me.neatmonster.nocheatplus.ConfigItem;
/**
* A class to keep all configurables of the plugin associated with
* a world
*
*/
public class ConfigurationCacheStore {
public final LoggingConfig logging;
private final Map<String, ConfigItem> configMap = new HashMap<String, ConfigItem>();
private final NoCheatPlusConfiguration data;
/**
* Instantiate a config cache and populate it with the data of a
* Config tree (and its parent tree)
*/
public ConfigurationCacheStore(final NoCheatPlusConfiguration data) {
logging = new LoggingConfig(data);
this.data = data;
}
@SuppressWarnings("unchecked")
public <T extends ConfigItem> T get(final String id) {
return (T) configMap.get(id);
}
public NoCheatPlusConfiguration getConfiguration() {
return data;
}
public void set(final String id, final ConfigItem config) {
configMap.put(id, config);
}
}

Some files were not shown because too many files have changed in this diff Show More