Search in sources :

Example 6 with Message

use of io.icker.factions.util.Message 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 7 with Message

use of io.icker.factions.util.Message 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 8 with Message

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

the class HomeCommand method go.

public static int go(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Faction faction = Member.get(player.getUuid()).getFaction();
    Home home = faction.getHome();
    if (home == null) {
        new Message("No faction home set").fail().send(player, false);
        return 0;
    }
    ServerWorld world = player.getServer().getWorld(RegistryKey.of(Registry.WORLD_KEY, new Identifier(home.level)));
    if (checkLimitToClaim(faction, world, new BlockPos(home.x, home.y, home.z))) {
        new Message("Cannot warp home to an unclaimed chunk").fail().send(player, false);
        return 0;
    }
    DamageTracker tracker = player.getDamageTracker();
    if (tracker.getMostRecentDamage() == null || tracker.getTimeSinceLastAttack() > Config.SAFE_TICKS_TO_WARP) {
        player.teleport(world, home.x, home.y, home.z, home.yaw, home.pitch);
        new Message("Warped to faction home").send(player, false);
    } else {
        new Message("Cannot warp while in combat").fail().send(player, false);
    }
    return 1;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) Identifier(net.minecraft.util.Identifier) DamageTracker(net.minecraft.entity.damage.DamageTracker) Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) Home(io.icker.factions.database.Home) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

Example 9 with Message

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

the class InfoCommand method any.

public static int any(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    // TODO: Suggestions for factions
    String factionName = StringArgumentType.getString(context, "faction");
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Faction faction = Faction.get(factionName);
    if (faction == null) {
        new Message("Faction does not exist").fail().send(player, false);
        return 0;
    }
    return info(player, faction);
}
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 10 with Message

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

the class JoinCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    String name = StringArgumentType.getString(context, "name");
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Faction faction = Faction.get(name);
    if (faction == null) {
        new Message("Cannot join faction as none exist with that name").fail().send(player, false);
        return 0;
    }
    Invite invite = Invite.get(player.getUuid(), faction.name);
    if (!faction.open && invite == null) {
        new Message("Cannot join faction as it is not open and you are not invited").fail().send(player, false);
        return 0;
    }
    if (faction.getMembers().size() >= Config.MAX_FACTION_SIZE && Config.MAX_FACTION_SIZE != -1) {
        new Message("Cannot join faction as it is currently full").fail().send(player, false);
        return 0;
    }
    if (invite != null)
        invite.remove();
    faction.addMember(player.getUuid());
    source.getServer().getPlayerManager().sendCommandTree(player);
    new Message(player.getName().asString() + " joined").send(faction);
    // TODO: change this, its ew
    FactionEvents.adjustPower(faction, Config.MEMBER_POWER);
    return 1;
}
Also used : Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Invite(io.icker.factions.database.Invite) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

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