Finished some issues

Fixed join messages appearing in addition to custom ones (#119)
For real this time
Not saying the game role color is the default one (#118)
Fixed role listing (#80)
This commit is contained in:
Norbi Peti 2020-01-18 03:54:17 +01:00
parent 703f1f8cd5
commit bdb7381ab4
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 14 additions and 5 deletions

View file

@ -44,7 +44,7 @@ class MCListener implements Listener {
.ifPresent(dcp -> MCChatUtils.callLogoutEvent(dcp, false)); .ifPresent(dcp -> MCChatUtils.callLogoutEvent(dcp, false));
} }
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent e) { public void onPlayerJoin(PlayerJoinEvent e) {
if (e.getPlayer() instanceof DiscordConnectedPlayer) if (e.getPlayer() instanceof DiscordConnectedPlayer)
return; // Don't show the joined message for the fake player return; // Don't show the joined message for the fake player
@ -67,7 +67,7 @@ class MCListener implements Listener {
}); });
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLeave(PlayerQuitEvent e) { public void onPlayerLeave(PlayerQuitEvent e) {
if (e.getPlayer() instanceof DiscordConnectedPlayer) if (e.getPlayer() instanceof DiscordConnectedPlayer)
return; // Only care about real users return; // Only care about real users

View file

@ -21,6 +21,10 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* Automatically collects roles with a certain color (the second to last in the upper row - #95a5a6).
* Users can add these roles to themselves using the /role Discord command.
*/
public class GameRoleModule extends Component<DiscordPlugin> { public class GameRoleModule extends Component<DiscordPlugin> {
public List<String> GameRoles; public List<String> GameRoles;
@ -35,6 +39,9 @@ public class GameRoleModule extends Component<DiscordPlugin> {
} }
/**
* The channel where the bot logs when it detects a role change that results in a new game role or one being removed.
*/
private ReadOnlyConfigData<Mono<MessageChannel>> logChannel() { private ReadOnlyConfigData<Mono<MessageChannel>> logChannel() {
return DPUtils.channelData(getConfig(), "logChannel"); return DPUtils.channelData(getConfig(), "logChannel");
} }
@ -52,7 +59,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
return Mono.empty(); //Deleted or not a game role return Mono.empty(); //Deleted or not a game role
GameRoles.add(role.getName()); GameRoles.add(role.getName());
if (logChannel != null) if (logChannel != null)
return logChannel.flatMap(ch -> ch.createMessage("Added " + role.getName() + " as game role. If you don't want this, change the role's color from the default.")); return logChannel.flatMap(ch -> ch.createMessage("Added " + role.getName() + " as game role. If you don't want this, change the role's color from the game role color."));
return Mono.empty(); return Mono.empty();
}).subscribe(); }).subscribe();
}, 100); }, 100);
@ -81,7 +88,7 @@ public class GameRoleModule extends Component<DiscordPlugin> {
if (removed) if (removed)
return logChannel.flatMap(ch -> ch.createMessage("Changed game role from " + or.getName() + " to " + event.getCurrent().getName() + ".")); return logChannel.flatMap(ch -> ch.createMessage("Changed game role from " + or.getName() + " to " + event.getCurrent().getName() + "."));
else else
return logChannel.flatMap(ch -> ch.createMessage("Added " + event.getCurrent().getName() + " as game role because it has the default color.")); return logChannel.flatMap(ch -> ch.createMessage("Added " + event.getCurrent().getName() + " as game role because it has the color of one."));
} }
} }
return Mono.empty(); return Mono.empty();

View file

@ -66,12 +66,14 @@ public class RoleCommand extends ICommand2DC {
for (String role : (Iterable<String>) grm.GameRoles.stream().sorted()::iterator) { for (String role : (Iterable<String>) grm.GameRoles.stream().sorted()::iterator) {
sb.append(role); sb.append(role);
if (!b) if (!b)
for (int j = 0; j < Math.min(0, 20 - role.length()); j++) for (int j = 0; j < Math.max(1, 20 - role.length()); j++)
sb.append(" "); sb.append(" ");
else else
sb.append("\n"); sb.append("\n");
b = !b; b = !b;
} }
if (sb.charAt(sb.length() - 1) != '\n')
sb.append('\n');
sender.sendMessage("list of roles:\n```\n" + sb + "```"); sender.sendMessage("list of roles:\n```\n" + sb + "```");
} }