From 6d0baaab9c942d498996605ef9af0f9fb518296b Mon Sep 17 00:00:00 2001 From: Wembler23 <62161570+Wembler23@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:48:29 -0800 Subject: [PATCH 1/3] Added delete all and fixed rounding Added a delete all command to allow for the bestiary data of a player to be reset; and fixed rounding errors in the bestiary entries. --- .../libraryofsouls/bestiary/BestiaryCommand.java | 7 +++++++ .../libraryofsouls/bestiary/BestiaryManager.java | 8 ++++++++ .../libraryofsouls/bestiary/BestiarySoulInventory.java | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryCommand.java b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryCommand.java index 7381dd3..c956fad 100644 --- a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryCommand.java +++ b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryCommand.java @@ -149,6 +149,13 @@ public static void register() { } soul.setLore("", sender); }))) + .withSubcommand(new CommandAPICommand("deleteall") + .withPermission(CommandPermission.fromString("los.bestiary.deleteall")) + .withArguments(new EntitySelectorArgument.OnePlayer("player")) + .executes((sender, args) -> { + Player player = (Player)args[0]; + BestiaryManager.deleteAll(player); + })) .register(); } diff --git a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java index 1f09102..28d1def 100644 --- a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java +++ b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java @@ -14,6 +14,7 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Logger; +import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; @@ -104,6 +105,13 @@ public static int addKillsToMob(Player player, SoulEntry soul, int amount) { return INSTANCE.mStorage.addKillsForMob(player, soul, amount); } + public static void deleteAll(Player player) { + List souls = SoulsDatabase.getInstance().getSouls(); + for (SoulEntry soul : souls) { + BestiaryManager.setKillsForMob(player, soul, 0); + } + } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void entityDamageByEntityEvent(EntityDamageByEntityEvent event) { Entity entity = event.getEntity(); diff --git a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiarySoulInventory.java b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiarySoulInventory.java index ddf2146..5e8d388 100644 --- a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiarySoulInventory.java +++ b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiarySoulInventory.java @@ -538,7 +538,7 @@ public static double getAttributeNumber(ItemStack item, Attribute attribute, Att } } } - return attributeNum; + return Math.round(attributeNum * 1000) / 1000.0; } private static ItemStack getHealthItem(double health) { @@ -710,6 +710,7 @@ private static ItemStack getSpeedItem(EntityNBT entityNBT, double speed, double speed *= speedPercent; } + speed = Math.round(speed * 1000) / 1000.0; lore.add(Component.text(speed + " Speed", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC, false)); speedMeta.lore(lore); speedMeta.displayName(Component.text("Speed", NamedTextColor.WHITE).decoration(TextDecoration.ITALIC, false)); From d21d52168a90d5c28b70785c422621a34ad4f3c6 Mon Sep 17 00:00:00 2001 From: Wembler23 <62161570+Wembler23@users.noreply.github.com> Date: Tue, 6 Feb 2024 16:53:43 -0800 Subject: [PATCH 2/3] alphabetical order --- .../playmonumenta/libraryofsouls/bestiary/BestiaryManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java index 28d1def..6e3b084 100644 --- a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java +++ b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryManager.java @@ -9,12 +9,12 @@ import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.logging.Logger; -import java.util.List; import net.kyori.adventure.text.Component; import org.bukkit.Bukkit; import org.bukkit.entity.Entity; From f5732d10255c64289e4c477ba807c8e589ad1574 Mon Sep 17 00:00:00 2001 From: Wembler23 <62161570+Wembler23@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:30:26 -0800 Subject: [PATCH 3/3] Turned doubles into integers Looks better --- .../libraryofsouls/bestiary/BestiaryAreaInventory.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryAreaInventory.java b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryAreaInventory.java index 1cd3894..329bd28 100644 --- a/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryAreaInventory.java +++ b/src/main/java/com/playmonumenta/libraryofsouls/bestiary/BestiaryAreaInventory.java @@ -88,8 +88,11 @@ public BestiaryAreaInventory(Player player, BestiaryArea area, int offset) { String secondBars = "|".repeat(20 - bars); progressBar = progressBar.append(Component.text(secondBars, NamedTextColor.RED).decoration(TextDecoration.ITALIC, false)); + //No way for discovered mobs to possibly be a non-integer, but safety first + int discInt = (int)Math.floor(discovered); + int totalInt = (int)Math.floor(total); progressBar = progressBar.append(Component.text("]", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)); - progressBar = progressBar.append(Component.text(" " + discovered + "/" + total, NamedTextColor.BLUE).decoration(TextDecoration.ITALIC, false)); + progressBar = progressBar.append(Component.text(" " + discInt + "/" + totalInt, NamedTextColor.BLUE).decoration(TextDecoration.ITALIC, false)); ItemMeta meta = item.getItemMeta(); List lore = meta.hasLore() ? meta.lore() : new ArrayList<>(); if (!lore.contains(progressBar)) {