Merge branch 'HorseNuggets:master' into fixes

This commit is contained in:
ThisTestUser
2022-11-19 17:05:27 -05:00
committed by GitHub
10 changed files with 127 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
blank_issues_enabled: false
contact_links:
- name: Community Support
url: https://discord.gg/horsenuggets
url: https://discord.gg/vZVSf2D6mz
about: Please ask and answer questions here.
- name: Project Channel
url: https://youtube.com/HorseNuggets

View File

@@ -9,7 +9,7 @@
### Download
Releases are currently available on our Discord server, which can be found [here](https://discord.gg/horsenuggets).
Releases are currently available on our Discord server, which can be found [here](https://discord.gg/vZVSf2D6mz).
### Machine Learning

View File

@@ -3,7 +3,7 @@ plugins {
}
group = "net.nuggetmc"
version = "3.3-BETA"
version = "3.3.1-BETA"
repositories {
mavenCentral()

View File

@@ -4,7 +4,7 @@ plugins {
}
group = "net.nuggetmc"
version = "3.3-BETA"
version = "3.3.1-BETA"
description = "TerminatorPlus"
java {

View File

@@ -4,6 +4,7 @@ import net.nuggetmc.tplus.api.TerminatorPlusAPI;
import net.nuggetmc.tplus.bot.BotManagerImpl;
import net.nuggetmc.tplus.bridge.InternalBridgeImpl;
import net.nuggetmc.tplus.command.CommandHandler;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
@@ -11,8 +12,13 @@ import java.util.Arrays;
public class TerminatorPlus extends JavaPlugin {
public static final String REQUIRED_VERSION = "1.19.2";
private static TerminatorPlus instance;
private static String version;
private static String mcVersion;
private static boolean correctVersion;
private BotManagerImpl manager;
private CommandHandler handler;
@@ -38,6 +44,14 @@ public class TerminatorPlus extends JavaPlugin {
instance = this;
version = getDescription().getVersion();
String version = Bukkit.getVersion();
correctVersion = version.contains(REQUIRED_VERSION);
if (version.contains("MC:")) { // git-ABX-123 (MC: ABCD)
version = version.substring(version.indexOf("MC:") + 3, version.indexOf(")")).trim();
}
mcVersion = version;
getLogger().info("Running on version: " + version + ", required version: " + REQUIRED_VERSION + ", correct version: " + correctVersion);
// Create Instances
this.manager = new BotManagerImpl();
this.handler = new CommandHandler(this);
@@ -47,6 +61,16 @@ public class TerminatorPlus extends JavaPlugin {
// Register event listeners
this.registerEvents(manager);
if (!correctVersion) {
for (int i = 0; i < 20; i++) { // Kids are stupid so we need to make sure they see this
getLogger().severe("----------------------------------------");
getLogger().severe("TerminatorPlus is not compatible with your server version!");
getLogger().severe("You are running on version: " + version + ", required version: " + REQUIRED_VERSION);
getLogger().severe("Either download the correct version of TerminatorPlus or update your server. (https://papermc.io/downloads)");
getLogger().severe("----------------------------------------");
}
}
}
@Override
@@ -57,4 +81,12 @@ public class TerminatorPlus extends JavaPlugin {
private void registerEvents(Listener... listeners) {
Arrays.stream(listeners).forEach(li -> this.getServer().getPluginManager().registerEvents(li, this));
}
public static boolean isCorrectVersion() {
return correctVersion;
}
public static String getMcVersion() {
return mcVersion;
}
}

View File

@@ -1,6 +1,6 @@
package net.nuggetmc.tplus.command;
import net.md_5.bungee.api.ChatColor;
import net.nuggetmc.tplus.TerminatorPlus;
import net.nuggetmc.tplus.api.utils.ChatUtils;
import net.nuggetmc.tplus.command.annotation.Arg;
import net.nuggetmc.tplus.command.annotation.OptArg;
@@ -9,6 +9,7 @@ import net.nuggetmc.tplus.command.exception.ArgCountException;
import net.nuggetmc.tplus.command.exception.ArgParseException;
import net.nuggetmc.tplus.command.exception.NonPlayerException;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.defaults.BukkitCommand;
import org.bukkit.entity.Player;
@@ -47,6 +48,12 @@ public abstract class CommandInstance extends BukkitCommand {
@Override
public boolean execute(@Nonnull CommandSender sender, @Nonnull String label, @Nonnull String[] args) {
if (!sender.hasPermission(MANAGE_PERMISSION)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command. (Check if you are OP.)");
return false;
}
if (!TerminatorPlus.isCorrectVersion()) {
sender.sendMessage(ChatColor.RED + "You are not running the correct server version of Minecraft!");
sender.sendMessage(ChatColor.RED + "You are using MC server version " + TerminatorPlus.getMcVersion() + " but this plugin requires " + TerminatorPlus.REQUIRED_VERSION);
return false;
}

View File

@@ -10,9 +10,12 @@ import net.nuggetmc.tplus.api.utils.ChatUtils;
import net.nuggetmc.tplus.command.CommandHandler;
import net.nuggetmc.tplus.command.CommandInstance;
import net.nuggetmc.tplus.command.annotation.Command;
import net.nuggetmc.tplus.utils.MCLogs;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.io.IOException;
public class MainCommand extends CommandInstance {
private BaseComponent[] rootInfo;
@@ -29,6 +32,23 @@ public class MainCommand extends CommandInstance {
sender.spigot().sendMessage(rootInfo);
}
@Command(
name = "debuginfo",
desc = "Upload debug info to mclo.gs"
)
public void debugInfo(CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + "Uploading debug info to mclogs...");
String url = null;
try {
url = MCLogs.postInfo();
} catch (IOException e) {
String error = e.getMessage();
sender.sendMessage(ChatColor.RED + "Failed to upload debug info to mclogs: " + error);
return;
}
sender.sendMessage(ChatColor.GREEN + "Debug info uploaded to " + url);
}
private void rootInfoSetup() {
ComponentBuilder message = new ComponentBuilder();
@@ -46,7 +66,7 @@ public class MainCommand extends CommandInstance {
message.event((ClickEvent) null);
message.event((HoverEvent) null);
message.append(ChatColor.BLUE + "Discord");
message.event(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://discord.gg/horsenuggets"));
message.event(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://discord.gg/vZVSf2D6mz"));
message.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to visit HorseNuggets' " + ChatColor.BLUE + "Discord" + ChatColor.RESET + "!")));
message.append("\n");
message.event((ClickEvent) null);

View File

@@ -0,0 +1,60 @@
package net.nuggetmc.tplus.utils;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.nuggetmc.tplus.TerminatorPlus;
import org.bukkit.Bukkit;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
/**
* Used for debug logs.
*/
public class MCLogs {
private static final String FORMAT =
"""
====== TERMINATOR PLUS DEBUG INFO ======
Plugin Version: %s
Server Version: %s
Server Software: %s
Server Plugins: %s
Server TPS: %s
Server Memory: %s
Correct Version: %s
Required Version: %s
====== TERMINATOR PLUS DEBUG INFO ======
""";
public static String postInfo() throws IOException {
String serverVersion = Bukkit.getVersion();
String pluginVersion = TerminatorPlus.getVersion();
String serverSoftware = Bukkit.getName();
String serverPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(plugin -> plugin.getName() + " v" + plugin.getDescription().getVersion()).reduce((s, s2) -> s + ", " + s2).orElse("No plugins");
String serverTPS = Arrays.stream(Bukkit.getTPS()).mapToObj(tps -> String.format("%.2f", tps)).reduce((s, s2) -> s + ", " + s2).orElse("No TPS");
String serverMemory = String.format("%.2f", (double) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024) + "MB";
String info = String.format(FORMAT, pluginVersion, serverVersion, serverSoftware, serverPlugins, serverTPS, serverMemory, TerminatorPlus.isCorrectVersion(), TerminatorPlus.REQUIRED_VERSION);
return pasteText(info);
}
private static String pasteText(String text) throws IOException {
URL url = new URL("https://api.mclo.gs/1/log"); // application/x-www-form-urlencoded
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);
try (OutputStream os = connection.getOutputStream()) {
os.write(("content=" + text).getBytes());
}
String response = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine();
JsonObject json = JsonParser.parseString(response).getAsJsonObject();
return json.get("url").getAsString();
}
}

View File

@@ -3,7 +3,7 @@ plugins {
}
group = "net.nuggetmc"
version = "3.3-BETA"
version = "3.3.1-BETA"
val jarName = "TerminatorPlus-" + version;

View File

@@ -1,7 +1,7 @@
name: TerminatorPlus
main: net.nuggetmc.tplus.TerminatorPlus
version: ${version}
api-version: 1.16
api-version: 1.16 # Set to 1.16 so the plugin loads, and we can tell the user that it may not be compatible with their version, because people can't scroll up.
author: HorseNuggets
permissions: