From e9c516fad49c87111bf5a3296e2ea22b8f91a52b Mon Sep 17 00:00:00 2001 From: TheTrouper <93684527+thetrouper@users.noreply.github.com> Date: Fri, 17 Feb 2023 22:38:55 -0600 Subject: [PATCH] Added Randomization --- README.md | 22 ++++++++----------- settings.gradle | 2 +- .../exampleplugin/ExamplePlugin.java | 4 ---- .../commands/CommandExample.java | 17 +++++++++----- .../itzispyder/exampleplugin/data/Config.java | 10 +++++++-- src/main/resources/config.yml | 10 ++++++--- src/main/resources/plugin.yml | 2 +- 7 files changed, 37 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index e0deb50..ce7f66e 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,22 @@ -# SlashWelcome -A simple way to welcome new players +# ExamplePluginTemplate +An example plugin template for beginners! ----------------------------------------------------- -Make poeple feel welcomed with one command! +Trying to create your first plugin? Use this template to get started easily! -- Multiple welcome messages -- Randomization -- Delay (Humanization) +- Comments to guide you +- Made some example classes +- Added some useful utils ----------------------------------------------------- ## How to use -Download the latest realease or build it in gradle +Download this template -\> Load it into your IDE or development environment. [Check out IntelliJ](https://www.jetbrains.com/idea/download/?fromIDE=#section=windows) -\> Get Creative! -- To build your jar file simply go into the terminal and run `gradlew build` +- To build your jar file simply go into the terminal and run `./gradlew build` - Your finished jar should appear in `build/libs`! -Install the plugin by dropping it in your plugins -- if you have [PlugManX](https://www.spigotmc.org/resources/plugmanx.88135/) -- - Do `/plugman load SlashWelcome` -- - Then `/plugman reload SlashWelcome` -- Otherwise do `/reload confirm` or restart the server ----------------------------------------------------- +Have a nice day, happy coding! diff --git a/settings.gradle b/settings.gradle index adb03af..d22861f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'ExamplePlugin' +rootProject.name = 'SlashWelcome' diff --git a/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java b/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java index f7d19f7..f833b3d 100644 --- a/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java +++ b/src/main/java/io/github/itzispyder/exampleplugin/ExamplePlugin.java @@ -34,10 +34,6 @@ 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 dbec453..bb922e5 100644 --- a/src/main/java/io/github/itzispyder/exampleplugin/commands/CommandExample.java +++ b/src/main/java/io/github/itzispyder/exampleplugin/commands/CommandExample.java @@ -19,6 +19,7 @@ import org.bukkit.scheduler.BukkitRunnable; import java.util.ArrayList; import java.util.List; +import java.util.Set; /** * Example command @@ -30,17 +31,21 @@ public class CommandExample implements CommandExecutor { try { Player P = (Player) sender; Player W = Bukkit.getPlayer(args[0]); - "messages.get(i)".replaceAll("%player%",W.getName()); - List messages = Config.Plugin.messages; + List options = new ArrayList(Config.Plugin.options); + int random = Config.choice(0,options.size()); + List messages = Config.config.getStringList("config.plugin.messages." + options.get(random)); + Integer delay = Config.Plugin.delay; + P.chat(options.toString() + " " + random); 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 ++; + if (i < messages.size()) { + P.chat(messages.get(i).replaceAll("%player%",W.getName())); + i ++; + } else this.cancel(); } - }.runTaskTimer(ExamplePlugin.getInstance(),0,20); + }.runTaskTimer(ExamplePlugin.getInstance(),0,delay); 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 5a44c9e..d1197bc 100644 --- a/src/main/java/io/github/itzispyder/exampleplugin/data/Config.java +++ b/src/main/java/io/github/itzispyder/exampleplugin/data/Config.java @@ -7,14 +7,19 @@ package io.github.itzispyder.exampleplugin.data; import io.github.itzispyder.exampleplugin.ExamplePlugin; import org.bukkit.configuration.file.FileConfiguration; +import java.util.Arrays; import java.util.List; +import java.util.Set; /** * Config loader */ public abstract class Config { - private static final FileConfiguration config = ExamplePlugin.getInstance().getConfig(); + public static final FileConfiguration config = ExamplePlugin.getInstance().getConfig(); + public static int choice(int min, int max) { + return min + (int) Math.floor(Math.random() * (max - min)); + } /** * Config plugin section @@ -23,6 +28,7 @@ public abstract class Config { public static String getPrefix() { return config.getString("config.plugin.prefix"); } - public static final List messages = config.getStringList("config.plugin.messages"); + public static final Integer delay = config.getInt("config.plugin.delay"); + public static final Set options = config.getConfigurationSection("config.plugin.messages").getKeys(false); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index abb2b30..9874b51 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,7 +6,11 @@ config: plugin: prefix: "§7[§aSlashWelcome§7]" - time: 24 + delay: 24 messages: - - "Welcome to OgreDupe, %player%!" - - "Do /daily for a key and /kit for some free gear." + A: + - "Welcome to OgreDupe, %player%!" + - "Do /daily for a key and /kit for some free gear." + B: + - "Have fun, %player%!" + - "Feel free to do /daily for a key and /kit for gear!" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index c669ffb..69ada35 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -11,6 +11,6 @@ permissions: default: op commands: welcome: - description: An example command. + description: Welcomes new players. usage: /welcome permission-message: You do not have permission! \ No newline at end of file