From 0b65533294e24a2b301a414cb8b603bafc14951a Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Thu, 25 Feb 2021 22:58:17 +0100 Subject: [PATCH] Show a message with install instructions when running the jar file Co-Authored-By: Matthew Miller --- buildSrc/src/main/kotlin/PlatformConfig.kt | 27 ++++++ config/checkstyle/checkstyle.xml | 8 +- worldedit-bukkit/build.gradle.kts | 2 + .../sk89q/worldedit/bukkit/BukkitWorld.java | 2 +- worldedit-cli/build.gradle.kts | 11 +-- .../sk89q/worldedit/WorldEditManifest.java | 31 ++++++- .../internal/util/InfoEntryPoint.java | 90 +++++++++++++++++++ worldedit-forge/build.gradle.kts | 2 +- worldedit-sponge/build.gradle.kts | 2 +- 9 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/InfoEntryPoint.java diff --git a/buildSrc/src/main/kotlin/PlatformConfig.kt b/buildSrc/src/main/kotlin/PlatformConfig.kt index 53750d461..1c8beebf5 100644 --- a/buildSrc/src/main/kotlin/PlatformConfig.kt +++ b/buildSrc/src/main/kotlin/PlatformConfig.kt @@ -37,6 +37,7 @@ fun Project.applyPlatformAndCoreConfiguration() { //options.compilerArgs.addAll(listOf("-Xlint:all") + disabledLint.map { "-Xlint:-$it" }) options.isDeprecation = false options.encoding = "UTF-8" + options.compilerArgs.add("-parameters") } // configure { @@ -126,3 +127,29 @@ val CLASSPATH = listOf("truezip", "truevfs", "js") .map { "$it.jar" } .flatMap { listOf(it, "WorldEdit/$it") } .joinToString(separator = " ") + +sealed class WorldEditKind( + val name: String, + val mainClass: String = "com.sk89q.worldedit.internal.util.InfoEntryPoint" +) { + class Standalone(mainClass: String) : WorldEditKind("STANDALONE", mainClass) + object Mod : WorldEditKind("MOD") + object Plugin : WorldEditKind("PLUGIN") +} + +fun Project.addJarManifest(kind: WorldEditKind, includeClasspath: Boolean = false) { + tasks.named("jar") { + val version = project(":worldedit-core").version + inputs.property("version", version) + val attributes = mutableMapOf( + "Implementation-Version" to version, + "WorldEdit-Version" to version, + "WorldEdit-Kind" to kind.name, + "Main-Class" to kind.mainClass + ) + if (includeClasspath) { + attributes["Class-Path"] = CLASSPATH + } + manifest.attributes(attributes) + } +} diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index d024993f8..692b0e999 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -60,7 +60,13 @@ Checks based on Google Checks, modified for EngineHub. - + + + + + + + diff --git a/worldedit-bukkit/build.gradle.kts b/worldedit-bukkit/build.gradle.kts index 8d8551ccc..cabbf55f2 100644 --- a/worldedit-bukkit/build.gradle.kts +++ b/worldedit-bukkit/build.gradle.kts @@ -147,6 +147,8 @@ tasks.named("jar") { } } +addJarManifest(WorldEditKind.Plugin, includeClasspath = true) + tasks.named("shadowJar") { from(zipTree("src/main/resources/worldedit-adapters.jar").matching { exclude("META-INF/") diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index 41a2a59ae..2e5b56167 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -249,7 +249,7 @@ public class BukkitWorld extends AbstractWorld { @Override public boolean clearContainerBlockContents(BlockVector3 pt) { checkNotNull(pt); - if (getBlock(pt).getBlockType().getMaterial().hasContainer()) { + if (!getBlock(pt).getBlockType().getMaterial().hasContainer()) { return false; } Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); diff --git a/worldedit-cli/build.gradle.kts b/worldedit-cli/build.gradle.kts index 43a537a44..a67caa684 100644 --- a/worldedit-cli/build.gradle.kts +++ b/worldedit-cli/build.gradle.kts @@ -7,6 +7,8 @@ plugins { applyPlatformAndCoreConfiguration() applyShadowConfiguration() +addJarManifest(WorldEditKind.Standalone("com.sk89q.worldedit.cli.CLIWorldEdit")) + dependencies { "api"(project(":worldedit-core")) "implementation"(platform("org.apache.logging.log4j:log4j-bom:2.14.0")) @@ -17,15 +19,6 @@ dependencies { "implementation"("com.google.code.gson:gson") } -tasks.named("jar") { - manifest { - attributes( - "Implementation-Version" to project.version, - "Main-Class" to "com.sk89q.worldedit.cli.CLIWorldEdit" - ) - } -} - tasks.named("shadowJar") { dependencies { include { true } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditManifest.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditManifest.java index 4c0e4cbb3..860966e8b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditManifest.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEditManifest.java @@ -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; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/InfoEntryPoint.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/InfoEntryPoint.java new file mode 100644 index 000000000..4a4290393 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/util/InfoEntryPoint.java @@ -0,0 +1,90 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +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("%1$s", 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", "
")); + 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); + } + } +} diff --git a/worldedit-forge/build.gradle.kts b/worldedit-forge/build.gradle.kts index f8e259d48..65481cf23 100644 --- a/worldedit-forge/build.gradle.kts +++ b/worldedit-forge/build.gradle.kts @@ -91,7 +91,7 @@ tasks.named("processResources") { from(project(":worldedit-core").tasks.named("processResources")) } -addJarManifest(includeClasspath = false) +addJarManifest(WorldEditKind.Mod, includeClasspath = false) tasks.named("shadowJar") { dependencies { diff --git a/worldedit-sponge/build.gradle.kts b/worldedit-sponge/build.gradle.kts index 2e46f5541..479faffa0 100644 --- a/worldedit-sponge/build.gradle.kts +++ b/worldedit-sponge/build.gradle.kts @@ -26,7 +26,7 @@ dependencies { } <<<<<<< HEAD -addJarManifest(includeClasspath = true) +addJarManifest(WorldEditKind.Mod, includeClasspath = true) ======= tasks.named("jar") { manifest {