Skip to content

Commit

Permalink
Cache SRP functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrptonaught committed Mar 11, 2024
1 parent 114a307 commit 781f084
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public class SwitchableResourcepacksMod extends ModuleWConfig<ResourcePackConfig

public static final HashMap<UUID, PackStatus> playerLoaded = new HashMap<>();

private static Collection<CommandFunction<ServerCommandSource>> RP_FAILED_FUNCTIONS, RP_LOADED_FUNCTIONS;

public void onConfigLoad(ResourcePackConfig config) {
RP_FAILED_FUNCTIONS = null;
RP_LOADED_FUNCTIONS = null;
rpOptionHashMap.clear();
config.packs.forEach(rpOption -> rpOptionHashMap.put(rpOption.packname, rpOption));

Expand Down Expand Up @@ -84,10 +88,15 @@ public static void packStatusUpdate(ServerPlayerEntity player, UUID packname, Pa
playerLoaded.get(player.getUuid()).setPackLoadStatus(packname, status);

if (allPacksLoaded(player)) {
if(RP_LOADED_FUNCTIONS == null)
RP_LOADED_FUNCTIONS = getFunctions(player.getServer(), ServerUtilsMod.SwitchableResourcepacksModule.getConfig().playerCompleteFunction);
if(RP_FAILED_FUNCTIONS == null)
RP_FAILED_FUNCTIONS = getFunctions(player.getServer(), ServerUtilsMod.SwitchableResourcepacksModule.getConfig().playerFailedFunction);

if (didPackFail(player))
CMDHelper.executeAs(player, getFunctions(player.getServer(), ServerUtilsMod.SwitchableResourcepacksModule.getConfig().playerFailedFunction));
CMDHelper.executeAs(player, RP_FAILED_FUNCTIONS);
else
CMDHelper.executeAs(player, getFunctions(player.getServer(), ServerUtilsMod.SwitchableResourcepacksModule.getConfig().playerCompleteFunction));
CMDHelper.executeAs(player, RP_LOADED_FUNCTIONS);
}
}

Expand Down

0 comments on commit 781f084

Please sign in to comment.