Skip to content

Commit

Permalink
Added delete all and fixed rounding (#50)
Browse files Browse the repository at this point in the history
* 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.

* alphabetical order

* Turned doubles into integers

Looks better
  • Loading branch information
Wembler23 authored Feb 9, 2024
1 parent f84c0d9 commit ae1b24a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component> lore = meta.hasLore() ? meta.lore() : new ArrayList<>();
if (!lore.contains(progressBar)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -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<SoulEntry> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit ae1b24a

Please sign in to comment.