mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-12 12:33:54 +00:00
Show a message with install instructions when running the jar file
Co-Authored-By: Matthew Miller <mnmiller1@me.com>
This commit is contained in:
@ -34,11 +34,32 @@ import javax.annotation.Nullable;
|
||||
public class WorldEditManifest {
|
||||
|
||||
public static final String WORLD_EDIT_VERSION = "WorldEdit-Version";
|
||||
public static final String WORLD_EDIT_KIND = "WorldEdit-Kind";
|
||||
|
||||
public enum Kind {
|
||||
MOD("mods"),
|
||||
PLUGIN("plugins"),
|
||||
UNKNOWN("mods/plugins"),
|
||||
;
|
||||
|
||||
public final String folderName;
|
||||
|
||||
Kind(String folderName) {
|
||||
this.folderName = folderName;
|
||||
}
|
||||
}
|
||||
|
||||
public static WorldEditManifest load() {
|
||||
Attributes attributes = readAttributes();
|
||||
Kind kind;
|
||||
try {
|
||||
kind = Kind.valueOf(readAttribute(attributes, WORLD_EDIT_KIND, () -> "UNKNOWN"));
|
||||
} catch (IllegalArgumentException e) {
|
||||
kind = Kind.UNKNOWN;
|
||||
}
|
||||
return new WorldEditManifest(
|
||||
readAttribute(attributes, WORLD_EDIT_VERSION, () -> "(unknown)")
|
||||
readAttribute(attributes, WORLD_EDIT_VERSION, () -> "(unknown)"),
|
||||
kind
|
||||
);
|
||||
}
|
||||
|
||||
@ -71,12 +92,18 @@ public class WorldEditManifest {
|
||||
}
|
||||
|
||||
private final String worldEditVersion;
|
||||
private final Kind worldEditKind;
|
||||
|
||||
private WorldEditManifest(String worldEditVersion) {
|
||||
private WorldEditManifest(String worldEditVersion, Kind worldEditKind) {
|
||||
this.worldEditVersion = worldEditVersion;
|
||||
this.worldEditKind = worldEditKind;
|
||||
}
|
||||
|
||||
public String getWorldEditVersion() {
|
||||
return worldEditVersion;
|
||||
}
|
||||
|
||||
public Kind getWorldEditKind() {
|
||||
return worldEditKind;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.internal.util;
|
||||
|
||||
import com.sk89q.worldedit.WorldEditManifest;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.text.html.HTMLDocument;
|
||||
import javax.swing.text.html.HTMLEditorKit;
|
||||
|
||||
public class InfoEntryPoint {
|
||||
|
||||
private static final String INSTALL_URL = "https://wiki.intellectualsites.com/FastAsyncWorldEdit";
|
||||
private static final String SUPPORT_URL = "https://discord.gg/intellectualsites";
|
||||
|
||||
private static String getMessage(boolean html) {
|
||||
WorldEditManifest manifest = WorldEditManifest.load();
|
||||
|
||||
return "To install FastAsyncWorldEdit, place it in the "
|
||||
+ manifest.getWorldEditKind().folderName + " folder.\n"
|
||||
+ "For more detailed instructions, see " + formatLink(INSTALL_URL, html) + "\n"
|
||||
+ "For further help, check out our support Discord at "
|
||||
+ formatLink(SUPPORT_URL, html) + "\n"
|
||||
+ "\n"
|
||||
+ "Version: " + manifest.getWorldEditVersion() + "\n";
|
||||
}
|
||||
|
||||
private static String formatLink(String url, boolean html) {
|
||||
return html ? String.format("<a href=\"%1$s\">%1$s</a>", url) : url;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (System.console() != null) {
|
||||
System.err.println(getMessage(false));
|
||||
} else {
|
||||
System.setProperty("awt.useSystemAAFontSettings", "lcd");
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
new NavigableEditorPane(getMessage(true)),
|
||||
"FastAsyncWorldEdit",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
}
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private static class NavigableEditorPane extends JTextPane {
|
||||
public NavigableEditorPane(String htmlBody) {
|
||||
super(new HTMLDocument());
|
||||
setEditorKit(new HTMLEditorKit());
|
||||
setText(htmlBody.replace("\n", "<br>"));
|
||||
setBackground(UIManager.getColor("Panel.background"));
|
||||
|
||||
addHyperlinkListener(e -> {
|
||||
if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(e.getURL().toURI());
|
||||
} catch (IOException | URISyntaxException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
setEditable(false);
|
||||
setBorder(null);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user