Made appendtext commands fully configurable
This commit is contained in:
parent
8ff45ad676
commit
ae49777007
8 changed files with 96 additions and 123 deletions
|
@ -2,6 +2,7 @@ package buttondevteam.chat;
|
|||
|
||||
import buttondevteam.chat.commands.YeehawCommand;
|
||||
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
||||
import buttondevteam.chat.components.appendext.AppendTextComponent;
|
||||
import buttondevteam.chat.components.flair.FlairComponent;
|
||||
import buttondevteam.chat.components.fun.FunComponent;
|
||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||
|
@ -66,6 +67,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
|
|||
Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin
|
||||
Component.registerComponent(this, new AnnouncerComponent());
|
||||
Component.registerComponent(this, new FunComponent());
|
||||
Component.registerComponent(this, new AppendTextComponent());
|
||||
}
|
||||
|
||||
public static Essentials essentials = null;
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@CommandClass(modOnly = false, excludeFromPath = true)
|
||||
public abstract class AppendTextCommandBase extends TBMCCommandBase {
|
||||
|
||||
public abstract String[] GetHelpText(String alias);
|
||||
|
||||
public abstract String GetAppendedText();
|
||||
|
||||
@Override
|
||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
for (String arg : args) msg.append(arg).append(" ");
|
||||
msg.append(GetAppendedText());
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender,
|
||||
ChromaGamerBase.getFromSender(sender), msg.toString())
|
||||
.fromCommand(true).build());
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class LennyCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Lenny ----", //
|
||||
"This command appends a Lenny face after your message", //
|
||||
"Or just sends one", //
|
||||
"Use either /" + alias + " <message> or just /" + alias }; //
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "( ͡° ͜ʖ ͡°)";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class ShrugCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Shrug ----", //
|
||||
"This command appends a shrug after your message", //
|
||||
"Or just makes you shrug", //
|
||||
"Use either /" + alias + " <message> or just /" + alias }; //
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "¯\\\\\\_(ツ)\\_/¯";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class TableflipCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Tableflip ----", //
|
||||
"This command appends a tableflip after your message", //
|
||||
"Or just makes you tableflip", //
|
||||
"Use either /" + alias + " <message> or just /" + alias };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "(╯°□°)╯︵ ┻━┻";
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
public final class UnflipCommand extends AppendTextCommandBase {
|
||||
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { "§6---- Unflip ----", //
|
||||
"This command appends an unflip after your message", //
|
||||
"Or just unflips as you", //
|
||||
"Use either /" + alias + " <message> or just /" + alias };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "┬─┬ ノ( ゜-゜ノ)";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package buttondevteam.chat.commands.appendtext;
|
||||
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
|
||||
@CommandClass(modOnly = false)
|
||||
public class WaitWhatCommand extends AppendTextCommandBase {
|
||||
@Override
|
||||
public String[] GetHelpText(String alias) {
|
||||
return new String[] { //
|
||||
"§6--- Wait what ----", //
|
||||
"Wait what" //
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String GetAppendedText() {
|
||||
return "wait what";
|
||||
}
|
||||
}
|
|
@ -1,27 +1,115 @@
|
|||
package buttondevteam.chat.components.appendext;
|
||||
|
||||
import buttondevteam.chat.PluginMain;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import buttondevteam.lib.chat.*;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import lombok.val;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class AppendTextComponent extends Component {
|
||||
private HashMap<String, IHaveConfig> appendTexts=new HashMap<>();
|
||||
public class AppendTextComponent extends Component<PluginMain> {
|
||||
private Map<String, IHaveConfig> appendTexts;
|
||||
private ConfigData<String[]> helpText(IHaveConfig config) {
|
||||
return config.getData("helpText", ()->new String[0]);
|
||||
return config.getData("helpText", () -> new String[]{
|
||||
"Tableflip", //
|
||||
"This command appends a tableflip after your message", //
|
||||
"Or just makes you tableflip", //
|
||||
});
|
||||
}
|
||||
|
||||
private ConfigData<String> appendedText(IHaveConfig config) {
|
||||
return config.getData("appendedText", () -> "tableflip");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void enable() {
|
||||
val cs=getConfig().getConfig(); //TODO
|
||||
val map = new HashMap<String, Consumer<IHaveConfig>>();
|
||||
map.put("tableflip", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Tableflip", //
|
||||
"This command appends a tableflip after your message", //
|
||||
"Or just makes you tableflip", //
|
||||
});
|
||||
appendedText(conf).set("(╯°□°)╯︵ ┻━┻");
|
||||
});
|
||||
map.put("unflip", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Unflip", //
|
||||
"This command appends an unflip after your message", //
|
||||
"Or just unflips as you", //
|
||||
});
|
||||
appendedText(conf).set("┬─┬ ノ( ゜-゜ノ)");
|
||||
});
|
||||
map.put("shrug", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Shrug", //
|
||||
"This command appends a shrug after your message", //
|
||||
"Or just makes you shrug", //
|
||||
});
|
||||
appendedText(conf).set("¯\\\\\\_(ツ)\\_/¯");
|
||||
});
|
||||
map.put("lenny", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Lenny", //
|
||||
"This command appends a Lenny face after your message", //
|
||||
"Or just sends one", //
|
||||
});
|
||||
appendedText(conf).set("( ͡° ͜ʖ ͡°)");
|
||||
});
|
||||
map.put("ww", conf -> {
|
||||
helpText(conf).set(new String[]{
|
||||
"Wait what", //
|
||||
"Wait what" //
|
||||
});
|
||||
appendedText(conf).set("wait what");
|
||||
});
|
||||
appendTexts = getConfigMap("texts", map);
|
||||
for (String cmd : appendTexts.keySet())
|
||||
registerCommand(new CommandHandler(cmd));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void disable() {
|
||||
|
||||
}
|
||||
|
||||
@CommandClass
|
||||
public class CommandHandler extends ICommand2MC {
|
||||
private final String path;
|
||||
private final String[] helpText;
|
||||
private final String appendedText;
|
||||
|
||||
CommandHandler(String command) {
|
||||
val conf = appendTexts.get(command);
|
||||
if (conf == null) throw new NoSuchElementException("AppendText command not found: " + command);
|
||||
path = command;
|
||||
helpText = helpText(conf).get();
|
||||
appendedText = appendedText(conf).get();
|
||||
|
||||
}
|
||||
|
||||
@Command2.Subcommand
|
||||
public void def(CommandSender sender, @Command2.OptionalArg @Command2.TextArg String message) {
|
||||
TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, ChromaGamerBase.getFromSender(sender),
|
||||
(message == null ? "" : message + " ") + appendedText).fromCommand(true).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommandPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHelpText(Method method, Command2.Subcommand ann) {
|
||||
return helpText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue