From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Sat, 4 May 2019 01:02:11 -0500
Subject: [PATCH] Rebrand


diff --git a/pom.xml b/pom.xml
index c917f825378dd16a329105b4e7fcc8882755bc5a..6fe8dad8df109531f2b38fbfcb58b6807dbb8cf0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,8 +39,10 @@
 
     <dependencies>
         <dependency>
-            <groupId>gg.airplane</groupId>
-            <artifactId>airplane-api</artifactId>
+            <!-- Purpur start - our "upstream" is Paper (not Tuinity), so this is necessary for DependencyLoading.kt to work properly -->
+            <groupId>net.pl3x.purpur</groupId>
+            <artifactId>purpur-api</artifactId>
+            <!-- Purpur end -->
             <version>${project.version}</version>
             <scope>compile</scope>
         </dependency>
@@ -182,6 +184,14 @@
         </dependency>
     </dependencies>
 
+    <repositories>
+        <!-- Purpur - Snapshots -->
+        <repository>
+            <id>purpur-snapshots</id>
+            <url>https://repo.pl3x.net/</url>
+        </repository>
+    </repositories>
+
     <!-- This builds a completely 'ready to start' jar with all dependencies inside -->
     <build>
         <finalName>tuinity-${minecraft.version}</finalName>
@@ -361,8 +371,15 @@
                     <dependency>
                         <groupId>org.eclipse.jdt</groupId>
                         <artifactId>ecj</artifactId>
-                        <version>3.24.0</version>
+                        <!-- Purpur start -->
+                        <version>3.25.0</version>
+                    </dependency>
+                    <dependency>
+                        <groupId>org.jetbrains.kotlin</groupId>
+                        <artifactId>kotlin-stdlib</artifactId>
+                        <version>1.4.33-SNAPSHOT</version>
                     </dependency>
+                    <!-- Purpur end -->
                 </dependencies>
             </plugin>
             <plugin>
diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
index ad87b575a0261200b280884e054a59e3ce59c41c..e56ebeaaa12494817d31099eed54ef2c50b98b9e 100644
--- a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
+++ b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
@@ -19,7 +19,7 @@ public final class PaperConsole extends SimpleTerminalConsole {
     @Override
     protected LineReader buildReader(LineReaderBuilder builder) {
         builder
-                .appName("Paper")
+                .appName("Purpur") // Purpur
                 .variable(LineReader.HISTORY_FILE, java.nio.file.Paths.get(".console_history"))
                 .completer(new ConsoleCommandCompleter(this.server))
                 .option(LineReader.Option.COMPLETE_IN_WORD, true);
diff --git a/src/main/java/gg/airplane/compat/ServerConfigurations.java b/src/main/java/gg/airplane/compat/ServerConfigurations.java
index f4976428bc721319d2926e97cbe0f64c6e9e503c..044ad28bd1fd1c1e25061f9f811fc10baf7f5f72 100644
--- a/src/main/java/gg/airplane/compat/ServerConfigurations.java
+++ b/src/main/java/gg/airplane/compat/ServerConfigurations.java
@@ -23,6 +23,7 @@ public class ServerConfigurations {
       "spigot.yml",
       "paper.yml",
       "tuinity.yml",
+      "purpur.yml", // Purpur
       "airplane.air"
     };
 
diff --git a/src/main/java/net/minecraft/server/EULA.java b/src/main/java/net/minecraft/server/EULA.java
index 3bc5cd1e53dd7c94b948e7f57f0dc8e073e349b0..87891161f5b06bb8be0e2016b490484e6daca9d7 100644
--- a/src/main/java/net/minecraft/server/EULA.java
+++ b/src/main/java/net/minecraft/server/EULA.java
@@ -72,7 +72,7 @@ public class EULA {
                     Properties properties = new Properties();
 
                     properties.setProperty("eula", "false");
-                    properties.store(outputstream, "By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).");  // Paper - fix lag; // Tuinity - Tacos are disgusting
+                    properties.store(outputstream, "By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).\nYou also agree that tacos are tasty, and the best food in the world.");  // Paper - fix lag; // Tuinity - Tacos are disgusting // Purpur - no they're not
                 } catch (Throwable throwable1) {
                     throwable = throwable1;
                     throw throwable1;
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 246fcc9b40152964810ceef356ecb2eee3551135..8620bbcc7c555e4760777397063f0392c9acc35e 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1646,7 +1646,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
     }
 
     public String getServerModName() {
-        return "Airplane"; // Airplane // Tuinity //Paper - Paper > // Spigot - Spigot > // CraftBukkit - cb > vanilla!
+        return "Purpur"; // Purpur // Airplane // Tuinity // Paper // Spigot // CraftBukkit
     }
 
     public CrashReport b(CrashReport crashreport) {
diff --git a/src/main/java/net/pl3x/purpur/PurpurVersionFetcher.java b/src/main/java/net/pl3x/purpur/PurpurVersionFetcher.java
new file mode 100644
index 0000000000000000000000000000000000000000..cabfcebf9f944f7a2a2a1cffc7401435803a8741
--- /dev/null
+++ b/src/main/java/net/pl3x/purpur/PurpurVersionFetcher.java
@@ -0,0 +1,119 @@
+package net.pl3x.purpur;
+
+import com.destroystokyo.paper.VersionHistoryManager;
+import com.destroystokyo.paper.util.VersionFetcher;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonSyntaxException;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.TextComponent;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.TextDecoration;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+public class PurpurVersionFetcher implements VersionFetcher {
+    private static final String JENKINS_URL = "https://ci.pl3x.net/job/Purpur/lastSuccessfulBuild/buildNumber";
+    private static final String GITHUB_BRANCH_NAME = "master";
+
+    @Override
+    public long getCacheTime() {
+        return 720000;
+    }
+
+    @Nonnull
+    @Override
+    public Component getVersionMessage(@Nonnull String serverVersion) {
+        String[] parts = serverVersion.substring("git-Purpur-".length()).split("[-\\s]");
+        final Component updateMessage = getUpdateStatusMessage("pl3xgaming/Purpur", GITHUB_BRANCH_NAME, parts[0]);
+        final Component history = getHistory();
+
+        return history != null ? TextComponent.ofChildren(updateMessage, Component.newline(), history) : updateMessage;
+    }
+
+    private static Component getUpdateStatusMessage(@Nonnull String repo, @Nonnull String branch, @Nonnull String versionInfo) {
+        int distance;
+        try {
+            int jenkinsBuild = Integer.parseInt(versionInfo);
+            distance = fetchDistanceFromJenkins(jenkinsBuild);
+        } catch (NumberFormatException ignored) {
+            versionInfo = versionInfo.replace("\"", "");
+            distance = fetchDistanceFromGitHub(repo, branch, versionInfo);
+        }
+
+        switch (distance) {
+            case -1:
+                return Component.text("Error obtaining version information", NamedTextColor.YELLOW);
+            case 0:
+                return Component.text("You are running the latest version", NamedTextColor.GREEN);
+            case -2:
+                return Component.text("Unknown version", NamedTextColor.YELLOW);
+            default:
+                return Component.text("You are " + distance + " version(s) behind", NamedTextColor.YELLOW);
+        }
+    }
+
+    private static int fetchDistanceFromJenkins(int jenkinsBuild) {
+        try {
+            try (BufferedReader reader = Resources.asCharSource(new URL(JENKINS_URL), Charsets.UTF_8).openBufferedStream()) {
+                return Integer.decode(reader.readLine()) - jenkinsBuild;
+            } catch (NumberFormatException ex) {
+                ex.printStackTrace();
+                return -2;
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            return -1;
+        }
+    }
+
+    // Contributed by Techcable <Techcable@outlook.com> in GH-65
+    private static int fetchDistanceFromGitHub(@Nonnull String repo, @Nonnull String branch, @Nonnull String hash) {
+        try {
+            HttpURLConnection connection = (HttpURLConnection) new URL("https://api.github.com/repos/" + repo + "/compare/" + branch + "..." + hash).openConnection();
+            connection.connect();
+            if (connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) return -2; // Unknown commit
+            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8))) {
+                JsonObject obj = new Gson().fromJson(reader, JsonObject.class);
+                String status = obj.get("status").getAsString();
+                switch (status) {
+                    case "identical":
+                        return 0;
+                    case "behind":
+                        return obj.get("behind_by").getAsInt();
+                    default:
+                        return -1;
+                }
+            } catch (JsonSyntaxException | NumberFormatException e) {
+                e.printStackTrace();
+                return -1;
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+            return -1;
+        }
+    }
+
+    @Nullable
+    private Component getHistory() {
+        final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
+        if (data == null) {
+            return null;
+        }
+
+        final String oldVersion = data.getOldVersion();
+        if (oldVersion == null) {
+            return null;
+        }
+
+        return Component.text("Previous version: " + oldVersion, NamedTextColor.GRAY, TextDecoration.ITALIC);
+    }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index aec6c036ed42078a6cc3540f1f6e46a551e87a2f..f9913d7bd66935f975b756f31e26153ec160b3b1 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -232,7 +232,7 @@ import javax.annotation.Nullable; // Paper
 import javax.annotation.Nonnull; // Paper
 
 public final class CraftServer implements Server {
-    private final String serverName = "Airplane"; // Paper // Tuinity // Airplane
+    private final String serverName = "Purpur"; // Paper // Tuinity // Airplane // Purpur
     private final String serverVersion;
     private final String bukkitVersion = Versioning.getBukkitVersion();
     private final Logger logger = Logger.getLogger("Minecraft");
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 6bfba82b428250e6725688d196b3dc6ac11a5e01..38e1bd3893b9dfcf1bac1333d06b4e9792793ec6 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -377,7 +377,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
 
     @Override
     public com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
-        return new com.destroystokyo.paper.PaperVersionFetcher();
+        return new net.pl3x.purpur.PurpurVersionFetcher();
     }
 
     @Override
diff --git a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
index 1788d79ea489e446d3d9f541693d4ba3dfc26015..191f5331f0c7871f80f0da9cc38345ce33353577 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java
@@ -11,7 +11,7 @@ public final class Versioning {
     public static String getBukkitVersion() {
         String result = "Unknown-Version";
 
-        InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/gg.airplane/airplane-api/pom.properties"); // Tuinity // Airplane
+        InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/net.pl3x.purpur/purpur-api/pom.properties"); // Tuinity // Airplane // Purpur
         Properties properties = new Properties();
 
         if (stream != null) {
