Search in sources :

Example 1 with Player

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();
}
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 2 with Player

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;
}
Also used : Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Player

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;
}
Also used : Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) GameProfile(com.mojang.authlib.GameProfile)

Example 4 with Player

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;
}
Also used : Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Player

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;
}
Also used : Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Aggregations

Player (com.minecolonies.api.colony.permissions.Player)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)11 NotNull (org.jetbrains.annotations.NotNull)6 Rank (com.minecolonies.api.colony.permissions.Rank)3 GameProfile (com.mojang.authlib.GameProfile)3 IColony (com.minecolonies.api.colony.IColony)2 ColonyView (com.minecolonies.coremod.colony.ColonyView)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 Action (com.minecolonies.api.colony.permissions.Action)1 JobGuard (com.minecolonies.coremod.colony.jobs.JobGuard)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Achievement (net.minecraft.stats.Achievement)1 Nullable (org.jetbrains.annotations.Nullable)1