diff --git a/src/main/java/kamkeel/npcs/controllers/SyncController.java b/src/main/java/kamkeel/npcs/controllers/SyncController.java index 01e4208f6..1b936cd9b 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncController.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncController.java @@ -165,7 +165,7 @@ public class SyncController { public static NBTTagCompound customEffectsNBT(){ NBTTagList list = new NBTTagList(); NBTTagCompound compound = new NBTTagCompound(); - for (CustomEffect effect : CustomEffectController.getInstance().customEffects.values()) { + for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) { list.appendTag(effect.writeToNBT(false)); } compound.setTag("Data", list); @@ -396,16 +396,18 @@ public class SyncController { } case CUSTOM_EFFECTS: { NBTTagList list = fullCompound.getTagList("Data", 10); + CustomEffectController ce = CustomEffectController.getInstance(); + ce.customEffectsSync.clear(); for (int i = 0; i < list.tagCount(); i++) { CustomEffect effect = new CustomEffect(); effect.readFromNBT(list.getCompoundTagAt(i)); ClientCacheHandler.getImageData(effect.icon); - CustomEffectController.getInstance().customEffectsSync.put(effect.id, effect); + ce.customEffectsSync.put(effect.id, effect); } - CustomEffectController.getInstance().customEffects = CustomEffectController.getInstance().customEffectsSync; - CustomEffectController.getInstance().customEffectsSync = new HashMap<>(); - CustomEffectController.getInstance().registerEffectMap(0, CustomEffectController.getInstance().customEffects); + ce.getCustomEffects().clear(); + ce.getCustomEffects().putAll(ce.customEffectsSync); + ce.customEffectsSync.clear(); break; } } @@ -486,7 +488,7 @@ public class SyncController { effect.readFromNBT(compound); ClientCacheHandler.getImageData(effect.icon); - CustomEffectController.Instance.customEffects.put(effect.id, effect); + CustomEffectController.Instance.getCustomEffects().put(effect.id, effect); break; } } @@ -559,7 +561,7 @@ public class SyncController { case MAGIC: break; case CUSTOM_EFFECTS: - CustomEffectController.Instance.customEffects.remove(id); + CustomEffectController.Instance.getCustomEffects().remove(id); break; } } diff --git a/src/main/java/noppes/npcs/NoppesUtilServer.java b/src/main/java/noppes/npcs/NoppesUtilServer.java index 5111262b6..f1cbe9118 100644 --- a/src/main/java/noppes/npcs/NoppesUtilServer.java +++ b/src/main/java/noppes/npcs/NoppesUtilServer.java @@ -658,7 +658,7 @@ public class NoppesUtilServer { public static void sendCustomEffectDataAll(EntityPlayerMP player) { Map map = new HashMap(); - for (CustomEffect effect : CustomEffectController.getInstance().customEffects.values()) { + for (CustomEffect effect : CustomEffectController.getInstance().getCustomEffects().values()) { map.put(effect.name, effect.id); } ScrollDataPacket.sendScrollData(player, map); diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java b/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java index 4e851ab65..6c33d9731 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiEffectGeneral.java @@ -131,7 +131,7 @@ public class SubGuiEffectGeneral extends SubGuiInterface implements ITextfieldLi // TODO: FIX TEXTURE // textureManager.bindTexture(new ResourceLocation(CustomNpcPlusDBC.ID + ":textures/gui/icons.png")); - func_152125_a(x, y, 0, 240, 16, 16, iconRenderSize, iconRenderSize, 256, 256); + // func_152125_a(x, y, 0, 240, 16, 16, iconRenderSize, iconRenderSize, 256, 256); GL11.glEnable(GL11.GL_DEPTH_TEST); } }; diff --git a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java index 8e5c10739..2b27317d4 100644 --- a/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java +++ b/src/main/java/noppes/npcs/client/gui/global/GuiNPCManageEffects.java @@ -112,7 +112,7 @@ public class GuiNPCManageEffects extends GuiNPCInterface2 implements ICustomScro effect.readFromNBT(compound); setSelected(effect.name); if (effect.id != -1) { - CustomEffectController.getInstance().customEffects.replace(effect.id, effect); + CustomEffectController.getInstance().getCustomEffects().replace(effect.id, effect); } initGui(); } diff --git a/src/main/java/noppes/npcs/controllers/CustomEffectController.java b/src/main/java/noppes/npcs/controllers/CustomEffectController.java index f336fa68f..17387ce51 100644 --- a/src/main/java/noppes/npcs/controllers/CustomEffectController.java +++ b/src/main/java/noppes/npcs/controllers/CustomEffectController.java @@ -34,7 +34,6 @@ public class CustomEffectController implements ICustomEffectHandler { public HashMap> indexMapper = new HashMap<>(); public HashMap customEffectsSync = new HashMap<>(); - public HashMap customEffects = new HashMap<>(); public HashMap customEffectScriptHandlers = new HashMap<>(); private HashMap bootOrder; @@ -42,15 +41,21 @@ public class CustomEffectController implements ICustomEffectHandler { private int lastUsedID = 0; public ConcurrentHashMap> playerEffects = new ConcurrentHashMap<>(); - public CustomEffectController(){} + public CustomEffectController(){ + HashMap customEffects = new HashMap<>(); + registerEffectMap(0, customEffects); + } public static CustomEffectController getInstance() { return Instance; } public void registerEffectMap(int index, HashMap effectHashMap) { - HashMap map = new HashMap<>(effectHashMap); - indexMapper.put(index, map); + indexMapper.put(index, (HashMap) effectHashMap); + } + + public HashMap getCustomEffects(){ + return indexMapper.get(0); } public void load() { @@ -104,12 +109,12 @@ public class CustomEffectController implements ICustomEffectHandler { if (effect.id == -1) { int id = getUnusedId(); - while (customEffects.containsKey(id)) { + while (getCustomEffects().containsKey(id)) { id = getUnusedId(); } effect.id = id; } - customEffects.put(effect.id, effect); + getCustomEffects().put(effect.id, effect); return effect; } @@ -122,14 +127,14 @@ public class CustomEffectController implements ICustomEffectHandler { public void deleteEffect(String name) { ICustomEffect effect = getEffect(name); if (effect != null) { - CustomEffect foundEffect = customEffects.remove(effect.getID()); + CustomEffect foundEffect = getCustomEffects().remove(effect.getID()); customEffectScriptHandlers.remove(effect.getID()); if (foundEffect != null && foundEffect.name != null) { File dir = this.getDir(); for (File file : dir.listFiles()) { if (!file.isFile() || !file.getName().endsWith(".json")) continue; - if (file.getName().equals(foundEffect.name + ".json")) { + if (file.getName().equalsIgnoreCase(foundEffect.name + ".json")) { file.delete(); SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID()); break; @@ -143,14 +148,14 @@ public class CustomEffectController implements ICustomEffectHandler { public void delete(int id) { ICustomEffect effect = get(id); if (effect != null) { - CustomEffect foundEffect = customEffects.remove(effect.getID()); + CustomEffect foundEffect = getCustomEffects().remove(effect.getID()); customEffectScriptHandlers.remove(effect.getID()); if (foundEffect != null && foundEffect.name != null) { File dir = this.getDir(); for (File file : dir.listFiles()) { if (!file.isFile() || !file.getName().endsWith(".json")) continue; - if (file.getName().equals(foundEffect.name + ".json")) { + if (file.getName().equalsIgnoreCase(foundEffect.name + ".json")) { file.delete(); SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID()); break; @@ -162,7 +167,7 @@ public class CustomEffectController implements ICustomEffectHandler { } public int getUnusedId() { - for (int catid : customEffects.keySet()) { + for (int catid : getCustomEffects().keySet()) { if (catid > lastUsedID) lastUsedID = catid; } @@ -300,14 +305,14 @@ public class CustomEffectController implements ICustomEffectHandler { while (has(customEffect.getName())) customEffect.setName(customEffect.getName() + "_"); } else { - CustomEffect existing = customEffects.get(customEffect.getID()); - if (existing != null && !existing.name.equals(customEffect.getName())) + CustomEffect existing = getCustomEffects().get(customEffect.getID()); + if (existing != null && !existing.name.equalsIgnoreCase(customEffect.getName())) while (has(customEffect.getName())) customEffect.setName(customEffect.getName() + "_"); } - customEffects.remove(customEffect.getID()); - customEffects.put(customEffect.getID(), (CustomEffect) customEffect); + getCustomEffects().remove(customEffect.getID()); + getCustomEffects().put(customEffect.getID(), (CustomEffect) customEffect); saveEffectLoadMap(); @@ -329,7 +334,7 @@ public class CustomEffectController implements ICustomEffectHandler { } catch (Exception e) { LogWriter.except(e); } - return customEffects.get(customEffect.getID()); + return getCustomEffects().get(customEffect.getID()); } public void clearEffects(EntityPlayer player) { @@ -437,7 +442,7 @@ public class CustomEffectController implements ICustomEffectHandler { } private void loadCustomEffects() { - customEffects.clear(); + getCustomEffects().clear(); File dir = getDir(); if (!dir.exists()) { @@ -455,9 +460,9 @@ public class CustomEffectController implements ICustomEffectHandler { } int originalID = effect.id; int setID = effect.id; - while (bootOrder.containsKey(setID) || customEffects.containsKey(setID)) { + while (bootOrder.containsKey(setID) || getCustomEffects().containsKey(setID)) { if (bootOrder.containsKey(setID)) - if (bootOrder.get(setID).equals(effect.name)) + if (bootOrder.get(setID).equalsIgnoreCase(effect.name)) break; setID++; } @@ -466,13 +471,13 @@ public class CustomEffectController implements ICustomEffectHandler { LogWriter.info("Found Custom Effect ID Mismatch: " + effect.name + ", New ID: " + setID); effect.save(); } - customEffects.put(effect.id, effect); + getCustomEffects().put(effect.id, effect); } catch (Exception e) { LogWriter.error("Error loading: " + file.getAbsolutePath(), e); } } } - this.registerEffectMap(0, customEffects); + this.registerEffectMap(0, getCustomEffects()); saveEffectLoadMap(); } @@ -513,8 +518,8 @@ public class CustomEffectController implements ICustomEffectHandler { private NBTTagCompound writeMapNBT() { NBTTagCompound nbt = new NBTTagCompound(); NBTTagList customEffectsList = new NBTTagList(); - for (Integer key : this.customEffects.keySet()) { - CustomEffect customEffect = this.customEffects.get(key); + for (Integer key : this.getCustomEffects().keySet()) { + CustomEffect customEffect = this.getCustomEffects().get(key); if (!customEffect.getName().isEmpty()) { NBTTagCompound effectCompound = new NBTTagCompound(); effectCompound.setString("Name", customEffect.getName());