Search in sources :

Example 1 with Action

use of com.minecolonies.api.colony.permissions.Action 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(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_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(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_OFF));
    } else {
        button.setLabel(LanguageHandler.format(COM_MINECOLONIES_COREMOD_GUI_WORKERHUTS_RETRIEVE_ON));
    }
}
Also used : Action(com.minecolonies.api.colony.permissions.Action) Rank(com.minecolonies.api.colony.permissions.Rank) NotNull(org.jetbrains.annotations.NotNull) Pane(com.minecolonies.blockout.Pane)

Example 2 with Action

use of com.minecolonies.api.colony.permissions.Action 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

Action (com.minecolonies.api.colony.permissions.Action)2 Rank (com.minecolonies.api.colony.permissions.Rank)2 NotNull (org.jetbrains.annotations.NotNull)2 Player (com.minecolonies.api.colony.permissions.Player)1 Pane (com.minecolonies.blockout.Pane)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 NBTTagString (net.minecraft.nbt.NBTTagString)1