add version checking, update discord URL, and add a message when you don't have perms

This commit is contained in:
Badbird5907
2022-11-06 14:52:35 -05:00
parent a44913aed6
commit bd9328d452
7 changed files with 83 additions and 4 deletions

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,9 +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 boolean correctVersion;
private BotManagerImpl manager;
private CommandHandler handler;
@@ -38,6 +43,13 @@ 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();
}
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 +59,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 +79,8 @@ 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;
}
}

View File

@@ -47,6 +47,7 @@ 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;
}

View File

@@ -46,7 +46,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,52 @@
package net.nuggetmc.tplus.utils;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import javax.net.ssl.HttpsURLConnection;
/**
* Used for debug logs.
* https://github.com/kaimu-kun/hastebin.java/blob/master/src/me/kaimu/hastebin/Hastebin.java
*/
public class Hastebin {
public String post(String text, boolean raw) throws IOException {
byte[] postData = text.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
String requestURL = "https://hastebin.com/documents";
URL url = new URL(requestURL);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("User-Agent", "Hastebin Java Api");
conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
conn.setUseCaches(false);
String response = null;
DataOutputStream wr;
try {
wr = new DataOutputStream(conn.getOutputStream());
wr.write(postData);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
response = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
if (response.contains("\"key\"")) {
response = response.substring(response.indexOf(":") + 2, response.length() - 2);
String postURL = raw ? "https://hastebin.com/raw/" : "https://hastebin.com/";
response = postURL + response;
}
return response;
}
}