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

1.20.4 fixes and modernization #66

Merged
merged 8 commits into from
Dec 21, 2024
Merged
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
11 changes: 8 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription

plugins {
id("com.playmonumenta.gradle-config") version "1.+"
id("com.playmonumenta.gradle-config") version "2.2+"
}

dependencies {
compileOnly(libs.commandapi)
compileOnly(libs.nbtapi)
compileOnly(libs.redissync) {
compileOnly(libs.mixinapi)
compileOnly(libs.nbteditor) {
artifact {
classifier = "all"
}
}
compileOnly(libs.nbteditor) {
compileOnly(libs.redissync) {
artifact {
classifier = "all"
}
}
compileOnly(libs.gson)
}

tasks.javadoc {
(options as StandardJavadocDocletOptions).addBooleanOption("Xdoclint:none", true)
}

monumenta {
name("LibraryOfSouls")
paper(
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ nbtapi = "2.12.0-SNAPSHOT"
redissync = "4.1"
nbteditor = "4.1"
gson = "2.8.5"
mixinapi = "1.0.4"

[libraries]
commandapi = { module = "dev.jorel:commandapi-bukkit-core", version.ref = "commandapi" }
nbtapi = { module = "de.tr7zw:item-nbt-api-plugin", version.ref = "nbtapi" }
redissync = { module = "com.playmonumenta:redissync", version.ref = "redissync" }
nbteditor = { module = "com.playmonumenta:nbteditor", version.ref = "nbteditor" }
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
mixinapi = { module = "com.playmonumenta.papermixins:plugin-api", version.ref = "mixinapi" }
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onEnable() {
/* Don't load the bestiary config initially - this will happen when the souls database loads */
Config.load(getLogger(), getDataFolder(), false);

getLogger().info("Library of Souls read only: " + Boolean.toString(Config.isReadOnly()));
getLogger().info("Library of Souls read only: " + Config.isReadOnly());

if (!Config.isReadOnly()) {
LibraryOfSoulsCommand.registerWriteAccessCommands();
Expand Down
65 changes: 25 additions & 40 deletions src/main/java/com/playmonumenta/libraryofsouls/SoulEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import com.playmonumenta.libraryofsouls.bestiary.BestiarySoulInventory;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.Set;
import net.kyori.adventure.text.Component;
Expand Down Expand Up @@ -51,7 +51,7 @@ public SoulEntry(List<SoulHistoryEntry> history, Set<String> locationNames, List
mHistory = history;

if (locationNames == null) {
mLocs = new HashSet<String>();
mLocs = new HashSet<>();
} else {
mLocs = locationNames;
}
Expand All @@ -62,18 +62,13 @@ public SoulEntry(List<SoulHistoryEntry> history, Set<String> locationNames, List
mLore = lore;
}

if (description == null) {
mDescription = new ArrayList<>();
} else {
mDescription = description;
}
mDescription = Objects.requireNonNullElseGet(description, ArrayList::new);

String refLabel = history.get(0).getLabel();
Component refName = history.get(0).getName();

for (SoulHistoryEntry entry : history) {
if (!entry.getLabel().equals(refLabel)) {
throw new Exception("Soul history has mismatching names! '" + refName + "' != '" + entry.getName());
throw new Exception("Soul history has mismatching labels! '" + refLabel + "' != '" + entry.getLabel());
}
}
}
Expand All @@ -82,8 +77,8 @@ public SoulEntry(List<SoulHistoryEntry> history, Set<String> locationNames, List
public SoulEntry(Player player, NBTTagCompound nbt) throws Exception {
SoulHistoryEntry newHist = new SoulHistoryEntry(player, nbt);

mLocs = new HashSet<String>();
mHistory = new ArrayList<SoulHistoryEntry>(1);
mLocs = new HashSet<>();
mHistory = new ArrayList<>(1);
mHistory.add(newHist);
mLore = new ArrayList<>();
mDescription = new ArrayList<>();
Expand Down Expand Up @@ -281,7 +276,7 @@ public ItemStack getBestiaryItem(Player player) {
// Hide weapon damage, book enchants, and potion effects:
meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
meta.addItemFlags(ItemFlag.HIDE_ITEM_SPECIFICS);

item.setItemMeta(meta);
return item;
Expand Down Expand Up @@ -346,15 +341,11 @@ public InfoTier getInfoTier(Player player) {
return InfoTier.EVERYTHING;
}

Integer kills = BestiaryManager.getKillsForMob(player, this);
if (kills != null && kills >= 1) {
if (kills >= 60
|| (isElite() && kills >= 10)
|| (isBoss() && kills >= 2)) {
int kills = BestiaryManager.getKillsForMob(player, this);
if (kills >= 1) {
if (kills >= 60 || (isElite() && kills >= 10) || (isBoss() && kills >= 2)) {
return InfoTier.EVERYTHING;
} else if (kills >= 30
|| (isElite() && kills >= 5)
|| (isBoss() && kills >= 1)) {
} else if (kills >= 30 || (isElite() && kills >= 5) || isBoss()) {
return InfoTier.STATS;
} else {
return InfoTier.MINIMAL;
Expand All @@ -366,11 +357,11 @@ public InfoTier getInfoTier(Player player) {
//Checks if the mob is invlunerable, for bestiary purposes
public boolean isInvulnerable() {
EntityNBT entityNBT = EntityNBT.fromEntityData(this.getNBT());
EffectsVariable effectVar = new EffectsVariable("ActiveEffects");
EffectsVariable effectVar = new EffectsVariable("active_effects");
BooleanVariable booVar = new BooleanVariable("Invulnerable");

String ret = ((BooleanVariable)booVar.bind(entityNBT.getData())).get();
boolean override = (ret != null && ret.toLowerCase().equals("true"));
String ret = booVar.bind(entityNBT.getData()).get();
boolean override = (ret != null && ret.equalsIgnoreCase("true"));

ItemStack effectItem = ((EffectsVariable)effectVar.bind(entityNBT.getData())).getItem();
if (effectItem != null && effectItem.hasItemMeta()) {
Expand All @@ -396,27 +387,25 @@ public MobType getMobType() {
}

public List<Soul> getHistory() {
return new ArrayList<Soul>(mHistory);
return new ArrayList<>(mHistory);
}

public Set<String> getLocationNames() {
return mLocs;
}

public static SoulEntry fromJson(JsonObject obj, boolean loadHistory) throws Exception {
Set<String> locs = new HashSet<String>();
Set<String> locs = new HashSet<>();
JsonElement elem = obj.get("location_names");
if (elem != null) {
JsonArray array = elem.getAsJsonArray();
if (array == null) {
throw new Exception("Failed to parse location_names as JSON array");
}

Iterator<JsonElement> iter = array.iterator();
while (iter.hasNext()) {
JsonElement tagElement = iter.next();
for (JsonElement tagElement : array) {
if (!tagElement.isJsonPrimitive()) {
throw new Exception("location_names entry for '" + elem.toString() + "' is not a string!");
throw new Exception("location_names entry for '" + elem + "' is not a string!");
}
locs.add(tagElement.getAsString());
}
Expand All @@ -430,11 +419,9 @@ public static SoulEntry fromJson(JsonObject obj, boolean loadHistory) throws Exc
throw new Exception("Failed to parse lore as JSON array");
}

Iterator<JsonElement> iter = array.iterator();
while (iter.hasNext()) {
JsonElement loreElement = iter.next();
for (JsonElement loreElement : array) {
if (!loreElement.isJsonPrimitive()) {
throw new Exception("location_names entry for '" + elem.toString() + "' is not a string!");
throw new Exception("location_names entry for '" + elem + "' is not a string!");
}
Component comp = GSON_SERIALIZER.deserialize(loreElement.getAsString());
lore.add(comp);
Expand All @@ -451,9 +438,7 @@ public static SoulEntry fromJson(JsonObject obj, boolean loadHistory) throws Exc
throw new Exception("Failed to parse description as JSON array");
}

Iterator<JsonElement> iter = array.iterator();
while (iter.hasNext()) {
JsonElement descriptionElement = iter.next();
for (JsonElement descriptionElement : array) {
if (!descriptionElement.isJsonPrimitive()) {
throw new Exception("description entry for '" + elem + "' is not a string!");
}
Expand All @@ -464,7 +449,7 @@ public static SoulEntry fromJson(JsonObject obj, boolean loadHistory) throws Exc
description.add(Component.text(elem.getAsString()));
}

List<SoulHistoryEntry> history = new ArrayList<SoulHistoryEntry>();
List<SoulHistoryEntry> history = new ArrayList<>();
elem = obj.get("history");
if (elem != null) {
JsonArray array = elem.getAsJsonArray();
Expand All @@ -475,16 +460,16 @@ public static SoulEntry fromJson(JsonObject obj, boolean loadHistory) throws Exc
if (loadHistory) {
for (JsonElement historyElement : array) {
if (!historyElement.isJsonObject()) {
throw new Exception("history entry for '" + elem.toString() + "' is not a string!");
throw new Exception("history entry for '" + elem + "' is not a string!");
}

history.add(SoulHistoryEntry.fromJson(historyElement.getAsJsonObject(), locs, lore, description));
}
} else {
if (array.size() >= 1) {
if (!array.isEmpty()) {
JsonElement historyElement = array.get(0);
if (!historyElement.isJsonObject()) {
throw new Exception("history entry for '" + elem.toString() + "' is not a string!");
throw new Exception("history entry for '" + elem + "' is not a string!");
}

history.add(SoulHistoryEntry.fromJson(historyElement.getAsJsonObject(), locs, lore, description));
Expand Down
Loading