diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-08-26 22:18:56 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-08-26 22:18:56 +1000 |
commit | 20f3ef5c6b35554118ad395e477b8d263ffbf936 (patch) | |
tree | 2c054f0b48ef246db39da6100f10e33ca43d2c7b | |
parent | e0f72471c5da950378a3102b4f5de781b5442ed8 (diff) | |
download | GT5-Unofficial-20f3ef5c6b35554118ad395e477b8d263ffbf936.tar.gz GT5-Unofficial-20f3ef5c6b35554118ad395e477b8d263ffbf936.tar.bz2 GT5-Unofficial-20f3ef5c6b35554118ad395e477b8d263ffbf936.zip |
% Initial changes to internal handling of PlayerCache.dat
> Cache is now populated upon player login.
5 files changed, 90 insertions, 54 deletions
diff --git a/src/Java/miscutil/core/handler/events/LoginEventHandler.java b/src/Java/miscutil/core/handler/events/LoginEventHandler.java index 9c3e012825..3efe8cea34 100644 --- a/src/Java/miscutil/core/handler/events/LoginEventHandler.java +++ b/src/Java/miscutil/core/handler/events/LoginEventHandler.java @@ -2,11 +2,8 @@ package miscutil.core.handler.events; import java.util.UUID; -import miscutil.core.item.ModItems; import miscutil.core.util.Utils; -import miscutil.core.util.item.UtilsItems; -import miscutil.core.util.math.MathUtils; -import net.minecraft.client.Minecraft; +import miscutil.core.util.player.PlayerCache; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import cpw.mods.fml.common.eventhandler.SubscribeEvent; @@ -29,14 +26,13 @@ public class LoginEventHandler { if (localPlayerRef instanceof EntityPlayerMP && localPlayerRef != null){ - /*Utils.LOG_INFO("Engaging Log in protection."); - localPlayerRef.*/ - if (localPlayerRef.getCommandSenderName().toLowerCase().equalsIgnoreCase("ImQ009")/* || localPlayerRef.getCommandSenderName().toLowerCase().contains("player")*/){ + //Populates player cache + PlayerCache.appendParamChanges(localPlayersName, localPlayersUUID.toString()); + /*if (localPlayerRef.getCommandSenderName().toLowerCase().equalsIgnoreCase("ImQ009") || localPlayerRef.getCommandSenderName().toLowerCase().contains("player")){ Utils.LOG_INFO("Spawning a new Santa Thread."); - Thread t = new Thread() { UUID threadHandlerIDthing = localPlayersUUID; @Override @@ -72,7 +68,7 @@ public class LoginEventHandler { //t.start(); - } + }*/ } diff --git a/src/Java/miscutil/core/handler/events/PickaxeBlockBreakEventHandler.java b/src/Java/miscutil/core/handler/events/PickaxeBlockBreakEventHandler.java index c8865ee02e..2445229a11 100644 --- a/src/Java/miscutil/core/handler/events/PickaxeBlockBreakEventHandler.java +++ b/src/Java/miscutil/core/handler/events/PickaxeBlockBreakEventHandler.java @@ -4,6 +4,9 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.BaseMetaTileEntity; import gregtech.api.metatileentity.BaseTileEntity; + +import java.util.UUID; + import miscutil.core.util.Utils; import miscutil.core.xmod.gregtech.api.metatileentity.implementations.base.machines.GregtechMetaSafeBlockBase; import net.minecraft.block.Block; @@ -29,7 +32,7 @@ public class PickaxeBlockBreakEventHandler { Block ThisBlock = X.getBaseMetaTileEntity().getBlock(event.x, event.y, event.z); if (X instanceof GregtechMetaSafeBlockBase){ - String ownerUUID = ((GregtechMetaSafeBlockBase)X).ownerUUID; + UUID ownerUUID = ((GregtechMetaSafeBlockBase)X).ownerUUID; String accessorUUID = playerInternal.getUniqueID().toString(); Utils.LOG_WARNING("Owner UUID: "+ownerUUID); Utils.LOG_WARNING("Accessor UUID: "+accessorUUID); diff --git a/src/Java/miscutil/core/util/player/PlayerCache.java b/src/Java/miscutil/core/util/player/PlayerCache.java index 5969766556..d1c40ec3fc 100644 --- a/src/Java/miscutil/core/util/player/PlayerCache.java +++ b/src/Java/miscutil/core/util/player/PlayerCache.java @@ -6,12 +6,14 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; +import java.io.ObjectInputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Objects; import java.util.Properties; +import java.util.UUID; import miscutil.core.lib.CORE; import miscutil.core.util.Utils; @@ -23,16 +25,21 @@ public class PlayerCache { public static final void initCache() { if (CORE.PlayerCache == null || CORE.PlayerCache.equals(null)){ try { - CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); - Utils.LOG_INFO("Loaded PlayerCache.dat"); + + if (cache != null){ + CORE.PlayerCache = PlayerCache.readPropertiesFileAsMap(); + Utils.LOG_INFO("Loaded PlayerCache.dat"); + } + + } catch (Exception e) { Utils.LOG_INFO("Failed to initialise PlayerCache.dat"); - PlayerCache.createPropertiesFile("CACHE_FILE_=", "THIS_CONTAINS_PLAYERDATA"); + PlayerCache.createPropertiesFile("PLAYER_", "DATA"); //e.printStackTrace(); } } } - + public static void createPropertiesFile(String playerName, String playerUUIDasString) { try { Properties props = new Properties(); @@ -47,25 +54,25 @@ public class PlayerCache { } public static void appendParamChanges(String playerName, String playerUUIDasString) { - Properties properties = new Properties(); - try { - Utils.LOG_WARNING("Attempting to load "+cache.getName()); - properties.load(new FileInputStream(cache)); - if (properties == null || properties.equals(null)){ - Utils.LOG_WARNING("Null properties"); - } - else { - Utils.LOG_WARNING("Loaded PlayerCache.dat"); - properties.setProperty(playerName+"_", playerUUIDasString); - FileOutputStream fr=new FileOutputStream(cache); - properties.store(fr, "Player Cache."); - fr.close(); - } - - } catch (IOException e) { - Utils.LOG_WARNING("No PlayerCache file found, creating one."); - createPropertiesFile(playerName, playerUUIDasString); - } + Properties properties = new Properties(); + try { + Utils.LOG_INFO("Attempting to load "+cache.getName()); + properties.load(new FileInputStream(cache)); + if (properties == null || properties.equals(null)){ + Utils.LOG_WARNING("Null properties"); + } + else { + Utils.LOG_INFO("Loaded PlayerCache.dat"); + properties.setProperty(playerName+"_", playerUUIDasString); + FileOutputStream fr=new FileOutputStream(cache); + properties.store(fr, "Player Cache."); + fr.close(); + } + + } catch (IOException e) { + Utils.LOG_INFO("No PlayerCache file found, creating one."); + createPropertiesFile(playerName, playerUUIDasString); + } } /** @@ -81,7 +88,8 @@ public class PlayerCache { * @return The Map that contains the key/value pairs. * @throws Exception */ - public static Map<String, String> readPropertiesFileAsMap() throws Exception { + @Deprecated + public static Map<String, String> readPropertiesFileAsMapOld() throws Exception { String delimiter = "="; @SuppressWarnings({ "rawtypes", "unchecked" }) Map<String, String> map = new HashMap(); @@ -103,25 +111,48 @@ public class PlayerCache { return map; } - public static String lookupPlayerByUUID(String UUID){ - try { - Map<String, String> map = null; + public static HashMap<String, UUID> readPropertiesFileAsMap() { + HashMap<String, UUID> map = null; + try + { + FileInputStream fis = new FileInputStream(cache); + ObjectInputStream ois = new ObjectInputStream(fis); + map = (HashMap) ois.readObject(); + ois.close(); + fis.close(); + }catch(IOException ioe) + { + ioe.printStackTrace(); + return null; + }catch(ClassNotFoundException c) + { + System.out.println("Class not found"); + c.printStackTrace(); + return null; + } + System.out.println("Deserialized HashMap.."); + return map; + } + + public static String lookupPlayerByUUID(UUID UUID){ try { - map = readPropertiesFileAsMap(); - } catch (Exception e) { + Map<String, UUID> map = null; + try { + map = readPropertiesFileAsMap(); + } catch (Exception e) { + Utils.LOG_ERROR("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); + //e.printStackTrace(); + } + for (Entry<String, UUID> entry : map.entrySet()) { + if (Objects.equals(UUID, entry.getValue())) { + return entry.getKey(); + } + } + return null; + } catch (NullPointerException e) { Utils.LOG_ERROR("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); //e.printStackTrace(); } - for (Entry<String, String> entry : map.entrySet()) { - if (Objects.equals(UUID, entry.getValue())) { - return entry.getKey(); - } - } return null; - } catch (NullPointerException e) { - Utils.LOG_ERROR("With "+e.getCause()+" as cause, Caught Exception: "+e.toString()); - //e.printStackTrace(); } - return null; -} } diff --git a/src/Java/miscutil/core/xmod/gregtech/api/gui/CONTAINER_SafeBlock.java b/src/Java/miscutil/core/xmod/gregtech/api/gui/CONTAINER_SafeBlock.java index 520787e286..1145ebfa67 100644 --- a/src/Java/miscutil/core/xmod/gregtech/api/gui/CONTAINER_SafeBlock.java +++ b/src/Java/miscutil/core/xmod/gregtech/api/gui/CONTAINER_SafeBlock.java @@ -3,6 +3,9 @@ package miscutil.core.xmod.gregtech.api.gui; import gregtech.api.gui.GT_ContainerMetaTile_Machine; import gregtech.api.gui.GT_Slot_Holo; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; + +import java.util.UUID; + import miscutil.core.util.player.PlayerCache; import miscutil.core.xmod.gregtech.api.metatileentity.implementations.GregtechMetaSafeBlock; import net.minecraft.entity.player.EntityPlayer; @@ -17,7 +20,7 @@ extends GT_ContainerMetaTile_Machine { } //public String UUID = ((BaseMetaTileEntity)mTileEntity).getMetaTileEntity().getBaseMetaTileEntity().getOwnerName(); - public String ownerUUID = ((GregtechMetaSafeBlock)this.mTileEntity.getMetaTileEntity()).ownerUUID; + public UUID ownerUUID = ((GregtechMetaSafeBlock)this.mTileEntity.getMetaTileEntity()).ownerUUID; public String tempPlayer = PlayerCache.lookupPlayerByUUID(ownerUUID); public boolean blockStatus = ((GregtechMetaSafeBlock)this.mTileEntity.getMetaTileEntity()).bUnbreakable; diff --git a/src/Java/miscutil/core/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java b/src/Java/miscutil/core/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java index 47d27784b9..d9d69dc294 100644 --- a/src/Java/miscutil/core/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java +++ b/src/Java/miscutil/core/xmod/gregtech/api/metatileentity/implementations/base/machines/GregtechMetaSafeBlockBase.java @@ -7,6 +7,9 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_TieredMachineBlock; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Utility; + +import java.util.UUID; + import miscutil.core.handler.events.UnbreakableBlockManager; import miscutil.core.util.Utils; import miscutil.core.util.player.PlayerCache; @@ -17,7 +20,7 @@ import net.minecraft.nbt.NBTTagCompound; public abstract class GregtechMetaSafeBlockBase extends GT_MetaTileEntity_TieredMachineBlock { public boolean bOutput = false, bRedstoneIfFull = false, bInvert = false, bUnbreakable = false; public int mSuccess = 0, mTargetStackSize = 0; - public String ownerUUID = ""; + public UUID ownerUUID; UnbreakableBlockManager Xasda = new UnbreakableBlockManager(); private boolean value_last = false, value_current = false; @@ -188,7 +191,7 @@ public abstract class GregtechMetaSafeBlockBase extends GT_MetaTileEntity_Tiered } if (!aPlayer.equals(null)) { - String tempUUID = aPlayer.getUniqueID().toString(); + UUID tempUUID = aPlayer.getUniqueID(); PlayerCache.appendParamChanges(aPlayer.getDisplayName(), aPlayer.getUniqueID().toString()); if (ownerUUID.equals("")){ Utils.LOG_WARNING("No owner yet for this block."); @@ -241,7 +244,7 @@ public abstract class GregtechMetaSafeBlockBase extends GT_MetaTileEntity_Tiered aNBT.setBoolean("bOutput", bOutput); aNBT.setBoolean("bRedstoneIfFull", bRedstoneIfFull); aNBT.setInteger("mTargetStackSize", mTargetStackSize); - aNBT.setString("ownerUUID", ownerUUID); + aNBT.setString("ownerUUID", ownerUUID.toString()); } @Override @@ -250,7 +253,7 @@ public abstract class GregtechMetaSafeBlockBase extends GT_MetaTileEntity_Tiered bOutput = aNBT.getBoolean("bOutput"); bRedstoneIfFull = aNBT.getBoolean("bRedstoneIfFull"); mTargetStackSize = aNBT.getInteger("mTargetStackSize"); - ownerUUID = aNBT.getString("ownerUUID"); + ownerUUID = UUID.fromString(aNBT.getString("ownerUUID")); } @Override |