Added Randomization
This commit is contained in:
22
README.md
22
README.md
@@ -1,26 +1,22 @@
|
|||||||
# SlashWelcome
|
# ExamplePluginTemplate
|
||||||
A simple way to welcome new players
|
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
|
- Comments to guide you
|
||||||
- Randomization
|
- Made some example classes
|
||||||
- Delay (Humanization)
|
- Added some useful utils
|
||||||
|
|
||||||
-----------------------------------------------------
|
-----------------------------------------------------
|
||||||
|
|
||||||
## How to use
|
## 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`!
|
- 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!
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
rootProject.name = 'ExamplePlugin'
|
rootProject.name = 'SlashWelcome'
|
||||||
|
|||||||
@@ -34,10 +34,6 @@ public final class ExamplePlugin extends JavaPlugin {
|
|||||||
// Files
|
// Files
|
||||||
getConfig().options().copyDefaults();
|
getConfig().options().copyDefaults();
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
List<String> messages = (List<String>)getConfig().getList("config.plugin.messages");
|
|
||||||
for (String message : messages) {
|
|
||||||
Bukkit.getLogger().info(message);
|
|
||||||
}
|
|
||||||
// Plugin startup logic
|
// Plugin startup logic
|
||||||
log.info("Example plugin has loaded! (" + getDescription().getVersion() + ")");
|
log.info("Example plugin has loaded! (" + getDescription().getVersion() + ")");
|
||||||
starter = Config.Plugin.getPrefix() + " ";
|
starter = Config.Plugin.getPrefix() + " ";
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example command
|
* Example command
|
||||||
@@ -30,17 +31,21 @@ public class CommandExample implements CommandExecutor {
|
|||||||
try {
|
try {
|
||||||
Player P = (Player) sender;
|
Player P = (Player) sender;
|
||||||
Player W = Bukkit.getPlayer(args[0]);
|
Player W = Bukkit.getPlayer(args[0]);
|
||||||
"messages.get(i)".replaceAll("%player%",W.getName());
|
List<String> options = new ArrayList(Config.Plugin.options);
|
||||||
List<String> messages = Config.Plugin.messages;
|
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() {
|
new BukkitRunnable() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (i >= messages.size()) this.cancel();
|
if (i < messages.size()) {
|
||||||
P.chat(messages.get(i).replaceAll("%player%",W.getName()));
|
P.chat(messages.get(i).replaceAll("%player%",W.getName()));
|
||||||
i ++;
|
i ++;
|
||||||
|
} else this.cancel();
|
||||||
}
|
}
|
||||||
}.runTaskTimer(ExamplePlugin.getInstance(),0,20);
|
}.runTaskTimer(ExamplePlugin.getInstance(),0,delay);
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
CmdExHandler handler = new CmdExHandler(ex,command);
|
CmdExHandler handler = new CmdExHandler(ex,command);
|
||||||
|
|||||||
@@ -7,14 +7,19 @@ package io.github.itzispyder.exampleplugin.data;
|
|||||||
import io.github.itzispyder.exampleplugin.ExamplePlugin;
|
import io.github.itzispyder.exampleplugin.ExamplePlugin;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Config loader
|
* Config loader
|
||||||
*/
|
*/
|
||||||
public abstract class Config {
|
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
|
* Config plugin section
|
||||||
@@ -23,6 +28,7 @@ public abstract class Config {
|
|||||||
public static String getPrefix() {
|
public static String getPrefix() {
|
||||||
return config.getString("config.plugin.prefix");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@
|
|||||||
config:
|
config:
|
||||||
plugin:
|
plugin:
|
||||||
prefix: "§7[§aSlashWelcome§7]"
|
prefix: "§7[§aSlashWelcome§7]"
|
||||||
time: 24
|
delay: 24
|
||||||
messages:
|
messages:
|
||||||
|
A:
|
||||||
- "Welcome to OgreDupe, %player%!"
|
- "Welcome to OgreDupe, %player%!"
|
||||||
- "Do /daily for a key and /kit for some free gear."
|
- "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!"
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ permissions:
|
|||||||
default: op
|
default: op
|
||||||
commands:
|
commands:
|
||||||
welcome:
|
welcome:
|
||||||
description: An example command.
|
description: Welcomes new players.
|
||||||
usage: /welcome <player>
|
usage: /welcome <player>
|
||||||
permission-message: You do not have permission!
|
permission-message: You do not have permission!
|
||||||
Reference in New Issue
Block a user