Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit mode move to player nbt #67

Draft
wants to merge 3 commits into
base: 1.12
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public List<String> getTooltip(int mx, int my) {
private List<String> getQuestTooltip(IQuest quest, EntityPlayer player, int qID) {
List<String> tooltip = getStandardTooltip(quest, player, qID);

if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips && QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips && QuestSettings.INSTANCE.getEditMode(player)) {
tooltip.add("");
tooltip.addAll(this.getAdvancedTooltip(quest, player, qID));
}
Expand Down Expand Up @@ -130,7 +130,7 @@ private List<String> getStandardTooltip(IQuest quest, EntityPlayer player, int q
timeTxt += df.format(time % 60) + "s";

list.add(TextFormatting.GRAY + QuestTranslation.translate("betterquesting.tooltip.repeat", timeTxt));
if (QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
if (QuestSettings.INSTANCE.getEditMode(player)) {
list.add(TextFormatting.RED + QuestTranslation.translate("betterquesting.tooltip.repeat_with_edit_mode"));
}
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/betterquesting/blocks/TileSubmitStation.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import betterquesting.core.BetterQuesting;
import betterquesting.questing.QuestDatabase;
import betterquesting.storage.QuestSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.ISidedInventory;
Expand Down Expand Up @@ -228,15 +229,21 @@ public IFluidTankProperties[] getTankProperties() {

@Override
public void update() {
if (world.isRemote || !isSetup() || QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) return;

MinecraftServer server = world.getMinecraftServer();
EntityPlayerMP player = null;

if(owner != null) {
player = server == null ? null : server.getPlayerList().getPlayerByUUID(owner);
}

if (world.isRemote || !isSetup() || (player != null && QuestSettings.INSTANCE.getEditMode(player))) return;

long wtt = world.getTotalWorldTime();
if (wtt % 5 == 0 && owner != null) {
if (wtt % 20 == 0) qCached = null; // Reset and lookup quest again once every second
DBEntry<IQuest> q = getQuest();
IItemTask t = getItemTask();
MinecraftServer server = world.getMinecraftServer();
EntityPlayerMP player = server == null ? null : server.getPlayerList().getPlayerByUUID(owner);
QuestCache qc = player == null ? null : player.getCapability(CapabilityProviderQuestCache.CAP_QUEST_CACHE, null);

// Check quest & task is present. Check input is populated and output is clear.
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/betterquesting/client/gui2/GuiHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ private void onButtonPress(PanelEvent event) {

if (qFile.exists()) {
FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> {
boolean editMode = QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
boolean hardMode = QuestSettings.INSTANCE.getProperty(NativeProps.HARDCORE);

NBTTagList jsonP = QuestDatabase.INSTANCE.writeProgressToNBT(new NBTTagList(), null);
Expand All @@ -193,7 +192,6 @@ private void onButtonPress(PanelEvent event) {
QuestLineDatabase.INSTANCE.readFromNBT(j1.getTagList("questLines", 10), false);
QuestDatabase.INSTANCE.readProgressFromNBT(jsonP, false);

QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, editMode);
QuestSettings.INSTANCE.setProperty(NativeProps.HARDCORE, hardMode);

NetSettingSync.sendSync(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,9 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend
}

if (args[1].equalsIgnoreCase("save")) {
boolean editMode = QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);

NBTTagCompound base = new NBTTagCompound();

QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, false);
base.setTag("questSettings", QuestSettings.INSTANCE.writeToNBT(new NBTTagCompound()));
QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, editMode);
base.setTag("questDatabase", QuestDatabase.INSTANCE.writeToNBT(new NBTTagList(), null));
base.setTag("questLines", QuestLineDatabase.INSTANCE.writeToNBT(new NBTTagList(), null));
base.setString("format", BetterQuesting.FORMAT);
Expand All @@ -86,7 +82,6 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend
}
} else if (args[1].equalsIgnoreCase("load")) {
if (qFile.exists()) {
boolean editMode = QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
boolean hardMode = QuestSettings.INSTANCE.getProperty(NativeProps.HARDCORE);

NBTTagList jsonP = QuestDatabase.INSTANCE.writeProgressToNBT(new NBTTagList(), null);
Expand All @@ -106,7 +101,6 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend

QuestDatabase.INSTANCE.readProgressFromNBT(jsonP, false);

QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, editMode);
QuestSettings.INSTANCE.setProperty(NativeProps.HARDCORE, hardMode);

if (args.length == 3 && !args[2].equalsIgnoreCase("DefaultQuests")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import betterquesting.handlers.SaveLoadHandler;
import betterquesting.network.handlers.NetSettingSync;
import betterquesting.storage.QuestSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.server.permission.DefaultPermissionLevel;
Expand Down Expand Up @@ -38,7 +42,7 @@ public List<String> autoComplete(MinecraftServer server, ICommandSender sender,

@Override
public void runCommand(MinecraftServer server, CommandBase command, ICommandSender sender, String[] args) throws CommandException {
boolean flag = !QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
boolean flag = !QuestSettings.INSTANCE.getEditMode((EntityPlayer) sender);

if (args.length == 2) {
try {
Expand All @@ -54,9 +58,9 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend
}
}

QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, flag);
QuestSettings.INSTANCE.setEditMode((EntityPlayer) sender, flag);

sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.edit", new TextComponentTranslation(QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE) ? "options.on" : "options.off")));
sender.sendMessage(new TextComponentTranslation("betterquesting.cmd.edit", new TextComponentTranslation(QuestSettings.INSTANCE.getEditMode((EntityPlayer) sender) ? "options.on" : "options.off")));

SaveLoadHandler.INSTANCE.markDirty();
NetSettingSync.sendSync(null);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/betterquesting/handlers/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void onLivingUpdate(LivingUpdateEvent event) {

EntityPlayerMP player = (EntityPlayerMP) event.getEntityLiving();
betterquesting.api2.cache.QuestCache qc = player.getCapability(CapabilityProviderQuestCache.CAP_QUEST_CACHE, null);
boolean editMode = QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE);
boolean editMode = QuestSettings.INSTANCE.getEditMode(player);

if (qc == null) return;

Expand Down Expand Up @@ -600,7 +600,7 @@ public void onBlockBreak(BlockEvent.BreakEvent event) {

@SubscribeEvent
public void onEntityLiving(LivingUpdateEvent event) {
if (!(event.getEntityLiving() instanceof EntityPlayer) || event.getEntityLiving().world.isRemote || event.getEntityLiving().ticksExisted % 20 != 0 || QuestingAPI.getAPI(ApiReference.SETTINGS).getProperty(NativeProps.EDIT_MODE))
if (!(event.getEntityLiving() instanceof EntityPlayer) || event.getEntityLiving().world.isRemote || event.getEntityLiving().ticksExisted % 20 != 0 || QuestSettings.INSTANCE.getEditMode((EntityPlayer) event.getEntityLiving()))
return;

EntityPlayer player = (EntityPlayer) event.getEntityLiving();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/betterquesting/handlers/SaveLoadHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import betterquesting.storage.QuestSettings;
import com.google.gson.JsonObject;
import io.netty.util.internal.ConcurrentSet;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void loadDatabases(MinecraftServer server) {
public void saveDatabases() {
List<Future<Void>> allFutures = new ArrayList<>();

if (isDirty || QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
if (isDirty || QuestSettings.INSTANCE.getEditMode(Minecraft.getMinecraft().player)) {
allFutures.add(saveConfig());
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/betterquesting/items/ItemLootChest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import betterquesting.network.handlers.NetLootClaim;
import betterquesting.questing.rewards.loot.LootGroup;
import betterquesting.questing.rewards.loot.LootRegistry;
import betterquesting.storage.QuestSettings;
import net.minecraft.client.Minecraft;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
Expand Down Expand Up @@ -228,7 +230,7 @@ public void addInformation(ItemStack stack, @Nullable World worldIn, List<String

NBTTagCompound tag = stack.getTagCompound();
boolean hideTooltip = tag == null || !tag.getBoolean("hideLootInfo");
if (hideTooltip && !QuestingAPI.getAPI(ApiReference.SETTINGS).getProperty(NativeProps.EDIT_MODE)) return;
if (hideTooltip && !QuestSettings.INSTANCE.getEditMode(Minecraft.getMinecraft().player)) return;

if (stack.getItemDamage() == 104) {
if (tag == null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public void readFromJson(JsonElement rawJson) {

if (json.has("editMode")) // This IS the file you are looking for
{
QuestSettings.INSTANCE.setProperty(NativeProps.EDIT_MODE, JsonHelper.GetBoolean(json, "editMode", true));
QuestSettings.INSTANCE.setProperty(NativeProps.HARDCORE, JsonHelper.GetBoolean(json, "hardcore", false));

QuestSettings.INSTANCE.setProperty(NativeProps.LIVES_DEF, JsonHelper.GetNumber(json, "defLives", 3).intValue());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/betterquesting/questing/QuestInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void detect(EntityPlayer player) {
return;
}

if (isUnlocked(playerID) || QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE)) {
if (isUnlocked(playerID) || QuestSettings.INSTANCE.getEditMode(player)) {
int done = 0;
boolean update = false;

Expand All @@ -137,7 +137,7 @@ public void detect(EntityPlayer player) {
// Note: Tasks can mark the quest dirty themselves if progress changed but hasn't fully completed.
if (tasks.size() <= 0 || qInfo.getProperty(NativeProps.LOGIC_TASK).getResult(done, tasks.size())) {
// State won't be auto updated in edit mode so we force change it here and mark it for re-sync
if (QuestSettings.INSTANCE.getProperty(NativeProps.EDIT_MODE))
if (QuestSettings.INSTANCE.getEditMode(player))
setComplete(playerID, System.currentTimeMillis());
qc.markQuestDirty(questID);
} else if (update && qInfo.getProperty(NativeProps.SIMULTANEOUS)) {
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/betterquesting/storage/QuestSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,42 @@
import betterquesting.api.properties.IPropertyType;
import betterquesting.api.properties.NativeProps;
import betterquesting.api.storage.IQuestSettings;
import betterquesting.core.BetterQuesting;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;

public class QuestSettings extends PropertyContainer implements IQuestSettings {
private static final String EDIT_MODE = BetterQuesting.MODID + ".edit_mode";
public static final QuestSettings INSTANCE = new QuestSettings();

public QuestSettings() {
this.setupProps();
}

public void setEditMode(EntityPlayer player, boolean edit){
if (player == null) return;
NBTTagCompound playerData = player.getEntityData();
NBTTagCompound data = playerData.hasKey(EntityPlayer.PERSISTED_NBT_TAG) ? playerData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG) : new NBTTagCompound();
data.setBoolean(EDIT_MODE, edit);
playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data);
}

public boolean getEditMode(EntityPlayer player){
if (player == null) return false;
NBTTagCompound playerData = player.getEntityData();
NBTTagCompound data = playerData.hasKey(EntityPlayer.PERSISTED_NBT_TAG) ? playerData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG) : null;

if (data == null)
return false;

return data.getBoolean(EDIT_MODE);
}

@Override
public boolean canUserEdit(EntityPlayer player) {
if (player == null) return false;
return this.getProperty(NativeProps.EDIT_MODE) && NameCache.INSTANCE.isOP(QuestingAPI.getQuestingUUID(player));
return getEditMode(player) && NameCache.INSTANCE.isOP(QuestingAPI.getQuestingUUID(player));
}

@Override
Expand All @@ -37,7 +59,6 @@ private void setupProps() {
this.setupValue(NativeProps.PACK_VER);

this.setupValue(NativeProps.PARTY_ENABLE);
this.setupValue(NativeProps.EDIT_MODE);
this.setupValue(NativeProps.HARDCORE);
this.setupValue(NativeProps.LIVES_DEF);
this.setupValue(NativeProps.LIVES_MAX);
Expand Down