mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-05 03:31:09 +02:00
Add WorldConfigProvider for future purpose.
This commit is contained in:
parent
0dc16d6a27
commit
a3656b92d9
|
@ -1,5 +1,7 @@
|
|||
package fr.neatmonster.nocheatplus.compat;
|
||||
|
||||
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||
|
||||
/**
|
||||
* Provide a setup method for additional BlockProperties initialization.<br>
|
||||
* Typically MCAccess can implement it. TODO: An extra factory for Bukkit level.
|
||||
|
@ -9,6 +11,7 @@ package fr.neatmonster.nocheatplus.compat;
|
|||
public interface BlockPropertiesSetup {
|
||||
/**
|
||||
* Additional initialization.
|
||||
* @param worldConfigProvider Configuration provider if needed.
|
||||
*/
|
||||
public void setupBlockProperties();
|
||||
public void setupBlockProperties(WorldConfigProvider<?> worldConfigProvider);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.bukkit.potion.PotionEffectType;
|
|||
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
|
||||
import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup;
|
||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.PotionUtil;
|
||||
|
@ -154,7 +155,7 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setupBlockProperties() {
|
||||
public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvider) {
|
||||
// TODO Set some generic properties matching what BlockCache.getShape returns.
|
||||
for (Material mat : Material.values()){
|
||||
if (!mat.isBlock()) continue;
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package fr.neatmonster.nocheatplus.config;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* This is to bridge the gap between ConfigFile which needs Action and RawConfigFile which has to be available in NCPCompat. <br>
|
||||
* Aim is not speed of execution but providing a way of accessing all configs to set properties from within compatibility modules.
|
||||
* <br>
|
||||
* This might be seen as a refactoring/structuring stage, leading to putting actions to NCPCompat as well.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public interface WorldConfigProvider <C extends RawConfigFile>{
|
||||
|
||||
/**
|
||||
* Get the default configuration.
|
||||
* @return
|
||||
*/
|
||||
public C getDefaultConfig();
|
||||
|
||||
/**
|
||||
* Get the world configuration.
|
||||
* @param worldName The default config has null as world. The default config is returned, if the world is not known.
|
||||
* @return
|
||||
*/
|
||||
public C getConfig(String worldName);
|
||||
|
||||
/**
|
||||
* Get a Collection-view of all worlds config files, including the default configuration.
|
||||
* @return
|
||||
*/
|
||||
public Collection<C> getAllConfigs();
|
||||
|
||||
// TODO: Add operations for all configs, like setForAllConfigs, get(Max|min)NumberForAllConfigs, ....
|
||||
}
|
|
@ -19,6 +19,7 @@ import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup;
|
|||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||
import fr.neatmonster.nocheatplus.config.RawConfigFile;
|
||||
import fr.neatmonster.nocheatplus.config.RootConfPaths;
|
||||
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
||||
|
||||
/**
|
||||
|
@ -281,14 +282,14 @@ public class BlockProperties {
|
|||
/** Penalty factor for block break duration if not on ground. */
|
||||
protected static float breakPenaltyOffGround = 4f;
|
||||
|
||||
public static void init(final MCAccess mcAccess) {
|
||||
public static void init(final MCAccess mcAccess, final WorldConfigProvider<?> worldConfigProvider) {
|
||||
blockCache = mcAccess.getBlockCache(null);
|
||||
pLoc = new PlayerLocation(mcAccess, null);
|
||||
try{
|
||||
initTools(mcAccess);
|
||||
initBlocks(mcAccess);
|
||||
initTools(mcAccess, worldConfigProvider);
|
||||
initBlocks(mcAccess, worldConfigProvider);
|
||||
if (mcAccess instanceof BlockPropertiesSetup){
|
||||
((BlockPropertiesSetup) mcAccess).setupBlockProperties();
|
||||
((BlockPropertiesSetup) mcAccess).setupBlockProperties(worldConfigProvider);
|
||||
}
|
||||
}
|
||||
catch(Throwable t){
|
||||
|
@ -296,7 +297,7 @@ public class BlockProperties {
|
|||
}
|
||||
}
|
||||
|
||||
private static void initTools(final MCAccess mcAccess) {
|
||||
private static void initTools(final MCAccess mcAccess, final WorldConfigProvider<?> worldConfigProvider) {
|
||||
tools.clear();
|
||||
tools.put(268, new ToolProps(ToolType.SWORD, MaterialBase.WOOD));
|
||||
tools.put(269, new ToolProps(ToolType.SPADE, MaterialBase.WOOD));
|
||||
|
@ -326,7 +327,7 @@ public class BlockProperties {
|
|||
tools.put(359, new ToolProps(ToolType.SHEARS, MaterialBase.NONE));
|
||||
}
|
||||
|
||||
private static void initBlocks(final MCAccess mcAccess) {
|
||||
private static void initBlocks(final MCAccess mcAccess, final WorldConfigProvider<?> worldConfigProvider) {
|
||||
Arrays.fill(blocks, null);
|
||||
///////////////////////////
|
||||
// Initalize block flags
|
||||
|
|
|
@ -650,7 +650,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
|
|||
*/
|
||||
protected void initBlockProperties(ConfigFile config){
|
||||
// Set up BlockProperties.
|
||||
BlockProperties.init(getMCAccess());
|
||||
BlockProperties.init(getMCAccess(), ConfigManager.getWorldConfigProvider());
|
||||
BlockProperties.applyConfig(config, ConfPaths.COMPATIBILITY_BLOCKS);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package fr.neatmonster.nocheatplus.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -26,9 +27,6 @@ import fr.neatmonster.nocheatplus.logging.LogUtil;
|
|||
* The synchronized methods are to ensure that changing the configurations won't lead to trouble for the asynchronous checks.
|
||||
*/
|
||||
public class ConfigManager {
|
||||
|
||||
/** The map containing the configuration files per world. */
|
||||
private static final Map<String, ConfigFile> worldsMap = new HashMap<String, ConfigFile>();
|
||||
|
||||
public static interface ActionFactoryFactory{
|
||||
public ActionFactory newActionFactory(Map<String, Object> library);
|
||||
|
@ -41,6 +39,28 @@ public class ConfigManager {
|
|||
}
|
||||
};
|
||||
|
||||
/** The map containing the configuration files per world. */
|
||||
private static final Map<String, ConfigFile> worldsMap = new HashMap<String, ConfigFile>();
|
||||
|
||||
private static final WorldConfigProvider<ConfigFile> worldConfigProvider = new WorldConfigProvider<ConfigFile>() {
|
||||
|
||||
@Override
|
||||
public ConfigFile getDefaultConfig() {
|
||||
return ConfigManager.getConfigFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFile getConfig(String worldName) {
|
||||
return ConfigManager.getConfigFile(worldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ConfigFile> getAllConfigs() {
|
||||
return ConfigManager.worldsMap.values();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Factory method.
|
||||
* @param library
|
||||
|
@ -70,6 +90,14 @@ public class ConfigManager {
|
|||
public static ActionFactoryFactory getActionFactoryFactory(){
|
||||
return actionFactoryFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the WorldConfigProvider in use.
|
||||
* @return
|
||||
*/
|
||||
public static WorldConfigProvider<ConfigFile> getWorldConfigProvider() {
|
||||
return worldConfigProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleanup.
|
||||
|
|
Loading…
Reference in New Issue
Block a user