use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.
the class QuestCommandDelete method runCommand.
@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
if (args[1].equalsIgnoreCase("all")) {
QuestDatabase.INSTANCE.reset();
QuestLineDatabase.INSTANCE.reset();
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
PacketSender.INSTANCE.sendToAll(QuestLineDatabase.INSTANCE.getSyncPacket());
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.all"));
} else {
try {
int id = Integer.parseInt(args[1].trim());
IQuest quest = QuestDatabase.INSTANCE.getValue(id);
QuestDatabase.INSTANCE.removeKey(id);
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.delete.single", new TextComponentTranslation(quest.getUnlocalisedName())));
} catch (Exception e) {
throw getException(command);
}
}
}
use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.
the class QuestCommandReset method runCommand.
@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
String action = args[1];
UUID uuid = null;
if (args.length == 3) {
uuid = this.findPlayerID(server, sender, args[2]);
if (uuid == null) {
throw this.getException(command);
}
}
String pName = uuid == null ? "NULL" : NameCache.INSTANCE.getName(uuid);
if (action.equalsIgnoreCase("all")) {
for (IQuest quest : QuestDatabase.INSTANCE.getAllValues()) {
if (uuid != null) {
// Clear progress and state
quest.resetUser(uuid, true);
} else {
quest.resetAll(true);
}
}
if (uuid != null) {
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_all", pName));
} else {
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_all"));
}
} else {
try {
int id = Integer.parseInt(action.trim());
IQuest quest = QuestDatabase.INSTANCE.getValue(id);
if (uuid != null) {
// Clear progress and state
quest.resetUser(uuid, true);
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_single", new TextComponentTranslation(quest.getUnlocalisedName()), pName));
} else {
quest.resetAll(true);
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_single", new TextComponentTranslation(quest.getUnlocalisedName())));
}
} catch (Exception e) {
throw getException(command);
}
}
PacketSender.INSTANCE.sendToAll(QuestDatabase.INSTANCE.getSyncPacket());
}
use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.
the class ToolboxToolCopy method onMouseClick.
@Override
public void onMouseClick(int mx, int my, int click) {
if (click == 1 && btnQuest != null) {
btnQuest = null;
} else if (click != 0) {
return;
}
int snap = ToolboxGuiMain.getSnapValue();
int modX = ((mx % snap) + snap) % snap;
int modY = ((my % snap) + snap) % snap;
mx -= modX;
my -= modY;
if (btnQuest == null) {
GuiButtonQuestInstance tmpBtn = gui.getQuestLine().getButtonAt(mx, my);
if (tmpBtn != null) {
// Unregistered but setup
QuestInstance tmpQ = new QuestInstance();
tmpQ.readFromNBT(tmpBtn.getQuest().writeToNBT(new NBTTagCompound(), EnumSaveType.CONFIG), EnumSaveType.CONFIG);
btnQuest = new GuiButtonQuestInstance(0, mx, my, tmpBtn.width, tmpBtn.height, tmpQ);
}
} else {
// Pre-sync
IQuest quest = btnQuest.getQuest();
IQuestLine qLine = gui.getQuestLine().getQuestLine();
int qID = QuestDatabase.INSTANCE.nextKey();
int lID = QuestLineDatabase.INSTANCE.getKey(qLine);
QuestLineEntry qe = new QuestLineEntry(mx, my, Math.max(btnQuest.width, btnQuest.height));
qLine.add(qe, qID);
btnQuest = null;
// 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.api.questing.IQuest in project BetterQuesting by Funwayguy.
the class QuestLineButtonTree method RebuildTree.
public void RebuildTree() {
buttonTree.clear();
treeW = 0;
treeH = 0;
if (line == null) {
return;
}
for (int id : line.getAllKeys()) {
IQuest quest = QuestingAPI.getAPI(ApiReference.QUEST_DB).getValue(id);
IQuestLineEntry entry = line.getValue(id);
if (quest != null && entry != null) {
buttonTree.add(new GuiButtonQuestInstance(0, entry.getPosX(), entry.getPosY(), entry.getSize(), entry.getSize(), quest));
}
}
// Offset origin to 0,0 and establish bounds
for (GuiButtonQuestInstance btn : buttonTree) {
if (btn == null) {
continue;
}
treeW = Math.max(btn.x + btn.width, treeW);
treeH = Math.max(btn.y + btn.height, treeH);
for (GuiButtonQuestInstance b2 : buttonTree) {
if (b2 == null || btn == b2 || btn.getQuest() == null) {
continue;
}
if (btn.getQuest().getPrerequisites().contains(b2.getQuest())) {
btn.addParent(b2);
}
}
}
}
use of betterquesting.api.questing.IQuest in project BetterQuesting by Funwayguy.
the class QuestLineButtonTree method getButtonAt.
public GuiButtonQuestInstance getButtonAt(int x, int y) {
if (line == null) {
return null;
}
int id = line.getQuestAt(x, y);
IQuest quest = QuestingAPI.getAPI(ApiReference.QUEST_DB).getValue(id);
if (quest == null) {
return null;
}
for (GuiButtonQuestInstance btn : buttonTree) {
if (btn.getQuest() == quest) {
return btn;
}
}
return null;
}
Aggregations