diff --git a/resources/assets/storagedrawers/lang/en_US.lang b/resources/assets/storagedrawers/lang/en_US.lang index 478f451..1c089f5 100644 --- a/resources/assets/storagedrawers/lang/en_US.lang +++ b/resources/assets/storagedrawers/lang/en_US.lang @@ -32,8 +32,10 @@ item.storagedrawers.upgradeSorting.name=Sorting Upgrade item.storagedrawers.upgradeSorting.description=For Refined Relocation item.storagedrawers.shroudKey.name=Concealment Key item.storagedrawers.shroudKey.description=Show or hide item labels -item.storagedrawers.personalKey.name=Personal Key -item.storagedrawers.personalKey.description=Protect access from other players +item.storagedrawers.personalKey.default.name=Personal Key +item.storagedrawers.personalKey.default.description=Protect access from other players +item.storagedrawers.personalKey.cofh.name=Personal Key (CoFH) +item.storagedrawers.personalKey.cofh.description=Protect access from other players item.storagedrawers.tape.name=Packing Tape item.storagedrawers.tape.description=Seals drawers for moving @@ -187,3 +189,4 @@ storageDrawers.config.integration.enableThaumcraft=Enable Thaumcraft Integration storageDrawers.config.integration.enableMineTweaker=Enable MineTweaker Integration storageDrawers.config.integration.enableRefinedRelocation=Enable Refined Relocation Integration storageDrawers.config.integration.enableThermalExpansion=Enable Thermal Expansion Integration +storageDrawers.config.integration.enableThermalFoundation=Enable Thermal Foundation Integration diff --git a/resources/assets/storagedrawers/textures/items/drawer_key_personal_cofh.png b/resources/assets/storagedrawers/textures/items/drawer_key_personal_cofh.png new file mode 100644 index 0000000..03ae7eb Binary files /dev/null and b/resources/assets/storagedrawers/textures/items/drawer_key_personal_cofh.png differ diff --git a/resources/assets/storagedrawers/textures/items/drawer_key_personal.png b/resources/assets/storagedrawers/textures/items/drawer_key_personal_default.png similarity index 100% rename from resources/assets/storagedrawers/textures/items/drawer_key_personal.png rename to resources/assets/storagedrawers/textures/items/drawer_key_personal_default.png diff --git a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java index dbdf1bc..aad246b 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/StorageDrawers.java @@ -8,6 +8,7 @@ import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler; import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; import com.jaquadro.minecraft.storagedrawers.network.CountUpdateMessage; +import com.jaquadro.minecraft.storagedrawers.security.SecurityRegistry; import cpw.mods.fml.client.event.ConfigChangedEvent; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; @@ -46,6 +47,7 @@ public class StorageDrawers public static RenderRegistry renderRegistry; public static WailaRegistry wailaRegistry; public static BlockRegistry blockRegistry; + public static SecurityRegistry securityRegistry; @Mod.Instance(MOD_ID) public static StorageDrawers instance; @@ -73,6 +75,7 @@ public class StorageDrawers renderRegistry = new RenderRegistry(); wailaRegistry = new WailaRegistry(); blockRegistry = new BlockRegistry(); + securityRegistry = new SecurityRegistry(); blocks.init(); items.init(); diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java index 119c8bb..66752c0 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java +++ b/src/com/jaquadro/minecraft/storagedrawers/api/security/ISecurityProvider.java @@ -5,5 +5,9 @@ import com.mojang.authlib.GameProfile; public interface ISecurityProvider { + String getProviderID (); + + boolean hasOwnership (GameProfile profile, IProtectable target); + boolean hasAccess (GameProfile profile, IProtectable target); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java index 845f4d0..b08649f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java +++ b/src/com/jaquadro/minecraft/storagedrawers/api/storage/attribute/IProtectable.java @@ -22,4 +22,10 @@ public interface IProtectable * @return null to use the default provider, which enforces strict owner access. */ ISecurityProvider getSecurityProvider (); + + /** + * Sets the provider managing security for the target. Set to null for default provider. + * @return false if the operation is not supported, true otherwise. + */ + boolean setSecurityProvider (ISecurityProvider provder); } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java index 3dfc0dc..d56624d 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockController.java @@ -1,11 +1,13 @@ package com.jaquadro.minecraft.storagedrawers.block; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityController; import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; import com.jaquadro.minecraft.storagedrawers.core.ModItems; +import com.jaquadro.minecraft.storagedrawers.item.ItemPersonalKey; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; @@ -130,8 +132,13 @@ public class BlockController extends BlockContainer implements INetworked return true; } else if (item.getItem() == ModItems.personalKey) { - if (!world.isRemote) - te.toggleProtection(player.getGameProfile()); + if (!world.isRemote) { + String securityKey = ((ItemPersonalKey) item.getItem()).getSecurityProviderKey(item.getItemDamage()); + ISecurityProvider provider = StorageDrawers.securityRegistry.getProvider(securityKey); + + te.toggleProtection(player.getGameProfile(), provider); + } + return true; } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java index 2d02e45..41579ed 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/BlockDrawers.java @@ -5,6 +5,7 @@ import com.google.gson.JsonParser; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.pack.BlockConfiguration; import com.jaquadro.minecraft.storagedrawers.api.pack.BlockType; +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; import com.jaquadro.minecraft.storagedrawers.api.storage.IDrawer; import com.jaquadro.minecraft.storagedrawers.api.storage.INetworked; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.LockAttribute; @@ -13,6 +14,7 @@ import com.jaquadro.minecraft.storagedrawers.block.tile.TileEntityDrawersStandar import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; import com.jaquadro.minecraft.storagedrawers.core.ModItems; import com.jaquadro.minecraft.storagedrawers.core.handlers.GuiHandler; +import com.jaquadro.minecraft.storagedrawers.item.ItemPersonalKey; import com.jaquadro.minecraft.storagedrawers.item.ItemTrim; import com.jaquadro.minecraft.storagedrawers.network.BlockClickMessage; @@ -348,11 +350,18 @@ public class BlockDrawers extends BlockContainer implements IExtendedBlockClickH tileDrawers.setIsShrouded(!tileDrawers.isShrouded()); return true; } - else if (item.getItem() == ModItems.personalKey) { - if (tileDrawers.getOwner() == null) + else if (item.getItem() instanceof ItemPersonalKey) { + String securityKey = ((ItemPersonalKey) item.getItem()).getSecurityProviderKey(item.getItemDamage()); + ISecurityProvider provider = StorageDrawers.securityRegistry.getProvider(securityKey); + + if (tileDrawers.getOwner() == null) { tileDrawers.setOwner(player.getPersistentID()); - else if (player.getPersistentID().equals(tileDrawers.getOwner())) + tileDrawers.setSecurityProvider(provider); + } + else if (SecurityManager.hasOwnership(player.getGameProfile(), tileDrawers)) { tileDrawers.setOwner(null); + tileDrawers.setSecurityProvider(null); + } else return false; return true; diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java index 99c4c10..2908ee4 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityController.java @@ -2,6 +2,7 @@ package com.jaquadro.minecraft.storagedrawers.block.tile; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.api.inventory.IDrawerInventory; +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; import com.jaquadro.minecraft.storagedrawers.api.storage.*; import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.*; import com.jaquadro.minecraft.storagedrawers.block.BlockSlave; @@ -232,7 +233,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP return remainder; } - public void toggleProtection (GameProfile profile) { + public void toggleProtection (GameProfile profile, ISecurityProvider provider) { IProtectable template = null; UUID state = null; @@ -242,7 +243,7 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (record.storage instanceof IProtectable) { IProtectable protectable = (IProtectable)record.storage; - if (!SecurityManager.hasAccess(profile, protectable)) + if (!SecurityManager.hasOwnership(profile, protectable)) continue; if (template == null) { @@ -250,11 +251,14 @@ public class TileEntityController extends TileEntity implements IDrawerGroup, IP if (template.getOwner() == null) state = profile.getId(); - else + else { state = null; + provider = null; + } } protectable.setOwner(state); + protectable.setSecurityProvider(provider); } } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java index 9d67794..60f695b 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java +++ b/src/com/jaquadro/minecraft/storagedrawers/block/tile/TileEntityDrawers.java @@ -50,6 +50,7 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe private boolean taped = false; private boolean hideUpgrade = false; private UUID owner; + private String securityKey; private EnumSet lockAttributes = null; @@ -271,7 +272,25 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe @Override public ISecurityProvider getSecurityProvider () { - return null; + return StorageDrawers.securityRegistry.getProvider(securityKey); + } + + @Override + public boolean setSecurityProvider (ISecurityProvider provider) { + if (!StorageDrawers.config.cache.enablePersonalUpgrades) + return false; + + String newKey = (provider == null) ? null : provider.getProviderID(); + if ((newKey != null && !newKey.equals(securityKey)) || (securityKey != null && !securityKey.equals(newKey))) { + securityKey = newKey; + + if (worldObj != null && !worldObj.isRemote) { + markDirty(); + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + } + + return true; } public boolean shouldHideUpgrades () { @@ -513,6 +532,10 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (tag.hasKey("Own")) owner = UUID.fromString(tag.getString("Own")); + securityKey = null; + if (tag.hasKey("Sec")) + securityKey = tag.getString("Sec"); + hideUpgrade = false; if (tag.hasKey("HideUp")) hideUpgrade = tag.getBoolean("HideUp"); @@ -557,6 +580,9 @@ public abstract class TileEntityDrawers extends BaseTileEntity implements IDrawe if (owner != null) tag.setString("Own", owner.toString()); + if (securityKey != null) + tag.setString("Sec", securityKey); + if (hideUpgrade) tag.setBoolean("HideUp", hideUpgrade); diff --git a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java index e346d29..c605877 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java +++ b/src/com/jaquadro/minecraft/storagedrawers/config/ConfigManager.java @@ -75,6 +75,7 @@ public class ConfigManager public boolean enableMineTweakerIntegration; public boolean enableRefinedRelocationIntegration; public boolean enableThermalExpansionIntegration; + public boolean enableThermalFoundationIntegration; public boolean enableTape; public boolean enableFallbackRecipes; public boolean invertShift; @@ -255,6 +256,7 @@ public class ConfigManager cache.enableMineTweakerIntegration = config.get(sectionIntegration.getQualifiedName(), "enableMineTweaker", true).setLanguageKey(LANG_PREFIX + "integration.enableMineTweaker").setRequiresMcRestart(true).getBoolean(); cache.enableRefinedRelocationIntegration = config.get(sectionIntegration.getQualifiedName(), "enableRefinedRelocation", true).setLanguageKey(LANG_PREFIX + "integration.enableRefinedRelocation").setRequiresMcRestart(true).getBoolean(); cache.enableThermalExpansionIntegration = config.get(sectionIntegration.getQualifiedName(), "enableThermalExpansion", true).setLanguageKey(LANG_PREFIX + "integration.enableThermalExpansion").setRequiresMcRestart(true).getBoolean(); + cache.enableThermalFoundationIntegration = config.get(sectionIntegration.getQualifiedName(), "enableThermalFoundation", true).setLanguageKey(LANG_PREFIX + "integration.enableThermalFoundation").setRequiresMcRestart(true).getBoolean(); config.get(sectionBlocksFullDrawers1x1.getQualifiedName(), "enabled", true).setLanguageKey(LANG_PREFIX + "prop.enabled").setRequiresMcRestart(true); config.get(sectionBlocksFullDrawers1x1.getQualifiedName(), "baseStorage", 32).setLanguageKey(LANG_PREFIX + "prop.baseStorage").setRequiresWorldRestart(true); diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java index be49974..000609c 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/IntegrationRegistry.java @@ -30,6 +30,8 @@ public class IntegrationRegistry reg.add(new NotEnoughItems()); if (Loader.isModLoaded("ThermalExpansion") && StorageDrawers.config.cache.enableThermalExpansionIntegration) reg.add(new ThermalExpansion()); + if (Loader.isModLoaded("ThermalFoundation") && StorageDrawers.config.cache.enableThermalFoundationIntegration) + reg.add(new ThermalFoundation()); } private IntegrationRegistry () { diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java new file mode 100644 index 0000000..6d716d9 --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/ThermalFoundation.java @@ -0,0 +1,40 @@ +package com.jaquadro.minecraft.storagedrawers.integration; + +import com.jaquadro.minecraft.storagedrawers.StorageDrawers; +import com.jaquadro.minecraft.storagedrawers.integration.thermalfoundation.CoFHSecurityProvider; +import com.mojang.authlib.GameProfile; + +import java.lang.reflect.Method; + +public class ThermalFoundation extends IntegrationModule +{ + private Class classRegistrySocial; + + private Method methodPlayerHasAccess; + + @Override + public String getModID () { + return "ThermalFoundation"; + } + + @Override + public void init () throws Throwable { + classRegistrySocial = Class.forName("cofh.core.RegistrySocial"); + + methodPlayerHasAccess = classRegistrySocial.getDeclaredMethod("playerHasAccess", String.class, GameProfile.class); + } + + @Override + public void postInit () { + StorageDrawers.securityRegistry.registerProvider(new CoFHSecurityProvider(this)); + } + + public boolean playerHasAccess (String playerName, GameProfile owner) { + try { + return (Boolean) methodPlayerHasAccess.invoke(null, playerName, owner); + } + catch (Throwable t) { + return false; + } + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java new file mode 100644 index 0000000..0ffe93e --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/integration/thermalfoundation/CoFHSecurityProvider.java @@ -0,0 +1,40 @@ +package com.jaquadro.minecraft.storagedrawers.integration.thermalfoundation; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; +import com.jaquadro.minecraft.storagedrawers.api.storage.attribute.IProtectable; +import com.jaquadro.minecraft.storagedrawers.integration.ThermalFoundation; +import com.jaquadro.minecraft.storagedrawers.security.DefaultSecurityProvider; +import com.mojang.authlib.GameProfile; +import net.minecraft.server.MinecraftServer; + +public class CoFHSecurityProvider implements ISecurityProvider +{ + ThermalFoundation foundation; + private DefaultSecurityProvider defaultProvider = new DefaultSecurityProvider(); + + public CoFHSecurityProvider (ThermalFoundation foundation) { + this.foundation = foundation; + } + + @Override + public String getProviderID () { + return "cofh"; + } + + @Override + public boolean hasOwnership (GameProfile profile, IProtectable target) { + return defaultProvider.hasOwnership(profile, target); + } + + @Override + public boolean hasAccess (GameProfile profile, IProtectable target) { + if (target.getOwner() == null) + return true; + + GameProfile ownerProfile = MinecraftServer.getServer().func_152358_ax().func_152652_a(target.getOwner()); + if (ownerProfile == null) + return false; + + return foundation.playerHasAccess(profile.getName(), ownerProfile); + } +} diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java index e6348a3..d3f8d5f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemPersonalKey.java @@ -3,26 +3,51 @@ package com.jaquadro.minecraft.storagedrawers.item; import com.google.common.collect.Multimap; import com.jaquadro.minecraft.storagedrawers.StorageDrawers; import com.jaquadro.minecraft.storagedrawers.core.ModCreativeTabs; +import com.jaquadro.minecraft.storagedrawers.integration.IntegrationRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.MathHelper; import net.minecraft.util.StatCollector; import java.util.List; public class ItemPersonalKey extends Item { + public static final String[] iconNames = new String[] { "default", "cofh" }; + + @SideOnly(Side.CLIENT) + private IIcon[] icons; + public ItemPersonalKey (String name) { setUnlocalizedName(name); setCreativeTab(ModCreativeTabs.tabStorageDrawers); - setTextureName(StorageDrawers.MOD_ID + ":drawer_key_personal"); + setHasSubtypes(true); setMaxDamage(0); } + @Override + @SideOnly(Side.CLIENT) + public IIcon getIconFromDamage (int meta) { + return icons[MathHelper.clamp_int(meta, 0, iconNames.length - 1)]; + } + + @Override + public String getUnlocalizedName (ItemStack itemStack) { + int meta = MathHelper.clamp_int(itemStack.getItemDamage(), 0, iconNames.length - 1); + if (iconNames[meta] == null) + return super.getUnlocalizedName(); + + return super.getUnlocalizedName() + "." + iconNames[meta]; + } + @Override @SideOnly(Side.CLIENT) public void addInformation (ItemStack itemStack, EntityPlayer player, List list, boolean par4) { @@ -42,4 +67,31 @@ public class ItemPersonalKey extends Item multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double)2, 0)); return multimap; } + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems (Item item, CreativeTabs creativeTabs, List list) { + list.add(new ItemStack(item, 1, 0)); + if (StorageDrawers.config.cache.enableThermalFoundationIntegration && IntegrationRegistry.instance().isModLoaded("ThermalFoundation")) + list.add(new ItemStack(item, 1, 1)); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons (IIconRegister register) { + icons = new IIcon[iconNames.length]; + + for (int i = 0, n = iconNames.length; i < n; i++) { + if (iconNames[i] != null) + icons[i] = register.registerIcon(StorageDrawers.MOD_ID + ":drawer_key_personal_" + iconNames[i]); + } + } + + public String getSecurityProviderKey (int meta) { + switch (meta) { + case 0: return null; + case 1: return "cofh"; + default: return null; + } + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java index 1145666..73bd98c 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java +++ b/src/com/jaquadro/minecraft/storagedrawers/item/ItemTape.java @@ -40,7 +40,7 @@ public class ItemTape extends Item TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof IProtectable) { - if (!SecurityManager.hasAccess(player.getGameProfile(), (IProtectable)tile)) + if (!SecurityManager.hasOwnership(player.getGameProfile(), (IProtectable)tile)) return false; } diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java b/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java index 6bea448..832275f 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java +++ b/src/com/jaquadro/minecraft/storagedrawers/security/DefaultSecurityProvider.java @@ -7,10 +7,20 @@ import com.mojang.authlib.GameProfile; public class DefaultSecurityProvider implements ISecurityProvider { @Override - public boolean hasAccess (GameProfile profile, IProtectable target) { + public String getProviderID () { + return null; + } + + @Override + public boolean hasOwnership (GameProfile profile, IProtectable target) { if (target == null || profile == null) return false; return target.getOwner() == null || target.getOwner().equals(profile.getId()); } + + @Override + public boolean hasAccess (GameProfile profile, IProtectable target) { + return hasOwnership(profile, target); + } } diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java index 78f29dd..f0e921a 100644 --- a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java +++ b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityManager.java @@ -8,6 +8,17 @@ public class SecurityManager { private static ISecurityProvider defaultProvider = new DefaultSecurityProvider(); + public static boolean hasOwnership (GameProfile profile, IProtectable target) { + if (target == null || profile == null) + return false; + + ISecurityProvider provider = target.getSecurityProvider(); + if (provider == null) + provider = defaultProvider; + + return provider.hasOwnership(profile, target); + } + public static boolean hasAccess (GameProfile profile, IProtectable target) { if (target == null || profile == null) return false; diff --git a/src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java new file mode 100644 index 0000000..8c5a3da --- /dev/null +++ b/src/com/jaquadro/minecraft/storagedrawers/security/SecurityRegistry.java @@ -0,0 +1,19 @@ +package com.jaquadro.minecraft.storagedrawers.security; + +import com.jaquadro.minecraft.storagedrawers.api.security.ISecurityProvider; + +import java.util.HashMap; +import java.util.Map; + +public class SecurityRegistry +{ + private Map registry = new HashMap(); + + public void registerProvider (ISecurityProvider provider) { + registry.put(provider.getProviderID(), provider); + } + + public ISecurityProvider getProvider (String name) { + return registry.get(name); + } +}