Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class DefaultConfig extends ConfigurationFile {
@Getter
private static boolean forceResourcePack;
@Getter
private static boolean autoMixOnStartup;
@Getter
private static String resourcePackPrompt;
@Getter
private static String resourcePackRerouting;
Expand Down Expand Up @@ -54,6 +56,11 @@ public void initializeValues() {
forceResourcePack = ConfigurationEngine.setBoolean(
List.of("Sets whether the resource pack use will be forced to clients"),
fileConfiguration, "forceResourcePack", false);
autoMixOnStartup = ConfigurationEngine.setBoolean(
List.of(
"Enable automatic resource pack mixing when the server starts.",
"If disabled, ResourcePackManager will wait for a resource pack change or manual reload before mixing."),
fileConfiguration, "autoMixOnStartup", true);
resourcePackPrompt = ConfigurationEngine.setString(
List.of("Sets whether the resource pack use will be forced to clients"),
fileConfiguration, "resourcePackPrompt", "Use recommended resource pack?");
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/magmaguy/resourcepackmanager/mixer/Mix.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,24 @@ private static void createOutputDefaultElements() {
// generateBedrockResourcePack();
}

public static boolean loadExistingFinalResourcePack() {
if (finalResourcePack != null) return true;
File possiblePack = new File(getOutputFolder().getAbsolutePath() + File.separatorChar + resourcePackName + ".zip");
if (!possiblePack.exists()) return false;
try {
finalResourcePack = possiblePack;
finalSHA1 = SHA1Generator.sha1CodeString(finalResourcePack);
finalSHA1Bytes = SHA1Generator.sha1CodeByteArray(finalResourcePack);
return true;
} catch (Exception e) {
Logger.warn("Failed to load existing merged resource pack from disk.");
finalResourcePack = null;
finalSHA1 = null;
finalSHA1Bytes = null;
return false;
}
}

private static File getOutputFolder() {
return new File(ResourcePackManager.plugin.getDataFolder().getAbsolutePath() + File.separatorChar + "output");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public ThirdPartyResourcePack(String pluginName, String localPath, String url, b
}

private static BukkitTask resourcePackChangeWatcher = null;
private static boolean initialStartup = true;

/**
* Checks whether a monitored plugin has finished its Magmacore initialization.
Expand Down Expand Up @@ -189,13 +190,30 @@ public void run() {
}

if (!stableAlreadySent && readyToSend) {
if (!DefaultConfig.isAutoMixOnStartup() && initialStartup) {
Logger.info("Automatic resource pack mixing on startup is disabled. Waiting for resource pack changes or manual reload before mixing.");
tagAsResourcePackSent();
initialStartup = false;
return;
}

notifyResourcePackSending();
tagAsResourcePackSent();
initialStartup = false;
Logger.info("Sending resource pack now.");
Bukkit.getScheduler().runTaskAsynchronously(ResourcePackManager.plugin, Mix::mixResourcePacks);
}
}
}.runTaskTimerAsynchronously(ResourcePackManager.plugin, 20, 20);

if (!DefaultConfig.isAutoMixOnStartup()) {
if (Mix.loadExistingFinalResourcePack()) {
Logger.info("autoMixOnStartup is disabled, reusing the last merged resource pack from disk.");
AutoHost.initialize();
} else {
Logger.info("autoMixOnStartup is disabled and no existing merged resource pack was found. Waiting for changes.");
}
}
}

public static void tagAsResourcePackSent(){
Expand Down