use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class NotificationsCommand method showNotifications.
public static int showNotifications(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
List<Text> notifs = PlayerUtils.getUnreadPingsFor(src.getPlayer());
if (!notifs.isEmpty()) {
MutableText response = new LiteralText("You have " + notifs.size() + " unread message" + (notifs.size() != 1 ? "s" : "") + ":").formatted(Formatting.GREEN);
for (Text notif : notifs) {
response.append(new LiteralText("\n- ").formatted(Formatting.WHITE).append(notif));
}
src.sendFeedback(response, false);
notifs.clear();
return 1;
} else {
src.sendFeedback(new LiteralText("You have no unread messages.").formatted(Formatting.GREEN), false);
return 0;
}
}
use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class GroupCommand method removePlayerGroup.
private static int removePlayerGroup(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
String group = StringArgumentType.getString(ctx, "groupname");
ServerPlayerEntity player = EntityArgumentType.getPlayer(ctx, "player");
List<String> groups = PlayerUtils.getPingGroupsOf(player);
if (!GROUPNAME_PATTERN.asPredicate().test(group))
throw INVALID_GROUPNAME.create();
if (groups.stream().noneMatch(x -> x.equalsIgnoreCase(group)))
throw NOT_IN_GROUP_OTHER.create(player);
groups.removeIf(x -> x.equalsIgnoreCase(group));
if (!NameLogic.isValidName(src.getMinecraftServer().getPlayerManager(), group, false))
ServerNetworkLogic.removePossibleName(src.getMinecraftServer().getPlayerManager(), group);
src.sendFeedback(new LiteralText("Removed player ").formatted(Formatting.RED).append(new LiteralText(player.getEntityName()).formatted(Formatting.AQUA)).append(" from group ").append(new LiteralText(group).formatted(Formatting.YELLOW)).append(new LiteralText(".")), true);
return 0;
}
use of net.minecraft.server.command.ServerCommandSource in project pingspam by BasiqueEvangelist.
the class PingIgnoreCommand method listIgnoredPlayers.
private static int listIgnoredPlayers(CommandContext<ServerCommandSource> ctx) throws CommandSyntaxException {
ServerCommandSource src = ctx.getSource();
ServerPlayerEntity player = src.getPlayer();
List<UUID> ignoredPlayers = PlayerUtils.getIgnoredPlayersOf(player);
if (ignoredPlayers.isEmpty()) {
src.sendFeedback(new LiteralText("You are not ignoring any players.").formatted(Formatting.GREEN), false);
return 0;
}
StringBuilder contentBuilder = new StringBuilder();
int count = 0;
for (UUID ignoredPlayerUuid : ignoredPlayers) {
contentBuilder.append("\n - ").append(OfflineNameCache.INSTANCE.getNameFromUUID(ignoredPlayerUuid));
count++;
}
src.sendFeedback(new LiteralText("You are ignoring " + count + " player(s):").formatted(Formatting.GREEN).append(new LiteralText(contentBuilder.toString()).formatted(Formatting.AQUA)), false);
return 0;
}
use of net.minecraft.server.command.ServerCommandSource in project mclogs-fabric by aternosorg.
the class CommandMclogsList method register.
static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("mclogs").then(literal("list").requires(source -> source.hasPermissionLevel(2)).executes((context) -> {
ServerCommandSource source = context.getSource();
try {
String[] logs = MclogsFabricLoader.getLogs(context);
if (logs.length == 0) {
source.sendFeedback(new LiteralText("No logs available!"), false);
return 0;
}
LiteralText feedback = new LiteralText("Available Logs:");
for (String log : logs) {
Style s = Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/mclogs share " + log));
LiteralText tempText = new LiteralText("\n" + log);
tempText.setStyle(s);
feedback.append(tempText);
}
source.sendFeedback(feedback, false);
return logs.length;
} catch (Exception e) {
MclogsFabricLoader.logger.error("An error occurred when listing your logs.");
MclogsFabricLoader.logger.error(e);
LiteralText error = new LiteralText("An error occurred. Check your log for more details.");
source.sendError(error);
return -1;
}
})));
}
use of net.minecraft.server.command.ServerCommandSource in project LuckPerms by lucko.
the class FabricCommandExecutor method register.
public void register() {
CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
for (String alias : COMMAND_ALIASES) {
LiteralCommandNode<ServerCommandSource> cmd = literal(alias).executes(this).build();
ArgumentCommandNode<ServerCommandSource, String> args = argument("args", greedyString()).suggests(this).executes(this).build();
cmd.addChild(args);
dispatcher.getRoot().addChild(cmd);
}
});
}
Aggregations