Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/main/java/betterquesting/api/storage/BQ_Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class BQ_Settings {

public static boolean spawnWithQuestBook = true;
public static boolean saveQuestsWithNames = false;
public static boolean updateDefaultQuestsOnStartup = true;

public static int retrievalDetectionDelay = 20;
}
43 changes: 14 additions & 29 deletions src/main/java/betterquesting/client/gui2/GuiHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import betterquesting.api.properties.NativeProps;
import betterquesting.api.questing.party.IParty;
import betterquesting.api.storage.BQ_Settings;
import betterquesting.api.utils.JsonHelper;
import betterquesting.api.utils.NBTConverter;
import betterquesting.api2.client.gui.GuiScreenCanvas;
import betterquesting.api2.client.gui.controls.IPanelButton;
import betterquesting.api2.client.gui.controls.PanelButton;
Expand All @@ -30,25 +28,22 @@
import betterquesting.client.gui2.party.GuiPartyCreate;
import betterquesting.client.gui2.party.GuiPartyManage;
import betterquesting.client.gui3.GuiStatus;
import betterquesting.commands.admin.QuestCommandDefaults;
import betterquesting.handlers.ConfigHandler;
import betterquesting.handlers.SaveLoadHandler;
import betterquesting.network.handlers.NetChapterSync;
import betterquesting.network.handlers.NetQuestSync;
import betterquesting.network.handlers.NetSettingSync;
import betterquesting.questing.QuestDatabase;
import betterquesting.questing.QuestLineDatabase;
import betterquesting.questing.party.PartyManager;
import betterquesting.storage.QuestSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.Level;
import org.lwjgl.util.vector.Vector4f;

import java.io.File;
Expand Down Expand Up @@ -179,33 +174,23 @@ private void onButtonPress(PanelEvent event) {
}));
} else if (btn.getButtonID() == 5) // Update me
{
final File qFile = new File(BQ_Settings.defaultDir, "DefaultQuests.json");
final File dir = new File(BQ_Settings.defaultDir, QuestCommandDefaults.DEFAULT_FILE);
final File file = new File(BQ_Settings.defaultDir, QuestCommandDefaults.DEFAULT_FILE + ".json");

if (qFile.exists()) {
if (dir.exists()) {
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> {
boolean editMode = QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
boolean hardMode = QuestSettings.INSTANCE.getProperty(NativeProps.HARDCORE);

NBTTagList jsonP = QuestDatabase.INSTANCE.writeProgressToNBT(new NBTTagList(), null);
NBTTagCompound j1 = NBTConverter.JSONtoNBT_Object(JsonHelper.ReadFromFile(qFile), new NBTTagCompound(), true);
QuestSettings.INSTANCE.readFromNBT(j1.getCompoundTag("questSettings"));
QuestDatabase.INSTANCE.readFromNBT(j1.getTagList("questDatabase", 10), false);
QuestLineDatabase.INSTANCE.readFromNBT(j1.getTagList("questLines", 10), false);
QuestDatabase.INSTANCE.readProgressFromNBT(jsonP, false);

QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, editMode);
QuestSettings.INSTANCE.setProperty(NativeProps.HARDCORE, hardMode);

NetSettingSync.sendSync(null);
NetQuestSync.quickSync(-1, true, true);
NetChapterSync.sendSync(null, null);

QuestCommandDefaults.load(null, null, dir, false);
SaveLoadHandler.INSTANCE.resetUpdate();
SaveLoadHandler.INSTANCE.markDirty();
});

//this.initGui(); // Reset the whole thing
mc.displayGuiScreen(null);
} else if (file.exists()) {
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> {
QuestCommandDefaults.loadLegacy(null, null, file, false);
SaveLoadHandler.INSTANCE.resetUpdate();
});
mc.displayGuiScreen(null);
} else {
QuestingAPI.getLogger().log(Level.WARN, "Could not update the quest database, as neither directory nor file exists");
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/betterquesting/handlers/ConfigHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public static void initConfigs() {

BQ_Settings.spawnWithQuestBook = config.getBoolean("Spawn with Quest Book", Configuration.CATEGORY_GENERAL, true, "If true, then the player will spawn with a Quest Book when they first join the world");
BQ_Settings.saveQuestsWithNames = config.getBoolean("DefaultQuests saves using Names", Configuration.CATEGORY_GENERAL, false, "If true, whenever you save your quests, they will have the first 16 characters of the quest name in the file name, this is useful if you want to be easily able to identify quests in file explorer, however it is less compatible when using version control.");
BQ_Settings.updateDefaultQuestsOnStartup = config.getBoolean("Load DefaultQuests when an Update is Available", Configuration.CATEGORY_GENERAL, true, "When the pack version of the DefaultQuests config is higher than the current version, attempt to load the config");

BQ_Settings.retrievalDetectionDelay = config.getInt("Retrieval Task Detection Interval", Configuration.CATEGORY_GENERAL, 20, 1, 200, "The delay, in ticks, after which quests with retrieval tasks will detect changes");
config.save();
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/betterquesting/handlers/SaveLoadHandler.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package betterquesting.handlers;

import betterquesting.api.api.QuestingAPI;
import betterquesting.api.events.DatabaseEvent;
import betterquesting.api.events.DatabaseEvent.DBType;
import betterquesting.api.properties.NativeProps;
Expand All @@ -13,7 +14,6 @@
import betterquesting.core.BetterQuesting;
import betterquesting.core.ModReference;
import betterquesting.legacy.ILegacyLoader;
import betterquesting.legacy.LegacyLoaderRegistry;
import betterquesting.questing.QuestDatabase;
import betterquesting.questing.QuestLineDatabase;
import betterquesting.questing.party.PartyInvitations;
Expand All @@ -28,6 +28,7 @@
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
import org.apache.logging.log4j.Level;

import java.io.File;
import java.util.*;
Expand Down Expand Up @@ -237,9 +238,29 @@ private void loadConfig() {
QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, false); // Force edit off
}

if (packName.equals(QuestSettings.INSTANCE.getProperty(NativeProps.PACK_NAME)) && packVer > QuestSettings.INSTANCE.getProperty(NativeProps.PACK_VER)) {
if (BQ_Settings.updateDefaultQuestsOnStartup) {
attemptUpdate();
// mark it as having an update if the new pack version doesn't match that from the settings.
hasUpdate = packVer != QuestSettings.INSTANCE.getProperty(NativeProps.PACK_VER);
} else {
hasUpdate = true;
}
}
}

private void attemptUpdate() {
final File dir = new File(BQ_Settings.defaultDir, QuestCommandDefaults.DEFAULT_FILE);
final File file = new File(BQ_Settings.defaultDir, QuestCommandDefaults.DEFAULT_FILE + ".json");

hasUpdate = packName.equals(QuestSettings.INSTANCE.getProperty(NativeProps.PACK_NAME)) && packVer > QuestSettings.INSTANCE.getProperty(NativeProps.PACK_VER);
QuestingAPI.getLogger().log(Level.INFO, "Attempting to load quest data...");
if (dir.exists()) {
QuestCommandDefaults.load(null, null, dir, false);
} else if (file.exists()) {
QuestCommandDefaults.loadLegacy(null, null, file, false);
} else {
QuestingAPI.getLogger().log(Level.WARN, "Could not update the quest database, as neither directory nor file exists");
}
}

private void loadProgress() {
Expand Down