Skip to content

Commit

Permalink
fix: Fix unformatted clear player suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Apr 25, 2022
1 parent f37255a commit 3d56ddf
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Expand Up @@ -43,7 +43,7 @@ dependencies {
}

group = "me.dreamerzero.chatregulator"
version = "3.0.0"
version = "3.0.1-SNAPSHOT"
description = "A global chat regulator for you Velocity network"
val url: String = "https://forums.velocitypowered.com/t/chatregulator-a-global-chat-regulator-for-velocity/962"
val id: String = "chatregulator"
Expand Down
Expand Up @@ -52,7 +52,11 @@ public static void registerCommand(ChatRegulator plugin){
.<CommandSource>literal("clear")
.executes(cmd -> {
plugin.getProxy().sendMessage(Components.SPACES_COMPONENT);
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getGlobalMessage()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getGlobalMessage()
)
);
return 1;
}).build())
.build();
Expand Down Expand Up @@ -122,7 +126,12 @@ private static LiteralCommandNode<CommandSource> playerCommand(String command, C
.<CommandSource>literal(command)
.requires(src -> src.hasPermission(Permissions.COMMAND_PLAYER))
.executes(cmd -> {
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getGeneralMessages().noArgument(), cmd.getSource()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().noArgument(),
cmd.getSource()
)
);
return 1;
})
.then(RequiredArgumentBuilder
Expand Down Expand Up @@ -167,7 +176,12 @@ private static LiteralCommandNode<CommandSource> resetCommand(String command, Ch
.<CommandSource>literal(command)
.requires(src -> src.hasPermission(Permissions.COMMAND_RESET))
.executes(cmd -> {
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getGeneralMessages().noArgument(), cmd.getSource()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().noArgument(),
cmd.getSource()
)
);
return 1;
})
.then(RequiredArgumentBuilder
Expand All @@ -183,10 +197,15 @@ private static LiteralCommandNode<CommandSource> resetCommand(String command, Ch
return builder.buildFuture();
})
.executes(cmd -> {
String arg = cmd.getArgument("player", String.class);
InfractionPlayer p = InfractionPlayer.get(arg);
final String arg = cmd.getArgument("player", String.class);
final InfractionPlayer p = InfractionPlayer.get(arg);
if(p == null){
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getGeneralMessages().playerNotFound(), cmd.getSource(), Placeholder.unparsed("player", arg)));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().playerNotFound(),
cmd.getSource(), Placeholder.unparsed("player", arg)
)
);
return 1;
}
resetAll(p, cmd.getSource(), plugin.getFormatter());
Expand Down Expand Up @@ -225,7 +244,13 @@ private static LiteralCommandNode<CommandSource> resetWithPlayerSubcommand(Stri
String arg = cmd.getArgument("player", String.class);
InfractionPlayer p = InfractionPlayer.get(arg);
if(p == null){
cmd.getSource().sendMessage(formatter.parse(Configuration.getMessages().getGeneralMessages().playerNotFound(), cmd.getSource(), Placeholder.unparsed("player", arg)));
cmd.getSource().sendMessage(
formatter.parse(
Configuration.getMessages().getGeneralMessages().playerNotFound(),
cmd.getSource(),
Placeholder.unparsed("player", arg)
)
);
return 1;
}
p.getViolations().resetViolations(type);
Expand All @@ -240,7 +265,11 @@ private static LiteralCommandNode<CommandSource> clearCommand(String command, Ch
.requires(p -> p.hasPermission(Permissions.COMMAND_CLEAR))
.executes(cmd -> {
plugin.getProxy().sendMessage(Components.SPACES_COMPONENT);
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getGlobalMessage()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getGlobalMessage()
)
);
return 1;
})
.then(LiteralArgumentBuilder
Expand All @@ -257,7 +286,12 @@ private static LiteralCommandNode<CommandSource> clearCommand(String command, Ch
));
});
} else {
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getGeneralMessages().noArgument(), cmd.getSource()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().noArgument(),
cmd.getSource()
)
);
}
return 1;
})
Expand All @@ -272,8 +306,20 @@ private static LiteralCommandNode<CommandSource> clearCommand(String command, Ch
TagResolver serverPlaceholder = Placeholder.unparsed("server", arg);
plugin.getProxy().getServer(arg).ifPresentOrElse(serverObjetive -> {
serverObjetive.sendMessage(Components.SPACES_COMPONENT);
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getServerMessage(), cmd.getSource(), serverPlaceholder));
}, () -> cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getNotFoundServerMessage(), cmd.getSource(), serverPlaceholder)));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getServerMessage(),
cmd.getSource(),
serverPlaceholder
)
);
}, () -> cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getNotFoundServerMessage(),
cmd.getSource(),
serverPlaceholder
)
));
return 1;
}).build()
)
Expand All @@ -282,22 +328,45 @@ private static LiteralCommandNode<CommandSource> clearCommand(String command, Ch
.<CommandSource>literal("player")
.requires(p -> p.hasPermission(Permissions.COMMAND_CLEAR_PLAYER))
.executes(cmd -> {
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getGeneralMessages().noArgument(), cmd.getSource()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().noArgument(),
cmd.getSource()
)
);
return 1;
})
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("player", StringArgumentType.word())
.suggests((arg, builder) -> {
plugin.getProxy().getAllPlayers().forEach(p -> builder.suggest(p.getUsername()));
plugin.getChatPlayers().forEach((uuid, p) -> builder.suggest(p.username(), VelocityBrigadierMessage.tooltip(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().getPlayerSuggestionsFormat(),
p,
Placeholder.unparsed("player", p.username())
)
)));
return builder.buildFuture();
})
.executes(cmd -> {
String arg = cmd.getArgument("player", String.class);
TagResolver serverPlaceholder = Placeholder.unparsed("player", arg);
plugin.getProxy().getPlayer(arg).ifPresentOrElse(playerObjetive -> {
playerObjetive.sendMessage(Components.SPACES_COMPONENT);
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getPlayerMessage(), cmd.getSource(), serverPlaceholder));
}, () -> cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getNotFoundServerMessage(), cmd.getSource(), serverPlaceholder)));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getPlayerMessage(),
cmd.getSource(),
serverPlaceholder
)
);
}, () -> cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getNotFoundServerMessage(),
cmd.getSource(),
serverPlaceholder
)
));
return 1;
}).build()
).build()
Expand All @@ -306,7 +375,12 @@ private static LiteralCommandNode<CommandSource> clearCommand(String command, Ch
.<CommandSource>literal("all")
.executes(cmd -> {
plugin.getProxy().sendMessage(Components.SPACES_COMPONENT);
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getClearMessages().getGlobalMessage(), cmd.getSource()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getClearMessages().getGlobalMessage(),
cmd.getSource()
)
);
return 1;
}).build()
).build();
Expand All @@ -318,7 +392,11 @@ private static LiteralCommandNode<CommandSource> reloadCommand(String command, C
.<CommandSource>literal(command)
.requires(p -> p.hasPermission(Permissions.COMMAND_RELOAD))
.executes(cmd -> {
cmd.getSource().sendMessage(plugin.getFormatter().parse(Configuration.getMessages().getGeneralMessages().getReloadMessage()));
cmd.getSource().sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getGeneralMessages().getReloadMessage()
)
);
plugin.reloadConfig();
return 1;
}).build();
Expand Down

0 comments on commit 3d56ddf

Please sign in to comment.