Allow for empty objective lores

This commit is contained in:
Indyuce 2021-08-25 21:13:17 +02:00
parent ebf0d40fbf
commit 63c837be2c
2 changed files with 184 additions and 182 deletions

View File

@ -3,9 +3,9 @@ package net.Indyuce.mmocore.api.quest;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.lumine.mythic.lib.MythicLib;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData;
import io.lumine.mythic.lib.MythicLib;
import org.bukkit.NamespacedKey;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
@ -32,7 +32,7 @@ public class PlayerQuests {
bossbar = MythicLib.plugin.getVersion().getWrapper().createBossBar(
new NamespacedKey(MMOCore.plugin, "quest_bar_" + playerData.getUniqueId().toString()),
"", BarColor.PURPLE, BarStyle.SEGMENTED_20);
if(playerData.isOnline())
if (playerData.isOnline())
bossbar.addPlayer(playerData.getPlayer());
}
@ -77,7 +77,7 @@ public class PlayerQuests {
public String toJsonString() {
JsonObject json = new JsonObject();
if(current != null) {
if (current != null) {
JsonObject cur = new JsonObject();
cur.addProperty("id", current.getQuest().getId());
cur.addProperty("objective", current.getObjectiveNumber());
@ -88,7 +88,7 @@ public class PlayerQuests {
for (String key : finished.keySet())
fin.addProperty(key, finished.get(key));
if(finished.size() != 0)
if (finished.size() != 0)
json.add("finished", fin);
return json.toString();
}
@ -96,7 +96,7 @@ public class PlayerQuests {
public void load(String json) {
Gson parser = new Gson();
JsonObject jo = parser.fromJson(json, JsonObject.class);
if(jo.has("current")) {
if (jo.has("current")) {
JsonObject cur = jo.getAsJsonObject("current");
try {
current = MMOCore.plugin.questManager.get(cur.get("id").getAsString()).generateNewProgress(playerData, cur.get("objective").getAsInt());
@ -104,12 +104,12 @@ public class PlayerQuests {
playerData.log(Level.WARNING, "Couldn't load current quest progress (ID '" + cur.get("id").getAsString() + "')");
}
}
if(jo.has("finished")) {
if (jo.has("finished")) {
for (Entry<String, JsonElement> entry : jo.getAsJsonObject("finished").entrySet())
finished.put(entry.getKey(), entry.getValue().getAsLong());
}
for(Entry<String, Long> entry : finished.entrySet())
for (Entry<String, Long> entry : finished.entrySet())
MMOCore.log("Finished: (" + entry.getKey() + ") - at: " + entry.getValue());
}
@ -173,7 +173,7 @@ public class PlayerQuests {
}
public void updateBossBar() {
if (!hasCurrent()) {
if (!hasCurrent() || !current.getProgress().getObjective().hasLore()) {
bossbar.setVisible(false);
return;
}

View File

@ -1,18 +1,17 @@
package net.Indyuce.mmocore.api.quest.objective;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.boss.BarColor;
import org.bukkit.configuration.ConfigurationSection;
import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
import net.Indyuce.mmocore.api.quest.QuestProgress;
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
import io.lumine.mythic.lib.api.MMOLineConfig;
import org.apache.commons.lang.Validate;
import org.bukkit.boss.BarColor;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
public abstract class Objective {
private final String id, lore;
@ -24,7 +23,6 @@ public abstract class Objective {
this.id = config.getName();
this.lore = config.getString("lore");
Validate.notNull(lore, "Could not find objective lore");
Validate.notNull(config.getStringList("triggers"), "Could not load trigger list");
String format = config.getString("bar-color", "PURPLE");
@ -47,6 +45,10 @@ public abstract class Objective {
return barColor;
}
public boolean hasLore() {
return lore != null && !lore.isEmpty();
}
public String getDefaultLore() {
return lore;
}