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));
}
}
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);
}
Aggregations