use of betterquesting.api.enums.EnumPacketAction in project BetterQuesting by Funwayguy.
the class PktHandlerLineEdit method handleServer.
@Override
public void handleServer(NBTTagCompound data, EntityPlayerMP sender) {
if (sender == null) {
return;
}
boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
if (!isOP) {
BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to edit quest lines without OP permissions!");
sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
// Player is not operator. Do nothing
return;
}
int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
int lID = !data.hasKey("lineID") ? -1 : data.getInteger("lineID");
int idx = !data.hasKey("order") ? -1 : data.getInteger("order");
IQuestLine questLine = QuestLineDatabase.INSTANCE.getValue(lID);
if (aID < 0 || aID >= EnumPacketAction.values().length) {
return;
}
EnumPacketAction action = EnumPacketAction.values()[aID];
if (action == EnumPacketAction.ADD) {
IQuestLine nq = new QuestLine();
int nID = QuestLineDatabase.INSTANCE.nextKey();
if (data.hasKey("data") && lID >= 0) {
nID = lID;
NBTTagCompound base = data.getCompoundTag("data");
nq.readFromNBT(base.getCompoundTag("line"), EnumSaveType.CONFIG);
}
QuestLineDatabase.INSTANCE.add(nq, nID);
PacketSender.INSTANCE.sendToAll(nq.getSyncPacket());
return;
} else if (// Edit quest lines
action == EnumPacketAction.EDIT && questLine != null) {
questLine.readPacket(data);
if (idx >= 0 && QuestLineDatabase.INSTANCE.getOrderIndex(lID) != idx) {
QuestLineDatabase.INSTANCE.setOrderIndex(lID, idx);
PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
} else {
PacketSender.INSTANCE.sendToAll(questLine.getSyncPacket());
}
return;
} else if (action == EnumPacketAction.REMOVE && questLine != null) {
QuestLineDatabase.INSTANCE.removeKey(lID);
PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
return;
}
}
use of betterquesting.api.enums.EnumPacketAction in project BetterQuesting by Funwayguy.
the class PktHandlerQuestEdit method handleServer.
@Override
public void handleServer(NBTTagCompound data, EntityPlayerMP sender) {
if (sender == null) {
return;
}
boolean isOP = sender.world.getMinecraftServer().getPlayerList().canSendCommands(sender.getGameProfile());
if (!isOP) {
BetterQuesting.logger.log(Level.WARN, "Player " + sender.getName() + " (UUID:" + QuestingAPI.getQuestingUUID(sender) + ") tried to edit quest without OP permissions!");
sender.sendStatusMessage(new TextComponentString(TextFormatting.RED + "You need to be OP to edit quests!"), false);
// Player is not operator. Do nothing
return;
}
int aID = !data.hasKey("action") ? -1 : data.getInteger("action");
int qID = !data.hasKey("questID") ? -1 : data.getInteger("questID");
IQuest quest = QuestDatabase.INSTANCE.getValue(qID);
EnumPacketAction action = null;
if (aID < 0 || aID >= EnumPacketAction.values().length) {
return;
}
action = EnumPacketAction.values()[aID];
if (action == EnumPacketAction.EDIT && quest != null) {
quest.readPacket(data);
PacketSender.INSTANCE.sendToAll(quest.getSyncPacket());
return;
} else if (action == EnumPacketAction.REMOVE) {
if (quest == null || qID < 0) {
BetterQuesting.logger.log(Level.ERROR, sender.getName() + " tried to delete non-existent quest with ID:" + qID);
return;
}
BetterQuesting.logger.log(Level.INFO, "Player " + sender.getName() + " deleted quest " + quest.getUnlocalisedName());
QuestDatabase.INSTANCE.removeKey(qID);
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
return;
} else if (// Force Complete/Reset
action == EnumPacketAction.SET && quest != null) {
if (data.getBoolean("state")) {
UUID senderID = QuestingAPI.getQuestingUUID(sender);
boolean com = quest.isComplete(senderID);
if (com && quest instanceof QuestInstance) {
((QuestInstance) quest).setClaimed(senderID, 0);
} else {
quest.setComplete(senderID, 0);
int done = 0;
if (// Preliminary check
!quest.getProperties().getProperty(NativeProps.LOGIC_TASK).getResult(done, quest.getTasks().size())) {
for (ITask task : quest.getTasks().getAllValues()) {
task.setComplete(senderID);
done += 1;
if (quest.getProperties().getProperty(NativeProps.LOGIC_TASK).getResult(done, quest.getTasks().size())) {
// Only complete enough quests to claim the reward
break;
}
}
}
}
} else {
quest.resetAll(true);
}
PacketSender.INSTANCE.sendToAll(quest.getSyncPacket());
return;
} else if (action == EnumPacketAction.ADD) {
IQuest nq = new QuestInstance();
int nID = QuestDatabase.INSTANCE.nextKey();
if (data.hasKey("data") && data.hasKey("questID")) {
nID = data.getInteger("questID");
NBTTagCompound base = data.getCompoundTag("data");
nq.readFromNBT(base.getCompoundTag("config"), EnumSaveType.CONFIG);
}
QuestDatabase.INSTANCE.add(nq, nID);
PacketSender.INSTANCE.sendToAll(nq.getSyncPacket());
return;
}
}
use of betterquesting.api.enums.EnumPacketAction 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;
}
Aggregations