Search in sources :

Example 1 with Invite

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

Example 2 with Invite

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

the class InviteCommand method list.

public static int list(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ArrayList<Invite> invites = Member.get(source.getPlayer().getUuid()).getFaction().getInvites();
    int count = invites.size();
    new Message("You have ").add(new Message(String.valueOf(count)).format(Formatting.YELLOW)).add(" outgoing invite%s", count == 1 ? "" : "s").send(source.getPlayer(), false);
    if (count == 0)
        return 1;
    UserCache cache = source.getServer().getUserCache();
    String players = invites.stream().map(invite -> cache.getByUuid(invite.playerId).orElse(new GameProfile(Util.NIL_UUID, "{Uncached Player}")).getName()).collect(Collectors.joining(", "));
    new Message(players).format(Formatting.ITALIC).send(source.getPlayer(), false);
    return 1;
}
Also used : Invite(io.icker.factions.database.Invite) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) CommandContext(com.mojang.brigadier.context.CommandContext) Faction(io.icker.factions.database.Faction) Util(net.minecraft.util.Util) GameProfile(com.mojang.authlib.GameProfile) UserCache(net.minecraft.util.UserCache) EntityArgumentType(net.minecraft.command.argument.EntityArgumentType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Formatting(net.minecraft.util.Formatting) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Message(io.icker.factions.util.Message) Member(io.icker.factions.database.Member) Message(io.icker.factions.util.Message) GameProfile(com.mojang.authlib.GameProfile) UserCache(net.minecraft.util.UserCache) Invite(io.icker.factions.database.Invite) ServerCommandSource(net.minecraft.server.command.ServerCommandSource)

Example 3 with Invite

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

the class InviteCommand method add.

public static int add(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity target = EntityArgumentType.getPlayer(context, "player");
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Faction faction = Member.get(source.getPlayer().getUuid()).getFaction();
    Invite invite = Invite.get(target.getUuid(), faction.name);
    if (invite != null) {
        new Message(target.getName().getString() + " was already invited to your faction").format(Formatting.RED).send(player, false);
        return 0;
    }
    for (Member member : faction.getMembers()) if (member.uuid.equals(target.getUuid()))
        new Message(target.getName().getString() + " is already in your faction").format(Formatting.RED).send(player, false);
    Invite.add(target.getUuid(), faction.name);
    new Message(target.getName().getString() + " has been invited").send(faction);
    new Message("You have been invited to join this faction").format(Formatting.YELLOW).hover("Click to join").click("/factions join " + faction.name).prependFaction(faction).send(target, false);
    return 1;
}
Also used : Message(io.icker.factions.util.Message) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Member(io.icker.factions.database.Member) Invite(io.icker.factions.database.Invite) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) Faction(io.icker.factions.database.Faction)

Example 4 with Invite

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

the class InviteCommand method remove.

public static int remove(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerPlayerEntity target = EntityArgumentType.getPlayer(context, "player");
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    Faction faction = Member.get(player.getUuid()).getFaction();
    new Invite(target.getUuid(), faction.name).remove();
    new Message(target.getName().getString() + " is no longer invited to your faction").send(player, false);
    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

Faction (io.icker.factions.database.Faction)4 Invite (io.icker.factions.database.Invite)4 Message (io.icker.factions.util.Message)4 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)4 Member (io.icker.factions.database.Member)2 GameProfile (com.mojang.authlib.GameProfile)1 CommandContext (com.mojang.brigadier.context.CommandContext)1 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 ArrayList (java.util.ArrayList)1 Collectors (java.util.stream.Collectors)1 EntityArgumentType (net.minecraft.command.argument.EntityArgumentType)1 Formatting (net.minecraft.util.Formatting)1 UserCache (net.minecraft.util.UserCache)1 Util (net.minecraft.util.Util)1