use of betterquesting.questing.party.PartyInstance 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;
}
use of betterquesting.questing.party.PartyInstance in project BetterQuesting by Funwayguy.
the class PktHandlerPartySync method handleClient.
@Override
public void handleClient(NBTTagCompound tag) {
int partyID = !tag.hasKey("partyID") ? -1 : tag.getInteger("partyID");
if (partyID < 0) {
return;
}
IParty party = PartyManager.INSTANCE.getValue(partyID);
if (party == null) {
party = new PartyInstance();
PartyManager.INSTANCE.add(party, partyID);
}
party.readPacket(tag);
MinecraftForge.EVENT_BUS.post(new DatabaseEvent.Update());
}
Aggregations