use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class ChatListener method onPlayerChat.
/**
* We listen to PlayerChat events for obvious reasons.
*
* @param event
* the event
*/
@EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST)
public void onPlayerChat(final AsyncPlayerChatEvent event) {
final Player player = event.getPlayer();
final boolean alreadyCancelled = event.isCancelled();
// Tell TickTask to update cached permissions.
// (Might omit this if already cancelled.)
final IPlayerData pData = DataManager.getPlayerData(player);
final ChatConfig cc = pData.getGenericInstance(ChatConfig.class);
// First the color check.
if (!alreadyCancelled && color.isEnabled(player, pData)) {
event.setMessage(color.check(player, event.getMessage(), false));
}
// TODO: isMainThread: Could consider event.isAsync ?
if (textChecks(player, event.getMessage(), cc, pData, false, alreadyCancelled)) {
event.setCancelled(true);
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class ChatListener method onPlayerCommandPreprocess.
/**
* We listen to PlayerCommandPreprocess events because commands can be used for spamming too.
*
* @param event
* the event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
final Player player = event.getPlayer();
// Tell TickTask to update cached permissions.
final IPlayerData pData = DataManager.getPlayerData(player);
final ChatConfig cc = pData.getGenericInstance(ChatConfig.class);
// Checks that replace parts of the message (color).
if (color.isEnabled(player, pData)) {
event.setMessage(color.check(player, event.getMessage(), true));
}
// Left-trim is necessary because the server accepts leading spaces with commands.
final String message = event.getMessage();
final String lcMessage = StringUtil.leftTrim(message).toLowerCase();
// TODO: Remove bukkit: etc.
final String[] split = lcMessage.split(" ", 2);
final String alias = split[0].substring(1);
final Command command = CommandUtil.getCommand(alias);
// Could as well use an array and allow null on input of SimpleCharPrefixTree.
final List<String> messageVars = new ArrayList<String>();
messageVars.add(lcMessage);
// Message to run chat checks on.
String checkMessage = message;
if (command != null) {
messageVars.add("/" + command.getLabel().toLowerCase() + (split.length > 1 ? (" " + split[1]) : ""));
}
if (alias.indexOf(":") != -1) {
final int index = message.indexOf(":") + 1;
if (index < message.length()) {
checkMessage = message.substring(index);
messageVars.add(checkMessage.toLowerCase());
}
}
// Prevent commands from being used by players (e.g. /op /deop /reload).
if (cc.consoleOnlyCheck && consoleOnlyCommands.hasAnyPrefixWords(messageVars)) {
if (command == null || command.testPermission(player)) {
player.sendMessage(cc.consoleOnlyMessage);
}
event.setCancelled(true);
return;
}
// Handle as chat or command.
if (chatCommands.hasAnyPrefixWords(messageVars)) {
// TODO: Cut off the command ?.
if (textChecks(player, checkMessage, cc, pData, true, false)) {
event.setCancelled(true);
}
} else if (!commandExclusions.hasAnyPrefixWords(messageVars)) {
// Treat as command.
if (commands.isEnabled(player, pData) && commands.check(player, checkMessage, cc, pData, captcha)) {
event.setCancelled(true);
} else {
// TODO: Consider always checking these?
// Note that this checks for prefixes, not prefix words.
final MovingConfig mcc = pData.getGenericInstance(MovingConfig.class);
if (mcc.passableUntrackedCommandCheck && mcc.passableUntrackedCommandPrefixes.hasAnyPrefix(messageVars)) {
if (checkUntrackedLocation(player, message, mcc, pData)) {
event.setCancelled(true);
}
}
}
}
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class NoCheatPlus method sendAdminNotifyMessageSubscriptions.
/**
* Send notification to all CommandSenders found in permission subscriptions for the notify-permission as well as players that have stored permissions (those get re-checked here).
* @param message
* @return
*/
public int sendAdminNotifyMessageSubscriptions(final String message) {
// TODO: Fetch from PlayerData - alt: update subscriptions on a regular basis - not every call!
final String lcPerm = Permissions.NOTIFY.getLowerCaseStringRepresentation();
final Permission bukkitPerm = Permissions.NOTIFY.getBukkitPermission();
final Set<Permissible> permissibles = Bukkit.getPluginManager().getPermissionSubscriptions(lcPerm);
final Set<String> done = new HashSet<String>(permissibles.size());
for (final Permissible permissible : permissibles) {
if (permissible instanceof CommandSender) {
final CommandSender sender = (CommandSender) permissible;
if (sender instanceof Player) {
// Use the permission caching feature.
final Player player = (Player) sender;
final IPlayerData data = DataManager.getPlayerData(player);
if (data.getNotifyOff() || !data.hasPermission(Permissions.NOTIFY, player)) {
continue;
}
} else if (!sender.hasPermission(bukkitPerm)) {
// TODO: Add permission cache for non-player-things?
continue;
}
// Finally send.
sender.sendMessage(message);
done.add(sender.getName());
}
}
return done.size();
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class AllViolationsHook method onCheckFailure.
@Override
public boolean onCheckFailure(final CheckType checkType, final Player player, final IViolationInfo info) {
final AllViolationsConfig config = this.config;
if (config == null) {
return false;
}
boolean debugSet = false;
if (config.debugOnly || config.debug) {
// TODO: Better mix the debug flag into IViolationInfo, for best performance AND consistency.
// TODO: (If debug is not in IViolationInfo, switch to PlayerData.isDebug(CheckType).)
final IPlayerData pData = DataManager.getPlayerData(player);
debugSet = pData.isDebugActive(checkType);
if (config.debugOnly && !debugSet) {
return false;
}
}
log(checkType, player, info, config.allToTrace || debugSet, config.allToNotify);
return false;
}
use of fr.neatmonster.nocheatplus.players.IPlayerData in project NoCheatPlus by NoCheatPlus.
the class MovingUtil method checkUntrackedLocation.
/**
* Detect if the given location is an untracked spot. This is spots for
* which a player is at the location, but the moving data has another
* "last to" position set for that player. Note that one matching player
* with "last to" being consistent is enough to let this return null, world spawn is exempted.
* <hr>
* Pre-conditions:<br>
* <li>Context-specific (e.g. activation flags for command, teleport).</li>
* <li>See MovingUtils.shouldCheckUntrackedLocation.</li>
*
* @param loc
* @return Corrected location, if loc is an "untracked location".
*/
public static Location checkUntrackedLocation(final Location loc) {
// TODO: More efficient method to get entities at the same position (might use MCAccess).
final Chunk toChunk = loc.getChunk();
final Entity[] entities = toChunk.getEntities();
MovingData untrackedData = null;
for (int i = 0; i < entities.length; i++) {
final Entity entity = entities[i];
if (entity.getType() != EntityType.PLAYER) {
continue;
}
final Location refLoc = entity.getLocation(useLoc);
// TODO: Exempt other warps -> HASH based exemption (expire by time, keep high count)?
if (TrigUtil.isSamePos(loc, refLoc) && (entity instanceof Player)) {
final Player other = (Player) entity;
final IPlayerData otherPData = DataManager.getPlayerData(other);
final MovingData otherData = otherPData.getGenericInstance(MovingData.class);
final PlayerMoveData otherLastMove = otherData.playerMoves.getFirstPastMove();
if (!otherLastMove.toIsValid) {
// TODO: Consider counting as tracked?
continue;
} else if (TrigUtil.isSamePos(refLoc, otherLastMove.to.getX(), otherLastMove.to.getY(), otherLastMove.to.getZ())) {
// Tracked.
return null;
} else {
// More leniency: allow moving inside of the same block.
if (TrigUtil.isSameBlock(loc, otherLastMove.to.getX(), otherLastMove.to.getY(), otherLastMove.to.getZ()) && !BlockProperties.isPassable(refLoc.getWorld(), otherLastMove.to.getX(), otherLastMove.to.getY(), otherLastMove.to.getZ())) {
continue;
}
untrackedData = otherData;
}
}
}
// Cleanup.
useLoc.setWorld(null);
if (untrackedData == null) {
return null;
} else {
// TODO: Count and log to TRACE_FILE, if multiple locations would match (!).
final PlayerMoveData lastMove = untrackedData.playerMoves.getFirstPastMove();
return new Location(loc.getWorld(), lastMove.to.getX(), lastMove.to.getY(), lastMove.to.getZ(), loc.getYaw(), loc.getPitch());
}
}
Aggregations