Skip to content

Commit

Permalink
Merge pull request #325 from ClubObsidian/fix/caching
Browse files Browse the repository at this point in the history
Fix gui and macro caching
  • Loading branch information
virustotalop committed Jul 7, 2023
2 parents f46056c + 74bf5ad commit 93afd4a
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,14 @@ private void loadGlobalMacroFromFile(File file) {
String macroName = file.getName().substring(0, file.getName().lastIndexOf("."));
byte[] fileHash = HashUtil.getMD5(file);
byte[] cachedHash = this.globalMacrosTimestamps.get(macroName);
if (cachedHash == null || fileHash != cachedHash) {
if (cachedHash == null || !Arrays.equals(fileHash, cachedHash)) {
List<MacroToken> tokens = new ArrayList<>();
Configuration config = Configuration.load(file);
for (Object key : config.getKeys()) {
ConfigurationSection section = config.getConfigurationSection(key);
MacroToken token = new SimpleMacroToken(section);
tokens.add(token);
}

this.modifiedMacros.add(macroName);
this.globalMacrosTimestamps.put(macroName, fileHash);
this.globalMacros.put(macroName, tokens);
Expand Down Expand Up @@ -314,11 +313,15 @@ private void loadGuiFromFile(Configuration yaml, File file) {
DynamicGui dynamicGui = DynamicGui.get();
try {
String guiName = file.getName().substring(0, file.getName().lastIndexOf("."));
Gui cachedGui = this.cachedGuis.get(guiName);
byte[] cachedHash = this.guiHashes.get(guiName);
GuiToken token = this.cachedTokens.get(guiName);
byte[] guiHash = HashUtil.getMD5(file);
if (token != null && cachedHash != null && cachedHash == guiHash && !hasUpdatedMacro(token)) {
Gui cachedGui = this.cachedGuis.get(guiName);
if (cachedGui != null
&& token != null
&& cachedHash != null
&& Arrays.equals(cachedHash, guiHash)
&& !hasUpdatedMacro(token)) {
for (String alias : token.getAlias()) {
this.commandRegistrar.registerGuiAliasCommand(guiName, alias, token.getCommandArguments());
}
Expand Down

0 comments on commit 93afd4a

Please sign in to comment.