use of com.minecolonies.api.colony.permissions.Player 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.Player in project minecolonies by Minecolonies.
the class Permissions method addPlayer.
/**
* Adds a player to the rankings.
*
* @param id UUID of the player..
* @param rank Desired rank.
* @param name name of the player.
* @return True if succesful, otherwise false.
*/
public boolean addPlayer(@NotNull final UUID id, final String name, final Rank rank) {
@NotNull final Player p = new Player(id, name, rank);
if (players.containsKey(p.getID())) {
players.remove(p.getID());
}
players.put(p.getID(), p);
markDirty();
AchievementUtils.syncAchievements(colony);
return true;
}
use of com.minecolonies.api.colony.permissions.Player in project minecolonies by Minecolonies.
the class Permissions method setPlayerRank.
/**
* Sets the player's rank to a given rank.
*
* @param id UUID of the player of the new rank.
* @param rank Desired rank.
* @param world the world the player is in.
* @return True if successful, otherwise false.
*/
public boolean setPlayerRank(final UUID id, final Rank rank, final World world) {
final Player player = getPlayers().get(id);
if (player != null) {
player.setRank(rank);
markDirty();
AchievementUtils.syncAchievements(colony);
} else {
final GameProfile gameprofile = world.getMinecraftServer().getPlayerProfileCache().getProfileByUUID(id);
return gameprofile != null && addPlayer(gameprofile, rank);
}
return true;
}
use of com.minecolonies.api.colony.permissions.Player in project minecolonies by Minecolonies.
the class Permissions method addPlayer.
/**
* Adds a player to the rankings.
*
* @param gameprofile GameProfile of the player.
* @param rank Desired rank.
* @return True if succesful, otherwise false.
*/
private boolean addPlayer(@NotNull final GameProfile gameprofile, final Rank rank) {
@NotNull final Player p = new Player(gameprofile.getId(), gameprofile.getName(), rank);
if (players.containsKey(p.getID())) {
players.remove(p.getID());
}
players.put(p.getID(), p);
markDirty();
AchievementUtils.syncAchievements(colony);
return true;
}
use of com.minecolonies.api.colony.permissions.Player in project minecolonies by Minecolonies.
the class Permissions method removePlayer.
/**
* Remove a player from the permissionMap.
*
* @param id UUID of the player.
* @return True if succesfull, otherwise false.
*/
public boolean removePlayer(final UUID id) {
final Player player = players.get(id);
AchievementUtils.syncAchievements(colony);
if (player != null && player.getRank() != Rank.OWNER && players.remove(id) != null) {
markDirty();
return true;
}
return false;
}
Aggregations