Added Randomization

This commit is contained in:
TheTrouper
2023-02-17 22:38:55 -06:00
committed by GitHub
parent e91df1b506
commit e9c516fad4
7 changed files with 37 additions and 30 deletions

View File

@@ -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!

View File

@@ -1 +1 @@
rootProject.name = 'ExamplePlugin'
rootProject.name = 'SlashWelcome'

View File

@@ -34,10 +34,6 @@ 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

@@ -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<String> messages = Config.Plugin.messages;
List<String> options = new ArrayList(Config.Plugin.options);
int random = Config.choice(0,options.size());
List<String> 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();
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);

View File

@@ -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<String> messages = config.getStringList("config.plugin.messages");
public static final Integer delay = config.getInt("config.plugin.delay");
public static final Set<String> options = config.getConfigurationSection("config.plugin.messages").getKeys(false);
}
}

View File

@@ -6,7 +6,11 @@
config:
plugin:
prefix: "§7[§aSlashWelcome§7]"
time: 24
delay: 24
messages:
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!"

View File

@@ -11,6 +11,6 @@ permissions:
default: op
commands:
welcome:
description: An example command.
description: Welcomes new players.
usage: /welcome <player>
permission-message: You do not have permission!