aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-12-11 00:57:21 +0100
committernea <romangraef@gmail.com>2022-12-18 22:32:50 +0100
commit4586700dc86d8061d2c627ea5b3559f26b09061b (patch)
tree672afd0ecafcb67175b0712aa90e4106f48b5a5c /src/main
parent4386cab2308f39b35a5ea156216117aedfe9263e (diff)
downloadNotEnoughUpdates-feat/jsonkey.tar.gz
NotEnoughUpdates-feat/jsonkey.tar.bz2
NotEnoughUpdates-feat/jsonkey.zip
RepoEditing: Allow opening files in the external editorfeat/jsonkey
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java8
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java29
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java13
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java3
4 files changed, 46 insertions, 7 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index ca0d91d2..ce15b09a 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -288,7 +288,7 @@ public class NEUManager {
public void loadItem(String internalName) {
itemstackCache.remove(internalName);
try {
- JsonObject json = getJsonFromFile(new File(new File(repoLocation, "items"), internalName + ".json"));
+ JsonObject json = getJsonFromFile(getItemFileForInternalName(internalName));
if (json == null) {
return;
}
@@ -971,6 +971,10 @@ public class NEUManager {
return getUUIDFromNBT(tag);
}
+ public File getItemFileForInternalName(String internalName) {
+ return new File(new File(repoLocation, "items"), internalName + ".json");
+ }
+
public void writeItemToFile(ItemStack stack) {
String internalname = getInternalNameForItem(stack);
@@ -984,7 +988,7 @@ public class NEUManager {
json.addProperty("modver", NotEnoughUpdates.VERSION);
try {
- writeJson(json, new File(new File(repoLocation, "items"), internalname + ".json"));
+ writeJson(json, getItemFileForInternalName(internalname));
} catch (IOException ignored) {
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
index cff83cca..686f6a27 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java
@@ -46,6 +46,7 @@ import io.github.moulberry.notenoughupdates.util.LerpingFloat;
import io.github.moulberry.notenoughupdates.util.NotificationHandler;
import io.github.moulberry.notenoughupdates.util.SpecialColour;
import io.github.moulberry.notenoughupdates.util.Utils;
+import lombok.var;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
@@ -84,8 +85,10 @@ import org.lwjgl.opengl.GL14;
import org.lwjgl.util.vector.Vector2f;
import java.awt.*;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@@ -1156,8 +1159,30 @@ public class NEUOverlay extends Gui {
manager.jsonToStack(item));
}
} else if (NotEnoughUpdates.INSTANCE.config.apiData.repositoryEditing &&
- Keyboard.getEventCharacter() == 'k') {
- Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(internalname.get(), item));
+ keyPressed == Keyboard.KEY_K) {
+ if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
+ var externalEditorCommand = NotEnoughUpdates.INSTANCE.config.hidden.externalEditor;
+ if (externalEditorCommand == null) {
+ Utils.addChatMessage(
+ "§e[NEU] §3No external editor set! Run §b/neudevtest exteditor <editorcommand>§3 " +
+ "to set your external editor. Optionally use {} as a placeholder for the filename.");
+ } else {
+ var externalFileName = manager.getItemFileForInternalName(internalname.get()).getAbsolutePath();
+ if (externalEditorCommand.contains("{}")) {
+ externalEditorCommand = externalEditorCommand.replace("{}", externalFileName);
+ } else {
+ externalEditorCommand += " " + externalFileName;
+ }
+ try {
+ Runtime.getRuntime().exec(externalEditorCommand);
+ } catch (IOException e) {
+ Utils.addChatMessage("§e[NEU]§4 Could not open external editor.");
+ e.printStackTrace();
+ }
+ }
+ } else {
+ Minecraft.getMinecraft().displayGuiScreen(new NEUItemEditor(internalname.get(), item));
+ }
return true;
} else if (keyPressed == manager.keybindItemSelect.getKeyCode() &&
NotEnoughUpdates.INSTANCE.config.toolbar.searchBar) {
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
index 69033345..cf266dca 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.java
@@ -19,20 +19,17 @@
package io.github.moulberry.notenoughupdates.commands.dev;
-import com.google.gson.Gson;
import io.github.moulberry.notenoughupdates.BuildFlags;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.commands.ClientCommandBase;
import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor;
import io.github.moulberry.notenoughupdates.core.util.MiscUtils;
import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper;
-import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay;
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes;
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent;
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone;
import io.github.moulberry.notenoughupdates.miscgui.GuiPriceGraph;
import io.github.moulberry.notenoughupdates.miscgui.minionhelper.MinionHelperManager;
-import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer;
import io.github.moulberry.notenoughupdates.util.PronounDB;
import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.TabListUtils;
@@ -142,6 +139,16 @@ public class DevTestCommand extends ClientCommandBase {
.collect(Collectors.joining("\n"))));
return;
}
+ if (args.length >= 1 && args[0].equalsIgnoreCase("exteditor")) {
+ if (args.length > 1) {
+ NotEnoughUpdates.INSTANCE.config.hidden.externalEditor = String.join(
+ " ",
+ Arrays.copyOfRange(args, 1, args.length)
+ );
+ }
+ Utils.addChatMessage("§e[NEU] §fYour external editor is: §Z" + NotEnoughUpdates.INSTANCE.config.hidden.externalEditor);
+ return;
+ }
if (args.length >= 1 && args[0].equalsIgnoreCase("pricetest")) {
if (args.length == 1) {
NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar();
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
index f936ceb1..b5237a46 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/options/NEUConfig.java
@@ -456,6 +456,9 @@ public class NEUConfig extends Config {
@Expose
public boolean hasOpenedWaypointMenu = false;
+ @Expose
+ public String externalEditor = null;
+
}
public static ArrayList<String> createDefaultEnchantColours() {