Search in sources :

Example 6 with EnumPartyStatus

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

the class PktHandlerPartyAction method handleServer.

@Override
public // Party management
void handleServer(// Party management
NBTTagCompound data, // Party management
EntityPlayerMP sender) {
    if (sender == null) {
        return;
    }
    /*
		 * If the user is OP than they will have owner permissions of any party
		 * Non OPs can only edit the party they own.
		 */
    boolean isOp = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
    int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
    if (aID < 0 || aID >= EnumPacketAction.values().length) {
        return;
    }
    EnumPacketAction action = EnumPacketAction.values()[aID];
    int partyID = !data.hasKey("partyID") ? -1 : data.getInteger("partyID");
    UUID tarUser = null;
    IParty tarParty = null;
    EnumPartyStatus status = null;
    UUID senderID = QuestingAPI.getQuestingUUID(sender);
    if (isOp) {
        tarParty = PartyManager.INSTANCE.getValue(partyID);
        status = EnumPartyStatus.OWNER;
    } else {
        if (action == EnumPacketAction.JOIN) {
            tarParty = PartyManager.INSTANCE.getValue(partyID);
        } else {
            tarParty = PartyManager.INSTANCE.getUserParty(senderID);
        }
        if (tarParty != null) {
            status = tarParty.getStatus(senderID);
        }
    }
    try {
        tarUser = UUID.fromString(data.getString("target"));
    } catch (Exception e) {
        // In case an unrecognized name was used instead of their UUID
        tarUser = NameCache.INSTANCE.getUUID(data.getString("target"));
    }
    if (// Create new party if not currently in a party
    action == EnumPacketAction.ADD && tarParty == null) {
        String name = data.getString("name");
        name = name.length() > 0 ? name : "New Party";
        IParty nParty = new PartyInstance();
        nParty.getProperties().setProperty(NativeProps.NAME, name);
        nParty.inviteUser(senderID);
        PartyManager.INSTANCE.add(nParty, PartyManager.INSTANCE.nextKey());
        PacketSender.INSTANCE.sendToAll(PartyManager.INSTANCE.getSyncPacket());
        return;
    } else if (// Operator force deletes party or owner disbands it
    action == EnumPacketAction.REMOVE && tarParty != null && status == EnumPartyStatus.OWNER) {
        PartyManager.INSTANCE.removeKey(partyID);
        PacketSender.INSTANCE.sendToAll(PartyManager.INSTANCE.getSyncPacket());
        return;
    } else if (// Kick/leave party
    action == EnumPacketAction.KICK && tarUser != null && tarParty != null && status != null && (status.ordinal() >= 2 || tarUser == senderID)) {
        tarParty.kickUser(tarUser);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    } else if (// Edit party
    action == EnumPacketAction.EDIT && tarParty != null && status == EnumPartyStatus.OWNER) {
        tarParty.readPacket(data);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    } else if (// Join party
    action == EnumPacketAction.JOIN && tarParty != null && (isOp || status == EnumPartyStatus.INVITE)) {
        if (isOp) {
            tarParty.inviteUser(senderID);
        }
        tarParty.setStatus(senderID, EnumPartyStatus.MEMBER);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    } else if (// Invite to party
    action == EnumPacketAction.INVITE && tarParty != null && tarUser != null && status.ordinal() >= 2) {
        tarParty.inviteUser(tarUser);
        PacketSender.INSTANCE.sendToAll(tarParty.getSyncPacket());
        return;
    }
    return;
}
Also used : EnumPartyStatus(betterquesting.api.enums.EnumPartyStatus) PartyInstance(betterquesting.questing.party.PartyInstance) EnumPacketAction(betterquesting.api.enums.EnumPacketAction) IParty(betterquesting.api.questing.party.IParty) 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