Search in sources :

Example 1 with Rank

use of com.minecolonies.api.colony.permissions.Rank in project minecolonies by Minecolonies.

the class Colony method sendPermissionsPackets.

/**
     * Sends packages to update the permissions.
     *
     * @param oldSubscribers    the existing subscribers.
     * @param hasNewSubscribers the new subscribers.
     */
private void sendPermissionsPackets(@NotNull final Set<EntityPlayerMP> oldSubscribers, final boolean hasNewSubscribers) {
    if (permissions.isDirty() || hasNewSubscribers) {
        subscribers.stream().filter(player -> permissions.isDirty() || !oldSubscribers.contains(player)).forEach(player -> {
            final Rank rank = getPermissions().getRank(player);
            MineColonies.getNetwork().sendTo(new PermissionsMessage.View(this, rank), player);
        });
    }
}
Also used : Permissions(com.minecolonies.coremod.colony.permissions.Permissions) AchievementUtils(com.minecolonies.coremod.util.AchievementUtils) java.util(java.util) ColonyUtils(com.minecolonies.coremod.util.ColonyUtils) Achievement(net.minecraft.stats.Achievement) com.minecolonies.coremod.network.messages(com.minecolonies.coremod.network.messages) NBTTagString(net.minecraft.nbt.NBTTagString) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Rank(com.minecolonies.api.colony.permissions.Rank) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) NBTTagList(net.minecraft.nbt.NBTTagList) ModAchievements(com.minecolonies.coremod.achievements.ModAchievements) Block(net.minecraft.block.Block) ServerUtils(com.minecolonies.coremod.util.ServerUtils) ConstructionTapeHelper(com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper) Field(com.minecolonies.coremod.entity.ai.citizen.farmer.Field) com.minecolonies.api.util(com.minecolonies.api.util) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) StatList(net.minecraft.stats.StatList) World(net.minecraft.world.World) StatBase(net.minecraft.stats.StatBase) BlockPos(net.minecraft.util.math.BlockPos) InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) TileEntityColonyBuilding(com.minecolonies.coremod.tileentities.TileEntityColonyBuilding) Collectors(java.util.stream.Collectors) com.minecolonies.coremod.colony.buildings(com.minecolonies.coremod.colony.buildings) IBlockState(net.minecraft.block.state.IBlockState) Nullable(org.jetbrains.annotations.Nullable) MinecraftForge(net.minecraftforge.common.MinecraftForge) ColonyPermissionEventHandler(com.minecolonies.coremod.permissions.ColonyPermissionEventHandler) NBT(net.minecraftforge.common.util.Constants.NBT) MineColonies(com.minecolonies.coremod.MineColonies) EntityPlayer(net.minecraft.entity.player.EntityPlayer) AbstractWorkOrder(com.minecolonies.coremod.colony.workorders.AbstractWorkOrder) TickEvent(net.minecraftforge.fml.common.gameevent.TickEvent) NotNull(org.jetbrains.annotations.NotNull) ScarecrowTileEntity(com.minecolonies.coremod.tileentities.ScarecrowTileEntity) NBTUtil(net.minecraft.nbt.NBTUtil) Configurations(com.minecolonies.api.configuration.Configurations) Rank(com.minecolonies.api.colony.permissions.Rank)

Example 2 with Rank

use of com.minecolonies.api.colony.permissions.Rank in project minecolonies by Minecolonies.

the class WindowTownHall method trigger.

/**
     * Called when the permission button has been triggered.
     *
     * @param button the triggered button.
     */
private void trigger(@NotNull final Button button) {
    @NotNull final Pane pane = button.getParent().getChildren().get(2);
    int index = 0;
    if (pane instanceof Label) {
        index = Integer.valueOf(((Label) pane).getLabelText());
    }
    final boolean trigger = LanguageHandler.format(ON).equals(button.getLabel());
    final Action action = Action.values()[index];
    final Rank rank = Rank.valueOf(actionsList.getParent().getID().toUpperCase(Locale.ENGLISH));
    MineColonies.getNetwork().sendToServer(new PermissionsMessage.Permission(townHall.getColony(), PermissionsMessage.MessageType.TOGGLE_PERMISSION, rank, action));
    townHall.getColony().getPermissions().togglePermission(rank, action);
    if (trigger) {
        button.setLabel(LanguageHandler.format(OFF));
    } else {
        button.setLabel(LanguageHandler.format(ON));
    }
}
Also used : Action(com.minecolonies.api.colony.permissions.Action) Label(com.minecolonies.blockout.controls.Label) Rank(com.minecolonies.api.colony.permissions.Rank) NotNull(org.jetbrains.annotations.NotNull) Pane(com.minecolonies.blockout.Pane)

Example 3 with Rank

use of com.minecolonies.api.colony.permissions.Rank in project minecolonies by Minecolonies.

the class Permissions method loadPermissions.

/**
     * Reads the permissionMap from a NBT.
     *
     * @param compound NBT to read from.
     */
public void loadPermissions(@NotNull final NBTTagCompound compound) {
    //  Owners
    final NBTTagList ownerTagList = compound.getTagList(TAG_OWNERS, net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < ownerTagList.tagCount(); ++i) {
        final NBTTagCompound ownerCompound = ownerTagList.getCompoundTagAt(i);
        @NotNull final UUID id = UUID.fromString(ownerCompound.getString(TAG_ID));
        final Rank rank = Rank.valueOf(ownerCompound.getString(TAG_RANK));
        final GameProfile player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache().getProfileByUUID(id);
        if (player != null) {
            players.put(id, new Player(id, player.getName(), rank));
        }
    }
    //Permissions
    final NBTTagList permissionsTagList = compound.getTagList(TAG_PERMISSIONS, net.minecraftforge.common.util.Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < permissionsTagList.tagCount(); ++i) {
        final NBTTagCompound permissionsCompound = permissionsTagList.getCompoundTagAt(i);
        final Rank rank = Rank.valueOf(permissionsCompound.getString(TAG_RANK));
        final NBTTagList flagsTagList = permissionsCompound.getTagList(TAG_FLAGS, net.minecraftforge.common.util.Constants.NBT.TAG_STRING);
        int flags = 0;
        for (int j = 0; j < flagsTagList.tagCount(); ++j) {
            final String flag = flagsTagList.getStringTagAt(j);
            flags = Utils.setFlag(flags, Action.valueOf(flag).getFlag());
        }
        permissionMap.put(rank, flags);
    }
    if (compound.hasKey(TAG_OWNER)) {
        ownerName = compound.getString(TAG_OWNER);
    }
    if (compound.hasKey(TAG_OWNER_ID)) {
        try {
            ownerUUID = UUID.fromString(compound.getString(TAG_OWNER_ID));
        } catch (final IllegalArgumentException e) {
        /*
                 * Intentionally left empty. Happens when the UUID hasn't been saved yet.
                 */
        }
    }
    this.updatedPermissionAlready = compound.getBoolean(TAG_UPDATE);
    if (!updatedPermissionAlready) {
        updateNewPermissions();
    }
    restoreOwnerIfNull();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) GameProfile(com.mojang.authlib.GameProfile) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Rank(com.minecolonies.api.colony.permissions.Rank) NBTTagString(net.minecraft.nbt.NBTTagString) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Rank

use of com.minecolonies.api.colony.permissions.Rank in project minecolonies by Minecolonies.

the class Permissions method savePermissions.

/**
     * Save the permissionMap to a NBT.
     *
     * @param compound NBT to write to.
     */
public void savePermissions(@NotNull final NBTTagCompound compound) {
    //  Owners
    @NotNull final NBTTagList ownerTagList = new NBTTagList();
    for (@NotNull final Player player : players.values()) {
        @NotNull final NBTTagCompound ownersCompound = new NBTTagCompound();
        ownersCompound.setString(TAG_ID, player.getID().toString());
        ownersCompound.setString(TAG_RANK, player.getRank().name());
        ownerTagList.appendTag(ownersCompound);
    }
    compound.setTag(TAG_OWNERS, ownerTagList);
    // Permissions
    @NotNull final NBTTagList permissionsTagList = new NBTTagList();
    for (@NotNull final Map.Entry<Rank, Integer> entry : permissionMap.entrySet()) {
        @NotNull final NBTTagCompound permissionsCompound = new NBTTagCompound();
        permissionsCompound.setString(TAG_RANK, entry.getKey().name());
        @NotNull final NBTTagList flagsTagList = new NBTTagList();
        for (@NotNull final Action action : Action.values()) {
            if (Utils.testFlag(entry.getValue(), action.getFlag())) {
                flagsTagList.appendTag(new NBTTagString(action.name()));
            }
        }
        permissionsCompound.setTag(TAG_FLAGS, flagsTagList);
        permissionsTagList.appendTag(permissionsCompound);
    }
    compound.setTag(TAG_PERMISSIONS, permissionsTagList);
    if (!ownerName.isEmpty()) {
        compound.setString(TAG_OWNER, ownerName);
    }
    if (ownerUUID != null) {
        compound.setString(TAG_OWNER_ID, ownerUUID.toString());
    }
    compound.setBoolean(TAG_UPDATE, updatedPermissionAlready);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Action(com.minecolonies.api.colony.permissions.Action) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) Rank(com.minecolonies.api.colony.permissions.Rank) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Rank (com.minecolonies.api.colony.permissions.Rank)4 NotNull (org.jetbrains.annotations.NotNull)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 NBTTagString (net.minecraft.nbt.NBTTagString)3 Action (com.minecolonies.api.colony.permissions.Action)2 Player (com.minecolonies.api.colony.permissions.Player)2 Configurations (com.minecolonies.api.configuration.Configurations)1 com.minecolonies.api.util (com.minecolonies.api.util)1 Pane (com.minecolonies.blockout.Pane)1 Label (com.minecolonies.blockout.controls.Label)1 MineColonies (com.minecolonies.coremod.MineColonies)1 ModAchievements (com.minecolonies.coremod.achievements.ModAchievements)1 com.minecolonies.coremod.colony.buildings (com.minecolonies.coremod.colony.buildings)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 AbstractWorkOrder (com.minecolonies.coremod.colony.workorders.AbstractWorkOrder)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 ConstructionTapeHelper (com.minecolonies.coremod.entity.ai.citizen.builder.ConstructionTapeHelper)1 Field (com.minecolonies.coremod.entity.ai.citizen.farmer.Field)1