use of betterquesting.questing.QuestInstance in project BetterQuesting by Funwayguy.
the class ImportedQuests method createNew.
@Override
public IQuest createNew() {
IQuest q = new QuestInstance();
q.setParentDatabase(this);
return q;
}
use of betterquesting.questing.QuestInstance in project BetterQuesting by Funwayguy.
the class ToolboxToolNew method onMouseClick.
@Override
public void onMouseClick(int mx, int my, int click) {
if (click != 0) {
return;
}
int snap = ToolboxGuiMain.getSnapValue();
int modX = ((mx % snap) + snap) % snap;
int modY = ((my % snap) + snap) % snap;
mx -= modX;
my -= modY;
// Pre-sync
IQuestLine qLine = gui.getQuestLine().getQuestLine();
IQuest quest = new QuestInstance();
int qID = QuestDatabase.INSTANCE.nextKey();
int lID = QuestLineDatabase.INSTANCE.getKey(qLine);
QuestLineEntry qe = new QuestLineEntry(mx, my, 24);
qLine.add(qe, qID);
// Sync Quest
NBTTagCompound tag1 = new NBTTagCompound();
NBTTagCompound base1 = new NBTTagCompound();
base1.setTag("config", quest.writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG));
tag1.setTag("data", base1);
tag1.setInteger("action", EnumPacketAction.ADD.ordinal());
tag1.setInteger("questID", qID);
PacketSender.INSTANCE.sendToServer(new QuestingPacket(PacketTypeNative.QUEST_EDIT.GetLocation(), tag1));
// Sync Line
NBTTagCompound tag2 = new NBTTagCompound();
NBTTagCompound base2 = new NBTTagCompound();
base2.setTag("line", qLine.writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG));
tag2.setTag("data", base2);
tag2.setInteger("action", EnumPacketAction.EDIT.ordinal());
tag2.setInteger("lineID", lID);
PacketSender.INSTANCE.sendToServer(new QuestingPacket(PacketTypeNative.LINE_EDIT.GetLocation(), tag2));
}
use of betterquesting.questing.QuestInstance 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.questing.QuestInstance in project BetterQuesting by Funwayguy.
the class PktHandlerQuestSync method handleClient.
@Override
public void handleClient(NBTTagCompound data) {
int questID = !data.hasKey("questID") ? -1 : data.getInteger("questID");
IQuest quest = QuestDatabase.INSTANCE.getValue(questID);
if (quest == null) {
quest = new QuestInstance();
QuestDatabase.INSTANCE.add(quest, questID);
}
quest.readPacket(data);
MinecraftForge.EVENT_BUS.post(new DatabaseEvent.Update());
}
Aggregations