More components, broadcasts #98
28 changed files with 428 additions and 608 deletions
|
@ -1,5 +1,10 @@
|
||||||
package buttondevteam.chat;
|
package buttondevteam.chat;
|
||||||
|
|
||||||
|
import buttondevteam.chat.commands.MWikiCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.HelpCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.HistoryCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.InfoCommand;
|
||||||
|
import buttondevteam.chat.commands.ucmds.admin.DebugCommand;
|
||||||
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
import buttondevteam.chat.components.announce.AnnouncerComponent;
|
||||||
import buttondevteam.chat.components.appendext.AppendTextComponent;
|
import buttondevteam.chat.components.appendext.AppendTextComponent;
|
||||||
import buttondevteam.chat.components.flair.FlairComponent;
|
import buttondevteam.chat.components.flair.FlairComponent;
|
||||||
|
@ -67,6 +72,11 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15
|
||||||
Component.registerComponent(this, new AnnouncerComponent());
|
Component.registerComponent(this, new AnnouncerComponent());
|
||||||
Component.registerComponent(this, new FunComponent());
|
Component.registerComponent(this, new FunComponent());
|
||||||
Component.registerComponent(this, new AppendTextComponent());
|
Component.registerComponent(this, new AppendTextComponent());
|
||||||
|
getCommand2MC().registerCommand(new DebugCommand());
|
||||||
|
getCommand2MC().registerCommand(new HelpCommand());
|
||||||
|
getCommand2MC().registerCommand(new HistoryCommand());
|
||||||
|
getCommand2MC().registerCommand(new InfoCommand());
|
||||||
|
getCommand2MC().registerCommand(new MWikiCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Essentials essentials = null;
|
public static Essentials essentials = null;
|
||||||
|
|
|
@ -1,33 +1,24 @@
|
||||||
package buttondevteam.chat.commands;
|
package buttondevteam.chat.commands;
|
||||||
|
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import buttondevteam.lib.chat.ICommand2MC;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
@CommandClass(modOnly = false, helpText = {
|
||||||
|
"Minecraft Wiki linker", //
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
|
||||||
public class MWikiCommand extends TBMCCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- Minecraft Wiki linker ----", //
|
|
||||||
"Use without parameters to get a link to the wiki", //
|
"Use without parameters to get a link to the wiki", //
|
||||||
"You can also search the wiki, for example:", //
|
"You can also search the wiki, for example:", //
|
||||||
" /" + alias + " beacon - Provides a link that redirects to the beacon's wiki page" //
|
" /mwiki beacon - Provides a link that redirects to the beacon's wiki page" //
|
||||||
};
|
})
|
||||||
}
|
public class MWikiCommand extends ICommand2MC {
|
||||||
|
@Command2.Subcommand
|
||||||
@Override
|
public boolean def(CommandSender sender, @Command2.OptionalArg String query) {
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
String query = "";
|
|
||||||
for (int i = 0; i < args.length; i++)
|
|
||||||
query += args[i] + " ";
|
|
||||||
query = query.trim();
|
|
||||||
try {
|
try {
|
||||||
if (query.length() == 0)
|
if (query == null)
|
||||||
sender.sendMessage(new String[] { "§bMinecraft Wiki link: http://minecraft.gamepedia.com/",
|
sender.sendMessage(new String[] { "§bMinecraft Wiki link: http://minecraft.gamepedia.com/",
|
||||||
"You can also search on it using /mwiki <query>" });
|
"You can also search on it using /mwiki <query>" });
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package buttondevteam.chat.commands.ucmds;
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||||
import buttondevteam.lib.chat.TBMCCommandBase;
|
import buttondevteam.lib.chat.TBMCCommandBase;
|
||||||
|
@ -9,30 +10,32 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
@CommandClass(modOnly = false, helpText = {
|
||||||
|
"Help",
|
||||||
|
"Prints out help messages for the TBMC plugins"
|
||||||
|
})
|
||||||
public final class HelpCommand extends UCommandBase {
|
public final class HelpCommand extends UCommandBase {
|
||||||
|
@Command2.Subcommand
|
||||||
@Override
|
public boolean def(CommandSender sender, @Command2.TextArg @Command2.OptionalArg String topicOrCommand) {
|
||||||
public String[] GetHelpText(String alias) {
|
if (topicOrCommand == null) {
|
||||||
return new String[] { "§6---- Help ----", "Prints out help messages for the TBMC plugins" };
|
sender.sendMessage(new String[]{
|
||||||
}
|
"§6---- Thorpe Help ----",
|
||||||
|
"Do /u help <topic> for more info",
|
||||||
@Override
|
"Do /u help <commandname> [subcommands] for more info about a command",
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
"Topics:",
|
||||||
if (args.length == 0) {
|
|
||||||
sender.sendMessage(new String[] { "§6---- TBMC Help ----", "Do /u help <topic> for more info",
|
|
||||||
"Do /u help <commandname> [subcommands] for more info about a command", "Topics:",
|
|
||||||
"commands: See all the commands from this plugin",
|
"commands: See all the commands from this plugin",
|
||||||
"chat: Shows some info about custom chat features", "colors: Shows Minecraft color codes" });
|
"chat: Shows some info about custom chat features",
|
||||||
|
"colors: Shows Minecraft color codes"
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("chat"))
|
if (topicOrCommand.equalsIgnoreCase("chat"))
|
||||||
sender.sendMessage(new String[] { "§6---- Chat features ----",
|
sender.sendMessage(new String[]{"§6---- Chat features ----",
|
||||||
"- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)",
|
"- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)",
|
||||||
"-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)",
|
"-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)",
|
||||||
"- Playernames: Hover over them to get some player info",
|
"- Playernames: Hover over them to get some player info",
|
||||||
"-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\"" });
|
"-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\""});
|
||||||
else if (args[0].equalsIgnoreCase("commands")) {
|
else if (topicOrCommand.equalsIgnoreCase("commands")) {
|
||||||
ArrayList<String> text = new ArrayList<String>();
|
ArrayList<String> text = new ArrayList<String>();
|
||||||
text.add("§6---- Command list ----");
|
text.add("§6---- Command list ----");
|
||||||
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values())
|
for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values())
|
||||||
|
@ -46,8 +49,8 @@ public final class HelpCommand extends UCommandBase {
|
||||||
text.add("/" + topcmd);
|
text.add("/" + topcmd);
|
||||||
}
|
}
|
||||||
sender.sendMessage(text.toArray(new String[0]));
|
sender.sendMessage(text.toArray(new String[0]));
|
||||||
} else if (args[0].equalsIgnoreCase("colors")) {
|
} else if (topicOrCommand.equalsIgnoreCase("colors")) {
|
||||||
sender.sendMessage(new String[] { "§6---- Chat colors/formats ----", //
|
sender.sendMessage(new String[]{"§6---- Chat colors/formats ----", //
|
||||||
"Tellraw name - Code | Tellraw name - Code", //
|
"Tellraw name - Code | Tellraw name - Code", //
|
||||||
"§0black - &0 | §1dark_blue - &1", //
|
"§0black - &0 | §1dark_blue - &1", //
|
||||||
"§2dark_green - &2 | §3dark_aqua - &3", //
|
"§2dark_green - &2 | §3dark_aqua - &3", //
|
||||||
|
@ -60,22 +63,15 @@ public final class HelpCommand extends UCommandBase {
|
||||||
"§rreset - &r | §kk§robfuscated - &k", //
|
"§rreset - &r | §kk§robfuscated - &k", //
|
||||||
"§lbold - &l | §mstrikethrough - &m", //
|
"§lbold - &l | §mstrikethrough - &m", //
|
||||||
"§nunderline - &n | §oitalic - &o", //
|
"§nunderline - &n | §oitalic - &o", //
|
||||||
"The format codes in tellraw should be used like \"italic\":\"true\"" }); //
|
"The format codes in tellraw should be used like \"italic\":\"true\""}); //
|
||||||
} else {
|
} else {
|
||||||
String path = args[0];
|
String[] text = getManager().getHelpText(topicOrCommand);
|
||||||
for (int i = 1; i < args.length; i++)
|
if (text == null)
|
||||||
path += " " + args[i];
|
|
||||||
TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path);
|
|
||||||
if (cmd == null) {
|
|
||||||
String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender);
|
|
||||||
if (subcmds.length > 0)
|
|
||||||
sender.sendMessage(subcmds);
|
|
||||||
else
|
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
new String[] { "§cError: Command not found or you don't have permission for it: " + path,
|
new String[]{"§cError: Command not found: " + topicOrCommand,
|
||||||
"Usage example: /u accept --> /u help u accept" });
|
"Usage example: /u accept --> /u help u accept"});
|
||||||
} else
|
else
|
||||||
sender.sendMessage(cmd.GetHelpText(args[0]));
|
sender.sendMessage(text);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
|
@ -2,48 +2,43 @@ package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
import buttondevteam.core.component.channel.Channel;
|
import buttondevteam.core.component.channel.Channel;
|
||||||
import buttondevteam.lib.chat.ChatMessage;
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.experimental.var;
|
import lombok.experimental.var;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@CommandClass
|
@CommandClass(helpText = {
|
||||||
|
"§6--- Chat History ----", //
|
||||||
|
"Returns the last 10 messages the player can see." //
|
||||||
|
})
|
||||||
public class HistoryCommand extends UCommandBase {
|
public class HistoryCommand extends UCommandBase {
|
||||||
/**
|
/**
|
||||||
* Key: ChannelID_groupID
|
* Key: ChannelID_groupID
|
||||||
*/
|
*/
|
||||||
private static HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
private static HashMap<String, LinkedList<HistoryEntry>> messages = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Command2.Subcommand
|
||||||
public String[] GetHelpText(String alias) {
|
public boolean def(CommandSender sender, @Command2.OptionalArg String channel) {
|
||||||
return new String[]{ //
|
return showHistory(sender, channel);
|
||||||
"§6--- Chat History ----", //
|
|
||||||
"Returns the last 10 messages the player can see." //
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static boolean showHistory(CommandSender sender, String channel) {
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
return showHistory(sender, alias, args, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean showHistory(CommandSender sender, String alias, String[] args, @Nullable HistoryCommand hc) {
|
|
||||||
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
|
Function<Channel, LinkedList<HistoryEntry>> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map
|
||||||
sender.sendMessage("§6---- Chat History ----");
|
sender.sendMessage("§6---- Chat History ----");
|
||||||
Stream<Channel> stream;
|
Stream<Channel> stream;
|
||||||
if (args.length == 0) {
|
if (channel == null) {
|
||||||
stream = Channel.getChannels();
|
stream = Channel.getChannels();
|
||||||
} else {
|
} else {
|
||||||
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny();
|
Optional<Channel> och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(channel)).findAny();
|
||||||
if (!och.isPresent()) {
|
if (!och.isPresent()) {
|
||||||
sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " g");
|
sender.sendMessage("§cChannel not found. Use the ID, for example: /u history g");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
stream = Stream.of(och.get());
|
stream = Stream.of(och.get());
|
||||||
|
|
|
@ -1,35 +1,26 @@
|
||||||
package buttondevteam.chat.commands.ucmds;
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
@CommandClass(modOnly = false, helpText = {
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
"User information", //
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
|
||||||
import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
|
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
|
||||||
public class InfoCommand extends UCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { //
|
|
||||||
"§6---- User information ----", //
|
|
||||||
"Get some information known about the user.", //
|
"Get some information known about the user.", //
|
||||||
"Usage: /" + alias + " info <playername>" //
|
})
|
||||||
};
|
public class InfoCommand extends UCommandBase {
|
||||||
}
|
@Command2.Subcommand
|
||||||
|
public boolean def(CommandSender sender, String player) {
|
||||||
@Override
|
if (player.equalsIgnoreCase("console") || player.equalsIgnoreCase("server")
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|| player.equalsIgnoreCase("@console")) {
|
||||||
if (args.length == 0)
|
|
||||||
return false;
|
|
||||||
if (args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("server")
|
|
||||||
|| args[0].equalsIgnoreCase("@console")) {
|
|
||||||
sender.sendMessage("The server console.");
|
sender.sendMessage("The server console.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
try (TBMCPlayer p = TBMCPlayerBase.getFromName(args[0], TBMCPlayer.class)) {
|
try (TBMCPlayer p = TBMCPlayerBase.getFromName(player, TBMCPlayer.class)) {
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
sender.sendMessage("§cThe specified player cannot be found");
|
sender.sendMessage("§cThe specified player cannot be found");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
package buttondevteam.chat.commands.ucmds;
|
package buttondevteam.chat.commands.ucmds;
|
||||||
|
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandBase;
|
import buttondevteam.lib.chat.ICommand2MC;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
|
|
||||||
@CommandClass(modOnly = false, path = "u")
|
@CommandClass(modOnly = false, path = "u")
|
||||||
@OptionallyPlayerCommandClass(playerOnly = false)
|
@OptionallyPlayerCommandClass(playerOnly = false)
|
||||||
public abstract class UCommandBase extends OptionallyPlayerCommandBase {
|
public abstract class UCommandBase extends ICommand2MC {
|
||||||
|
|
||||||
public abstract String[] GetHelpText(String alias);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,4 @@ import buttondevteam.lib.chat.CommandClass;
|
||||||
@CommandClass(modOnly = true)
|
@CommandClass(modOnly = true)
|
||||||
public abstract class AdminCommandBase extends UCommandBase {
|
public abstract class AdminCommandBase extends UCommandBase {
|
||||||
|
|
||||||
public abstract String[] GetHelpText(String alias);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
package buttondevteam.chat.commands.ucmds.admin;
|
package buttondevteam.chat.commands.ucmds.admin;
|
||||||
|
|
||||||
|
import buttondevteam.chat.PluginMain;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
@CommandClass(helpText = {
|
||||||
|
"Debug mode",
|
||||||
|
"Toggles debug mode, which prints debug messages to the console."
|
||||||
|
})
|
||||||
public class DebugCommand extends AdminCommandBase {
|
public class DebugCommand extends AdminCommandBase {
|
||||||
public static boolean DebugMode = false;
|
public static boolean DebugMode = false;
|
||||||
|
|
||||||
@Override
|
@Command2.Subcommand
|
||||||
public String[] GetHelpText(String alias) {
|
public boolean def(CommandSender sender, String alias, String[] args) {
|
||||||
return new String[] { "§6---- Debug mode ----",
|
|
||||||
"Toggles debug mode, which prints debug messages to the console." };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled."));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
package buttondevteam.chat.components.announce;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class AddCommand extends AnnounceCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] {
|
|
||||||
"§6---- Add announcement ----",
|
|
||||||
"This command adds a new announcement",
|
|
||||||
"Note: Please avoid using this command, if possible",
|
|
||||||
"Instead, use the command blocks in flatworld to set announcements",
|
|
||||||
"This makes editing announcements easier" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias,
|
|
||||||
String[] args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
|
||||||
sb.append(args[i]);
|
|
||||||
if (i != args.length - 1)
|
|
||||||
sb.append(" ");
|
|
||||||
}
|
|
||||||
String finalmessage = sb.toString().replace('&', '§');
|
|
||||||
AnnouncerComponent component = (AnnouncerComponent) getComponent();
|
|
||||||
component.AnnounceMessages().get().add(finalmessage);
|
|
||||||
sender.sendMessage("§bAnnouncement added. - Plase avoid using this command if possible, see /u announce add without args.§r");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
package buttondevteam.chat.components.announce;
|
||||||
|
|
||||||
|
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.val;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
@CommandClass(modOnly = true)
|
||||||
|
@OptionallyPlayerCommandClass(playerOnly = false)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AnnounceCommand extends UCommandBase {
|
||||||
|
private final AnnouncerComponent component;
|
||||||
|
|
||||||
|
@Command2.Subcommand(helpText = {
|
||||||
|
"Add announcement",
|
||||||
|
"This command adds a new announcement",
|
||||||
|
})
|
||||||
|
public boolean add(CommandSender sender, @Command2.TextArg String text) {
|
||||||
|
String finalmessage = text.replace('&', '§');
|
||||||
|
component.AnnounceMessages().get().add(finalmessage);
|
||||||
|
sender.sendMessage("§bAnnouncement added.§r");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command2.Subcommand(helpText = {
|
||||||
|
"Edit announcement",
|
||||||
|
"This command lets you edit an announcement by its index.",
|
||||||
|
"Shouldn't be used directly, use either command blocks or click on an announcement in /u announce list (WIP) instead." //TODO: <--
|
||||||
|
})
|
||||||
|
public boolean edit(CommandSender sender, byte index, @Command2.TextArg String text) {
|
||||||
|
String finalmessage1 = text.replace('&', '§');
|
||||||
|
if (index > 100)
|
||||||
|
return false;
|
||||||
|
while (component.AnnounceMessages().get().size() <= index)
|
||||||
|
component.AnnounceMessages().get().add("");
|
||||||
|
component.AnnounceMessages().get().set(index, finalmessage1);
|
||||||
|
sender.sendMessage("Announcement edited.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command2.Subcommand(helpText = {
|
||||||
|
"List announcements",
|
||||||
|
"This command lists the announcements and the time between them"
|
||||||
|
})
|
||||||
|
public boolean list(CommandSender sender) {
|
||||||
|
sender.sendMessage("§bList of announce messages:§r");
|
||||||
|
sender.sendMessage("§bFormat: [index] message§r");
|
||||||
|
int i = 0;
|
||||||
|
for (String message : component.AnnounceMessages().get())
|
||||||
|
sender.sendMessage("[" + i++ + "] " + message);
|
||||||
|
sender.sendMessage("§bCurrent wait time between announcements: "
|
||||||
|
+ component.AnnounceTime().get() / 60 / 1000 + " minute(s)§r");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command2.Subcommand(helpText = {
|
||||||
|
"Remove announcement",
|
||||||
|
"This command removes an announcement"
|
||||||
|
})
|
||||||
|
public boolean remove(CommandSender sender, int index) {
|
||||||
|
val msgs = component.AnnounceMessages().get();
|
||||||
|
if (index < 0 || index > msgs.size()) return false;
|
||||||
|
msgs.remove(index);
|
||||||
|
sender.sendMessage("Announcement removed.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command2.Subcommand(helpText = {
|
||||||
|
"Set time",
|
||||||
|
"This command sets the time between the announcements"
|
||||||
|
})
|
||||||
|
public boolean settime(CommandSender sender, int minutes) {
|
||||||
|
component.AnnounceTime().set(minutes * 60 * 1000);
|
||||||
|
sender.sendMessage("Time set between announce messages to " + minutes + " minutes");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,13 +0,0 @@
|
||||||
package buttondevteam.chat.components.announce;
|
|
||||||
|
|
||||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
|
||||||
|
|
||||||
@CommandClass(modOnly = true)
|
|
||||||
@OptionallyPlayerCommandClass(playerOnly = false)
|
|
||||||
public abstract class AnnounceCommandBase extends UCommandBase {
|
|
||||||
|
|
||||||
public abstract String[] GetHelpText(String alias);
|
|
||||||
|
|
||||||
}
|
|
|
@ -44,11 +44,7 @@ public class AnnouncerComponent extends Component<PluginMain> implements Runnabl
|
||||||
@Override
|
@Override
|
||||||
protected void enable() {
|
protected void enable() {
|
||||||
target= TBMCSystemChatEvent.BroadcastTarget.add("announcements");
|
target= TBMCSystemChatEvent.BroadcastTarget.add("announcements");
|
||||||
registerCommand(new AddCommand());
|
registerCommand(new AnnounceCommand(this));
|
||||||
registerCommand(new EditCommand());
|
|
||||||
registerCommand(new ListCommand());
|
|
||||||
registerCommand(new RemoveCommand());
|
|
||||||
registerCommand(new SetTimeCommand());
|
|
||||||
new Thread(this).start();
|
new Thread(this).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
package buttondevteam.chat.components.announce;
|
|
||||||
|
|
||||||
import org.bukkit.command.BlockCommandSender;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class EditCommand extends AnnounceCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- Edit announcement ----",
|
|
||||||
"This command can only be used in a command block.",
|
|
||||||
"Usage: /u annonunce edit <index> <text>" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias,
|
|
||||||
String[] args) {
|
|
||||||
if (!(sender instanceof BlockCommandSender)) {
|
|
||||||
sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args.length < 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
StringBuilder sb1 = new StringBuilder();
|
|
||||||
for (int i1 = 1; i1 < args.length; i1++) {
|
|
||||||
sb1.append(args[i1]);
|
|
||||||
if (i1 != args.length - 1)
|
|
||||||
sb1.append(" ");
|
|
||||||
}
|
|
||||||
String finalmessage1 = sb1.toString().replace('&', '§');
|
|
||||||
int index = Integer.parseInt(args[0]);
|
|
||||||
if (index > 100)
|
|
||||||
return false;
|
|
||||||
AnnouncerComponent component = (AnnouncerComponent) getComponent();
|
|
||||||
while (component.AnnounceMessages().get().size() <= index)
|
|
||||||
component.AnnounceMessages().get().add("");
|
|
||||||
component.AnnounceMessages().get().set(Integer.parseInt(args[0]),
|
|
||||||
finalmessage1);
|
|
||||||
sender.sendMessage("Announcement edited.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package buttondevteam.chat.components.announce;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class ListCommand extends AnnounceCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- List announcements ----",
|
|
||||||
"This command lists the announcements and the time between them" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias,
|
|
||||||
String[] args) {
|
|
||||||
sender.sendMessage("§bList of announce messages:§r");
|
|
||||||
sender.sendMessage("§bFormat: [index] message§r");
|
|
||||||
int i = 0;
|
|
||||||
AnnouncerComponent component = (AnnouncerComponent) getComponent();
|
|
||||||
for (String message : component.AnnounceMessages().get())
|
|
||||||
sender.sendMessage("[" + i++ + "] " + message);
|
|
||||||
sender.sendMessage("§bCurrent wait time between announcements: "
|
|
||||||
+ component.AnnounceTime().get() / 60 / 1000 + " minute(s)§r");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
package buttondevteam.chat.components.announce;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class RemoveCommand extends AnnounceCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] {
|
|
||||||
"§6---- Remove announcement ----",
|
|
||||||
"This command removes an announcement",
|
|
||||||
"Note: Please avoid using this command, if possible",
|
|
||||||
"Instead, use the command blocks in flatworld to set announcements",
|
|
||||||
"This makes editing announcements easier" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias,
|
|
||||||
String[] args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
sender.sendMessage("§cUsage: /u announce remove <index>");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
((AnnouncerComponent) getComponent()).AnnounceMessages().get().remove(Integer.parseInt(args[0]));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,31 +0,0 @@
|
||||||
package buttondevteam.chat.components.announce;
|
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class SetTimeCommand extends AnnounceCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- Set time ----",
|
|
||||||
"This command sets the time between the announcements",
|
|
||||||
"Usage: /u anonunce settime <minutes>", "Default: 15" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias,
|
|
||||||
String[] args) {
|
|
||||||
if (args.length < 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
((AnnouncerComponent) getComponent()).AnnounceTime().set(Integer.parseInt(args[0]) * 60 * 1000);
|
|
||||||
} catch (Exception e) {
|
|
||||||
sender.sendMessage("§cMinutes argument must be a number. Got: "
|
|
||||||
+ args[0]);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
sender.sendMessage("Time set between announce messages");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -4,45 +4,46 @@ import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.PlayerJoinTimerTask;
|
import buttondevteam.chat.PlayerJoinTimerTask;
|
||||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
@CommandClass(modOnly = false, helpText = {
|
||||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
"Accept flair", //
|
||||||
public class AcceptCommand extends UCommandBase {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- Accept flair ----", //
|
|
||||||
"Accepts a flair from Reddit", //
|
"Accepts a flair from Reddit", //
|
||||||
"Use /u accept <username> if you commented from multiple accounts" //
|
"Use /u accept <username> if you commented from multiple accounts"
|
||||||
};
|
})
|
||||||
}
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class AcceptCommand extends UCommandBase {
|
||||||
|
private final FlairComponent component;
|
||||||
|
|
||||||
@Override
|
@Command2.Subcommand
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
public boolean def(CommandSender sender, @Command2.OptionalArg String username) {
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||||
if (args.length < 1 && p.UserNames().size() > 1) {
|
if (username == null && p.UserNames().size() > 1) {
|
||||||
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
|
player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept <username>");
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("§6Usernames:");
|
sb.append("§6Usernames:");
|
||||||
for (String username : p.UserNames())
|
for (String name : p.UserNames())
|
||||||
sb.append(" ").append(username);
|
sb.append(" ").append(name);
|
||||||
player.sendMessage(sb.toString());
|
player.sendMessage(sb.toString());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().size() == 0) {
|
if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().size() == 0) {
|
||||||
player.sendMessage("§cError: You need to write your username to the reddit thread at /r/ChromaGamers§r");
|
player.sendMessage("§cError: You need to write your username to the reddit thread§r");
|
||||||
|
player.sendMessage(component.FlairThreadURL().get());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length > 0 && !p.UserNames().contains(args[0])) {
|
if (username != null && !p.UserNames().contains(username)) {
|
||||||
player.sendMessage("§cError: Unknown name: " + args[0] + "§r");
|
player.sendMessage("§cError: Unknown name: " + username + "§r");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (p.Working) {
|
if (p.Working) {
|
||||||
|
@ -50,12 +51,12 @@ public class AcceptCommand extends UCommandBase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((args.length > 0 ? args[0] : p.UserNames().get(0)).equals(p.UserName().get())) {
|
if ((username != null ? username : p.UserNames().get(0)).equals(p.UserName().get())) {
|
||||||
player.sendMessage("§cYou already have this user's flair.§r");
|
player.sendMessage("§cYou already have this user's flair.§r");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length > 0)
|
if (username != null)
|
||||||
p.UserName().set(args[0]);
|
p.UserName().set(username);
|
||||||
else
|
else
|
||||||
p.UserName().set(p.UserNames().get(0));
|
p.UserName().set(p.UserNames().get(0));
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ public class AcceptCommand extends UCommandBase {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
FlairComponent.DownloadFlair(mp);
|
component.DownloadFlair(mp);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException(
|
TBMCCoreAPI.SendException(
|
||||||
"An error occured while downloading flair for " + player.getCustomName() + "!", e);
|
"An error occured while downloading flair for " + player.getCustomName() + "!", e);
|
||||||
|
@ -93,5 +94,4 @@ public class AcceptCommand extends UCommandBase {
|
||||||
timer.schedule(tt, 20);
|
timer.schedule(tt, 20);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class FlairComponent extends Component<PluginMain> {
|
public class FlairComponent extends Component<PluginMain> {
|
||||||
private ConfigData<String> FlairThreadURL() {
|
ConfigData<String> FlairThreadURL() {
|
||||||
return getConfig().getData("flairThreadURL", "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/");
|
return getConfig().getData("flairThreadURL", "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class FlairComponent extends Component<PluginMain> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void enable() {
|
protected void enable() {
|
||||||
registerCommand(new AcceptCommand());
|
registerCommand(new AcceptCommand(this));
|
||||||
registerCommand(new IgnoreCommand());
|
registerCommand(new IgnoreCommand());
|
||||||
registerCommand(new SetFlairCommand());
|
registerCommand(new SetFlairCommand());
|
||||||
new Thread(this::FlairGetterThreadMethod).start();
|
new Thread(this::FlairGetterThreadMethod).start();
|
||||||
|
@ -106,7 +106,7 @@ public class FlairComponent extends Component<PluginMain> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DownloadFlair(ChatPlayer mp) throws IOException {
|
void DownloadFlair(ChatPlayer mp) throws IOException {
|
||||||
String[] flairdata = TBMCCoreAPI
|
String[] flairdata = TBMCCoreAPI
|
||||||
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get())
|
.DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get())
|
||||||
.replace("\"", "").split(":");
|
.replace("\"", "").split(":");
|
||||||
|
|
|
@ -2,24 +2,21 @@ package buttondevteam.chat.components.flair;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandClass(modOnly = false)
|
@CommandClass(modOnly = false, helpText = {
|
||||||
|
"Ignore flair",
|
||||||
|
"Stop the \"write your name in the thread\" message from showing up"
|
||||||
|
})
|
||||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
public final class IgnoreCommand extends UCommandBase {
|
public final class IgnoreCommand extends UCommandBase {
|
||||||
|
@Command2.Subcommand
|
||||||
@Override
|
public boolean def(CommandSender sender) {
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- Ignore flair ----",
|
|
||||||
"Stop the \"write your name in the thread\" message from showing up" };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
final Player player = (Player) sender;
|
final Player player = (Player) sender;
|
||||||
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
|
||||||
if (p.FlairState().get().equals(FlairStates.Accepted)) {
|
if (p.FlairState().get().equals(FlairStates.Accepted)) {
|
||||||
|
@ -39,5 +36,4 @@ public final class IgnoreCommand extends UCommandBase {
|
||||||
player.sendMessage("§cYou already ignored the message.§r");
|
player.sendMessage("§cYou already ignored the message.§r");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,65 +2,52 @@ package buttondevteam.chat.components.flair;
|
||||||
|
|
||||||
import buttondevteam.chat.ChatPlayer;
|
import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.player.TBMCPlayerBase;
|
import buttondevteam.lib.player.TBMCPlayerBase;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class SetFlairCommand extends AdminCommandBase {
|
@CommandClass(helpText = {
|
||||||
|
"§6---- Set flair -----", "Set a flair for a player",
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { "§6---- Set flair -----", "Set a flair for a player",
|
|
||||||
"Usage: /u admin setflair <player> <flairtime (or non-presser, cant-press, none)> <cheater(true/false)> [username]",
|
"Usage: /u admin setflair <player> <flairtime (or non-presser, cant-press, none)> <cheater(true/false)> [username]",
|
||||||
"Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)",
|
"Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)",
|
||||||
"Example 2: /u admin setflair iie 0 true asde --> purple (0s)" };
|
"Example 2: /u admin setflair iie 0 true asde --> purple (0s)"
|
||||||
}
|
})
|
||||||
|
public class SetFlairCommand extends AdminCommandBase {
|
||||||
@Override
|
@Command2.Subcommand
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
public boolean def(CommandSender sender, String player, String flairtime, boolean cheater, @Command2.OptionalArg String username) {
|
||||||
if (args.length < 3) {
|
Player p = Bukkit.getPlayer(player);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Player p = Bukkit.getPlayer(args[0]);
|
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
sender.sendMessage("§cPlayer not found.&r");
|
sender.sendMessage("§cPlayer not found.&r");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
short flairtime = 0x00;
|
short ft = 0x00;
|
||||||
if (args[1].equalsIgnoreCase("non-presser"))
|
if (flairtime.equalsIgnoreCase("non-presser"))
|
||||||
flairtime = ChatPlayer.FlairTimeNonPresser;
|
ft = ChatPlayer.FlairTimeNonPresser;
|
||||||
else if (args[1].equalsIgnoreCase("cant-press"))
|
else if (flairtime.equalsIgnoreCase("cant-press"))
|
||||||
flairtime = ChatPlayer.FlairTimeCantPress;
|
ft = ChatPlayer.FlairTimeCantPress;
|
||||||
else if (args[1].equalsIgnoreCase("none"))
|
else if (flairtime.equalsIgnoreCase("none"))
|
||||||
flairtime = ChatPlayer.FlairTimeNone;
|
ft = ChatPlayer.FlairTimeNone;
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
flairtime = Short.parseShort(args[1]);
|
ft = Short.parseShort(flairtime);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
"§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage.");
|
"§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean cheater;
|
|
||||||
if (args[2].equalsIgnoreCase("true"))
|
|
||||||
cheater = true;
|
|
||||||
else if (args[2].equalsIgnoreCase("false"))
|
|
||||||
cheater = false;
|
|
||||||
else {
|
|
||||||
sender.sendMessage("§cUnknown value for cheater parameter.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class);
|
||||||
mp.SetFlair(flairtime, cheater);
|
mp.SetFlair(ft, cheater);
|
||||||
mp.FlairState().set(FlairStates.Accepted);
|
mp.FlairState().set(FlairStates.Accepted);
|
||||||
if (args.length < 4)
|
if (username == null)
|
||||||
mp.UserName().set("");
|
mp.UserName().set("");
|
||||||
else {
|
else {
|
||||||
mp.UserName().set(args[3]);
|
mp.UserName().set(username);
|
||||||
if (!mp.UserNames().contains(args[3]))
|
if (!mp.UserNames().contains(username))
|
||||||
mp.UserNames().add(args[3]);
|
mp.UserNames().add(username);
|
||||||
}
|
}
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
|
"§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r");
|
||||||
|
|
|
@ -4,6 +4,7 @@ import buttondevteam.chat.ChatPlayer;
|
||||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
import buttondevteam.chat.components.towny.TownyComponent;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
@ -16,21 +17,16 @@ import java.util.Arrays;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
@CommandClass
|
@CommandClass(helpText = {
|
||||||
public class NColorCommand extends UCommandBase {
|
"Name color", //
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { //
|
|
||||||
"§6---- Name color ----", //
|
|
||||||
"This command allows you to set how the town colors look on your name.", //
|
"This command allows you to set how the town colors look on your name.", //
|
||||||
"To use this command, you need to be in a town which has town colors set.", //
|
"To use this command, you need to be in a town which has town colors set.", //
|
||||||
"Use a vertical line as a separator between the colors.", //
|
"Use a vertical line (or a colon) as a separator between the colors.", //
|
||||||
"Example: /u ncolor Norbi|Peti --> §6Norbi§ePeti" //
|
"Example: /u ncolor Norbi|Peti --> §6Norbi§ePeti" //
|
||||||
};
|
})
|
||||||
}
|
public class NColorCommand extends UCommandBase {
|
||||||
|
@Command2.Subcommand
|
||||||
@Override
|
public boolean def(Player player, String nameWithLines) {
|
||||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
|
||||||
Resident res;
|
Resident res;
|
||||||
Town town;
|
Town town;
|
||||||
try {
|
try {
|
||||||
|
@ -43,16 +39,14 @@ public class NColorCommand extends UCommandBase {
|
||||||
player.sendMessage("§cYou need to be in a town. (" + e + ")");
|
player.sendMessage("§cYou need to be in a town. (" + e + ")");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length == 0)
|
|
||||||
return false;
|
|
||||||
final String name = ChatColor.stripColor(player.getDisplayName()).replace("~", ""); //Remove ~
|
final String name = ChatColor.stripColor(player.getDisplayName()).replace("~", ""); //Remove ~
|
||||||
String arg = args[0]; //Don't add ~ for nicknames
|
//Don't add ~ for nicknames
|
||||||
if (!arg.replace("|", "").replace(":", "").equalsIgnoreCase(name)) {
|
if (!nameWithLines.replace("|", "").replace(":", "").equalsIgnoreCase(name)) {
|
||||||
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
|
player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use "
|
||||||
+ name + "§c with added vertical lines (|) or colons (:).");
|
+ name + "§c with added vertical lines (|) or colons (:).");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String[] nameparts = arg.split("[|:]");
|
String[] nameparts = nameWithLines.split("[|:]");
|
||||||
Color[] towncolors = TownColorComponent.TownColors.get(town.getName().toLowerCase());
|
Color[] towncolors = TownColorComponent.TownColors.get(town.getName().toLowerCase());
|
||||||
if (towncolors == null) {
|
if (towncolors == null) {
|
||||||
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor.");
|
||||||
|
|
|
@ -3,48 +3,38 @@ package buttondevteam.chat.components.towncolors;
|
||||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
import buttondevteam.chat.components.towny.TownyComponent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandClass
|
@CommandClass(helpText = {
|
||||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
"Nation Color", //
|
||||||
public class NationColorCommand extends UCommandBase {
|
|
||||||
@Override
|
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[]{ //
|
|
||||||
"§6---- Nation Color ----", //
|
|
||||||
"This command allows setting a color for a nation.", //
|
"This command allows setting a color for a nation.", //
|
||||||
"Each town in the nation will have it's first color (border) set to this color.", //
|
"Each town in the nation will have it's first color (border) set to this color.", //
|
||||||
"See the help text for /u towncolor for more details.", //
|
"See the help text for /u towncolor for more details.", //
|
||||||
"Usage: /" + GetCommandPath() + " <colorname>", //
|
})
|
||||||
"Example: /" + GetCommandPath() + " blue" //
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
};
|
public class NationColorCommand extends UCommandBase {
|
||||||
}
|
@Command2.Subcommand
|
||||||
|
public boolean def(Player player, String color) {
|
||||||
@Override
|
|
||||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
|
||||||
Resident res;
|
Resident res;
|
||||||
if (!(TownyComponent.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
if (!(TownyComponent.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
||||||
&& (res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase())).isKing())) {
|
&& (res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase())).isKing())) {
|
||||||
player.sendMessage("§cYou need to be the king of a nation to set it's colors.");
|
player.sendMessage("§cYou need to be the king of a nation to set it's colors.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (args.length > 1) {
|
final Nation n;
|
||||||
player.sendMessage("You can only use one color.");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
String[] a = new String[args.length + 1];
|
|
||||||
System.arraycopy(args, 0, a, 1, args.length);
|
|
||||||
try {
|
try {
|
||||||
a[0] = res.getTown().getNation().getName();
|
n = res.getTown().getNation();
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
TBMCCoreAPI.SendException("Failed to set nation color for player " + player + "!", e);
|
TBMCCoreAPI.SendException("Failed to set nation color for player " + player + "!", e);
|
||||||
player.sendMessage("§cCouldn't find your town/nation... Error reported.");
|
player.sendMessage("§cCouldn't find your town/nation... Error reported.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, alias, a);
|
return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, n, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,54 +3,62 @@ package buttondevteam.chat.components.towncolors;
|
||||||
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
import buttondevteam.chat.commands.ucmds.UCommandBase;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
import buttondevteam.chat.components.towny.TownyComponent;
|
||||||
import buttondevteam.lib.TBMCCoreAPI;
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
import buttondevteam.lib.chat.CommandClass;
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
import buttondevteam.lib.chat.OptionallyPlayerCommandClass;
|
||||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||||
import com.palmergames.bukkit.towny.object.Resident;
|
import com.palmergames.bukkit.towny.object.Resident;
|
||||||
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandClass // TODO: /u u when annotation not present
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
@CommandClass(helpText = {
|
||||||
|
"Town Color", //
|
||||||
|
"This command allows setting a color for a town.", //
|
||||||
|
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
||||||
|
"The colors will split the name evenly but residents can override that with /u ncolor.", //
|
||||||
|
}) // TODO: /u u when annotation not present
|
||||||
@OptionallyPlayerCommandClass(playerOnly = true)
|
@OptionallyPlayerCommandClass(playerOnly = true)
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class TownColorCommand extends UCommandBase {
|
public class TownColorCommand extends UCommandBase {
|
||||||
|
private final TownColorComponent component;
|
||||||
@Override
|
@Override
|
||||||
public String GetHelpText(String alias)[] {
|
public String[] getHelpText(Method method, Command2.Subcommand ann) {
|
||||||
StringBuilder cns = new StringBuilder(" <colorname1>");
|
StringBuilder cns = new StringBuilder(" <colorname1>");
|
||||||
val comp = (TownColorComponent) getComponent();
|
for (int i = 2; i <= component.colorCount().get(); i++)
|
||||||
for (int i = 2; i <= comp.colorCount().get(); i++)
|
|
||||||
cns.append(" [colorname").append(i).append("]");
|
cns.append(" [colorname").append(i).append("]");
|
||||||
return new String[] { //
|
return new String[] { //
|
||||||
"§6---- Town Color ----", //
|
"§6---- Town Color ----", //
|
||||||
"This command allows setting a color for a town.", //
|
"This command allows setting color(s) for a town.", //
|
||||||
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
||||||
"The colors will split the name evenly.", //
|
"The colors will split the name evenly.", //
|
||||||
"Usage: /" + GetCommandPath() + cns, //
|
|
||||||
"Example: /" + GetCommandPath() + " blue" //
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Command2.Subcommand
|
||||||
public boolean OnCommand(Player player, String alias, String[] args) {
|
public boolean def(Player player, String... colornames) {
|
||||||
Resident res;
|
Resident res;
|
||||||
if (!(TownyComponent.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
if (!(TownyComponent.TU.getResidentMap().containsKey(player.getName().toLowerCase())
|
||||||
&& (res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase())).isMayor())) {
|
&& (res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase())).isMayor())) {
|
||||||
player.sendMessage("§cYou need to be the mayor of a town to set it's colors.");
|
player.sendMessage("§cYou need to be the mayor of a town to set its colors.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
val comp = (TownColorComponent) getComponent();
|
val cc = component.colorCount().get();
|
||||||
if (args.length > comp.colorCount().get()) {
|
if (colornames.length > cc) {
|
||||||
player.sendMessage("You can only use " + comp.colorCount().get() + " color" + (comp.colorCount().get() > 1 ? "s" : "") + ".");
|
player.sendMessage("You can only use " + cc + " color" + (cc > 1 ? "s" : "") + ".");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String[] a = new String[args.length + 1];
|
final Town t;
|
||||||
System.arraycopy(args, 0, a, 1, args.length);
|
|
||||||
try {
|
try {
|
||||||
a[0] = res.getTown().getName();
|
t = res.getTown();
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
|
TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e);
|
||||||
player.sendMessage("§cCouldn't find your town... Error reported.");
|
player.sendMessage("§cCouldn't find your town... Error reported.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, alias, a);
|
return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, t, colornames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class TownColorComponent extends Component<PluginMain> implements Listene
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
registerCommand(new TownColorCommand());
|
registerCommand(new TownColorCommand(this));
|
||||||
if (useNationColors().get())
|
if (useNationColors().get())
|
||||||
registerCommand(new NationColorCommand());
|
registerCommand(new NationColorCommand());
|
||||||
registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand());
|
registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand());
|
||||||
|
|
|
@ -6,40 +6,31 @@ import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.chat.components.towncolors.TownyListener;
|
import buttondevteam.chat.components.towncolors.TownyListener;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
import buttondevteam.chat.components.towny.TownyComponent;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import com.palmergames.bukkit.towny.object.Nation;
|
import com.palmergames.bukkit.towny.object.Nation;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class NationColorCommand extends AdminCommandBase {
|
@CommandClass(helpText = {
|
||||||
@Override
|
"Nation color", //
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[]{ //
|
|
||||||
"§6---- Nation color ----", //
|
|
||||||
"Sets the color of the nation.", //
|
"Sets the color of the nation.", //
|
||||||
"Usage: /u admin nationcolor <color>" //
|
})
|
||||||
};
|
public class NationColorCommand extends AdminCommandBase {
|
||||||
}
|
@Command2.Subcommand
|
||||||
|
public boolean def(CommandSender sender, String nation, String color) {
|
||||||
@Override
|
final Nation n = TownyComponent.TU.getNationsMap().get(nation.toLowerCase());
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
if (n == null) {
|
||||||
return SetNationColor(sender, alias, args);
|
sender.sendMessage("§cThe nation '" + nation + "' cannot be found.");
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean SetNationColor(CommandSender sender, String alias, String[] args) {
|
|
||||||
if (args.length < 2)
|
|
||||||
return false;
|
|
||||||
if (args.length > 2) {
|
|
||||||
sender.sendMessage("§cYou can only use one color as a nation color.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
final Nation nation = TownyComponent.TU.getNationsMap().get(args[0].toLowerCase());
|
return SetNationColor(sender, n, color);
|
||||||
if (nation == null) {
|
|
||||||
sender.sendMessage("§cThe nation '" + args[0] + "' cannot be found.");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
val c = TownColorCommand.getColorOrSendError(args[1], sender);
|
|
||||||
|
public static boolean SetNationColor(CommandSender sender, Nation nation, String color) {
|
||||||
|
val c = TownColorCommand.getColorOrSendError(color, sender);
|
||||||
if (!c.isPresent()) return true;
|
if (!c.isPresent()) return true;
|
||||||
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
if (!c.get().getName().equals(Color.White.getName())) { //Default nation color
|
||||||
for (val e : TownColorComponent.NationColor.entrySet()) {
|
for (val e : TownColorComponent.NationColor.entrySet()) {
|
||||||
|
@ -49,7 +40,7 @@ public class NationColorCommand extends AdminCommandBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TownColorComponent.NationColor.put(args[0].toLowerCase(), c.get());
|
TownColorComponent.NationColor.put(nation.getName().toLowerCase(), c.get());
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
|
||||||
for (Town t : nation.getTowns())
|
for (Town t : nation.getTowns())
|
||||||
TownyListener.updateTownMembers(t);
|
TownyListener.updateTownMembers(t);
|
||||||
|
|
|
@ -2,28 +2,19 @@ package buttondevteam.chat.components.towncolors.admin;
|
||||||
|
|
||||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class TCCount extends AdminCommandBase {
|
@CommandClass(helpText = {
|
||||||
@Override
|
"Town Color Count", //
|
||||||
public String[] GetHelpText(String alias) {
|
|
||||||
return new String[] { //
|
|
||||||
"§6---- Town Color Count", //
|
|
||||||
"Sets how many colors can be used for a town." //
|
"Sets how many colors can be used for a town." //
|
||||||
};
|
})
|
||||||
}
|
public class TCCount extends AdminCommandBase {
|
||||||
|
@Command2.Subcommand
|
||||||
@Override
|
public boolean def(CommandSender sender, byte count) {
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
val comp = TownColorComponent.getComponent();
|
||||||
byte count;
|
|
||||||
try {
|
|
||||||
if (args.length == 0 || (count = Byte.parseByte(args[0])) <= 0)
|
|
||||||
return false;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
val comp = (TownColorComponent) getComponent();
|
|
||||||
comp.colorCount().set(count);
|
comp.colorCount().set(count);
|
||||||
sender.sendMessage("Color count set to " + count);
|
sender.sendMessage("Color count set to " + count);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package buttondevteam.chat.components.towncolors.admin;
|
package buttondevteam.chat.components.towncolors.admin;
|
||||||
|
|
||||||
import buttondevteam.chat.PluginMain;
|
|
||||||
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase;
|
||||||
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
import buttondevteam.chat.components.towncolors.TownColorComponent;
|
||||||
import buttondevteam.chat.components.towncolors.TownyListener;
|
import buttondevteam.chat.components.towncolors.TownyListener;
|
||||||
import buttondevteam.chat.components.towny.TownyComponent;
|
import buttondevteam.chat.components.towny.TownyComponent;
|
||||||
import buttondevteam.lib.chat.Color;
|
import buttondevteam.lib.chat.Color;
|
||||||
|
import buttondevteam.lib.chat.Command2;
|
||||||
|
import buttondevteam.lib.chat.CommandClass;
|
||||||
import com.palmergames.bukkit.towny.object.Town;
|
import com.palmergames.bukkit.towny.object.Town;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -17,35 +18,27 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TownColorCommand extends AdminCommandBase {
|
@CommandClass(helpText = {
|
||||||
@Override
|
"Town Color", //
|
||||||
public String GetHelpText(String alias)[] { // TODO: Command path aliases
|
|
||||||
return new String[]{ //
|
|
||||||
"§6---- Town Color ----", //
|
|
||||||
"This command allows setting a color for a town.", //
|
"This command allows setting a color for a town.", //
|
||||||
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
"The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", //
|
||||||
"The colors will split the name evenly.", //
|
"The colors will split the name evenly.", //
|
||||||
"Usage: /" + GetCommandPath() + " <town> <colorname1> [colorname2...]", //
|
})
|
||||||
"Example: /" + GetCommandPath() + " Alderon blue gray" //
|
public class TownColorCommand extends AdminCommandBase { //TODO: Command path aliases
|
||||||
};
|
@Command2.Subcommand
|
||||||
}
|
public boolean def(CommandSender sender, String town, String... colornames) {
|
||||||
|
if (!TownyComponent.TU.getTownsMap().containsKey(town.toLowerCase())) {
|
||||||
@Override
|
sender.sendMessage("§cThe town '" + town + "' cannot be found.");
|
||||||
public boolean OnCommand(CommandSender sender, String alias, String[] args) {
|
|
||||||
return SetTownColor(sender, alias, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean SetTownColor(CommandSender sender, String alias, String[] args) {
|
|
||||||
if (args.length < 2)
|
|
||||||
return false;
|
|
||||||
if (!TownyComponent.TU.getTownsMap().containsKey(args[0].toLowerCase())) {
|
|
||||||
sender.sendMessage("§cThe town '" + args[0] + "' cannot be found.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Color[] clrs = new Color[args.length - 1];
|
Town targetTown = TownyComponent.TU.getTownsMap().get(town.toLowerCase());
|
||||||
Town targetTown = TownyComponent.TU.getTownsMap().get(args[0].toLowerCase());
|
return SetTownColor(sender, targetTown, colornames);
|
||||||
for (int i = 1; i < args.length; i++) {
|
}
|
||||||
val c = getColorOrSendError(args[i], sender);
|
|
||||||
|
public static boolean SetTownColor(CommandSender sender, Town town, String[] colors) {
|
||||||
|
Color[] clrs = new Color[colors.length];
|
||||||
|
for (int i = 0; i < colors.length; i++) {
|
||||||
|
val c = getColorOrSendError(colors[i], sender);
|
||||||
if (!c.isPresent())
|
if (!c.isPresent())
|
||||||
return true;
|
return true;
|
||||||
clrs[i - 1] = c.get();
|
clrs[i - 1] = c.get();
|
||||||
|
@ -54,7 +47,7 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
boolean usenc = TownColorComponent.getComponent().useNationColors().get();
|
boolean usenc = TownColorComponent.getComponent().useNationColors().get();
|
||||||
if (usenc) {
|
if (usenc) {
|
||||||
try {
|
try {
|
||||||
tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase());
|
tnc = TownColorComponent.NationColor.get(town.getNation().getName().toLowerCase());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
tnc = null;
|
tnc = null;
|
||||||
}
|
}
|
||||||
|
@ -83,16 +76,12 @@ public class TownColorCommand extends AdminCommandBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TownColorComponent.TownColors.put(args[0].toLowerCase(), clrs);
|
TownColorComponent.TownColors.put(town.getName().toLowerCase(), clrs);
|
||||||
TownyListener.updateTownMembers(targetTown);
|
TownyListener.updateTownMembers(town);
|
||||||
|
|
||||||
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny");
|
||||||
if (dtp == null) {
|
if (dtp != null) //If it's not found then it's not loaded, it'll be noticed by the admins if needed
|
||||||
sender.sendMessage("§cDynmap-Towny couldn't be found §6but otherwise §btown color set.");
|
TownColorComponent.setTownColor(dtp, town.getName(), clrs, tnc);
|
||||||
PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs, tnc);
|
|
||||||
sender.sendMessage("§bColor(s) set.");
|
sender.sendMessage("§bColor(s) set.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public class PlayerJoinLeaveListener implements Listener {
|
||||||
nwithoutformatting = p.getName();
|
nwithoutformatting = p.getName();
|
||||||
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent
|
PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent
|
||||||
|
|
||||||
HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null);
|
HistoryCommand.showHistory(e.getPlayer(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
|
Loading…
Reference in a new issue