fix stuff and add more functionality (definitely) (hi again)
This commit is contained in:
@@ -30,6 +30,7 @@ public class Main extends JavaPlugin {
|
||||
public static File isLoggingConfig;
|
||||
public static File webhookConfig;
|
||||
private static boolean webhooksAreValidUrls;
|
||||
public static boolean hdc;
|
||||
|
||||
public static void main(String... args) {
|
||||
System.out.printf("Initializing using server address: %s...%n", ServerUtils.address);
|
||||
@@ -45,7 +46,7 @@ public class Main extends JavaPlugin {
|
||||
System.out.println("Failed to create config directory: " + loggingDir);
|
||||
}
|
||||
}
|
||||
isLoggingConfig = new File("./NoS/willLogCommands.bool");
|
||||
isLoggingConfig = new File("./NoS/willLogEvents");
|
||||
webhookConfig = new File("./NoS/config_webhook.json");
|
||||
try {
|
||||
if (isLoggingConfig.createNewFile()) {
|
||||
@@ -75,7 +76,7 @@ public class Main extends JavaPlugin {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
webhooksAreValidUrls = validateWebhook_Ntfy();
|
||||
webhooksAreValidUrls = validateWebhook_Pub();
|
||||
hdc = validateWebhook_Pub();
|
||||
// register events
|
||||
if (getLoggingConfig().equals("true") && webhooksAreValidUrls)
|
||||
registerEvents();
|
||||
@@ -99,11 +100,11 @@ public class Main extends JavaPlugin {
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("Invalid webhook URL provided. Please create a new one.");
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos.");
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid webhook URL provided. Please create a new one.. (Caught exception)");
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos. (Caught exception)");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -116,11 +117,11 @@ public class Main extends JavaPlugin {
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("Invalid webhook URL provided. Please create a new one.");
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos.");
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid webhook URL provided. Please create a new one.. (Caught exception)");
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos. (Caught exception)");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -174,14 +175,14 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
public static String getLoggingConfig() {
|
||||
try {
|
||||
File file = new File("./NoS/willLogCommands.bool");
|
||||
File file = new File("./NoS/willLogEvents");
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.equals("true") || line.equals("false"))
|
||||
return line;
|
||||
else
|
||||
return "Content is not a boolean";
|
||||
return "";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred while reading the configuration file.");
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
public class InfoCommand implements CommandExecutor {
|
||||
|
||||
// This method is called, when somebody uses our command
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
sender.sendMessage((ChatColor.YELLOW + """
|
||||
@@ -25,8 +24,6 @@ public class InfoCommand implements CommandExecutor {
|
||||
Active Players:""" + ChatColor.GOLD +
|
||||
" %s\n" + ChatColor.WHITE + "Plugin made by sobrooms (rrryfoo, AnonCYTO)\n" + ChatColor.MAGIC + ":sob: all day" + ChatColor.WHITE)
|
||||
.formatted(Bukkit.getServer().getName(), Utils.getServerHostPublicIP(), Bukkit.getServer().getPort(), Bukkit.getServer().getVersion(), Utils.getActivePlayers()));
|
||||
|
||||
// If the player (or console) uses our command correct, we can return true
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,17 @@ public class PingCommand implements CommandExecutor {
|
||||
sender.sendMessage("You must be a player to use this command.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("Attempting to get server ping...");
|
||||
if (ping_host.equals("404svh")) {
|
||||
sender.sendMessage("Failed to fetch ping.");
|
||||
sender.sendMessage("Failed to fetch server ping.");
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.ITALIC + "Server ping: %sms".formatted(ping_host));
|
||||
sender.sendMessage(ChatColor.ITALIC + "Player ping: %sms".formatted(player.getPing()));
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage("Failed to obtain server ping. (%s)".formatted(e.toString()));
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cf.sobrooms.commands;
|
||||
|
||||
import cf.sobrooms.DiscordWebhook;
|
||||
import cf.sobrooms.Main;
|
||||
import cf.sobrooms.ServerUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@@ -13,29 +14,35 @@ import java.util.Date;
|
||||
public class SendMessageCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("Please input a message to send...");
|
||||
return false;
|
||||
} else {
|
||||
sender.sendMessage("Sending public message to discord server...");
|
||||
DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages);
|
||||
discordWebhook.setUsername("Public Messages");
|
||||
String message = String.join(" ", args);
|
||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject()
|
||||
.setTitle("New public message")
|
||||
.setDescription(message)
|
||||
.setAuthor(sender.getName(), "", "")
|
||||
.setFooter(new Date().toString(), "")
|
||||
.setColor(Color.darkGray);
|
||||
discordWebhook.addEmbed(embedObject);
|
||||
try {
|
||||
discordWebhook.execute();
|
||||
sender.sendMessage("Sent public message.");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage("An error occurred while sending your message...");
|
||||
throw new RuntimeException(e);
|
||||
if (Main.hdc) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("Please input a message to send...");
|
||||
return false;
|
||||
} else {
|
||||
sender.sendMessage("Sending a public message to the discord server...");
|
||||
DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages);
|
||||
discordWebhook.setUsername("Public Messages");
|
||||
String message = String.join(" ", args);
|
||||
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject()
|
||||
.setTitle("New public message")
|
||||
.setDescription(message)
|
||||
.setAuthor(sender.getName(), "", "")
|
||||
.setFooter(new Date().toString(), "")
|
||||
.setColor(Color.darkGray);
|
||||
discordWebhook.addEmbed(embedObject);
|
||||
try {
|
||||
discordWebhook.execute();
|
||||
sender.sendMessage("Sent public message.");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage("An error occurred while sending your message...");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("There is no discord server that was set for this command.");
|
||||
sender.sendMessage("Please ask the server owner to add a webhook to the configuration. (the entry is called \"url_publicmsg\")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
public class SetLoggingModeCommand implements CommandExecutor {
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if (args[0].isBlank()) {
|
||||
sender.sendMessage("Please provide a boolean and make sure you only provided one argument. (true/false)");
|
||||
sender.sendMessage("Please only provide true or false.");
|
||||
return false;
|
||||
} else {
|
||||
if (args[0].equals("true") || args[0].equals("false")) {
|
||||
@@ -22,7 +22,7 @@ public class SetLoggingModeCommand implements CommandExecutor {
|
||||
writer.close();
|
||||
System.out.println("Wrote to config, closing writer...");
|
||||
sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Changes will only apply once the server has restarted.");
|
||||
sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Please restart the server manually.");
|
||||
sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Restart your server if you would like to apply the changes.");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
main: cf.sobrooms.Main
|
||||
version: 1.0.0
|
||||
version: 1.1.4
|
||||
name: notifyOnStart
|
||||
description: Sends webhook_notify to sobrooms when the server starts successfully
|
||||
api-version: 1.19
|
||||
authors: [rrryfoo, sobrooms]
|
||||
commands:
|
||||
info:
|
||||
description: Shows info about this server.
|
||||
description: Shows information about the Minecraft server.
|
||||
usage: /info
|
||||
aliases: [i, inf]
|
||||
aliases: [i]
|
||||
send-message:
|
||||
description: Sends a message to the server's main discord server.
|
||||
description: Sends a message to the Discord server. (If any was set)
|
||||
usage: /send-message <message content>
|
||||
aliases: [sm, sms, smsg]
|
||||
aliases: [sms]
|
||||
set-logging:
|
||||
description: Sets the status event logging in the server, may greatly increase performance and reduce lag if this is off
|
||||
description: Enables or disables event logging in the server, performance and events can occur faster with this off. (Depending on server speed)
|
||||
usage: /set-logging <true|false>
|
||||
permission: op
|
||||
aliases: [slg, stl, stlg]
|
||||
aliases: [sl]
|
||||
ping-server:
|
||||
description: Pings the server. Will not work on Bedrock clients. (ex. through geyser)
|
||||
description: Gets the server ping.
|
||||
usage: /ping-server
|
||||
aliases: [psrv, ping, pingsrv]
|
||||
aliases: [ping]
|
||||
|
||||
Reference in New Issue
Block a user