[BREAKING API] Add module NCPCore between NCPCompat and NCPPlugin.

* Static utility NCPAPIProvider instead of NoCheatPlus.getAPI().
* Extend NoCheatPlusAPI: Some previously static access methods are now
part of the NoCheatPlusAPI interface instead. MCAccessHolder is
implemented and allows external setting of MCAccess.
* Fix some static members/calls to non-static.
* Moving some packages to NCPCore.
* Prepares for moving most check stuff between NCPCompat and NCPPlugin
to allow more optional higher level components.
This commit is contained in:
asofold 2013-05-21 22:49:05 +02:00
parent 6e6b198188
commit 463700cb3a
42 changed files with 419 additions and 261 deletions

32
NCPCore/pom.xml Normal file
View File

@ -0,0 +1,32 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcore</artifactId>
<packaging>jar</packaging>
<name>NCPCore</name>
<version>static</version>
<parent>
<groupId>fr.neatmonster</groupId>
<artifactId>nocheatplus-parent</artifactId>
<version>static</version>
</parent>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.4.7-R1.0</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcompat</artifactId>
<version>static</version>
</dependency>
</dependencies>
<description>Core components and checks implementations. This contains about everything, just not the component/compat factories and not the plugin itself. NCPCore allows to add more modules/components that use check-specific classes to be added in the factories on NCPPlugin level. Later checks might be put between this and the plugin, some component setup might be put to compat or between compat and this.
Version updating is done for NCPPlugin mainly, expect the other poms version to change randomly rather.</description>
</project>

View File

@ -0,0 +1,30 @@
package fr.neatmonster.nocheatplus;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
/**
* Static API provider utility.
* @author mc_dev
*
*/
public class NCPAPIProvider {
private static NoCheatPlusAPI noCheatPlusAPI = null;
/**
* Get the registered API instance. This will work after the plugin has loaded (onLoad).
*/
public static NoCheatPlusAPI getNoCheatPlusAPI(){
return noCheatPlusAPI;
}
/**
* Setter for the NoCheatPlusAPI instance.
* <hr>
* For internal use only (onLoad).<br>
* Setting this to anything else than the NoCheatPlus plugin instance might lead to inconsistencies.
* @param noCheatPlusAPI
*/
protected static void setNoCheatPlusAPI(NoCheatPlusAPI noCheatPlusAPI){
NCPAPIProvider.noCheatPlusAPI = noCheatPlusAPI;
}
}

View File

@ -1,6 +1,5 @@
package fr.neatmonster.nocheatplus.components;
import fr.neatmonster.nocheatplus.command.INotifyReload;
/**
* Indicate that a component needs config after time of creation but in onEnable.

View File

@ -0,0 +1,10 @@
package fr.neatmonster.nocheatplus.components;
/**
* Interface for a component that needs to be notified about a reload.
* @author mc_dev
*
*/
public interface INotifyReload {
public void onReload();
}

View File

@ -0,0 +1,78 @@
package fr.neatmonster.nocheatplus.components;
/**
* ComponentRegistry:
* <li>Supported components: Listener, TickListener, PermStateReceiver, INotifyReload, INeedConfig, IRemoveData, MCAccessHolder, ConsistencyChecker, JoinLeaveListener</li>
* <li>ComponentRegistry instances will be registered as sub registries unless you use the addComponent(Object, boolean) method appropriately. </li>
* <li>IHoldSubComponents instances will be registered in the next tick (scheduled task), those added within onEnable will get registered after looping in onEnable.</li>
* <li>Registering components should be done during onEnable or any time while the plugin is enabled, all components will be unregistered in onDisable.</li>
* <li>References to all components will be held until onDisable is finished.</li>
* <li>Interfaces checked for managed listeners: IHaveMethodOrder (method), ComponentWithName (tag)</li>
* <hr>
* Not sure about all the login-denial API, some of those might get removed.
* @author mc_dev
*
*/
public interface NoCheatPlusAPI extends ComponentRegistry<Object>, ComponentRegistryProvider, MCAccessHolder{
/**
* By default addComponent(Object) will register ComponentFactories as well.
* @param obj
* @param allowComponentRegistry If to allow registering ComponentFactories.
* @return
*/
public boolean addComponent(Object obj, boolean allowComponentRegistry);
/**
* Send all players with the nocheatplus.admin.notify permission a message.<br>
* This will act according to configuration (stored permissions and/or permission subscriptions).
*
* @param message
* @return Number of players messaged.
*/
public int sendAdminNotifyMessage(final String message);
/**
* Allow login (remove from deny login map).
* @param playerName
* @return If player was denied to login.
*/
public boolean allowLogin(String playerName);
/**
* Remove all players from the allow login set.
* @return Number of players that had actually been denied to login.
*/
public int allowLoginAll();
/**
* Deny the player to login. This will also remove expired entries.
* @param playerName
* @param duration Duration from now on, in milliseconds.
*/
public void denyLogin(String playerName, long duration);
/**
* Check if player is denied to login right now.
* @param playerName
* @return
*/
public boolean isLoginDenied(String playerName);
/**
* Get the names of all players who are denied to log in at present.
* @return
*/
public String[] getLoginDeniedPlayers();
/**
* Check if a player is denied to login at a certain point of time.
* @param playerName
* @param currentTimeMillis
* @return
*/
public boolean isLoginDenied(String playerName, long time);
}

View File

@ -45,6 +45,11 @@
<artifactId>ncpcompat</artifactId>
<version>static</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcore</artifactId>
<version>static</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>
<artifactId>ncpcompatbukkit</artifactId>
@ -137,6 +142,7 @@
<include>fr.neatmonster:ncpbuildbase</include>
<include>fr.neatmonster:ncpcommons</include>
<include>fr.neatmonster:ncpcompat</include>
<include>fr.neatmonster:ncpcore</include>
<include>fr.neatmonster:ncpcompatbukkit</include>
<include>fr.neatmonster:ncpcompatcb2511</include>
<include>fr.neatmonster:ncpcompatcb2512</include>

View File

@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.Callable;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -44,7 +45,6 @@ import fr.neatmonster.nocheatplus.checks.inventory.InventoryListener;
import fr.neatmonster.nocheatplus.checks.moving.MovingListener;
import fr.neatmonster.nocheatplus.clients.ModUtil;
import fr.neatmonster.nocheatplus.command.CommandHandler;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.compat.MCAccessFactory;
import fr.neatmonster.nocheatplus.components.ComponentRegistry;
@ -52,6 +52,7 @@ import fr.neatmonster.nocheatplus.components.ComponentWithName;
import fr.neatmonster.nocheatplus.components.ConsistencyChecker;
import fr.neatmonster.nocheatplus.components.IHoldSubComponents;
import fr.neatmonster.nocheatplus.components.INeedConfig;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
import fr.neatmonster.nocheatplus.components.MCAccessHolder;
import fr.neatmonster.nocheatplus.components.NCPListener;
@ -96,195 +97,31 @@ import fr.neatmonster.nocheatplus.utilities.Updates;
*/
public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
/** Lower case player name to milliseconds point of time of release */
private static final Map<String, Long> denyLoginNames = Collections.synchronizedMap(new HashMap<String, Long>());
/** Names of players with a certain permission. */
protected static final NameSetPermState nameSetPerms = new NameSetPermState(Permissions.ADMINISTRATION_NOTIFY);
/** MCAccess instance. */
protected static MCAccess mcAccess = null;
//////////////////
// Static API
//////////////////
/**
* Get the wrapper for accessing Minecraft properties.
* @return
*/
public static MCAccess getMCAccess(){
if (mcAccess == null) initMCAccess();
return mcAccess;
}
private static void initMCAccess() {
synchronized (NoCheatPlus.class) {
if (mcAccess != null) return;
mcAccess = new MCAccessFactory().getMCAccess();
}
LogUtil.logInfo("[NoCheatPlus] McAccess set to: " + mcAccess.getMCVersion() + " / " + mcAccess.getServerVersionTag());
}
/**
* Remove expired entries.
*/
private static void checkDenyLoginsNames() {
final long ts = System.currentTimeMillis();
final List<String> rem = new LinkedList<String>();
synchronized (denyLoginNames) {
for (final Entry<String, Long> entry : denyLoginNames.entrySet()){
if (entry.getValue().longValue() < ts) rem.add(entry.getKey());
}
for (final String name : rem){
denyLoginNames.remove(name);
}
}
}
/**
* Allow login (remove from deny login map).
* @param playerName
* @return If player was denied to login.
*/
public static boolean allowLogin(String playerName){
playerName = playerName.trim().toLowerCase();
final Long time = denyLoginNames.remove(playerName);
if (time == null) return false;
return System.currentTimeMillis() <= time;
}
/**
* Remove all players from the allow login set.
* @return Number of players that had actually been denied to login.
*/
public static int allowLoginAll(){
int denied = 0;
final long now = System.currentTimeMillis();
for (final String playerName : denyLoginNames.keySet()){
final Long time = denyLoginNames.get(playerName);
if (time != null && time > now) denied ++;
}
denyLoginNames.clear();
return denied;
}
/**
* Deny the player to login. This will also remove expired entries.
* @param playerName
* @param duration Duration from now on, in milliseconds.
*/
public static void denyLogin(String playerName, long duration){
final long ts = System.currentTimeMillis() + duration;
playerName = playerName.trim().toLowerCase();
synchronized (denyLoginNames) {
final Long oldTs = denyLoginNames.get(playerName);
if (oldTs != null && ts < oldTs.longValue()) return;
denyLoginNames.put(playerName, ts);
// TODO: later maybe save these ?
}
checkDenyLoginsNames();
}
/**
* Check if player is denied to login right now.
* @param playerName
* @return
*/
public static boolean isLoginDenied(String playerName){
return isLoginDenied(playerName, System.currentTimeMillis());
}
public static String[] getLoginDeniedPlayers() {
checkDenyLoginsNames();
String[] kicked = new String[denyLoginNames.size()];
denyLoginNames.keySet().toArray(kicked);
return kicked;
}
/**
* Check if a player is denied to login at a certain point of time.
* @param playerName
* @param currentTimeMillis
* @return
*/
public static boolean isLoginDenied(String playerName, long time) {
playerName = playerName.trim().toLowerCase();
final Long oldTs = denyLoginNames.get(playerName);
if (oldTs == null) return false;
else return time < oldTs.longValue();
}
/**
* Convenience method, delegates to
* Convenience method.
* @deprecated Use fr.neatmonster.nocheatplus.utilities.NCPAPIProvider.getNoCheatPlusAPI() instead, this method might get removed.
* @return
*/
public static NoCheatPlusAPI getAPI() {
return (NoCheatPlusAPI) Bukkit.getPluginManager().getPlugin("NoCheatPlus");
return NCPAPIProvider.getNoCheatPlusAPI();
}
/**
* Send all players with the nocheatplus.admin.notify permission a message.<br>
* This will act according to configuration (stored permissions or permission subscriptions).
*
* @param message
* @return Number of players messaged.
*/
public static int sendAdminNotifyMessage(final String message){
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_USESUBSCRIPTIONS)){
// TODO: Might respect console settings, or add extra config section (e.g. notifications).
return sendAdminNotifyMessageSubscriptions(message);
}
else{
return sendAdminNotifyMessageStored(message);
}
}
//////////////////
// Not static.
//////////////////
/**
* Send notification to players with stored notify-permission (world changes, login, permissions are not re-checked here).
* @param message
* @return
*/
public static int sendAdminNotifyMessageStored(final String message){
final Set<String> names = nameSetPerms.getPlayers(Permissions.ADMINISTRATION_NOTIFY);
if (names == null) return 0;
int done = 0;
for (final String name : names){
final Player player = DataManager.getPlayerExact(name);
if (player != null){
player.sendMessage(message);
done ++;
}
}
return done;
}
/** Names of players with a certain permission. */
protected final NameSetPermState nameSetPerms = new NameSetPermState(Permissions.ADMINISTRATION_NOTIFY);
/**
* 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 static int sendAdminNotifyMessageSubscriptions(final String message){
final Set<Permissible> permissibles = Bukkit.getPluginManager().getPermissionSubscriptions(Permissions.ADMINISTRATION_NOTIFY);
final Set<String> names = nameSetPerms.getPlayers(Permissions.ADMINISTRATION_NOTIFY);
final Set<String> done = new HashSet<String>(permissibles.size() + (names == null ? 0 : names.size()));
for (final Permissible permissible : permissibles){
if (permissible instanceof CommandSender && permissible.hasPermission(Permissions.ADMINISTRATION_NOTIFY)){
final CommandSender sender = (CommandSender) permissible;
sender.sendMessage(message);
done.add(sender.getName());
}
}
// Fall-back checking for players.
if (names != null){
for (final String name : names){
if (!done.contains(name)){
final Player player = DataManager.getPlayerExact(name);
if (player != null && player.hasPermission(Permissions.ADMINISTRATION_NOTIFY)){
player.sendMessage(message);
done.add(name);
}
}
}
}
return done.size();
}
/** Lower case player name to milliseconds point of time of release */
private final Map<String, Long> denyLoginNames = Collections.synchronizedMap(new HashMap<String, Long>());
/** MCAccess instance. */
protected MCAccess mcAccess = null;
/** Is the configuration outdated? */
private boolean configOutdated = false;
@ -348,6 +185,137 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
return false;
}
};
/**
* Remove expired entries.
*/
private void checkDenyLoginsNames() {
final long ts = System.currentTimeMillis();
final List<String> rem = new LinkedList<String>();
synchronized (denyLoginNames) {
for (final Entry<String, Long> entry : denyLoginNames.entrySet()){
if (entry.getValue().longValue() < ts) rem.add(entry.getKey());
}
for (final String name : rem){
denyLoginNames.remove(name);
}
}
}
@Override
public boolean allowLogin(String playerName){
playerName = playerName.trim().toLowerCase();
final Long time = denyLoginNames.remove(playerName);
if (time == null) return false;
return System.currentTimeMillis() <= time;
}
@Override
public int allowLoginAll(){
int denied = 0;
final long now = System.currentTimeMillis();
for (final String playerName : denyLoginNames.keySet()){
final Long time = denyLoginNames.get(playerName);
if (time != null && time > now) denied ++;
}
denyLoginNames.clear();
return denied;
}
@Override
public void denyLogin(String playerName, long duration){
final long ts = System.currentTimeMillis() + duration;
playerName = playerName.trim().toLowerCase();
synchronized (denyLoginNames) {
final Long oldTs = denyLoginNames.get(playerName);
if (oldTs != null && ts < oldTs.longValue()) return;
denyLoginNames.put(playerName, ts);
// TODO: later maybe save these ?
}
checkDenyLoginsNames();
}
@Override
public boolean isLoginDenied(String playerName){
return isLoginDenied(playerName, System.currentTimeMillis());
}
@Override
public String[] getLoginDeniedPlayers() {
checkDenyLoginsNames();
String[] kicked = new String[denyLoginNames.size()];
denyLoginNames.keySet().toArray(kicked);
return kicked;
}
@Override
public boolean isLoginDenied(String playerName, long time) {
playerName = playerName.trim().toLowerCase();
final Long oldTs = denyLoginNames.get(playerName);
if (oldTs == null) return false;
else return time < oldTs.longValue();
}
@Override
public int sendAdminNotifyMessage(final String message){
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_USESUBSCRIPTIONS)){
// TODO: Might respect console settings, or add extra config section (e.g. notifications).
return sendAdminNotifyMessageSubscriptions(message);
}
else{
return sendAdminNotifyMessageStored(message);
}
}
/**
* Send notification to players with stored notify-permission (world changes, login, permissions are not re-checked here).
* @param message
* @return
*/
public int sendAdminNotifyMessageStored(final String message){
final Set<String> names = nameSetPerms.getPlayers(Permissions.ADMINISTRATION_NOTIFY);
if (names == null) return 0;
int done = 0;
for (final String name : names){
final Player player = DataManager.getPlayerExact(name);
if (player != null){
player.sendMessage(message);
done ++;
}
}
return done;
}
/**
* 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){
final Set<Permissible> permissibles = Bukkit.getPluginManager().getPermissionSubscriptions(Permissions.ADMINISTRATION_NOTIFY);
final Set<String> names = nameSetPerms.getPlayers(Permissions.ADMINISTRATION_NOTIFY);
final Set<String> done = new HashSet<String>(permissibles.size() + (names == null ? 0 : names.size()));
for (final Permissible permissible : permissibles){
if (permissible instanceof CommandSender && permissible.hasPermission(Permissions.ADMINISTRATION_NOTIFY)){
final CommandSender sender = (CommandSender) permissible;
sender.sendMessage(message);
done.add(sender.getName());
}
}
// Fall-back checking for players.
if (names != null){
for (final String name : names){
if (!done.contains(name)){
final Player player = DataManager.getPlayerExact(name);
if (player != null && player.hasPermission(Permissions.ADMINISTRATION_NOTIFY)){
player.sendMessage(message);
done.add(name);
}
}
}
}
return done.size();
}
@SuppressWarnings("unchecked")
@Override
@ -652,6 +620,16 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
Arrays.asList("plugins", "version", "icanhasbukkit"), "nocheatplus.feature.command", false);
if (this.changedCommands == null) this.changedCommands = changedCommands;
else this.changedCommands.addAll(changedCommands);
}
/* (non-Javadoc)
* @see org.bukkit.plugin.java.JavaPlugin#onLoad()
*/
@Override
public void onLoad() {
NCPAPIProvider.setNoCheatPlusAPI(this);
// TODO: Can not set to null in onDisable...
super.onLoad(); // TODO: Check what this does / order.
}
/* (non-Javadoc)
@ -681,7 +659,10 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
final ConfigFile config = ConfigManager.getConfigFile();
// Initialize BlockProperties
// Initialize MCAccess.
initMCAccess(config);
// Initialize BlockProperties.
initBlockProperties(config);
// Initialize data manager.
@ -728,7 +709,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
// Register sub-components (!).
processQueuedSubComponentHolders();
// Register "highe level" components (check listeners).
// Register "higher level" components (check listeners).
for (final Object obj : new Object[]{
new BlockInteractListener(),
new BlockBreakListener(),
@ -871,20 +852,57 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
scheduleConsistencyCheckers();
}
@Override
public MCAccess getMCAccess(){
if (mcAccess == null) initMCAccess();
return mcAccess;
}
/**
* Fall-back method to initialize from factory, only if not yet set. Uses the BukkitScheduler to ensure this works if called from async checks.
*/
private void initMCAccess() {
getServer().getScheduler().callSyncMethod(this, new Callable<MCAccess>() {
@Override
public MCAccess call() throws Exception {
if (mcAccess != null) return mcAccess;
return initMCAccess(ConfigManager.getConfigFile());
}
});
}
/**
* Re-setup MCAccess and pass it to MCAccessHolder components.
* Re-setup MCAccess from internal factory and pass it to MCAccessHolder components, only call from the main thread.
* @param config
*/
protected void initMCAccess(final ConfigFile config) {
public MCAccess initMCAccess(final ConfigFile config) {
// Reset MCAccess.
NoCheatPlus.mcAccess = null;
final MCAccess mcAccess = getMCAccess();
// TODO: Might fire a NCPSetMCAccessFromFactoryEvent (include getting and setting)!
final MCAccess mcAccess = new MCAccessFactory().getMCAccess(config.getBoolean(ConfPaths.COMPATIBILITY_BUKKITONLY));
setMCAccess(mcAccess);
return mcAccess;
}
/**
* Set and propagate to registered MCAccessHolder instances.
*/
@Override
public void setMCAccess(final MCAccess mcAccess){
// Just sets it and propagates it.
// TODO: Might fire a NCPSetMCAccessEvent (include getting and setting)!
this.mcAccess = mcAccess;
for (final Object obj : this.allComponents){
if (obj instanceof MCAccessHolder){
((MCAccessHolder) obj).setMCAccess(mcAccess);
try{
((MCAccessHolder) obj).setMCAccess(mcAccess);
} catch(Throwable t){
LogUtil.logSevere("[NoCheatPlus] MCAccessHolder(" + obj.getClass().getName() + ") failed to set MCAccess: " + t.getClass().getSimpleName());
LogUtil.logSevere(t);
}
}
}
}
LogUtil.logInfo("[NoCheatPlus] McAccess set to: " + mcAccess.getMCVersion() + " / " + mcAccess.getServerVersionTag());
}
/**
* Initialize BlockProperties, including config.

View File

@ -2,7 +2,7 @@ package fr.neatmonster.nocheatplus.actions.types;
import org.bukkit.ChatColor;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.actions.Action;
import fr.neatmonster.nocheatplus.actions.ActionList;
import fr.neatmonster.nocheatplus.checks.ViolationData;
@ -77,7 +77,7 @@ public class LogAction extends ActionWithParameters<ViolationData, ActionList> {
public boolean execute(final ViolationData violationData) {
if (!violationData.player.hasPermission(violationData.getPermissionSilent())) {
final String message = super.getMessage(violationData);
if (toChat) NoCheatPlus.sendAdminNotifyMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + ColorUtil.replaceColors(message));
if (toChat) NCPAPIProvider.getNoCheatPlusAPI().sendAdminNotifyMessage(ChatColor.RED + "NCP: " + ChatColor.WHITE + ColorUtil.replaceColors(message));
if (toConsole) LogUtil.logInfo("[NoCheatPlus] " + ColorUtil.removeColors(message));
if (toFile) StaticLogFile.fileLogger.info(ColorUtil.removeColors(message));
}

View File

@ -5,7 +5,7 @@ import java.util.Map;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.actions.ActionList;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.compat.MCAccess;
@ -61,7 +61,7 @@ public abstract class Check implements MCAccessHolder{
*/
public Check(final CheckType type) {
this.type = type;
mcAccess = NoCheatPlus.getMCAccess();
mcAccess = NCPAPIProvider.getNoCheatPlusAPI().getMCAccess();
ViolationHistory.checkTypeMap.put(getClass().getName(), type);
DataManager.registerExecutionHistory(type, histories);
}

View File

@ -5,7 +5,7 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.components.IHoldSubComponents;
import fr.neatmonster.nocheatplus.components.MCAccessHolder;
@ -32,7 +32,7 @@ public class CheckListener extends NCPListener implements MCAccessHolder, IHoldS
public CheckListener(CheckType checkType){
this.checkType = checkType;
this.mcAccess = NoCheatPlus.getMCAccess();
this.mcAccess = NCPAPIProvider.getNoCheatPlusAPI().getMCAccess();
}
@Override

View File

@ -13,7 +13,7 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandUtil;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;

View File

@ -7,7 +7,7 @@ import java.util.Map;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.AsyncCheck;
import fr.neatmonster.nocheatplus.checks.CheckType;
@ -16,7 +16,8 @@ import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
import fr.neatmonster.nocheatplus.checks.chat.analysis.WordLetterCount;
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine;
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.logging.LogUtil;
@ -66,13 +67,14 @@ public class Text extends AsyncCheck implements INotifyReload{
private void init() {
// Set some things from the global config.
ConfigFile config = ConfigManager.getConfigFile();
final ConfigFile config = ConfigManager.getConfigFile();
final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
if (engine != null){
engine.clear();
NoCheatPlus.getAPI().removeComponent(engine);
api.removeComponent(engine);
}
engine = new LetterEngine(config);
NoCheatPlus.getAPI().addComponent(engine);
api.addComponent(engine);
}
@Override

View File

@ -39,6 +39,7 @@ import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.checks.CheckListener;
import fr.neatmonster.nocheatplus.checks.CheckType;
@ -46,10 +47,10 @@ import fr.neatmonster.nocheatplus.checks.combined.BedLeave;
import fr.neatmonster.nocheatplus.checks.combined.Combined;
import fr.neatmonster.nocheatplus.checks.combined.CombinedConfig;
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.components.IData;
import fr.neatmonster.nocheatplus.components.IHaveCheckType;
import fr.neatmonster.nocheatplus.components.INeedConfig;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.components.IRemoveData;
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
import fr.neatmonster.nocheatplus.components.TickListener;
@ -94,18 +95,6 @@ import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;
* @see MovingEvent
*/
public class MovingListener extends CheckListener implements TickListener, IRemoveData, IHaveCheckType, INotifyReload, INeedConfig, JoinLeaveListener{
/**
* Determine "some jump amplifier": 1 is jump boost, 2 is jump boost II. <br>
* NOTE: This is not the original amplifier value (use mcAccess for that).
* @param mcPlayer
* @return
*/
public static final double getJumpAmplifier(final Player player) {
final double amplifier = NoCheatPlus.getMCAccess().getJumpAmplifier(player);
if (amplifier == Double.NEGATIVE_INFINITY) return 0D;
else return 1D + amplifier;
}
/**
* Heavier check, but convenient for seldom events (not for use in the player-move check).
@ -133,7 +122,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
{
// This might get extended to a check-like thing.
boolean restored = false;
final PlayerLocation pLoc = new PlayerLocation(NoCheatPlus.getMCAccess(), null);
final PlayerLocation pLoc = new PlayerLocation(NCPAPIProvider.getNoCheatPlusAPI().getMCAccess(), null);
// (Mind that we don't set the block cache here).
final Location loc = player.getLocation();
if (!restored && data.hasSetBack()) {
@ -157,7 +146,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
pLoc.cleanup();
if (!restored && MovingConfig.getConfig(player).tempKickIllegal){
// TODO: correct the location ?
NoCheatPlus.denyLogin(player.getName(), 24L * 60L * 60L * 1000L);
NCPAPIProvider.getNoCheatPlusAPI().denyLogin(player.getName(), 24L * 60L * 60L * 1000L);
LogUtil.logSevere("[NCP] could not restore location for " + player.getName() + " deny login for 24 hours");
}
// TODO: reset the bounding box of the player ?
@ -502,7 +491,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
}
// Potion effect "Jump".
final double jumpAmplifier = MovingListener.getJumpAmplifier(player);
final double jumpAmplifier = survivalFly.getJumpAmplifier(player);
if (jumpAmplifier > data.jumpAmplifier) data.jumpAmplifier = jumpAmplifier;
// TODO: same for speed (oncemedium is introduced).

View File

@ -439,7 +439,7 @@ public class SurvivalFly extends Check {
if (data.noFallAssumeGround || fromOnGround || toOnGround) {
// Some reset condition.
data.jumpAmplifier = MovingListener.getJumpAmplifier(player);
data.jumpAmplifier = getJumpAmplifier(player);
}
// TODO: on ground -> on ground improvements
@ -802,7 +802,7 @@ public class SurvivalFly extends Check {
// data.ground ?
// ? set jumpphase to height / 0.15 ?
data.sfJumpPhase = 0;
data.jumpAmplifier = MovingListener.getJumpAmplifier(player);
data.jumpAmplifier = getJumpAmplifier(player);
data.clearAccounting();
// Tell NoFall that we assume the player to have been on ground somehow.
data.noFallAssumeGround = true;
@ -999,7 +999,7 @@ public class SurvivalFly extends Check {
double estimate = 1.15;
if (data.jumpAmplifier > 0){
// TODO: Could skip this.
estimate += 0.5 * MovingListener.getJumpAmplifier(player);
estimate += 0.5 * getJumpAmplifier(player);
}
if (setBackYDistance < estimate){
// Low jump, further check if there might have been a reason for low jumping.
@ -1145,4 +1145,17 @@ public class SurvivalFly extends Check {
else reallySneaking.remove(player.getName());
}
/**
* Determine "some jump amplifier": 1 is jump boost, 2 is jump boost II. <br>
* NOTE: This is not the original amplifier value (use mcAccess for that).
* @param mcPlayer
* @return
*/
protected final double getJumpAmplifier(final Player player) {
final double amplifier = mcAccess.getJumpAmplifier(player);
if (amplifier == Double.NEGATIVE_INFINITY) return 0D;
else return 1D + amplifier;
}
}

View File

@ -34,6 +34,7 @@ import fr.neatmonster.nocheatplus.command.admin.NCPVersionCommand;
import fr.neatmonster.nocheatplus.command.admin.ReloadCommand;
import fr.neatmonster.nocheatplus.command.admin.RemovePlayerCommand;
import fr.neatmonster.nocheatplus.command.admin.UnexemptCommand;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigManager;

View File

@ -14,7 +14,7 @@ import org.bukkit.command.SimpleCommandMap;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.logging.LogUtil;
@ -27,7 +27,7 @@ public class CommandUtil {
public static CommandMap getCommandMap(){
// TODO: compat / null
try{
return NoCheatPlus.getMCAccess().getCommandMap();
return NCPAPIProvider.getNoCheatPlusAPI().getMCAccess().getCommandMap();
}
catch(Throwable t){
LogUtil.logSevere(t);

View File

@ -1,10 +1,10 @@
package fr.neatmonster.nocheatplus.command;
/**
* Interface for a component that needs to be notified about a reload.
* @deprecated Use instead: fr.neatmonster.nocheatplus.components.INotifyReload
* @author mc_dev
*
*/
public interface INotifyReload {
public void onReload();
public interface INotifyReload extends fr.neatmonster.nocheatplus.components.INotifyReload {
}

View File

@ -5,6 +5,7 @@ import java.util.Arrays;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
@ -18,7 +19,7 @@ public class KickListCommand extends NCPCommand {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
final String[] kicked = NoCheatPlus.getLoginDeniedPlayers();
final String[] kicked = NCPAPIProvider.getNoCheatPlusAPI().getLoginDeniedPlayers();
if (kicked.length < 100) Arrays.sort(kicked);
sender.sendMessage(TAG + "Temporarily kicked players:");
sender.sendMessage(StringUtil.join(Arrays.asList(kicked), " "));

View File

@ -4,6 +4,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.DelayableCommand;
import fr.neatmonster.nocheatplus.logging.LogUtil;
@ -48,7 +49,7 @@ public class TempKickCommand extends DelayableCommand {
protected void tempKick(CommandSender sender, String name, long duration, String reason){
Player player = DataManager.getPlayer(name);
NoCheatPlus.denyLogin(name, duration);
NCPAPIProvider.getNoCheatPlusAPI().denyLogin(name, duration);
if (player == null) return;
player.kickPlayer(reason);
LogUtil.logInfo("[NoCheatPlus] (" + sender.getName() + ") Kicked " + player.getName() + " for " + duration/60000 +" minutes: " + reason);

View File

@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.command.actions;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.permissions.Permissions;
@ -18,9 +19,9 @@ public class UnKickCommand extends NCPCommand {
String label, String[] args) {
if (args.length != 2) return false;
if (args[1].trim().equals("*")){
sender.sendMessage(TAG + "Removed " + NoCheatPlus.allowLoginAll() + " players from the 'deny-login' list.");
sender.sendMessage(TAG + "Removed " + NCPAPIProvider.getNoCheatPlusAPI().allowLoginAll() + " players from the 'deny-login' list.");
}
else if (NoCheatPlus.allowLogin(args[1])){
else if (NCPAPIProvider.getNoCheatPlusAPI().allowLogin(args[1])){
sender.sendMessage(TAG + "Allow to login again: " + args[1].trim());
}
else{

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.compat.MCAccess;
@ -18,7 +19,7 @@ public class NCPVersionCommand extends NCPCommand{
@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
MCAccess mc = NoCheatPlus.getMCAccess();
final MCAccess mc = NCPAPIProvider.getNoCheatPlusAPI().getMCAccess();
sender.sendMessage(new String[]{
"---- Version information ----",
"#### Server ####",

View File

@ -11,8 +11,8 @@ import org.bukkit.command.ConsoleCommandSender;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.command.CommandHandler.NCPReloadEvent;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.command.NCPCommand;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;
import fr.neatmonster.nocheatplus.config.ConfigManager;

View File

@ -109,7 +109,7 @@ public class MCAccessFactory {
};
}
// Try to set up api-only access (ca. 1.4.7).
// Try to set up api-only access (since 1.4.6).
try{
final String msg;
if (bukkitOnly){

View File

@ -1,25 +0,0 @@
package fr.neatmonster.nocheatplus.components;
/**
* ComponentRegistry:
* <li>Supported components: Listener, TickListener, PermStateReceiver, INotifyReload, INeedConfig, IRemoveData, MCAccessHolder, ConsistencyChecker, JoinLeaveListener</li>
* <li>ComponentRegistry instances will be registered as sub registries unless you use the addComponent(Object, boolean) method appropriately. </li>
* <li>IHoldSubComponents instances will be registered in the next tick (scheduled task), those added within onEnable will get registered after looping in onEnable.</li>
* <li>Registering components should be done during onEnable or any time while the plugin is enabled, all components will be unregistered in onDisable.</li>
* <li>References to all components will be held until onDisable is finished.</li>
* <li>Interfaces checked for managed listeners: IHaveMethodOrder (method), ComponentWithName (tag)</li>
* @author mc_dev
*
*/
public interface NoCheatPlusAPI extends ComponentRegistry<Object>, ComponentRegistryProvider{
/**
* By default addComponent(Object) will register ComponentFactories as well.
* @param obj
* @param allowComponentRegistry If to allow registering ComponentFactories.
* @return
*/
public boolean addComponent(Object obj, boolean allowComponentRegistry);
}

View File

@ -33,12 +33,12 @@ import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
import fr.neatmonster.nocheatplus.checks.fight.FightConfig;
import fr.neatmonster.nocheatplus.checks.inventory.InventoryConfig;
import fr.neatmonster.nocheatplus.checks.moving.MovingConfig;
import fr.neatmonster.nocheatplus.command.INotifyReload;
import fr.neatmonster.nocheatplus.components.ComponentRegistry;
import fr.neatmonster.nocheatplus.components.ComponentWithName;
import fr.neatmonster.nocheatplus.components.ConsistencyChecker;
import fr.neatmonster.nocheatplus.components.IHaveCheckType;
import fr.neatmonster.nocheatplus.components.INeedConfig;
import fr.neatmonster.nocheatplus.components.INotifyReload;
import fr.neatmonster.nocheatplus.components.IRemoveData;
import fr.neatmonster.nocheatplus.config.ConfPaths;
import fr.neatmonster.nocheatplus.config.ConfigFile;

View File

@ -9,8 +9,8 @@ import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import fr.neatmonster.nocheatplus.NoCheatPlus;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.ViolationData;
import fr.neatmonster.nocheatplus.checks.access.ICheckData;
@ -380,7 +380,7 @@ public class TickTask implements Runnable {
// Public methods for internal use.
////////////////////////////////////////
public static int start(final NoCheatPlus plugin){
public static int start(final Plugin plugin){
cancel();
taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new TickTask(), 1, 1);
if (taskId != -1) timeStart = System.currentTimeMillis();

View File

@ -17,6 +17,7 @@
<module>NCPBuildBase</module>
<module>NCPCommons</module>
<module>NCPCompat</module>
<module>NCPCore</module>
<module>NCPCompatBukkit</module>
<module>NCPCompatCB2511</module>
<module>NCPCompatCB2512</module>