Search in sources :

Example 1 with EnumPartyStatus

use of betterquesting.api.enums.EnumPartyStatus in project BetterQuesting by Funwayguy.

the class QuestInstance method claimReward.

@Override
public void claimReward(EntityPlayer player) {
    for (IReward rew : rewards.getAllValues()) {
        rew.claimReward(player, this);
    }
    UUID pID = QuestingAPI.getQuestingUUID(player);
    IParty party = PartyManager.INSTANCE.getUserParty(pID);
    if (party != null && this.qInfo.getProperty(NativeProps.PARTY_LOOT)) {
        for (UUID mem : party.getMembers()) {
            EnumPartyStatus pStat = party.getStatus(mem);
            if (pStat == null || pStat == EnumPartyStatus.INVITE) {
                continue;
            }
            UserEntry entry = GetUserEntry(mem);
            if (entry == null) {
                entry = new UserEntry(mem);
                this.completeUsers.add(entry);
            }
            entry.setClaimed(true, player.world.getTotalWorldTime());
        }
    } else {
        UserEntry entry = GetUserEntry(pID);
        if (entry == null) {
            entry = new UserEntry(pID);
            this.completeUsers.add(entry);
        }
        entry.setClaimed(true, player.world.getTotalWorldTime());
    }
    PacketSender.INSTANCE.sendToAll(getSyncPacket());
}
Also used : EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) IReward(betterquesting.api.questing.rewards.IReward) UserEntry(betterquesting.misc.UserEntry) IParty(betterquesting.api.questing.party.IParty) UUID(java.util.UUID)

Example 2 with EnumPartyStatus

use of betterquesting.api.enums.EnumPartyStatus in project BetterQuesting by Funwayguy.

the class PartyInstance method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound jObj, EnumSaveType saveType) {
    if (saveType != EnumSaveType.CONFIG) {
        return;
    }
    if (jObj.hasKey("properties", 10)) {
        pInfo.readFromNBT(jObj.getCompoundTag("properties"), EnumSaveType.CONFIG);
    } else // Legacy stuff
    {
        pInfo.readFromNBT(new NBTTagCompound(), EnumSaveType.CONFIG);
        pInfo.setProperty(NativeProps.NAME, jObj.getString("name"));
        pInfo.setProperty(NativeProps.PARTY_LIVES, jObj.getBoolean("lifeShare"));
        pInfo.setProperty(NativeProps.PARTY_LOOT, jObj.getBoolean("lootShare"));
        pInfo.setProperty(NativeProps.LIVES, jObj.getInteger("lives"));
    }
    members.clear();
    NBTTagList memList = jObj.getTagList("members", 10);
    for (int i = 0; i < memList.tagCount(); i++) {
        NBTBase entry = memList.get(i);
        if (entry == null || entry.getId() != 10) {
            continue;
        }
        NBTTagCompound jMem = (NBTTagCompound) entry;
        UUID uuid = null;
        EnumPartyStatus priv = EnumPartyStatus.INVITE;
        try {
            uuid = UUID.fromString(jMem.getString("uuid"));
        } catch (Exception e) {
            uuid = null;
        }
        try {
            priv = EnumPartyStatus.valueOf(jMem.hasKey("status", 8) ? jMem.getString("status") : EnumPartyStatus.INVITE.toString());
            priv = priv != null ? priv : EnumPartyStatus.INVITE;
        } catch (Exception e) {
            priv = EnumPartyStatus.INVITE;
        }
        if (uuid != null) {
            members.put(uuid, priv);
        }
    }
    this.setupProps();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) NBTBase(net.minecraft.nbt.NBTBase) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID)

Example 3 with EnumPartyStatus

use of betterquesting.api.enums.EnumPartyStatus in project BetterQuesting by Funwayguy.

the class PartyInstance method kickUser.

@Override
public void kickUser(UUID uuid) {
    if (!members.containsKey(uuid)) {
        return;
    }
    EnumPartyStatus old = members.get(uuid);
    members.remove(uuid);
    if (members.size() <= 0) {
        PartyManager.INSTANCE.removeValue(this);
        PacketSender.INSTANCE.sendToAll(PartyManager.INSTANCE.getSyncPacket());
    } else if (old == EnumPartyStatus.OWNER) {
        hostMigrate();
    }
    PacketSender.INSTANCE.sendToAll(getSyncPacket());
}
Also used : EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus)

Example 4 with EnumPartyStatus

use of betterquesting.api.enums.EnumPartyStatus in project BetterQuesting by Funwayguy.

the class PartyInstance method writeToNBT.

@Override
public NBTTagCompound writeToNBT(NBTTagCompound json, EnumSaveType saveType) {
    if (saveType != EnumSaveType.CONFIG) {
        return json;
    }
    NBTTagList memJson = new NBTTagList();
    for (Entry<UUID, EnumPartyStatus> mem : members.entrySet()) {
        NBTTagCompound jm = new NBTTagCompound();
        jm.setString("uuid", mem.getKey().toString());
        jm.setString("status", mem.getValue().toString());
        memJson.appendTag(jm);
    }
    json.setTag("members", memJson);
    json.setTag("properties", pInfo.writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG));
    return json;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) UUID(java.util.UUID)

Example 5 with EnumPartyStatus

use of betterquesting.api.enums.EnumPartyStatus in project BetterQuesting by Funwayguy.

the class PartyInstance method setStatus.

@Override
public void setStatus(UUID uuid, EnumPartyStatus priv) {
    if (!members.containsKey(uuid)) {
        return;
    }
    EnumPartyStatus old = members.get(uuid);
    if (old == priv) {
        return;
    }
    members.put(uuid, priv);
    if (priv == EnumPartyStatus.OWNER) {
        for (UUID mem : getMembers()) {
            if (mem != uuid && members.get(mem) == EnumPartyStatus.OWNER) {
                // Removes previous owner
                members.put(mem, EnumPartyStatus.ADMIN);
                break;
            }
        }
    } else if (old == EnumPartyStatus.OWNER) {
        UUID migrate = null;
        // Find new owner
        for (UUID mem : getMembers()) {
            if (mem == uuid) {
                continue;
            } else if (members.get(mem) == EnumPartyStatus.ADMIN) {
                migrate = mem;
                break;
            } else if (migrate == null) {
                migrate = mem;
            }
        }
        // No other valid owners found
        if (migrate == null) {
            members.put(uuid, old);
            return;
        } else {
            members.put(migrate, EnumPartyStatus.OWNER);
        }
    }
    PacketSender.INSTANCE.sendToAll(getSyncPacket());
}
Also used : EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) UUID(java.util.UUID)

Aggregations

EnumPartyStatus (betterquesting.api.enums.EnumPartyStatus)6 UUID (java.util.UUID)5 IParty (betterquesting.api.questing.party.IParty)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 EnumPacketAction (betterquesting.api.enums.EnumPacketAction)1 IReward (betterquesting.api.questing.rewards.IReward)1 UserEntry (betterquesting.misc.UserEntry)1 PartyInstance (betterquesting.questing.party.PartyInstance)1 NBTBase (net.minecraft.nbt.NBTBase)1