Search in sources :

Example 1 with Claim

use of io.icker.factions.database.Claim in project factions by ickerio.

the class ClaimCommand method remove.

public static int remove(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();
    Claim existingClaim = Claim.get(chunkPos.x, chunkPos.z, dimension);
    if (existingClaim == null) {
        new Message("Cannot remove a claim on an unclaimed chunk").fail().send(player, false);
        return 0;
    }
    Faction faction = Member.get(player.getUuid()).getFaction();
    PlayerConfig config = PlayerConfig.get(player.getUuid());
    if (existingClaim.getFaction().name != faction.name && !config.bypass) {
        new Message("Cannot remove a claim owned by another faction").fail().send(player, false);
        return 0;
    }
    existingClaim.remove();
    new Message("%s removed claim at chunk (%d, %d)", player.getName().asString(), existingClaim.x, existingClaim.z).send(faction);
    return 1;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ChunkPos(net.minecraft.util.math.ChunkPos) Claim(io.icker.factions.database.Claim) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction) PlayerConfig(io.icker.factions.database.PlayerConfig)

Example 2 with Claim

use of io.icker.factions.database.Claim in project factions by ickerio.

the class ClaimCommand method list.

public static int list(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    ArrayList<Claim> claims = Member.get(player.getUuid()).getFaction().getClaims();
    int count = claims.size();
    new Message("You have ").add(new Message(String.valueOf(count)).format(Formatting.YELLOW)).add(" claim%s", count == 1 ? "" : "s").send(source.getPlayer(), false);
    if (count == 0)
        return 1;
    String claimText = // TODO: show dimension
    claims.stream().map(claim -> String.format("(%d, %d)", claim.x, claim.z)).collect(Collectors.joining(", "));
    new Message(claimText).format(Formatting.ITALIC).send(source.getPlayer(), false);
    return 1;
}
Also used : 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) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Formatting(net.minecraft.util.Formatting) Claim(io.icker.factions.database.Claim) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Message(io.icker.factions.util.Message) Member(io.icker.factions.database.Member) PlayerConfig(io.icker.factions.database.PlayerConfig) Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Claim(io.icker.factions.database.Claim) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 3 with Claim

use of io.icker.factions.database.Claim in project factions by ickerio.

the class ClaimCommand method add.

public static int add(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());
    Claim existingClaim = Claim.get(chunkPos.x, chunkPos.z, dimension);
    if (existingClaim == null) {
        Faction faction = member.getFaction();
        faction.addClaim(chunkPos.x, chunkPos.z, dimension);
        new Message("%s claimed chunk (%d, %d)", player.getName().asString(), chunkPos.x, chunkPos.z).send(faction);
        return 1;
    }
    String owner = existingClaim.getFaction().name == member.getFaction().name ? "Your" : "Another";
    new Message(owner + " faction already owns this chunk").fail().send(player, false);
    return 0;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ChunkPos(net.minecraft.util.math.ChunkPos) Member(io.icker.factions.database.Member) Claim(io.icker.factions.database.Claim) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

Example 4 with Claim

use of io.icker.factions.database.Claim in project factions by ickerio.

the class HomeCommand method checkLimitToClaim.

private static boolean checkLimitToClaim(Faction faction, ServerWorld world, BlockPos pos) {
    if (Config.HOME != Config.HomeOptions.CLAIMS)
        return false;
    ChunkPos chunkPos = world.getChunk(pos).getPos();
    String dimension = world.getRegistryKey().getValue().toString();
    Claim possibleClaim = Claim.get(chunkPos.x, chunkPos.z, dimension);
    return possibleClaim == null || possibleClaim.getFaction().name != faction.name;
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos) Claim(io.icker.factions.database.Claim)

Example 5 with Claim

use of io.icker.factions.database.Claim 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)

Aggregations

Claim (io.icker.factions.database.Claim)6 ChunkPos (net.minecraft.util.math.ChunkPos)6 Faction (io.icker.factions.database.Faction)5 Member (io.icker.factions.database.Member)4 Message (io.icker.factions.util.Message)4 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 ServerWorld (net.minecraft.server.world.ServerWorld)4 PlayerConfig (io.icker.factions.database.PlayerConfig)3 CommandContext (com.mojang.brigadier.context.CommandContext)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)2 Formatting (net.minecraft.util.Formatting)2 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 HoverEvent (net.minecraft.text.HoverEvent)1 LiteralText (net.minecraft.text.LiteralText)1 MutableText (net.minecraft.text.MutableText)1