From cd5afc1030e1a83da5432823747f6caa29659232 Mon Sep 17 00:00:00 2001 From: TheTrouper <93684527+thetrouper@users.noreply.github.com> Date: Fri, 17 Feb 2023 17:52:45 -0600 Subject: [PATCH] Config for multiple messages --- .../exampleplugin/ExamplePlugin.java | 5 +++++ .../commands/CommandExample.java | 21 ++++++++++++------- .../itzispyder/exampleplugin/data/Config.java | 3 +++ src/main/resources/config.yml | 6 +++++- src/main/resources/plugin.yml | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java b/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java index 535b8b0..f7d19f7 100644 --- a/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java +++ b/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java @@ -12,6 +12,7 @@ import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import java.util.List; import java.util.logging.Logger; /** @@ -33,6 +34,10 @@ public final class ExamplePlugin extends JavaPlugin { // Files getConfig().options().copyDefaults(); saveDefaultConfig(); + List messages = (List)getConfig().getList("config.plugin.messages"); + for (String message : messages) { + Bukkit.getLogger().info(message); + } // Plugin startup logic log.info("Example plugin has loaded! (" + getDescription().getVersion() + ")"); starter = Config.Plugin.getPrefix() + " "; diff --git a/src/main/java/io/github/itzispyder/exampleplugin/commands/CommandExample.java b/src/main/java/io/github/itzispyder/exampleplugin/commands/CommandExample.java index 01a3677..dbec453 100644 --- a/src/main/java/io/github/itzispyder/exampleplugin/commands/CommandExample.java +++ b/src/main/java/io/github/itzispyder/exampleplugin/commands/CommandExample.java @@ -5,6 +5,7 @@ package io.github.itzispyder.exampleplugin.commands; import io.github.itzispyder.exampleplugin.ExamplePlugin; +import io.github.itzispyder.exampleplugin.data.Config; import io.github.itzispyder.exampleplugin.exceptions.CmdExHandler; import io.github.itzispyder.exampleplugin.server.util.ServerUtils; import org.bukkit.Bukkit; @@ -13,6 +14,8 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.List; @@ -27,13 +30,17 @@ public class CommandExample implements CommandExecutor { try { Player P = (Player) sender; Player W = Bukkit.getPlayer(args[0]); - for (int i = 0; i < 1; i++) { - P.chat("§bWelcome " + W.getName() + "!"); - Bukkit.getScheduler().scheduleSyncDelayedTask(ExamplePlugin.getInstance(),() -> { - P.chat("§bDo /daily for a key and /kit for some free gear!"); - }, 20); - - } + "messages.get(i)".replaceAll("%player%",W.getName()); + List messages = Config.Plugin.messages; + new BukkitRunnable() { + int i = 0; + @Override + public void run() { + if (i >= messages.size()) this.cancel(); + P.chat(messages.get(i).replaceAll("%player%",W.getName())); + i ++; + } + }.runTaskTimer(ExamplePlugin.getInstance(),0,20); return true; } catch (Exception ex) { CmdExHandler handler = new CmdExHandler(ex,command); diff --git a/src/main/java/io/github/itzispyder/exampleplugin/data/Config.java b/src/main/java/io/github/itzispyder/exampleplugin/data/Config.java index c054433..5a44c9e 100644 --- a/src/main/java/io/github/itzispyder/exampleplugin/data/Config.java +++ b/src/main/java/io/github/itzispyder/exampleplugin/data/Config.java @@ -7,6 +7,8 @@ package io.github.itzispyder.exampleplugin.data; import io.github.itzispyder.exampleplugin.ExamplePlugin; import org.bukkit.configuration.file.FileConfiguration; +import java.util.List; + /** * Config loader */ @@ -21,5 +23,6 @@ public abstract class Config { public static String getPrefix() { return config.getString("config.plugin.prefix"); } + public static final List messages = config.getStringList("config.plugin.messages"); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3dde858..abb2b30 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,4 +5,8 @@ # config: plugin: - prefix: "§7[§aExamplePlugin§7]" + prefix: "§7[§aSlashWelcome§7]" + time: 24 + messages: + - "Welcome to OgreDupe, %player%!" + - "Do /daily for a key and /kit for some free gear." diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1deb018..c669ffb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -12,5 +12,5 @@ permissions: commands: welcome: description: An example command. - usage: /example + usage: /welcome permission-message: You do not have permission! \ No newline at end of file