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