Search in sources :

Example 11 with Message

use of io.icker.factions.util.Message in project factions by ickerio.

the class KickMemberCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity target = EntityArgumentType.getPlayer(context, "player");
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    if (target.getUuid().equals(player.getUuid())) {
        new Message("You cannot kick yourself").format(Formatting.RED).send(player, false);
        return 0;
    }
    Faction faction = Member.get(player.getUuid()).getFaction();
    for (Member member : faction.getMembers()) if (member.uuid.equals(target.getUuid())) {
        if (Member.get(player.getUuid()).getRank() == Member.Rank.CO_OWNER && (member.getRank() == Member.Rank.CO_OWNER || member.getRank() == Member.Rank.OWNER)) {
            new Message("You can only kick members with a lower rank than yours").format(Formatting.RED).send(player, false);
            return 0;
        }
        member.remove();
        context.getSource().getServer().getPlayerManager().sendCommandTree(player);
        new Message("Kicked " + target.getName().getString()).send(player, false);
        return 1;
    }
    new Message("That player is not a member of your faction");
    return 0;
}
Also used : Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Member(io.icker.factions.database.Member) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

Example 12 with Message

use of io.icker.factions.util.Message in project factions by ickerio.

the class LeaveCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Member member = Member.get(player.getUuid());
    Faction faction = member.getFaction();
    new Message(player.getName().asString() + " left").send(faction);
    member.remove();
    context.getSource().getServer().getPlayerManager().sendCommandTree(player);
    if (faction.getMembers().size() == 0) {
        faction.remove();
    } else {
        FactionEvents.adjustPower(faction, -Config.MEMBER_POWER);
    }
    return 1;
}
Also used : Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Member(io.icker.factions.database.Member) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

Example 13 with Message

use of io.icker.factions.util.Message in project factions by ickerio.

the class ListCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    ArrayList<Faction> factions = Faction.all();
    int size = factions.size();
    new Message("There %s ", size == 1 ? "is" : "are").add(new Message(String.valueOf(size)).format(Formatting.YELLOW)).add(" faction%s", size == 1 ? "" : "s").send(source.getPlayer(), false);
    factions.forEach(f -> InfoCommand.info(player, f));
    return 1;
}
Also used : Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

Example 14 with Message

use of io.icker.factions.util.Message in project factions by ickerio.

the class MapCommand method show.

public static int show(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    ServerWorld world = player.getWorld();
    ChunkPos chunkPos = world.getChunk(player.getBlockPos()).getPos();
    String dimension = world.getRegistryKey().getValue().toString();
    Member member = Member.get(player.getUuid());
    Faction faction = member == null ? null : member.getFaction();
    // Print the header of the faction map.
    new Message("---------------[").format(Formatting.GRAY).add(new Message(" F MAP ").format(Formatting.AQUA)).add(new Message("]---------------").format(Formatting.GRAY)).send(player, false);
    Map<String, Formatting> factions = new HashMap<>();
    // Create and fill an array with the faction map.
    MutableText[] rows = new MutableText[11];
    for (int z = -5; z <= 5; z++) {
        MutableText row = new LiteralText("");
        for (int x = -6; x <= 6; x++) {
            Claim claim = Claim.get(chunkPos.x + x, chunkPos.z + z, dimension);
            if (x == 0 && z == 0) {
                row.append(new LiteralText(" ■").formatted(Formatting.YELLOW));
            } else if (claim == null) {
                row.append(new LiteralText(" ■").formatted(Formatting.GRAY));
            } else if (faction != null && claim.getFaction().name.equals(faction.name)) {
                row.append(new LiteralText(" ■").formatted(Formatting.GREEN));
            } else {
                Faction owner = claim.getFaction();
                factions.put(owner.name, owner.color);
                row.append(new LiteralText(" ■").formatted(owner.color).styled((style) -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText(owner.name)))));
            }
        }
        rows[z + 5] = row;
    }
    // Attach the legend to the rows and send them to the player.
    player.sendMessage(rows[0].append(new LiteralText("  ■").formatted(Formatting.GRAY)).append(" Wilderness"), false);
    player.sendMessage(rows[1].append(new LiteralText("  ■").formatted(Formatting.GREEN)).append(" Your faction"), false);
    player.sendMessage(rows[2].append(new LiteralText("  ■").formatted(Formatting.YELLOW)).append(" Your position"), false);
    int i = 3;
    for (Map.Entry<String, Formatting> entry : factions.entrySet()) {
        if (i >= rows.length)
            break;
        player.sendMessage(rows[i].append(new LiteralText("  ■").formatted(entry.getValue())).append(" " + entry.getKey()), false);
        i++;
    }
    // Send remaining rows.
    for (; i < rows.length; i++) {
        player.sendMessage(rows[i], false);
    }
    // Print the footer of the faction map.
    new Message("---------------------------------------").format(Formatting.GRAY).send(player, false);
    return 1;
}
Also used : MutableText(net.minecraft.text.MutableText) LiteralText(net.minecraft.text.LiteralText) java.util(java.util) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) CommandContext(com.mojang.brigadier.context.CommandContext) Faction(io.icker.factions.database.Faction) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkPos(net.minecraft.util.math.ChunkPos) HoverEvent(net.minecraft.text.HoverEvent) Formatting(net.minecraft.util.Formatting) Claim(io.icker.factions.database.Claim) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) MutableText(net.minecraft.text.MutableText) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Message(io.icker.factions.util.Message) Member(io.icker.factions.database.Member) HoverEvent(net.minecraft.text.HoverEvent) Message(io.icker.factions.util.Message) Formatting(net.minecraft.util.Formatting) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkPos(net.minecraft.util.math.ChunkPos) Member(io.icker.factions.database.Member) Claim(io.icker.factions.database.Claim) Faction(io.icker.factions.database.Faction) LiteralText(net.minecraft.text.LiteralText)

Example 15 with Message

use of io.icker.factions.util.Message in project factions by ickerio.

the class ModifyCommand method description.

public static int description(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    String description = StringArgumentType.getString(context, "description");
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Member.get(player.getUuid()).getFaction().setDescription(description);
    new Message("Successfully updated faction description").send(player, false);
    return 1;
}
Also used : Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Aggregations

Message (io.icker.factions.util.Message)34 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)29 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)28 Faction (io.icker.factions.database.Faction)24 Member (io.icker.factions.database.Member)14 ServerWorld (net.minecraft.server.world.ServerWorld)5 Formatting (net.minecraft.util.Formatting)5 CommandContext (com.mojang.brigadier.context.CommandContext)4 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)4 Claim (io.icker.factions.database.Claim)4 Invite (io.icker.factions.database.Invite)4 ChunkPos (net.minecraft.util.math.ChunkPos)4 PlayerConfig (io.icker.factions.database.PlayerConfig)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 GameProfile (com.mojang.authlib.GameProfile)2 Ally (io.icker.factions.database.Ally)2 Home (io.icker.factions.database.Home)2 UserCache (net.minecraft.util.UserCache)2 Util (net.minecraft.util.Util)2