forked from Upstream/mmocore
Allow for empty objective lores
This commit is contained in:
parent
ebf0d40fbf
commit
63c837be2c
@ -3,9 +3,9 @@ package net.Indyuce.mmocore.api.quest;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
import io.lumine.mythic.lib.MythicLib;
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.boss.BarColor;
|
import org.bukkit.boss.BarColor;
|
||||||
import org.bukkit.boss.BarStyle;
|
import org.bukkit.boss.BarStyle;
|
||||||
@ -32,7 +32,7 @@ public class PlayerQuests {
|
|||||||
bossbar = MythicLib.plugin.getVersion().getWrapper().createBossBar(
|
bossbar = MythicLib.plugin.getVersion().getWrapper().createBossBar(
|
||||||
new NamespacedKey(MMOCore.plugin, "quest_bar_" + playerData.getUniqueId().toString()),
|
new NamespacedKey(MMOCore.plugin, "quest_bar_" + playerData.getUniqueId().toString()),
|
||||||
"", BarColor.PURPLE, BarStyle.SEGMENTED_20);
|
"", BarColor.PURPLE, BarStyle.SEGMENTED_20);
|
||||||
if(playerData.isOnline())
|
if (playerData.isOnline())
|
||||||
bossbar.addPlayer(playerData.getPlayer());
|
bossbar.addPlayer(playerData.getPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ public class PlayerQuests {
|
|||||||
|
|
||||||
public String toJsonString() {
|
public String toJsonString() {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
if(current != null) {
|
if (current != null) {
|
||||||
JsonObject cur = new JsonObject();
|
JsonObject cur = new JsonObject();
|
||||||
cur.addProperty("id", current.getQuest().getId());
|
cur.addProperty("id", current.getQuest().getId());
|
||||||
cur.addProperty("objective", current.getObjectiveNumber());
|
cur.addProperty("objective", current.getObjectiveNumber());
|
||||||
@ -88,7 +88,7 @@ public class PlayerQuests {
|
|||||||
for (String key : finished.keySet())
|
for (String key : finished.keySet())
|
||||||
fin.addProperty(key, finished.get(key));
|
fin.addProperty(key, finished.get(key));
|
||||||
|
|
||||||
if(finished.size() != 0)
|
if (finished.size() != 0)
|
||||||
json.add("finished", fin);
|
json.add("finished", fin);
|
||||||
return json.toString();
|
return json.toString();
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ public class PlayerQuests {
|
|||||||
public void load(String json) {
|
public void load(String json) {
|
||||||
Gson parser = new Gson();
|
Gson parser = new Gson();
|
||||||
JsonObject jo = parser.fromJson(json, JsonObject.class);
|
JsonObject jo = parser.fromJson(json, JsonObject.class);
|
||||||
if(jo.has("current")) {
|
if (jo.has("current")) {
|
||||||
JsonObject cur = jo.getAsJsonObject("current");
|
JsonObject cur = jo.getAsJsonObject("current");
|
||||||
try {
|
try {
|
||||||
current = MMOCore.plugin.questManager.get(cur.get("id").getAsString()).generateNewProgress(playerData, cur.get("objective").getAsInt());
|
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() + "')");
|
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())
|
for (Entry<String, JsonElement> entry : jo.getAsJsonObject("finished").entrySet())
|
||||||
finished.put(entry.getKey(), entry.getValue().getAsLong());
|
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());
|
MMOCore.log("Finished: (" + entry.getKey() + ") - at: " + entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ public class PlayerQuests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateBossBar() {
|
public void updateBossBar() {
|
||||||
if (!hasCurrent()) {
|
if (!hasCurrent() || !current.getProgress().getObjective().hasLore()) {
|
||||||
bossbar.setVisible(false);
|
bossbar.setVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,17 @@
|
|||||||
package net.Indyuce.mmocore.api.quest.objective;
|
package net.Indyuce.mmocore.api.quest.objective;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||||
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 net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
import net.Indyuce.mmocore.api.quest.ObjectiveProgress;
|
||||||
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
import net.Indyuce.mmocore.api.quest.QuestProgress;
|
||||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
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 {
|
public abstract class Objective {
|
||||||
private final String id, lore;
|
private final String id, lore;
|
||||||
@ -24,7 +23,6 @@ public abstract class Objective {
|
|||||||
this.id = config.getName();
|
this.id = config.getName();
|
||||||
this.lore = config.getString("lore");
|
this.lore = config.getString("lore");
|
||||||
|
|
||||||
Validate.notNull(lore, "Could not find objective lore");
|
|
||||||
Validate.notNull(config.getStringList("triggers"), "Could not load trigger list");
|
Validate.notNull(config.getStringList("triggers"), "Could not load trigger list");
|
||||||
|
|
||||||
String format = config.getString("bar-color", "PURPLE");
|
String format = config.getString("bar-color", "PURPLE");
|
||||||
@ -47,6 +45,10 @@ public abstract class Objective {
|
|||||||
return barColor;
|
return barColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasLore() {
|
||||||
|
return lore != null && !lore.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
public String getDefaultLore() {
|
public String getDefaultLore() {
|
||||||
return lore;
|
return lore;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user