Config for multiple messages

This commit is contained in:
TheTrouper
2023-02-17 17:52:45 -06:00
committed by GitHub
parent fccb0454c6
commit cd5afc1030
5 changed files with 28 additions and 9 deletions

View File

@@ -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<String> messages = (List<String>)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() + " ";

View File

@@ -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<String> 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);

View File

@@ -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<String> messages = config.getStringList("config.plugin.messages");
}
}

View File

@@ -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."

View File

@@ -12,5 +12,5 @@ permissions:
commands:
welcome:
description: An example command.
usage: /example
usage: /welcome <player>
permission-message: You do not have permission!