mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-18 18:01:17 +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;
|
package fr.neatmonster.nocheatplus.compat;
|
||||||
|
|
||||||
|
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a setup method for additional BlockProperties initialization.<br>
|
* Provide a setup method for additional BlockProperties initialization.<br>
|
||||||
* Typically MCAccess can implement it. TODO: An extra factory for Bukkit level.
|
* Typically MCAccess can implement it. TODO: An extra factory for Bukkit level.
|
||||||
@ -9,6 +11,7 @@ package fr.neatmonster.nocheatplus.compat;
|
|||||||
public interface BlockPropertiesSetup {
|
public interface BlockPropertiesSetup {
|
||||||
/**
|
/**
|
||||||
* Additional initialization.
|
* 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.AlmostBoolean;
|
||||||
import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup;
|
import fr.neatmonster.nocheatplus.compat.BlockPropertiesSetup;
|
||||||
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
import fr.neatmonster.nocheatplus.compat.MCAccess;
|
||||||
|
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
import fr.neatmonster.nocheatplus.utilities.BlockCache;
|
||||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||||
import fr.neatmonster.nocheatplus.utilities.PotionUtil;
|
import fr.neatmonster.nocheatplus.utilities.PotionUtil;
|
||||||
@ -154,7 +155,7 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupBlockProperties() {
|
public void setupBlockProperties(final WorldConfigProvider<?> worldConfigProvider) {
|
||||||
// TODO Set some generic properties matching what BlockCache.getShape returns.
|
// TODO Set some generic properties matching what BlockCache.getShape returns.
|
||||||
for (Material mat : Material.values()){
|
for (Material mat : Material.values()){
|
||||||
if (!mat.isBlock()) continue;
|
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.compat.MCAccess;
|
||||||
import fr.neatmonster.nocheatplus.config.RawConfigFile;
|
import fr.neatmonster.nocheatplus.config.RawConfigFile;
|
||||||
import fr.neatmonster.nocheatplus.config.RootConfPaths;
|
import fr.neatmonster.nocheatplus.config.RootConfPaths;
|
||||||
|
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
|
||||||
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -281,14 +282,14 @@ public class BlockProperties {
|
|||||||
/** Penalty factor for block break duration if not on ground. */
|
/** Penalty factor for block break duration if not on ground. */
|
||||||
protected static float breakPenaltyOffGround = 4f;
|
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);
|
blockCache = mcAccess.getBlockCache(null);
|
||||||
pLoc = new PlayerLocation(mcAccess, null);
|
pLoc = new PlayerLocation(mcAccess, null);
|
||||||
try{
|
try{
|
||||||
initTools(mcAccess);
|
initTools(mcAccess, worldConfigProvider);
|
||||||
initBlocks(mcAccess);
|
initBlocks(mcAccess, worldConfigProvider);
|
||||||
if (mcAccess instanceof BlockPropertiesSetup){
|
if (mcAccess instanceof BlockPropertiesSetup){
|
||||||
((BlockPropertiesSetup) mcAccess).setupBlockProperties();
|
((BlockPropertiesSetup) mcAccess).setupBlockProperties(worldConfigProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(Throwable t){
|
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.clear();
|
||||||
tools.put(268, new ToolProps(ToolType.SWORD, MaterialBase.WOOD));
|
tools.put(268, new ToolProps(ToolType.SWORD, MaterialBase.WOOD));
|
||||||
tools.put(269, new ToolProps(ToolType.SPADE, 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));
|
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);
|
Arrays.fill(blocks, null);
|
||||||
///////////////////////////
|
///////////////////////////
|
||||||
// Initalize block flags
|
// Initalize block flags
|
||||||
|
@ -650,7 +650,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI {
|
|||||||
*/
|
*/
|
||||||
protected void initBlockProperties(ConfigFile config){
|
protected void initBlockProperties(ConfigFile config){
|
||||||
// Set up BlockProperties.
|
// Set up BlockProperties.
|
||||||
BlockProperties.init(getMCAccess());
|
BlockProperties.init(getMCAccess(), ConfigManager.getWorldConfigProvider());
|
||||||
BlockProperties.applyConfig(config, ConfPaths.COMPATIBILITY_BLOCKS);
|
BlockProperties.applyConfig(config, ConfPaths.COMPATIBILITY_BLOCKS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package fr.neatmonster.nocheatplus.config;
|
package fr.neatmonster.nocheatplus.config;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -27,9 +28,6 @@ import fr.neatmonster.nocheatplus.logging.LogUtil;
|
|||||||
*/
|
*/
|
||||||
public class ConfigManager {
|
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 static interface ActionFactoryFactory{
|
||||||
public ActionFactory newActionFactory(Map<String, Object> library);
|
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.
|
* Factory method.
|
||||||
* @param library
|
* @param library
|
||||||
@ -71,6 +91,14 @@ public class ConfigManager {
|
|||||||
return actionFactoryFactory;
|
return actionFactoryFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the WorldConfigProvider in use.
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static WorldConfigProvider<ConfigFile> getWorldConfigProvider() {
|
||||||
|
return worldConfigProvider;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleanup.
|
* Cleanup.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user