Skip to content

Instantly share code, notes, and snippets.

@WouterG
Last active February 27, 2020 12:58
Show Gist options
  • Save WouterG/987fee2c99f96f8cf8a59fd28896b478 to your computer and use it in GitHub Desktop.
Save WouterG/987fee2c99f96f8cf8a59fd28896b478 to your computer and use it in GitHub Desktop.
import net.menoni.rd.RuntimeDebugger;
import net.menoni.rd.model.Debugger;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class messages implements Debugger, Debugger.CommandExecutor {
private Player p;
@Override
public void debug(RuntimeDebugger plugin, CommandSender cs) {
if (!(cs instanceof Player)) {
cs.sendMessage("Command needs to be run by a player");
return;
}
this.p = (Player) cs;
}
public void showHelp() {
List<String> options = new ArrayList<>();
for (Messages value : Messages.values()) {
options.add(value.name());
}
p.sendMessage(ChatColor.YELLOW + "Choose one of: " + ChatColor.GOLD + String.join(ChatColor.YELLOW + ", " + ChatColor.GOLD, options));
}
public void msg(String message, Object... formatObjects) {
if (formatObjects != null && formatObjects.length > 0) {
for (int i = 0; i < formatObjects.length; i++) {
String s = "null";
if (formatObjects[i] != null)
s = formatObjects[i].toString();
message = message.replaceAll(Pattern.quote("{" + i + "}"), s);
}
}
p.sendMessage(message);
}
@Override
public void onCommand(CommandSender cs, String[] cmdArgs) {
if (cmdArgs.length > 0) {
for (Messages value : Messages.values()) {
if (value.name().equalsIgnoreCase(cmdArgs[0])) {
msg("");
value.send(this);
msg("");
return;
}
}
}
showHelp();
}
public static class Msg {
private String message;
private Object[] formatObjects;
public Msg(String message) {
this.message = message;
}
public Msg(String message, Object[] formatObjects) {
this.message = message;
this.formatObjects = formatObjects;
}
public String getMessage() {
return message;
}
public Object[] getFormatObjects() {
return formatObjects;
}
}
public enum Messages {
PASSPORT_NOARGS(
new Msg(ChatColor.GREEN + "Start creating a CubeCraft account by going to our website" + ChatColor.DARK_GREEN + ChatColor.BOLD + " HERE")
),
PASSPORT_CODE_ENTERED(
new Msg(ChatColor.GREEN + "Your minecraft account has successfully been linked")
),
;
private Msg[] messages;
Messages(Msg... messages) {
this.messages = messages;
}
public void send(messages m) {
for (Msg message : this.messages) {
m.msg(message.getMessage(), message.getFormatObjects());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment