commit c794b19531b5222fb0edc0d5af199111ffb82da6 Author: rattatwinko Date: Sat Apr 26 21:43:14 2025 +0200 initial diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..7bc07ec --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Environment-dependent path to Maven home directory +/mavenHomeManager.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..741b3c3 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..942f3a2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..8c89be5 --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..bd1edea --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml new file mode 100644 index 0000000..250ea61 --- /dev/null +++ b/.idea/material_theme_project_new.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eda147d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..78ba208 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MOTD.iml b/MOTD.iml new file mode 100644 index 0000000..3cf00db --- /dev/null +++ b/MOTD.iml @@ -0,0 +1,13 @@ + + + + + + + PAPER + + 1 + + + + \ No newline at end of file diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml new file mode 100644 index 0000000..94531d5 --- /dev/null +++ b/dependency-reduced-pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + org.server_info + MOTD + MOTD + 1.0-SNAPSHOT + + ${project.basedir}/src/main/kotlin + clean package + + + true + src/main/resources + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + + ${java.version} + + + + maven-shade-plugin + 3.5.3 + + + package + + shade + + + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + io.papermc.paper + paper-api + 1.21.5-R0.1-SNAPSHOT + provided + + + + UTF-8 + 2.2.0-Beta1 + 21 + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ceb2f2a --- /dev/null +++ b/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + org.server_info + MOTD + 1.0-SNAPSHOT + jar + + MOTD + + + 21 + 2.2.0-Beta1 + UTF-8 + + + + clean package + ${project.basedir}/src/main/kotlin + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.5.3 + + + package + + shade + + + + + + + + src/main/resources + true + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + io.papermc.paper + paper-api + 1.21.5-R0.1-SNAPSHOT + provided + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + diff --git a/src/main/kotlin/org/server_info/mOTD/MOTD.kt b/src/main/kotlin/org/server_info/mOTD/MOTD.kt new file mode 100644 index 0000000..7e5263a --- /dev/null +++ b/src/main/kotlin/org/server_info/mOTD/MOTD.kt @@ -0,0 +1,123 @@ +package org.server_info.MOTD + +import org.bukkit.Bukkit +import org.bukkit.plugin.java.JavaPlugin + +class MOTD : JavaPlugin() { + private var quotesTask: Int = -1 + private val quotesList = ArrayList() + + override fun onEnable() { + // Save default config if it doesn't exist + saveDefaultConfig() + + // Load quotes from config + loadQuotes() + + // Register command + getCommand("motd")?.setExecutor(MOTDCommand(this)) + + // Schedule the MOTD update task + startQuoteTask() + + logger.info("MOTD Quote Plugin enabled! Loaded ${quotesList.size} quotes.") + } + + override fun onDisable() { + // Cancel the task when the plugin is disabled + if (quotesTask != -1) { + Bukkit.getScheduler().cancelTask(quotesTask) + } + logger.info("MOTD Quote Plugin disabled!") + } + + private fun loadQuotes() { + // Clear existing quotes + quotesList.clear() + + // Load quotes from config + val configQuotes = config.getStringList("quotes") + if (configQuotes.isNotEmpty()) { + quotesList.addAll(configQuotes) + } else { + // Add default quotes if none found in config + quotesList.add("If at first you don't succeed, then skydiving definitely isn't for you.") + quotesList.add("I told my wife she was drawing her eyebrows too high. She looked surprised.") + quotesList.add("I'm not lazy, I'm just on energy-saving mode.") + quotesList.add("I don't have a bad handwriting, I have my own font.") + quotesList.add("When life gives you lemons, squirt someone in the eye.") + + // Save default quotes to config + config.set("quotes", quotesList) + saveConfig() + logger.info("No quotes found in config, created default quotes list.") + } + } + + fun startQuoteTask() { + // Cancel existing task if running + if (quotesTask != -1) { + Bukkit.getScheduler().cancelTask(quotesTask) + } + + // Get update interval from config (default: 60 minutes) + val intervalMinutes = config.getLong("update-interval-minutes", 60) + + // Schedule repeating task + quotesTask = Bukkit.getScheduler().scheduleSyncRepeatingTask( + this, + { updateServerMOTD() }, + 20L, // Initial delay (1 second) + intervalMinutes * 60 * 20L // Convert minutes to ticks (20 ticks = 1 second) + ) + + logger.info("MOTD update task scheduled to run every $intervalMinutes minutes.") + } + + fun updateServerMOTD() { + if (quotesList.isEmpty()) { + logger.warning("No quotes available to set MOTD!") + return + } + + // Get a random quote + val quote = getRandomQuote() + + // Format the quote + val formattedQuote = formatMOTD(quote) + + // Set the server MOTD + val server = Bukkit.getServer() + server.motd = formattedQuote + + logger.info("MOTD updated: $formattedQuote") + } + + fun getRandomQuote(): String { + return if (quotesList.isNotEmpty()) { + quotesList.random() + } else { + "No quotes available" + } + } + + private fun formatMOTD(quote: String): String { + // Get prefix and suffix from config + val prefix = config.getString("motd-prefix", "§e§l") ?: "§e§l" + val suffix = config.getString("motd-suffix", "") ?: "" + + // Trim and limit the quote length if it's too long (Minecraft has MOTD length limitations) + val maxLength = config.getInt("max-motd-length", 50) + var trimmedQuote = quote + if (trimmedQuote.length > maxLength) { + trimmedQuote = trimmedQuote.substring(0, maxLength - 3) + "..." + } + + return prefix + trimmedQuote + suffix + } + + fun reloadQuotes() { + reloadConfig() + loadQuotes() + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/server_info/mOTD/MOTDCommand.kt b/src/main/kotlin/org/server_info/mOTD/MOTDCommand.kt new file mode 100644 index 0000000..0bc4040 --- /dev/null +++ b/src/main/kotlin/org/server_info/mOTD/MOTDCommand.kt @@ -0,0 +1,48 @@ +package org.server_info.MOTD + +import org.bukkit.ChatColor +import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor +import org.bukkit.command.CommandSender + +class MOTDCommand(private val plugin: MOTD) : CommandExecutor { + + override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array): Boolean { + if (args.isEmpty()) { + // Display help + sender.sendMessage("${ChatColor.GOLD}==== MOTD Quote Plugin ====") + sender.sendMessage("${ChatColor.YELLOW}/motd refresh ${ChatColor.WHITE}- Set a new random quote") + sender.sendMessage("${ChatColor.YELLOW}/motd reload ${ChatColor.WHITE}- Reload quotes from config") + return true + } + + when (args[0].lowercase()) { + "refresh" -> { + if (!sender.hasPermission("motd.refresh")) { + sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.") + return true + } + + sender.sendMessage("${ChatColor.YELLOW}Setting a new random quote...") + plugin.updateServerMOTD() + sender.sendMessage("${ChatColor.GREEN}MOTD has been updated!") + return true + } + "reload" -> { + if (!sender.hasPermission("motd.reload")) { + sender.sendMessage("${ChatColor.RED}You don't have permission to use this command.") + return true + } + + plugin.reloadQuotes() + plugin.startQuoteTask() + sender.sendMessage("${ChatColor.GREEN}MOTD quotes reloaded from config!") + return true + } + else -> { + sender.sendMessage("${ChatColor.RED}Unknown command. Use /motd for help.") + return true + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..96908dc --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,21 @@ +# MOTD Quote Plugin Configuration + +# How often to update the MOTD (in minutes) +update-interval-minutes: 60 + +# Maximum length for MOTD quotes +max-motd-length: 50 + +# Style settings +motd-prefix: "§e§l" # Gold color and bold +motd-suffix: "" + +# Debug mode (shows more console output) +debug: false + +# List of quotes to use for MOTD +quotes: + - "Wie heißt der Workshop? Rassismus ohne Schule" + - "What da fäck is hier passiert bitte sehr?" + - "Digga meine Yeezys!" + - "Da Sessel kommt auffi, nd owi." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..0e80500 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,22 @@ +name: MOTD +version: 1.0-SNAPSHOT +main: org.server_info.MOTD.MOTD +api-version: 1.19 +description: Sets the server MOTD to random quotes from config +author: YourName +commands: + motd: + description: Control the MOTD quote plugin + usage: /motd [refresh|reload] + permission: motd.use + aliases: [quotemotd] +permissions: + motd.use: + description: Allows using basic MOTD commands + default: true + motd.refresh: + description: Allows refreshing the MOTD quote + default: op + motd.reload: + description: Allows reloading the plugin configuration + default: op \ No newline at end of file diff --git a/target/MOTD-1.0-SNAPSHOT.jar b/target/MOTD-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..5f67735 Binary files /dev/null and b/target/MOTD-1.0-SNAPSHOT.jar differ diff --git a/target/classes/META-INF/MOTD.kotlin_module b/target/classes/META-INF/MOTD.kotlin_module new file mode 100644 index 0000000..ef915de Binary files /dev/null and b/target/classes/META-INF/MOTD.kotlin_module differ diff --git a/target/classes/config.yml b/target/classes/config.yml new file mode 100644 index 0000000..96908dc --- /dev/null +++ b/target/classes/config.yml @@ -0,0 +1,21 @@ +# MOTD Quote Plugin Configuration + +# How often to update the MOTD (in minutes) +update-interval-minutes: 60 + +# Maximum length for MOTD quotes +max-motd-length: 50 + +# Style settings +motd-prefix: "§e§l" # Gold color and bold +motd-suffix: "" + +# Debug mode (shows more console output) +debug: false + +# List of quotes to use for MOTD +quotes: + - "Wie heißt der Workshop? Rassismus ohne Schule" + - "What da fäck is hier passiert bitte sehr?" + - "Digga meine Yeezys!" + - "Da Sessel kommt auffi, nd owi." diff --git a/target/classes/org/server_info/MOTD/MOTD.class b/target/classes/org/server_info/MOTD/MOTD.class new file mode 100644 index 0000000..858578a Binary files /dev/null and b/target/classes/org/server_info/MOTD/MOTD.class differ diff --git a/target/classes/org/server_info/MOTD/MOTDCommand.class b/target/classes/org/server_info/MOTD/MOTDCommand.class new file mode 100644 index 0000000..82ec72c Binary files /dev/null and b/target/classes/org/server_info/MOTD/MOTDCommand.class differ diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml new file mode 100644 index 0000000..0e80500 --- /dev/null +++ b/target/classes/plugin.yml @@ -0,0 +1,22 @@ +name: MOTD +version: 1.0-SNAPSHOT +main: org.server_info.MOTD.MOTD +api-version: 1.19 +description: Sets the server MOTD to random quotes from config +author: YourName +commands: + motd: + description: Control the MOTD quote plugin + usage: /motd [refresh|reload] + permission: motd.use + aliases: [quotemotd] +permissions: + motd.use: + description: Allows using basic MOTD commands + default: true + motd.refresh: + description: Allows refreshing the MOTD quote + default: op + motd.reload: + description: Allows reloading the plugin configuration + default: op \ No newline at end of file diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..d6bf5e5 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,3 @@ +artifactId=MOTD +groupId=org.server_info +version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/target/original-MOTD-1.0-SNAPSHOT.jar b/target/original-MOTD-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..85041dc Binary files /dev/null and b/target/original-MOTD-1.0-SNAPSHOT.jar differ