Use of reworked Module-System. Dependend submodules

This commit is contained in:
Jascha Starke 2013-10-01 15:57:04 +02:00
parent 9061e18db9
commit 4b345cf880
19 changed files with 115 additions and 155 deletions

View file

@ -12,7 +12,6 @@ import de.jaschastarke.maven.ArchiveDocComments;
import de.jaschastarke.maven.PluginConfigurations; import de.jaschastarke.maven.PluginConfigurations;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* Limited Creative - Configuration * Limited Creative - Configuration
@ -36,14 +35,13 @@ public class Config extends PluginConfiguration {
public void setValues(ConfigurationSection sect) { public void setValues(ConfigurationSection sect) {
super.setValues(sect); super.setValues(sect);
if (plugin.getModules().size() > 0) if (plugin.getModules().count() > 0)
setModuleStates(); setModuleStates();
} }
public void setModuleStates() { public void setModuleStates() {
ModuleEntry<IModule> metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry(); ModuleEntry<IModule> metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry();
if (metricsEntry.initialState != ModuleState.NOT_INITIALIZED) metricsEntry.setEnabled(getMetrics());
metricsEntry.initialState = getMetrics() ? ModuleState.ENABLED : ModuleState.DISABLED;
} }
@Override @Override
@ -51,13 +49,7 @@ public class Config extends PluginConfiguration {
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("metrics")) { if (node.getName().equals("metrics")) {
ModuleEntry<IModule> metricsEntry = plugin.getModule(FeatureMetrics.class).getModuleEntry(); setModuleStates();
if (getMetrics()) {
if (metricsEntry.initialState != ModuleState.NOT_INITIALIZED)
metricsEntry.enable();
} else {
metricsEntry.disable();
}
} }
} }

View file

@ -24,8 +24,7 @@ public class DependencyListener implements Listener {
String incomp = Hooks.InventoryIncompatible.test(); String incomp = Hooks.InventoryIncompatible.test();
if (incomp != null) { if (incomp != null) {
mod.getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, mod.getName())); mod.getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, mod.getName()));
mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; mod.getModuleEntry().deactivateUsage();
mod.getModuleEntry().disable();
} }
} }
} }
@ -36,15 +35,13 @@ public class DependencyListener implements Listener {
ModGameModePerm mod = plugin.getModule(ModGameModePerm.class); ModGameModePerm mod = plugin.getModule(ModGameModePerm.class);
if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) {
mod.getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", mod.getName())); mod.getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", mod.getName()));
mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; mod.getModuleEntry().deactivateUsage();
mod.getModuleEntry().disable();
} }
} else if (event.getPlugin().getName().equals("WorldGuard")) { } else if (event.getPlugin().getName().equals("WorldGuard")) {
ModRegions mod = plugin.getModule(ModRegions.class); ModRegions mod = plugin.getModule(ModRegions.class);
if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) { if (mod != null && mod.getModuleEntry().getState() == ModuleState.ENABLED) {
mod.getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", mod.getName())); mod.getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", mod.getName()));
mod.getModuleEntry().initialState = ModuleState.NOT_INITIALIZED; mod.getModuleEntry().deactivateUsage();
mod.getModuleEntry().disable();
} }
} }
} }

View file

@ -97,10 +97,8 @@ public class FeatureBlockItemSpawn extends CoreModule<LimitedCreative> implement
scheduleCleanUp(); scheduleCleanUp();
} }
@EventHandler @EventHandler(ignoreCancelled = true)
public void onItemSpawn(ItemSpawnEvent event) { public void onItemSpawn(ItemSpawnEvent event) {
if (event.isCancelled())
return;
if (event.getEntity() instanceof Item) { if (event.getEntity() instanceof Item) {
if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) { if (this.isBlocked(event.getLocation().getBlock().getLocation(), ((Item) event.getEntity()).getItemStack().getType())) {
event.setCancelled(true); event.setCancelled(true);

View file

@ -4,6 +4,7 @@ import de.jaschastarke.I18n;
import de.jaschastarke.bukkit.lib.Core; import de.jaschastarke.bukkit.lib.Core;
import de.jaschastarke.bukkit.lib.PluginLang; import de.jaschastarke.bukkit.lib.PluginLang;
import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand; import de.jaschastarke.bukkit.lib.configuration.command.ConfigCommand;
import de.jaschastarke.bukkit.lib.modules.AdditionalBlockBreaks;
import de.jaschastarke.utils.ClassDescriptorStorage; import de.jaschastarke.utils.ClassDescriptorStorage;
public class LimitedCreative extends Core { public class LimitedCreative extends Core {
@ -25,6 +26,8 @@ public class LimitedCreative extends Core {
Hooks.inizializeHooks(this); Hooks.inizializeHooks(this);
modules.addSharedModule(new AdditionalBlockBreaks(this));
modules.addSharedModule(new FeatureBlockItemSpawn(this));
addModule(new FeatureSwitchGameMode(this)); addModule(new FeatureSwitchGameMode(this));
addModule(new ModInventories(this)); addModule(new ModInventories(this));
addModule(new ModCreativeLimits(this)); addModule(new ModCreativeLimits(this));

View file

@ -18,7 +18,6 @@ import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel;
import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory; import de.jaschastarke.minecraft.limitedcreative.blockstate.worldedit.LCEditSessionFactory;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
public class ModBlockStates extends CoreModule<LimitedCreative> { public class ModBlockStates extends CoreModule<LimitedCreative> {
private BlockStateConfig config; private BlockStateConfig config;
@ -38,17 +37,12 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
public void initialize(ModuleEntry<IModule> entry) { public void initialize(ModuleEntry<IModule> entry) {
super.initialize(entry); super.initialize(entry);
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class);
if (blockDrops == null)
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
config = new BlockStateConfig(this, entry); config = new BlockStateConfig(this, entry);
plugin.getPluginConfig().registerSection(config); plugin.getPluginConfig().registerSection(config);
if (plugin.getModule(AdditionalBlockBreaks.class) == null) { blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
plugin.addModule(new AdditionalBlockBreaks(plugin)); modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules());
} this.addModule(new BlockFall(plugin));
addModule(new BlockFall(plugin));
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
listeners.addListener(new HangingListener(this)); listeners.addListener(new HangingListener(this));
@ -72,7 +66,7 @@ public class ModBlockStates extends CoreModule<LimitedCreative> {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
getLog().warn(plugin.getLocale().trans("block_state.error.sql_connection_failed", getName())); getLog().warn(plugin.getLocale().trans("block_state.error.sql_connection_failed", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED; entry.deactivateUsage();
return; return;
} }
super.onEnable(); super.onEnable();

View file

@ -12,7 +12,6 @@ import de.jaschastarke.minecraft.limitedcreative.limits.LimitConfig;
import de.jaschastarke.minecraft.limitedcreative.limits.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.limits.PlayerListener;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
public class ModCreativeLimits extends CoreModule<LimitedCreative> { public class ModCreativeLimits extends CoreModule<LimitedCreative> {
protected LimitConfig config; protected LimitConfig config;
@ -37,18 +36,8 @@ public class ModCreativeLimits extends CoreModule<LimitedCreative> {
listeners.addListener(new BlockListener(this)); listeners.addListener(new BlockListener(this));
config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry)); config = plugin.getPluginConfig().registerSection(new LimitConfig(this, entry));
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class); blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
if (blockDrops == null) modules.linkSharedModule(AdditionalBlockBreaks.class, plugin.getModules());
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;
}
} }
public FeatureBlockItemSpawn getBlockSpawn() { public FeatureBlockItemSpawn getBlockSpawn() {

View file

@ -6,7 +6,6 @@ import de.jaschastarke.minecraft.limitedcreative.gmperm.PermissionInterface;
import de.jaschastarke.minecraft.limitedcreative.gmperm.PlayerListener; import de.jaschastarke.minecraft.limitedcreative.gmperm.PlayerListener;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
public class ModGameModePerm extends CoreModule<LimitedCreative> { public class ModGameModePerm extends CoreModule<LimitedCreative> {
private GMPermConfig config; private GMPermConfig config;
@ -30,7 +29,7 @@ public class ModGameModePerm extends CoreModule<LimitedCreative> {
if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) { if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) {
if (config.getEnabled()) if (config.getEnabled())
getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName())); getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED; entry.deactivateUsage();
return; return;
} }
@ -39,7 +38,7 @@ public class ModGameModePerm extends CoreModule<LimitedCreative> {
if (config.getEnabled()) { if (config.getEnabled()) {
if (!permission.isPresent()) { if (!permission.isPresent()) {
getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName())); getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED; entry.deactivateUsage();
return; return;
} /*else if (!getVaultPermission().hasGroupSupport()) { } /*else if (!getVaultPermission().hasGroupSupport()) {
getLog().warn(plugin.getLocale().trans("gmperm.warning.no_group_support", getName())); getLog().warn(plugin.getLocale().trans("gmperm.warning.no_group_support", getName()));

View file

@ -19,7 +19,6 @@ import de.jaschastarke.minecraft.limitedcreative.inventories.store.InvYamlStorag
import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage; import de.jaschastarke.minecraft.limitedcreative.inventories.store.PlayerInventoryStorage;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
public class ModInventories extends CoreModule<LimitedCreative> { public class ModInventories extends CoreModule<LimitedCreative> {
protected PlayerInventoryStorage storage; protected PlayerInventoryStorage storage;
@ -42,17 +41,13 @@ public class ModInventories extends CoreModule<LimitedCreative> {
config = plugin.getPluginConfig().registerSection(new InventoryConfig(this, entry)); config = plugin.getPluginConfig().registerSection(new InventoryConfig(this, entry));
armor_config = config.registerSection(new ArmoryConfig(this)); armor_config = config.registerSection(new ArmoryConfig(this));
if (!config.getEnabled()) {
entry.initialState = ModuleState.DISABLED;
return;
}
if (plugin.getServer().getPluginManager().isPluginEnabled("AuthMe")) { if (plugin.getServer().getPluginManager().isPluginEnabled("AuthMe")) {
addModule(new AuthMeInventories(plugin, this)); addModule(new AuthMeInventories(plugin, this));
} }
String incomp = Hooks.InventoryIncompatible.test(); String incomp = Hooks.InventoryIncompatible.test();
if (config.getEnabled() && incomp != null) { if (config.getEnabled() && incomp != null) {
getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName())); getLog().warn(plugin.getLocale().trans("inventory.warning.conflict", incomp, this.getName()));
entry.initialState = ModuleState.NOT_INITIALIZED; entry.deactivateUsage();
} }
} }
@Override @Override

View file

@ -18,7 +18,6 @@ import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.CustomRegion
import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.PlayerRegionListener; import de.jaschastarke.minecraft.limitedcreative.regions.worldguard.PlayerRegionListener;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
public class ModRegions extends CoreModule<LimitedCreative> { public class ModRegions extends CoreModule<LimitedCreative> {
private CustomRegionManager mgr; private CustomRegionManager mgr;
@ -40,16 +39,14 @@ public class ModRegions extends CoreModule<LimitedCreative> {
public void initialize(ModuleEntry<IModule> pEntry) { public void initialize(ModuleEntry<IModule> pEntry) {
super.initialize(pEntry); super.initialize(pEntry);
blockDrops = plugin.getModule(FeatureBlockItemSpawn.class); blockDrops = modules.linkSharedModule(FeatureBlockItemSpawn.class, plugin.getModules());
if (blockDrops == null)
blockDrops = plugin.addModule(new FeatureBlockItemSpawn(plugin)).getModule();
config = plugin.getPluginConfig().registerSection(new RegionConfig(this, entry)); config = plugin.getPluginConfig().registerSection(new RegionConfig(this, entry));
if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) {
if (config.getEnabled()) if (config.getEnabled())
getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName())); getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName()));
entry.initialState = ModuleState.NOT_INITIALIZED; entry.deactivateUsage();
return; return;
} }

View file

@ -20,7 +20,7 @@ public abstract class AbstractModel {
protected void moveMetaState(Block from, Block to) { protected void moveMetaState(Block from, Block to) {
HasBlockState metaBlock = getMetaBlock(from); HasBlockState metaBlock = getMetaBlock(from);
if (metaBlock.set && metaBlock.state != null) { if (metaBlock.isSet() && metaBlock.getState() != null) {
BlockState state = metaBlock.state; BlockState state = metaBlock.state;
state.setLocation(to.getLocation()); state.setLocation(to.getLocation());
setMetaBlock(to, state); setMetaBlock(to, state);
@ -45,28 +45,43 @@ public abstract class AbstractModel {
m.setMetadata(BSMDKEY, new FixedMetadataValue(plugin, s)); m.setMetadata(BSMDKEY, new FixedMetadataValue(plugin, s));
} }
protected HasBlockState getMetaBlock(Metadatable m) { protected HasBlockState getMetaBlock(Metadatable m) {
HasBlockState has = new HasBlockState(); HasBlockState has = null;
List<MetadataValue> metadata = m.getMetadata(BSMDKEY); List<MetadataValue> metadata = m.getMetadata(BSMDKEY);
for (MetadataValue v : metadata) { for (MetadataValue v : metadata) {
if (v.value() instanceof BlockState) { if (v.value() instanceof BlockState) {
has.set = true; has = new HasBlockState((BlockState) v.value());
has.state = (BlockState) v.value();
break; break;
} else if (v == metadataNull) { } else if (v == metadataNull) {
has.set = true; // Metadata Knows, that there is no entry in DB
has.state = null; has = new HasBlockState(true);
break; break;
} }
} }
return has; if (has == null)
return new HasBlockState(false);
else
return has;
} }
protected void removeMetaBlock(Metadatable m) { protected void removeMetaBlock(Metadatable m) {
m.removeMetadata(BSMDKEY, plugin); m.removeMetadata(BSMDKEY, plugin);
} }
public static class HasBlockState { public static class HasBlockState {
public boolean set = false; private boolean set = false;
public BlockState state = null; 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;
}
} }
} }

View file

@ -16,7 +16,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config;
import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; import de.jaschastarke.minecraft.limitedcreative.ModBlockStates;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* BlockState-Feature * BlockState-Feature
@ -45,14 +44,9 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
else else
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("enabled")) { if (node.getName().equals("enabled")) {
if (getEnabled()) { entry.setEnabled(getEnabled());
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
} else if (node.getName().equals("useThreading")) { } else if (node.getName().equals("useThreading")) {
if (entry.getState() == ModuleState.ENABLED) { if (entry.isEnabled()) {
entry.disable(); entry.disable();
entry.enable(); entry.enable();
} }
@ -62,8 +56,7 @@ public class BlockStateConfig extends Configuration implements IConfigurationSub
@Override @Override
public void setValues(ConfigurationSection sect) { public void setValues(ConfigurationSection sect) {
super.setValues(sect); super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED) entry.setEnabled(getEnabled());
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
} }
@Override @Override
public String getName() { public String getName() {

View file

@ -71,8 +71,8 @@ public class SyncronizedModel extends AbstractModel implements DBModel {
Cuboid c = new Cuboid(); Cuboid c = new Cuboid();
for (Block block : blocks) { for (Block block : blocks) {
HasBlockState has = getMetaBlock(block); HasBlockState has = getMetaBlock(block);
if (has.set) { if (has.isSet()) {
ret.put(block, has.state); ret.put(block, has.getState());
} else { } else {
c.add(block.getLocation()); c.add(block.getLocation());
} }
@ -120,7 +120,7 @@ public class SyncronizedModel extends AbstractModel implements DBModel {
public BlockState getState(Block block) { public BlockState getState(Block block) {
HasBlockState has = getMetaBlock(block); HasBlockState has = getMetaBlock(block);
if (!has.set) { if (!has.isSet()) {
try { try {
BlockState state = q.find(block.getLocation()); BlockState state = q.find(block.getLocation());
setMetaBlock(block, state); setMetaBlock(block, state);
@ -131,7 +131,7 @@ public class SyncronizedModel extends AbstractModel implements DBModel {
return null; return null;
} }
} }
return has.state; return has.getState();
} }
public void setState(BlockState state) { public void setState(BlockState state) {
Block block = state.getLocation().getBlock(); Block block = state.getLocation().getBlock();

View file

@ -91,7 +91,7 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener {
Map<Block, Boolean> ret = new HashMap<Block, Boolean>(); Map<Block, Boolean> ret = new HashMap<Block, Boolean>();
for (Block block : blocks) { for (Block block : blocks) {
HasBlockState has = getMetaBlock(block); HasBlockState has = getMetaBlock(block);
ret.put(block, has.restricted); ret.put(block, has.isRestricted());
} }
return ret; return ret;
} }
@ -104,8 +104,8 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener {
c = new Cuboid(); c = new Cuboid();
for (Block block : blocks) { for (Block block : blocks) {
HasBlockState has = getMetaBlock(block); HasBlockState has = getMetaBlock(block);
if (has.set) { if (has.getState() != null || has.isNull()) {
ret.put(block, has.state); ret.put(block, has.getState());
} else { } else {
c.add(block.getLocation()); c.add(block.getLocation());
ret.put(block, null); ret.put(block, null);
@ -125,14 +125,17 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener {
@Override @Override
public BlockState getState(Block block) { public BlockState getState(Block block) {
HasBlockState has = getMetaBlock(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 threads.callUpdate(block);
} }
return has.state; return has.getState();
} }
@Override @Override
public boolean isRestricted(Block block) { public boolean isRestricted(Block block) {
return getMetaBlock(block).restricted; return getMetaBlock(block).isRestricted();
} }
@Override @Override
@ -201,37 +204,56 @@ public class ThreadedModel extends AbstractModel implements DBModel, Listener {
block.setMetadata(BSMDKEY, metadataSet); block.setMetadata(BSMDKEY, metadataSet);
} }
protected HasBlockState getMetaBlock(Metadatable m) { protected HasBlockState getMetaBlock(Metadatable m) {
HasBlockState has = new HasBlockState(); HasBlockState has = null;
List<MetadataValue> metadata = m.getMetadata(BSMDKEY); List<MetadataValue> metadata = m.getMetadata(BSMDKEY);
for (MetadataValue v : metadata) { for (MetadataValue v : metadata) {
if (v.value() instanceof BlockState) { if (v.value() instanceof BlockState) {
has.set = true; // The actual DB-entry is in Metadata (requires more memory)
has.state = (BlockState) v.value(); has = new HasBlockState((BlockState) v.value());
has.dbSet = true;
has.restricted = has.state.isRestricted();
break; break;
} else if (v.getOwningPlugin() == mod.getPlugin()) { } else if (v.getOwningPlugin() == mod.getPlugin()) {
if (v == metadataNull) { if (v == metadataNull) {
has.set = true; // Metadata knows, that there is no entry in DB
has.state = null; has = new HasBlockState(true);
break;
} else if (v == metadataSet) { } else if (v == metadataSet) {
has.set = true; // Metadata knows, that there is survival-entry in DB
has.state = null; has = new HasBlockState(true, false);
has.dbSet = true; break;
} else if (v == metadataSetRestricted) { } else if (v == metadataSetRestricted) {
has.set = true; // Metadata knows, that there is creative-entry in DB
has.state = null; has = new HasBlockState(true, true);
has.dbSet = true;
has.restricted = true;
} }
break; break;
} }
} }
return has; if (has == null)
return new HasBlockState(false);
else
return has;
} }
public static class HasBlockState extends AbstractModel.HasBlockState { public static class HasBlockState extends AbstractModel.HasBlockState {
public boolean dbSet = false; private boolean restricted = false;
public 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() { public ModBlockStates getModel() {

View file

@ -16,14 +16,14 @@ public class UpdateBlockStateAction extends TransactionAction implements Action
@Override @Override
public void process(ThreadLink link, DBQueries q) { public void process(ThreadLink link, DBQueries q) {
HasBlockState state = link.getMetaState(block); HasBlockState state = link.getMetaState(block);
if (state.set) { if (state.isSet()) {
try { try {
q.delete(block.getLocation()); q.delete(block.getLocation());
if (state.state != null) if (state.getState() != null)
q.insert(state.state); q.insert(state.getState());
} catch (SQLException e) { } catch (SQLException e) {
link.getLog().severe(e.getMessage()); 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 @Override
public void processInTransaction(ThreadLink link, DBQueries q) throws SQLException { public void processInTransaction(ThreadLink link, DBQueries q) throws SQLException {
HasBlockState state = link.getMetaState(block); HasBlockState state = link.getMetaState(block);
if (state.set) { if (state.isSet()) {
q.delete(block.getLocation()); q.delete(block.getLocation());
if (state.state != null) if (state.getState() != null)
q.insert(state.state); q.insert(state.getState());
} }
} }

View file

@ -14,7 +14,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config;
import de.jaschastarke.minecraft.limitedcreative.ModCmdBlocker; import de.jaschastarke.minecraft.limitedcreative.ModCmdBlocker;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* CommandBlocker-Feature * CommandBlocker-Feature
@ -39,20 +38,14 @@ public class CmdBlockerConfig extends Configuration implements IConfigurationSub
@Override @Override
public void setValues(ConfigurationSection sect) { public void setValues(ConfigurationSection sect) {
super.setValues(sect); super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED) entry.setEnabled(getEnabled());
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
} }
@Override @Override
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("enabled")) { if (node.getName().equals("enabled")) {
if (getEnabled()) { entry.setEnabled(getEnabled());
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
} }
} }

View file

@ -14,7 +14,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config;
import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm; import de.jaschastarke.minecraft.limitedcreative.ModGameModePerm;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* GameMode-Permissions-Feature * GameMode-Permissions-Feature
@ -42,20 +41,14 @@ public class GMPermConfig extends Configuration implements IConfigurationSubGrou
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("enabled")) { if (node.getName().equals("enabled")) {
if (getEnabled()) { entry.setEnabled(getEnabled());
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
} }
} }
@Override @Override
public void setValues(ConfigurationSection sect) { public void setValues(ConfigurationSection sect) {
super.setValues(sect); super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED) entry.setEnabled(getEnabled());
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
} }
@Override @Override
public String getName() { public String getName() {

View file

@ -14,7 +14,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config;
import de.jaschastarke.minecraft.limitedcreative.ModInventories; import de.jaschastarke.minecraft.limitedcreative.ModInventories;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* Inventory-Feature * Inventory-Feature
@ -40,12 +39,7 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException { public void setValue(IConfigurationNode node, Object pValue) throws InvalidValueException {
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("enabled")) { if (node.getName().equals("enabled")) {
if (getEnabled()) { entry.setEnabled(getEnabled());
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
} }
} }
@ -59,8 +53,8 @@ public class InventoryConfig extends Configuration implements IConfigurationSubG
} }
super.setValues(sect); super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED) entry.setEnabled(getEnabled());
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
// Config Upgrade // Config Upgrade
if (!sect.contains("storeCreative") && sect.contains("creative")) if (!sect.contains("storeCreative") && sect.contains("creative"))
sect.set("storeCreative", sect.getBoolean("creative")); sect.set("storeCreative", sect.getBoolean("creative"));

View file

@ -17,7 +17,6 @@ import de.jaschastarke.minecraft.limitedcreative.Config;
import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits; import de.jaschastarke.minecraft.limitedcreative.ModCreativeLimits;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* Creative Limits-Feature * Creative Limits-Feature
@ -44,20 +43,14 @@ public class LimitConfig extends Configuration implements IConfigurationSubGroup
if (!(pValue instanceof BlackList)) if (!(pValue instanceof BlackList))
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("enabled")) { if (node.getName().equals("enabled")) {
if (getEnabled()) { entry.setEnabled(getEnabled());
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
} }
} }
@Override @Override
public void setValues(ConfigurationSection sect) { public void setValues(ConfigurationSection sect) {
super.setValues(sect); super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED) entry.setEnabled(getEnabled());
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
// Config Upgrade // Config Upgrade
if (!sect.contains("interact") && sect.contains("sign")) { if (!sect.contains("interact") && sect.contains("sign")) {

View file

@ -15,7 +15,6 @@ import de.jaschastarke.minecraft.limitedcreative.ModRegions;
import de.jaschastarke.minecraft.limitedcreative.limits.BlackList; import de.jaschastarke.minecraft.limitedcreative.limits.BlackList;
import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.IModule;
import de.jaschastarke.modularize.ModuleEntry; import de.jaschastarke.modularize.ModuleEntry;
import de.jaschastarke.modularize.ModuleEntry.ModuleState;
/** /**
* Region GameModes-Feature * Region GameModes-Feature
@ -42,19 +41,13 @@ public class RegionConfig extends Configuration implements IConfigurationSubGrou
if (!(pValue instanceof BlackList)) if (!(pValue instanceof BlackList))
super.setValue(node, pValue); super.setValue(node, pValue);
if (node.getName().equals("enabled")) { if (node.getName().equals("enabled")) {
if (getEnabled()) { entry.setEnabled(getEnabled());
if (entry.initialState != ModuleState.NOT_INITIALIZED)
entry.enable();
} else {
entry.disable();
}
} }
} }
@Override @Override
public void setValues(ConfigurationSection sect) { public void setValues(ConfigurationSection sect) {
super.setValues(sect); super.setValues(sect);
if (entry.initialState != ModuleState.NOT_INITIALIZED) entry.setEnabled(getEnabled());
entry.initialState = getEnabled() ? ModuleState.ENABLED : ModuleState.DISABLED;
// Config Upgrade // Config Upgrade
if (!sect.contains("rememberOptional") && sect.contains("remember")) if (!sect.contains("rememberOptional") && sect.contains("remember"))