mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 00:47:42 +01:00
274 lines
12 KiB
Diff
274 lines
12 KiB
Diff
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 6fd5968178..5b540e606e 100644
|
|
--- a/pom.xml
|
|
+++ b/pom.xml
|
|
@@ -1,12 +1,11 @@
|
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
<modelVersion>4.0.0</modelVersion>
|
|
- <artifactId>tuinity</artifactId>
|
|
+ <artifactId>purpur</artifactId>
|
|
<packaging>jar</packaging>
|
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
|
- <name>Tuinity-Server</name>
|
|
- <url>https://github.com/Spottedleaf/Tuinity</url>
|
|
-
|
|
+ <name>Purpur</name>
|
|
+ <url>https://github.com/pl3xgaming/Purpur</url>
|
|
<properties>
|
|
<!-- <skipTests>true</skipTests> Paper - This [was] not going to end well -->
|
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
@@ -18,16 +17,16 @@
|
|
</properties>
|
|
|
|
<parent>
|
|
- <groupId>com.tuinity</groupId>
|
|
- <artifactId>tuinity-parent</artifactId>
|
|
+ <groupId>net.pl3x.purpur</groupId>
|
|
+ <artifactId>purpur-parent</artifactId>
|
|
<version>dev-SNAPSHOT</version>
|
|
<relativePath>../pom.xml</relativePath>
|
|
</parent>
|
|
|
|
<dependencies>
|
|
<dependency>
|
|
- <groupId>com.tuinity</groupId>
|
|
- <artifactId>tuinity-api</artifactId>
|
|
+ <groupId>net.pl3x.purpur</groupId>
|
|
+ <artifactId>purpur-api</artifactId>
|
|
<version>${project.version}</version>
|
|
<scope>compile</scope>
|
|
</dependency>
|
|
@@ -43,6 +42,20 @@
|
|
<version>${minecraft.version}-SNAPSHOT</version>
|
|
<scope>compile</scope>
|
|
</dependency>
|
|
+ <!-- Purpur start -->
|
|
+ <dependency>
|
|
+ <groupId>org.mozilla</groupId>
|
|
+ <artifactId>rhino</artifactId>
|
|
+ <version>1.7.7.1</version>
|
|
+ <scope>compile</scope>
|
|
+ </dependency>
|
|
+ <dependency>
|
|
+ <groupId>cat.inspiracio</groupId>
|
|
+ <artifactId>rhino-js-engine</artifactId>
|
|
+ <version>1.7.7.1</version>
|
|
+ <scope>compile</scope>
|
|
+ </dependency>
|
|
+ <!-- Purpur end -->
|
|
<dependency>
|
|
<groupId>net.minecrell</groupId>
|
|
<artifactId>terminalconsoleappender</artifactId>
|
|
@@ -164,15 +177,15 @@
|
|
|
|
<!-- This builds a completely 'ready to start' jar with all dependencies inside -->
|
|
<build>
|
|
- <finalName>tuinity-${minecraft.version}</finalName>
|
|
- <defaultGoal>install</defaultGoal> <!-- Paper -->
|
|
+ <finalName>purpur-${minecraft.version}</finalName>
|
|
+ <defaultGoal>clean install</defaultGoal> <!-- Paper -->
|
|
<plugins>
|
|
<plugin>
|
|
<groupId>com.lukegb.mojo</groupId>
|
|
<artifactId>gitdescribe-maven-plugin</artifactId>
|
|
<version>1.3</version>
|
|
<configuration>
|
|
- <outputPrefix>git-Tuinity-</outputPrefix> <!-- Tuinity -->
|
|
+ <outputPrefix>git-Purpur-</outputPrefix>
|
|
<scmDirectory>..</scmDirectory>
|
|
</configuration>
|
|
<executions>
|
|
diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
|
index 74ed02fa92..c1280478ee 100644
|
|
--- a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
|
+++ b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java
|
|
@@ -17,7 +17,7 @@ public final class PaperConsole extends SimpleTerminalConsole {
|
|
@Override
|
|
protected LineReader buildReader(LineReaderBuilder builder) {
|
|
return super.buildReader(builder
|
|
- .appName("Paper")
|
|
+ .appName("Purpur") // Purpur
|
|
.variable(LineReader.HISTORY_FILE, java.nio.file.Paths.get(".console_history"))
|
|
.completer(new ConsoleCommandCompleter(this.server))
|
|
);
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index eb71fa6e39..e23e47ee77 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1504,7 +1504,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
}
|
|
|
|
public String getServerModName() {
|
|
- return "Tuinity"; // Tuinity //Paper - Paper > // Spigot - Spigot > // CraftBukkit - cb > vanilla!
|
|
+ return "Purpur"; // Purpur // 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 0000000000..d8b408f061
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurVersionFetcher.java
|
|
@@ -0,0 +1,115 @@
|
|
+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 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 String getVersionMessage(@Nonnull String serverVersion) {
|
|
+ String[] parts = serverVersion.substring("git-Purpur-".length()).split("[-\\s]");
|
|
+ String updateMessage = getUpdateStatusMessage("pl3xgaming/Purpur", GITHUB_BRANCH_NAME, parts[0]);
|
|
+ String history = getHistory();
|
|
+
|
|
+ return history != null ? history + "\n" + updateMessage : updateMessage;
|
|
+ }
|
|
+
|
|
+ private static String 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 "Error obtaining version information";
|
|
+ case 0:
|
|
+ return "You are running the latest version";
|
|
+ case -2:
|
|
+ return "Unknown version";
|
|
+ default:
|
|
+ return "You are " + distance + " version(s) behind";
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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 String getHistory() {
|
|
+ final VersionHistoryManager.VersionData data = VersionHistoryManager.INSTANCE.getVersionData();
|
|
+ if (data == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ final String oldVersion = data.getOldVersion();
|
|
+ if (oldVersion == null) {
|
|
+ return null;
|
|
+ }
|
|
+
|
|
+ return "Previous version: " + oldVersion;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
index ba42171096..6aa60eb602 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -231,7 +231,7 @@ import javax.annotation.Nullable; // Paper
|
|
import javax.annotation.Nonnull; // Paper
|
|
|
|
public final class CraftServer implements Server {
|
|
- private final String serverName = "Tuinity"; // Paper // Tuinity
|
|
+ private final String serverName = "Purpur"; // Paper // Tuinity // 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 f1e60981ab..1fe87d7637 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -323,7 +323,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 001b1e5197..13b9843932 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/com.tuinity/tuinity-api/pom.properties"); // Tuinity
|
|
+ InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/net.pl3x.purpur/purpur-api/pom.properties"); // Tuinity // Purpur
|
|
Properties properties = new Properties();
|
|
|
|
if (stream != null) {
|