Finished game roles
This commit is contained in:
parent
e7963e4f9a
commit
355ba01929
2 changed files with 55 additions and 30 deletions
|
@ -45,7 +45,6 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
lastannouncementtime = getConfig().getLong("lastannouncementtime");
|
lastannouncementtime = getConfig().getLong("lastannouncementtime");
|
||||||
lastseentime = getConfig().getLong("lastseentime");
|
lastseentime = getConfig().getLong("lastseentime");
|
||||||
GameRoles = (List<String>) getConfig().getList("gameroles", new ArrayList<String>());
|
GameRoles = (List<String>) getConfig().getList("gameroles", new ArrayList<String>());
|
||||||
saveConfig();
|
|
||||||
ClientBuilder cb = new ClientBuilder();
|
ClientBuilder cb = new ClientBuilder();
|
||||||
cb.withToken(Files.readFirstLine(new File("TBMC", "Token.txt"), StandardCharsets.UTF_8));
|
cb.withToken(Files.readFirstLine(new File("TBMC", "Token.txt"), StandardCharsets.UTF_8));
|
||||||
dc = cb.login();
|
dc = cb.login();
|
||||||
|
|
|
@ -24,23 +24,35 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
}
|
}
|
||||||
String[] argsa = args.split(" ");
|
String[] argsa = args.split(" ");
|
||||||
if (argsa[0].equalsIgnoreCase("add")) {
|
if (argsa[0].equalsIgnoreCase("add")) {
|
||||||
if (argsa.length < 2) {
|
final IRole role = checkAndGetRole(message, argsa, "This command adds a game role to your account.");
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
if (role == null)
|
||||||
"This command adds a game role to your account.\nUsage: add <rolename>");
|
|
||||||
return;
|
return;
|
||||||
|
try {
|
||||||
|
DiscordPlugin.perform(() -> message.getAuthor().addRole(role));
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Added game role.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
TBMCCoreAPI.SendException("Error while adding role!", e);
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while adding the role.");
|
||||||
}
|
}
|
||||||
if (!DiscordPlugin.GameRoles.contains(argsa[1].toLowerCase())) {
|
} else if (argsa[0].equalsIgnoreCase("remove")) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
final IRole role = checkAndGetRole(message, argsa, "This command removes a game role from your account.");
|
||||||
"That game role cannot be found.\nList of game roles:\n"
|
if (role == null)
|
||||||
+ DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
|
||||||
return;
|
return;
|
||||||
|
try {
|
||||||
|
DiscordPlugin.perform(() -> message.getAuthor().removeRole(role));
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Removed game role.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
TBMCCoreAPI.SendException("Error while removing role!", e);
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while removing the role.");
|
||||||
}
|
}
|
||||||
|
} else if (argsa[0].equalsIgnoreCase("list")) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
||||||
|
} else if (argsa[0].equalsIgnoreCase("addrole")) {
|
||||||
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
||||||
.getRolesByName(argsa[1]);
|
.getRolesByName(argsa[1]);
|
||||||
if (roles.size() == 0) {
|
if (roles.size() == 0) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "That role cannot be found on Discord.");
|
||||||
"The specified role cannot be found on Discord! Removing from the list.");
|
|
||||||
DiscordPlugin.GameRoles.remove(argsa[1].toLowerCase());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (roles.size() > 1) {
|
if (roles.size() > 1) {
|
||||||
|
@ -48,30 +60,44 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
"There are more roles with this name. Why are there more roles with this name?");
|
"There are more roles with this name. Why are there more roles with this name?");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
DiscordPlugin.GameRoles.add(roles.get(0).getName());
|
||||||
DiscordPlugin.perform(() -> message.getAuthor().addRole(roles.get(0)));
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "Game role added.");
|
||||||
} catch (Exception e) {
|
|
||||||
TBMCCoreAPI.SendException("Error while adding role!", e);
|
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while adding the role.");
|
|
||||||
}
|
|
||||||
} else if (argsa[0].equalsIgnoreCase("remove"))
|
|
||||||
|
|
||||||
{
|
|
||||||
if (argsa.length < 2) {
|
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
|
||||||
"This command removes a game role from your account.\nUsage: remove <rolename>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (argsa[0].equalsIgnoreCase("list")) {
|
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
|
||||||
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IRole checkAndGetRole(IMessage message, String[] argsa, String usage) {
|
||||||
|
if (argsa.length < 2) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), usage + "\nUsage: " + argsa[0] + " <rolename>");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!DiscordPlugin.GameRoles.contains(argsa[1])) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
"That game role cannot be found.\nList of game roles:\n"
|
||||||
|
+ DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
||||||
|
.getRolesByName(argsa[1]);
|
||||||
|
if (roles.size() == 0) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
"The specified role cannot be found on Discord! Removing from the list.");
|
||||||
|
DiscordPlugin.GameRoles.remove(argsa[1].toLowerCase());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (roles.size() > 1) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
"There are more roles with this name. Why are there more roles with this name?");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return roles.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getHelpText() {
|
public String[] getHelpText() {
|
||||||
// TODO Auto-generated method stub
|
return new String[] { //
|
||||||
return null;
|
"Add or remove game roles from yourself.", //
|
||||||
|
"Usage: role add|remove <name> or role list", //
|
||||||
|
"Mods can use role addrole <name> to add a role as a game role" };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue