Search in sources :

Example 1 with PlayerConfig

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

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

the class PlayerInteractEvents method actionPermitted.

public static boolean actionPermitted(BlockPos pos, World world, ServerPlayerEntity player) {
    PlayerConfig config = PlayerConfig.get(player.getUuid());
    if (config.bypass) {
        if (player.hasPermissionLevel(Config.REQUIRED_BYPASS_LEVEL)) {
            return true;
        } else {
            config.setBypass(false);
        }
    }
    String dimension = world.getRegistryKey().getValue().toString();
    ChunkPos actionPos = world.getChunk(pos).getPos();
    Claim claim = Claim.get(actionPos.x, actionPos.z, dimension);
    if (claim == null)
        return true;
    Member member = Member.get(player.getUuid());
    Faction owner = claim.getFaction();
    boolean overclaimed = owner.getClaims().size() * Config.CLAIM_WEIGHT > owner.power;
    boolean validMember = member == null ? false : member.getFaction().name == owner.name;
    boolean allied = Ally.checkIfAlly(owner.name, member.getFaction().name);
    boolean permitted = overclaimed || validMember || allied;
    if (!permitted)
        syncBlocks(player, world, pos);
    return permitted;
}
Also used : ChunkPos(net.minecraft.util.math.ChunkPos) Member(io.icker.factions.database.Member) Claim(io.icker.factions.database.Claim) PlayerConfig(io.icker.factions.database.PlayerConfig) Faction(io.icker.factions.database.Faction)

Example 3 with PlayerConfig

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

the class BypassCommand method run.

@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
    ServerCommandSource source = context.getSource();
    ServerPlayerEntity player = source.getPlayer();
    PlayerConfig config = PlayerConfig.get(player.getUuid());
    boolean bypass = !config.bypass;
    config.setBypass(bypass);
    new Message("Successfully toggled claim bypass").filler("ยท").add(new Message(bypass ? "ON" : "OFF").format(bypass ? Formatting.GREEN : Formatting.RED)).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) PlayerConfig(io.icker.factions.database.PlayerConfig)

Aggregations

PlayerConfig (io.icker.factions.database.PlayerConfig)3 Claim (io.icker.factions.database.Claim)2 Faction (io.icker.factions.database.Faction)2 Message (io.icker.factions.util.Message)2 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 Member (io.icker.factions.database.Member)1 ServerWorld (net.minecraft.server.world.ServerWorld)1