fix stuff and add more functionality (definitely) (hi again)

This commit is contained in:
rrryfu
2023-09-25 23:44:12 +08:00
parent 628bfc397e
commit fe402f7dde
8 changed files with 114 additions and 51 deletions
+60 -5
View File
@@ -4,12 +4,14 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ce97b9f5-6785-4670-b350-12f90ab9ea27" name="Changes" comment=""> <list default="true" id="ce97b9f5-6785-4670-b350-12f90ab9ea27" name="Changes" comment="hmmm">
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules/notifyonstart.main.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/settings.gradle" beforeDir="false" afterPath="$PROJECT_DIR$/settings.gradle" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cf/sobrooms/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cf/sobrooms/Main.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/cf/sobrooms/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cf/sobrooms/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/InfoCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/InfoCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/PingCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/PingCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/SendMessageCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/SendMessageCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/SetLoggingModeCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/cf/sobrooms/commands/SetLoggingModeCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/plugin.yml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/plugin.yml" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -19,6 +21,22 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="GitLabMergeRequestFiltersHistory"><![CDATA[{
"lastFilter": {
"state": "OPENED",
"assignee": {
"type": "org.jetbrains.plugins.gitlab.mergerequest.ui.filters.GitLabMergeRequestsFiltersValue.MergeRequestsMemberFilterValue.MergeRequestsAssigneeFilterValue",
"username": "mangorifo",
"fullname": "rrryfoo"
}
}
}]]></component>
<component name="GitLabMergeRequestsSettings"><![CDATA[{
"selectedUrlAndAccountId": {
"first": "https://git.sob.moe/sobrooms/notify-on-start",
"second": "bb8a3a4e-cb6a-4b4f-aca5-fb589330d6a4"
}
}]]></component>
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
@@ -39,6 +57,30 @@
"git-widget-placeholder": "main" "git-widget-placeholder": "main"
} }
}]]></component> }]]></component>
<component name="RunManager">
<configuration name="notify-on-start [build]" type="GradleRunConfiguration" factoryName="Gradle" nameIsGenerated="true">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value="build" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">
@@ -48,6 +90,19 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1695653315409</updated> <updated>1695653315409</updated>
</task> </task>
<task id="LOCAL-00001" summary="hmmm">
<option name="closed" value="true" />
<created>1695655158506</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1695655158506</updated>
</task>
<option name="localTasksCounter" value="2" />
<servers /> <servers />
</component> </component>
<component name="VcsManagerConfiguration">
<MESSAGE value="hmmm" />
<option name="LAST_COMMIT_MESSAGE" value="hmmm" />
</component>
</project> </project>
+1 -1
View File
@@ -3,7 +3,7 @@ plugins {
} }
group 'cf.sobrooms' group 'cf.sobrooms'
version '1.1' version '1.1.3'
repositories { repositories {
mavenCentral() mavenCentral()
+9 -8
View File
@@ -30,6 +30,7 @@ public class Main extends JavaPlugin {
public static File isLoggingConfig; public static File isLoggingConfig;
public static File webhookConfig; public static File webhookConfig;
private static boolean webhooksAreValidUrls; private static boolean webhooksAreValidUrls;
public static boolean hdc;
public static void main(String... args) { public static void main(String... args) {
System.out.printf("Initializing using server address: %s...%n", ServerUtils.address); 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); 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"); webhookConfig = new File("./NoS/config_webhook.json");
try { try {
if (isLoggingConfig.createNewFile()) { if (isLoggingConfig.createNewFile()) {
@@ -75,7 +76,7 @@ public class Main extends JavaPlugin {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
webhooksAreValidUrls = validateWebhook_Ntfy(); webhooksAreValidUrls = validateWebhook_Ntfy();
webhooksAreValidUrls = validateWebhook_Pub(); hdc = validateWebhook_Pub();
// register events // register events
if (getLoggingConfig().equals("true") && webhooksAreValidUrls) if (getLoggingConfig().equals("true") && webhooksAreValidUrls)
registerEvents(); registerEvents();
@@ -99,11 +100,11 @@ public class Main extends JavaPlugin {
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
return true; return true;
} else { } 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; return false;
} }
} catch (Exception e) { } 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; return false;
} }
} }
@@ -116,11 +117,11 @@ public class Main extends JavaPlugin {
if (responseCode == HttpURLConnection.HTTP_OK) { if (responseCode == HttpURLConnection.HTTP_OK) {
return true; return true;
} else { } 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; return false;
} }
} catch (Exception e) { } 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; return false;
} }
} }
@@ -174,14 +175,14 @@ public class Main extends JavaPlugin {
} }
public static String getLoggingConfig() { public static String getLoggingConfig() {
try { try {
File file = new File("./NoS/willLogCommands.bool"); File file = new File("./NoS/willLogEvents");
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
String line; String line;
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
if (line.equals("true") || line.equals("false")) if (line.equals("true") || line.equals("false"))
return line; return line;
else else
return "Content is not a boolean"; return "";
} }
} catch (IOException e) { } catch (IOException e) {
System.out.println("An error occurred while reading the configuration file."); 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 { public class InfoCommand implements CommandExecutor {
// This method is called, when somebody uses our command
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
sender.sendMessage((ChatColor.YELLOW + """ sender.sendMessage((ChatColor.YELLOW + """
@@ -25,8 +24,6 @@ public class InfoCommand implements CommandExecutor {
Active Players:""" + ChatColor.GOLD + Active Players:""" + ChatColor.GOLD +
" %s\n" + ChatColor.WHITE + "Plugin made by sobrooms (rrryfoo, AnonCYTO)\n" + ChatColor.MAGIC + ":sob: all day" + ChatColor.WHITE) " %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())); .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; return true;
} }
} }
@@ -20,14 +20,17 @@ public class PingCommand implements CommandExecutor {
sender.sendMessage("You must be a player to use this command."); sender.sendMessage("You must be a player to use this command.");
return true; return true;
} }
sender.sendMessage("Attempting to get server ping...");
if (ping_host.equals("404svh")) { if (ping_host.equals("404svh")) {
sender.sendMessage("Failed to fetch ping."); sender.sendMessage("Failed to fetch server ping.");
} else { } else {
sender.sendMessage(ChatColor.ITALIC + "Server ping: %sms".formatted(ping_host)); sender.sendMessage(ChatColor.ITALIC + "Server ping: %sms".formatted(ping_host));
sender.sendMessage(ChatColor.ITALIC + "Player ping: %sms".formatted(player.getPing())); sender.sendMessage(ChatColor.ITALIC + "Player ping: %sms".formatted(player.getPing()));
} }
return true; return true;
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage("Failed to obtain server ping. (%s)".formatted(e.toString()));
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@@ -1,6 +1,7 @@
package cf.sobrooms.commands; package cf.sobrooms.commands;
import cf.sobrooms.DiscordWebhook; import cf.sobrooms.DiscordWebhook;
import cf.sobrooms.Main;
import cf.sobrooms.ServerUtils; import cf.sobrooms.ServerUtils;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@@ -13,11 +14,12 @@ import java.util.Date;
public class SendMessageCommand implements CommandExecutor { public class SendMessageCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (Main.hdc) {
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage("Please input a message to send..."); sender.sendMessage("Please input a message to send...");
return false; return false;
} else { } else {
sender.sendMessage("Sending public message to discord server..."); sender.sendMessage("Sending a public message to the discord server...");
DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages); DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages);
discordWebhook.setUsername("Public Messages"); discordWebhook.setUsername("Public Messages");
String message = String.join(" ", args); String message = String.join(" ", args);
@@ -37,5 +39,10 @@ public class SendMessageCommand implements CommandExecutor {
throw new RuntimeException(e); 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 class SetLoggingModeCommand implements CommandExecutor {
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args[0].isBlank()) { 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; return false;
} else { } else {
if (args[0].equals("true") || args[0].equals("false")) { if (args[0].equals("true") || args[0].equals("false")) {
@@ -22,7 +22,7 @@ public class SetLoggingModeCommand implements CommandExecutor {
writer.close(); writer.close();
System.out.println("Wrote to config, closing writer..."); 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 + "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) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
+9 -9
View File
@@ -1,24 +1,24 @@
main: cf.sobrooms.Main main: cf.sobrooms.Main
version: 1.0.0 version: 1.1.4
name: notifyOnStart name: notifyOnStart
description: Sends webhook_notify to sobrooms when the server starts successfully description: Sends webhook_notify to sobrooms when the server starts successfully
api-version: 1.19 api-version: 1.19
authors: [rrryfoo, sobrooms] authors: [rrryfoo, sobrooms]
commands: commands:
info: info:
description: Shows info about this server. description: Shows information about the Minecraft server.
usage: /info usage: /info
aliases: [i, inf] aliases: [i]
send-message: 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> usage: /send-message <message content>
aliases: [sm, sms, smsg] aliases: [sms]
set-logging: 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> usage: /set-logging <true|false>
permission: op permission: op
aliases: [slg, stl, stlg] aliases: [sl]
ping-server: ping-server:
description: Pings the server. Will not work on Bedrock clients. (ex. through geyser) description: Gets the server ping.
usage: /ping-server usage: /ping-server
aliases: [psrv, ping, pingsrv] aliases: [ping]