From 4b345cf8802db2596dcafbdbe23329a2db627a14 Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 1 Oct 2013 15:57:04 +0200 Subject: [PATCH] Use of reworked Module-System. Dependend submodules --- .../minecraft/limitedcreative/Config.java | 14 +--- .../limitedcreative/DependencyListener.java | 9 +-- .../FeatureBlockItemSpawn.java | 4 +- .../limitedcreative/LimitedCreative.java | 3 + .../limitedcreative/ModBlockStates.java | 14 ++-- .../limitedcreative/ModCreativeLimits.java | 15 +--- .../limitedcreative/ModGameModePerm.java | 5 +- .../limitedcreative/ModInventories.java | 7 +- .../minecraft/limitedcreative/ModRegions.java | 7 +- .../blockstate/AbstractModel.java | 33 ++++++--- .../blockstate/BlockStateConfig.java | 13 +--- .../blockstate/SyncronizedModel.java | 8 +-- .../blockstate/ThreadedModel.java | 68 ++++++++++++------- .../thread/UpdateBlockStateAction.java | 14 ++-- .../cmdblocker/CmdBlockerConfig.java | 11 +-- .../limitedcreative/gmperm/GMPermConfig.java | 11 +-- .../inventories/InventoryConfig.java | 12 +--- .../limitedcreative/limits/LimitConfig.java | 11 +-- .../limitedcreative/regions/RegionConfig.java | 11 +-- 19 files changed, 115 insertions(+), 155 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java index d62e9ab..ea72555 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/Config.java @@ -12,7 +12,6 @@ import de.jaschastarke.maven.ArchiveDocComments; import de.jaschastarke.maven.PluginConfigurations; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * Limited Creative - Configuration @@ -36,14 +35,13 @@ public class Config extends PluginConfiguration { public void setValues(ConfigurationSection sect) { super.setValues(sect); - if (plugin.getModules().size() > 0) + if (plugin.getModules().count() > 0) setModuleStates(); } public void setModuleStates() { ModuleEntry metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry(); - if (metricsEntry.initialState != ModuleState.NOT_INITIALIZED) - metricsEntry.initialState = getMetrics() ? ModuleState.ENABLED : ModuleState.DISABLED; + metricsEntry.setEnabled(getMetrics()); } @Override @@ -51,13 +49,7 @@ public class Config extends PluginConfiguration { super.setValue(node, pValue); if (node.getName().equals("metrics")) { - ModuleEntry metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry(); - if (getMetrics()) { - if (metricsEntry.initialState != ModuleState.NOT_INITIALIZED) - metricsEntry.enable(); - } else { - metricsEntry.disable(); - } + setModuleStates(); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java index 3ab35e9..b16265c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/DependencyListener.java @@ -24,8 +24,7 @@ public class DependencyListener implements Listener { String incomp = Hooks.InventoryIncompatible.test(); if (incomp != null) { mod.getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, mod.getName())); - mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; - mod.getModuleEntry().disable(); + mod.getModuleEntry().deactivateUsage(); } } } @@ -36,15 +35,13 @@ public class DependencyListener implements Listener { ModGameModePerm mod = plugin.getModule(ModGameModePerm.class); if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { mod.getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", mod.getName())); - mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; - mod.getModuleEntry().disable(); + mod.getModuleEntry().deactivateUsage(); } } else if (event.getPlugin().getName().equals("WorldGuard")) { ModRegions mod = plugin.getModule(ModRegions.class); if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { mod.getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", mod.getName())); - mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; - mod.getModuleEntry().disable(); + mod.getModuleEntry().deactivateUsage(); } } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java index 6ce6a97..79f2039 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/FeatureBlockItemSpawn.java @@ -97,10 +97,8 @@ public class FeatureBlockItemSpawn extends CoreModule implement scheduleCleanUp(); } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onItemSpawn(ItemSpawnEvent event) { - if (event.isCancelled()) - return; if (event.getEntity() instanceof Item) { if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) { event.setCancelled(true); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java index 3b1471e..8480faa 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/LimitedCreative.java @@ -4,6 +4,7 @@ import de.jaschastarke.I18n; import de.jaschastarke.bukkit.lib.Core; import de.jaschastarke.bukkit.lib.PluginLang; import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand; +import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks; import de.jaschastarke.utils.ClassDescriptorStorage; public class LimitedCreative extends Core { @@ -25,6 +26,8 @@ public class LimitedCreative extends Core { Hooks.inizializeHooks(this); + modules.addSharedModule(new AdditionalBlockBreaks(this)); + modules.addSharedModule(new FeatureBlockItemSpawn(this)); addModule(new FeatureSwitchGameMode(this)); addModule(new ModInventories(this)); addModule(new ModCreativeLimits(this)); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java index cedb08b..f47c21e 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModBlockStates.java @@ -18,7 +18,6 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; public class ModBlockStates extends CoreModule { private BlockStateConfig config; @@ -38,17 +37,12 @@ public class ModBlockStates extends CoreModule { public void initialize(ModuleEntry entry) { super.initialize(entry); - blockDrops = plugin.getModule(FeatureBlockItemSpawn.class); - if (blockDrops == null) - blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule(); - config = new BlockStateConfig(this, entry); plugin.getPluginConfig().registerSection(config); - if (plugin.getModule(AdditionalBlockBreaks.class) == null) { - plugin.addModule(new AdditionalBlockBreaks(plugin)); - } - addModule(new BlockFall(plugin)); + blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules()); + modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules()); + this.addModule(new BlockFall(plugin)); listeners.addListener(new BlockListener(this)); listeners.addListener(new HangingListener(this)); @@ -72,7 +66,7 @@ public class ModBlockStates extends CoreModule { } catch (Exception e) { e.printStackTrace(); getLog().warn(plugin.getLocale().trans("block_state.error.sql_connection_failed", getName())); - entry.initialState = ModuleState.NOT_INITIALIZED; + entry.deactivateUsage(); return; } super.onEnable(); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java index d0918cf..61b4c3a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModCreativeLimits.java @@ -12,7 +12,6 @@ import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig; import de.jaschastarke.minecraft.limitedcreative.limits.PlayerListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; public class ModCreativeLimits extends CoreModule { protected LimitConfig config; @@ -37,18 +36,8 @@ public class ModCreativeLimits extends CoreModule { listeners.addListener(new BlockListener(this)); config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry)); - blockDrops = plugin.getModule(FeatureBlockItemSpawn.class); - if (blockDrops == null) - blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule(); - - if (plugin.getModule(AdditionalBlockBreaks.class) == null) { - plugin.addModule(new AdditionalBlockBreaks(plugin)); - } - - if (!config.getEnabled()) { - entry.initialState = ModuleState.DISABLED; - return; - } + blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules()); + modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules()); } public FeatureBlockItemSpawn getBlockSpawn() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java index feb7e3b..f163d6c 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java @@ -6,7 +6,6 @@ import de.jaschastarke.minecraft.limitedcreative.gmperm.PermissionInterface; import de.jaschastarke.minecraft.limitedcreative.gmperm.PlayerListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; public class ModGameModePerm extends CoreModule { private GMPermConfig config; @@ -30,7 +29,7 @@ public class ModGameModePerm extends CoreModule { if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) { if (config.getEnabled()) getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName())); - entry.initialState = ModuleState.NOT_INITIALIZED; + entry.deactivateUsage(); return; } @@ -39,7 +38,7 @@ public class ModGameModePerm extends CoreModule { if (config.getEnabled()) { if (!permission.isPresent()) { getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName())); - entry.initialState = ModuleState.NOT_INITIALIZED; + entry.deactivateUsage(); return; } /*else if (!getVaultPermission().hasGroupSupport()) { getLog().warn(plugin.getLocale().trans("gmperm.warning.no_group_support", getName())); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java index 2858e08..1b968ef 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModInventories.java @@ -19,7 +19,6 @@ import de.jaschastarke.minecraft.limitedcreative.inventories.store.InvYamlStorag import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; public class ModInventories extends CoreModule { protected PlayerInventoryStorage storage; @@ -42,17 +41,13 @@ public class ModInventories extends CoreModule { config = plugin.getPluginConfig().registerSection(new InventoryConfig(this, entry)); armor_config = config.registerSection(new ArmoryConfig(this)); - if (!config.getEnabled()) { - entry.initialState = ModuleState.DISABLED; - return; - } if (plugin.getServer().getPluginManager().isPluginEnabled("AuthMe")) { addModule(new AuthMeInventories(plugin, this)); } String incomp = Hooks.InventoryIncompatible.test(); if (config.getEnabled() && incomp != null) { getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName())); - entry.initialState = ModuleState.NOT_INITIALIZED; + entry.deactivateUsage(); } } @Override diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java index a6345e2..4ebffc9 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java @@ -18,7 +18,6 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegion import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.PlayerRegionListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; public class ModRegions extends CoreModule { private CustomRegionManager mgr; @@ -40,16 +39,14 @@ public class ModRegions extends CoreModule { public void initialize(ModuleEntry pEntry) { super.initialize(pEntry); - blockDrops = plugin.getModule(FeatureBlockItemSpawn.class); - if (blockDrops == null) - blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule(); + blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules()); config = plugin.getPluginConfig().registerSection(new RegionConfig(this, entry)); if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { if (config.getEnabled()) getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName())); - entry.initialState = ModuleState.NOT_INITIALIZED; + entry.deactivateUsage(); return; } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/AbstractModel.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/AbstractModel.java index 432d75a..83ebee8 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/AbstractModel.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/AbstractModel.java @@ -20,7 +20,7 @@ public abstract class AbstractModel { protected void moveMetaState(Block from, Block to) { HasBlockState metaBlock = getMetaBlock(from); - if (metaBlock.set && metaBlock.state != null) { + if (metaBlock.isSet() && metaBlock.getState() != null) { BlockState state = metaBlock.state; state.setLocation(to.getLocation()); setMetaBlock(to, state); @@ -45,28 +45,43 @@ public abstract class AbstractModel { m.setMetadata(BSMDKEY, new FixedMetadataValue(plugin, s)); } protected HasBlockState getMetaBlock(Metadatable m) { - HasBlockState has = new HasBlockState(); + HasBlockState has = null; List metadata = m.getMetadata(BSMDKEY); for (MetadataValue v : metadata) { if (v.value() instanceof BlockState) { - has.set = true; - has.state = (BlockState) v.value(); + has = new HasBlockState((BlockState) v.value()); break; } else if (v == metadataNull) { - has.set = true; - has.state = null; + // Metadata Knows, that there is no entry in DB + has = new HasBlockState(true); break; } } - return has; + if (has == null) + return new HasBlockState(false); + else + return has; } protected void removeMetaBlock(Metadatable m) { m.removeMetadata(BSMDKEY, plugin); } public static class HasBlockState { - public boolean set = false; - public BlockState state = null; + private boolean set = false; + private BlockState state = null; + public HasBlockState(BlockState state) { + set = true; + this.state = state; + } + public HasBlockState(boolean isSet) { + set = isSet; + } + public boolean isSet() { + return set; + } + public BlockState getState() { + return state; + } } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java index b56d7cc..dda499f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/BlockStateConfig.java @@ -16,7 +16,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config; import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * BlockState-Feature @@ -45,14 +44,9 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub else super.setValue(node, pValue); if (node.getName().equals("enabled")) { - if (getEnabled()) { - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.enable(); - } else { - entry.disable(); - } + entry.setEnabled(getEnabled()); } else if (node.getName().equals("useThreading")) { - if (entry.getState() == ModuleState.ENABLED) { + if (entry.isEnabled()) { entry.disable(); entry.enable(); } @@ -62,8 +56,7 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED; + entry.setEnabled(getEnabled()); } @Override public String getName() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/SyncronizedModel.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/SyncronizedModel.java index 3d3a498..7a5633f 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/SyncronizedModel.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/SyncronizedModel.java @@ -71,8 +71,8 @@ public class SyncronizedModel extends AbstractModel implements DBModel { Cuboid c = new Cuboid(); for (Block block : blocks) { HasBlockState has = getMetaBlock(block); - if (has.set) { - ret.put(block, has.state); + if (has.isSet()) { + ret.put(block, has.getState()); } else { c.add(block.getLocation()); } @@ -120,7 +120,7 @@ public class SyncronizedModel extends AbstractModel implements DBModel { public BlockState getState(Block block) { HasBlockState has = getMetaBlock(block); - if (!has.set) { + if (!has.isSet()) { try { BlockState state = q.find(block.getLocation()); setMetaBlock(block, state); @@ -131,7 +131,7 @@ public class SyncronizedModel extends AbstractModel implements DBModel { return null; } } - return has.state; + return has.getState(); } public void setState(BlockState state) { Block block = state.getLocation().getBlock(); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java index b94484d..3025b8b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/ThreadedModel.java @@ -91,7 +91,7 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { Map ret = new HashMap(); for (Block block : blocks) { HasBlockState has = getMetaBlock(block); - ret.put(block, has.restricted); + ret.put(block, has.isRestricted()); } return ret; } @@ -104,8 +104,8 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { c = new Cuboid(); for (Block block : blocks) { HasBlockState has = getMetaBlock(block); - if (has.set) { - ret.put(block, has.state); + if (has.getState() != null || has.isNull()) { + ret.put(block, has.getState()); } else { c.add(block.getLocation()); ret.put(block, null); @@ -125,14 +125,17 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { @Override public BlockState getState(Block block) { HasBlockState has = getMetaBlock(block); - if (!has.set || (has.dbSet && has.state == null)) { + if (has.getState() == null && !has.isNull()) { + // The DB-Entry isn't set + // and the entry doesn't tell us that it knows that it isn't set + // (while using the threaded model, even having no Metadata entry, tells us there is no one in DB) return threads.callUpdate(block); } - return has.state; + return has.getState(); } @Override public boolean isRestricted(Block block) { - return getMetaBlock(block).restricted; + return getMetaBlock(block).isRestricted(); } @Override @@ -201,37 +204,56 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener { block.setMetadata(BSMDKEY, metadataSet); } protected HasBlockState getMetaBlock(Metadatable m) { - HasBlockState has = new HasBlockState(); + HasBlockState has = null; List metadata = m.getMetadata(BSMDKEY); for (MetadataValue v : metadata) { if (v.value() instanceof BlockState) { - has.set = true; - has.state = (BlockState) v.value(); - has.dbSet = true; - has.restricted = has.state.isRestricted(); + // The actual DB-entry is in Metadata (requires more memory) + has = new HasBlockState((BlockState) v.value()); break; } else if (v.getOwningPlugin() == mod.getPlugin()) { if (v == metadataNull) { - has.set = true; - has.state = null; + // Metadata knows, that there is no entry in DB + has = new HasBlockState(true); + break; } else if (v == metadataSet) { - has.set = true; - has.state = null; - has.dbSet = true; + // Metadata knows, that there is survival-entry in DB + has = new HasBlockState(true, false); + break; } else if (v == metadataSetRestricted) { - has.set = true; - has.state = null; - has.dbSet = true; - has.restricted = true; + // Metadata knows, that there is creative-entry in DB + has = new HasBlockState(true, true); } break; } } - return has; + if (has == null) + return new HasBlockState(false); + else + return has; } public static class HasBlockState extends AbstractModel.HasBlockState { - public boolean dbSet = false; - public boolean restricted = false; + private boolean restricted = false; + private boolean isNull = false; + + public HasBlockState(BlockState state) { + super(state); + restricted = state.isRestricted(); + } + public HasBlockState(boolean isSet) { + super(isSet); + isNull = true; + } + public HasBlockState(boolean isSet, boolean isRestricted) { + super(isSet); + restricted = isRestricted; + } + public boolean isRestricted() { + return restricted; + } + public boolean isNull() { + return isNull; + } } public ModBlockStates getModel() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/UpdateBlockStateAction.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/UpdateBlockStateAction.java index 9c16172..541daea 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/UpdateBlockStateAction.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/UpdateBlockStateAction.java @@ -16,14 +16,14 @@ public class UpdateBlockStateAction extends TransactionAction implements Action @Override public void process(ThreadLink link, DBQueries q) { HasBlockState state = link.getMetaState(block); - if (state.set) { + if (state.isSet()) { try { q.delete(block.getLocation()); - if (state.state != null) - q.insert(state.state); + if (state.getState() != null) + q.insert(state.getState()); } catch (SQLException e) { link.getLog().severe(e.getMessage()); - link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to save BlockState to DB: " + state.state); + link.getLog().warn("Thread " + Thread.currentThread().getName() + " failed to save BlockState to DB: " + state.getState()); } } } @@ -31,10 +31,10 @@ public class UpdateBlockStateAction extends TransactionAction implements Action @Override public void processInTransaction(ThreadLink link, DBQueries q) throws SQLException { HasBlockState state = link.getMetaState(block); - if (state.set) { + if (state.isSet()) { q.delete(block.getLocation()); - if (state.state != null) - q.insert(state.state); + if (state.getState() != null) + q.insert(state.getState()); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java index 4c98810..0220fa3 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/cmdblocker/CmdBlockerConfig.java @@ -14,7 +14,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config; import de.jaschastarke.minecraft.limitedcreative.ModCmdBlocker; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * CommandBlocker-Feature @@ -39,20 +38,14 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED; + entry.setEnabled(getEnabled()); } @Override public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { super.setValue(node, pValue); if (node.getName().equals("enabled")) { - if (getEnabled()) { - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.enable(); - } else { - entry.disable(); - } + entry.setEnabled(getEnabled()); } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java index 1637818..4f4f221 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/GMPermConfig.java @@ -14,7 +14,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config; import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * GameMode-Permissions-Feature @@ -42,20 +41,14 @@ public class GMPermConfig extends Configuration implements IConfigurationSubGrou public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { super.setValue(node, pValue); if (node.getName().equals("enabled")) { - if (getEnabled()) { - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.enable(); - } else { - entry.disable(); - } + entry.setEnabled(getEnabled()); } } @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED; + entry.setEnabled(getEnabled()); } @Override public String getName() { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java index ec6ab59..f6fba61 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/inventories/InventoryConfig.java @@ -14,7 +14,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config; import de.jaschastarke.minecraft.limitedcreative.ModInventories; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * Inventory-Feature @@ -40,12 +39,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { super.setValue(node, pValue); if (node.getName().equals("enabled")) { - if (getEnabled()) { - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.enable(); - } else { - entry.disable(); - } + entry.setEnabled(getEnabled()); } } @@ -59,8 +53,8 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG } super.setValues(sect); - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED; + entry.setEnabled(getEnabled()); + // Config Upgrade if (!sect.contains("storeCreative") && sect.contains("creative")) sect.set("storeCreative", sect.getBoolean("creative")); diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java index 985f269..989c47b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/limits/LimitConfig.java @@ -17,7 +17,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config; import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * Creative Limits-Feature @@ -44,20 +43,14 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup if (!(pValue instanceof BlackList)) super.setValue(node, pValue); if (node.getName().equals("enabled")) { - if (getEnabled()) { - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.enable(); - } else { - entry.disable(); - } + entry.setEnabled(getEnabled()); } } @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED; + entry.setEnabled(getEnabled()); // Config Upgrade if (!sect.contains("interact") && sect.contains("sign")) { diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java index 03fa1cd..b0dcd72 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/regions/RegionConfig.java @@ -15,7 +15,6 @@ import de.jaschastarke.minecraft.limitedcreative.ModRegions; import de.jaschastarke.minecraft.limitedcreative.limits.BlackList; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; -import de.jaschastarke.modularize.ModuleEntry.ModuleState; /** * Region GameModes-Feature @@ -42,19 +41,13 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou if (!(pValue instanceof BlackList)) super.setValue(node, pValue); if (node.getName().equals("enabled")) { - if (getEnabled()) { - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.enable(); - } else { - entry.disable(); - } + entry.setEnabled(getEnabled()); } } @Override public void setValues(ConfigurationSection sect) { super.setValues(sect); - if (entry.initialState != ModuleState.NOT_INITIALIZED) - entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED; + entry.setEnabled(getEnabled()); // Config Upgrade if (!sect.contains("rememberOptional") && sect.contains("remember"))