From 281a125584e139717830687af864cfa2f782b35b Mon Sep 17 00:00:00 2001 From: unurled Date: Tue, 19 Mar 2024 21:29:34 +0100 Subject: [PATCH] code refactoring --- .../me/unurled/sacredrealms/sr/components/item/Item.java | 5 +++-- .../unurled/sacredrealms/sr/components/item/ItemManager.java | 5 +---- .../me/unurled/sacredrealms/sr/components/item/Rarity.java | 5 +++-- .../unurled/sacredrealms/sr/components/player/SRPlayer.java | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/item/Item.java b/src/main/java/me/unurled/sacredrealms/sr/components/item/Item.java index c502265..12dd25b 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/item/Item.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/item/Item.java @@ -8,6 +8,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -73,7 +74,7 @@ public class Item { this.rarity = Rarity.COMMON; this.customModelData = 0; this.abilities = List.of(); - this.attributes = new HashMap<>(); + this.attributes = new EnumMap<>(Attribute.class); this.enchantments = new HashMap<>(); this.type = ItemType.MISC; } @@ -86,7 +87,7 @@ public class Item { this.rarity = Rarity.COMMON; this.customModelData = 0; this.abilities = List.of(); - this.attributes = new HashMap<>(); + this.attributes = new EnumMap<>(Attribute.class); this.enchantments = new HashMap<>(); this.type = ItemType.MISC; } diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/item/ItemManager.java b/src/main/java/me/unurled/sacredrealms/sr/components/item/ItemManager.java index af83f7a..46c00c9 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/item/ItemManager.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/item/ItemManager.java @@ -32,10 +32,7 @@ public class ItemManager extends Manager { Gson gson = new GsonBuilder().registerTypeAdapter(Item.class, new ItemStackSerializer()).create(); - items.forEach( - (id, item) -> { - dh.set("sr.items." + id, gson.toJson(item)); - }); + items.forEach((id, item) -> dh.set("sr.items." + id, gson.toJson(item))); } /** Load the data */ diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/item/Rarity.java b/src/main/java/me/unurled/sacredrealms/sr/components/item/Rarity.java index 4770e2f..cb4c5c5 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/item/Rarity.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/item/Rarity.java @@ -23,9 +23,9 @@ public enum Rarity { private final Integer weight; private final TextColor color; - Rarity(String name, String ID, Integer weight, TextColor color) { + Rarity(String name, String id, Integer weight, TextColor color) { this.name = name; - this.id = ID; + this.id = id; this.weight = weight; this.color = color; } @@ -34,6 +34,7 @@ public enum Rarity { return name; } + @SuppressWarnings("unused") public String getId() { return id; } diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/player/SRPlayer.java b/src/main/java/me/unurled/sacredrealms/sr/components/player/SRPlayer.java index 03220eb..b808976 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/player/SRPlayer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/player/SRPlayer.java @@ -213,7 +213,7 @@ public class SRPlayer { @SuppressWarnings("unused") public @NotNull Map getItemAttributes(Item item) { if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); - HashMap map = new HashMap<>(); + Map map = new HashMap<>(); itemAttributes.forEach((k, v) -> map.put(k, v.getOrDefault(item.toItemStack(), 0d))); return map; }