diff --git a/src/main/java/me/unurled/sacredrealms/sr/commands/admin/ItemCommand.java b/src/main/java/me/unurled/sacredrealms/sr/commands/admin/ItemCommand.java index 17930e2..6f6378f 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/commands/admin/ItemCommand.java +++ b/src/main/java/me/unurled/sacredrealms/sr/commands/admin/ItemCommand.java @@ -302,7 +302,7 @@ public class ItemCommand implements TabExecutor { return; } Item item = new Item(); - item.setID(args[1]); + item.setId(args[1]); im.addItem(item); sender.sendMessage( comp( diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/entity/SREntityType.java b/src/main/java/me/unurled/sacredrealms/sr/components/entity/SREntityType.java index 855460f..a02d704 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/entity/SREntityType.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/entity/SREntityType.java @@ -133,7 +133,7 @@ public class SREntityType { @SuppressWarnings("unused") public Double getTotalItemAttribute(Attribute attribute) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); return itemAttributes.getOrDefault(attribute, new HashMap<>()).values().stream() .reduce(0.0, Double::sum); } 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 470549e..c502265 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 @@ -45,7 +45,7 @@ import org.jetbrains.annotations.NotNull; * */ public class Item { - @NotNull private String ID; + @NotNull private String id; @NotNull private String name; @@ -59,14 +59,14 @@ public class Item { @NotNull private ItemType type; - @NotNull private HashMap attributes; + @NotNull private Map attributes; - @NotNull private HashMap enchantments; + @NotNull private Map enchantments; @NotNull private List abilities; public Item() { - this.ID = ""; + this.id = ""; this.name = ""; this.material = Material.AIR; this.description = ""; @@ -78,8 +78,8 @@ public class Item { this.type = ItemType.MISC; } - public Item(@NotNull String ID, @NotNull String name, @NotNull Material material) { - this.ID = ID; + public Item(@NotNull String id, @NotNull String name, @NotNull Material material) { + this.id = id; this.name = name; this.material = material; this.description = ""; @@ -91,8 +91,8 @@ public class Item { this.type = ItemType.MISC; } - public @NotNull String getID() { - return ID; + public @NotNull String getId() { + return id; } public @NotNull String getName() { @@ -103,46 +103,46 @@ public class Item { this.name = name; } - public Material getMaterial() { - return material; + public void setId(@NotNull String arg) { + this.id = arg; } public void setMaterial(@NotNull Material material) { this.material = material; } - public String getDescription() { + public @NotNull Material getMaterial() { + return material; + } + + public @NotNull String getDescription() { return description; } - public void setDescription(String description) { + public void setDescription(@NotNull String description) { this.description = description; } - public Rarity getRarity() { + public @NotNull Rarity getRarity() { return rarity; } - public void setRarity(Rarity rarity) { + public void setRarity(@NotNull Rarity rarity) { this.rarity = rarity; } - public ItemType getType() { + public @NotNull ItemType getType() { return type; } - public void setType(ItemType type) { + public void setType(@NotNull ItemType type) { this.type = type; } - public HashMap getAttributes() { + public @NotNull Map getAttributes() { return attributes; } - public void setAttributes(HashMap attributes) { - this.attributes = attributes; - } - public Double getAttribute(Attribute attribute) { return attributes.get(attribute); } @@ -155,43 +155,54 @@ public class Item { attributes.remove(attribute); } - public HashMap getEnchantments() { + public void setAttributes(@NotNull Map attributes) { + this.attributes = attributes; + } + + public @NotNull Map getEnchantments() { return enchantments; } - public void setEnchantments(HashMap enchantments) { + @SuppressWarnings("unused") + public void setEnchantments(@NotNull Map enchantments) { this.enchantments = enchantments; } + @SuppressWarnings("unused") public void addEnchantment(Enchantment enchantment, int level) { enchantments.put(enchantment, level); } + @SuppressWarnings("unused") public void removeEnchantment(Enchantment enchantment) { enchantments.remove(enchantment); } - public List getAbilities() { + public @NotNull List getAbilities() { return abilities; } - public void setAbilities(List abilities) { + @SuppressWarnings("unused") + public void setAbilities(@NotNull List abilities) { this.abilities = abilities; } + @SuppressWarnings("unused") public void addAbility(Ability ability) { abilities.add(ability); } + @SuppressWarnings("unused") public void removeAbility(Ability ability) { abilities.remove(ability); } - public Integer getCustomModelData() { + @SuppressWarnings("unused") + public @NotNull Integer getCustomModelData() { return customModelData; } - public void setCustomModelData(Integer customModelData) { + public void setCustomModelData(@NotNull Integer customModelData) { this.customModelData = customModelData; } @@ -203,7 +214,7 @@ public class Item { } PersistentDataContainer p = meta.getPersistentDataContainer(); - p.set(ItemManager.ID, PersistentDataType.STRING, ID); + p.set(ItemManager.ID, PersistentDataType.STRING, id); meta.displayName(comp(name).color(rarity.getColor())); @@ -221,7 +232,7 @@ public class Item { public String toString() { return "{" + "\"id\": \"" - + ID + + id + "\", \"name\": \"" + name + "\", \"material\": \"" @@ -251,7 +262,7 @@ public class Item { Map map = gson.fromJson(item, new TypeToken>() {}.getType()); - this.ID = (String) map.get("id"); + this.id = (String) map.get("id"); this.name = (String) map.get("name"); this.material = Material.valueOf((String) map.get("material")); this.description = (String) map.get("description"); @@ -271,8 +282,4 @@ public class Item { error("Failed to parse item from string: " + item + "\n" + e.getMessage()); } } - - public void setID(String arg) { - this.ID = arg; - } } 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 44fa1e8..af83f7a 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 @@ -23,12 +23,6 @@ public class ItemManager extends Manager { items = new HashMap<>(); } - /** Load the manager */ - @Override - public void load() { - super.load(); - } - /** Save the data */ @Override public void saveData() { @@ -56,12 +50,12 @@ public class ItemManager extends Manager { .forEach( key -> { Item item = gson.fromJson(dh.get(key), Item.class); - items.put(item.getID(), item); + items.put(item.getId(), item); }); } public void addItem(Item item) { - items.put(item.getID(), item); + items.put(item.getId(), item); } public Item getItem(String id) { 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 85b7d9c..4770e2f 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 @@ -19,13 +19,13 @@ public enum Rarity { NamedTextColor.DARK_RED); private final String name; - private final String ID; + private final String id; private final Integer weight; private final 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,10 +34,11 @@ public enum Rarity { return name; } - public String getID() { - return ID; + public String getId() { + return id; } + @SuppressWarnings("unused") public Integer getWeight() { return weight; } 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 aaa6aae..03220eb 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 @@ -5,6 +5,7 @@ import static me.unurled.sacredrealms.sr.utils.Logger.warn; import com.google.gson.annotations.Expose; import java.util.ArrayList; +import java.util.EnumMap; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -33,8 +34,8 @@ public class SRPlayer { @Expose private int level = 1; @Expose private Long experience = 0L; private double health = 100; - @Expose private HashMap attributes = new HashMap<>(); - private HashMap> itemAttributes = new HashMap<>(); + @Expose private Map attributes = new EnumMap<>(Attribute.class); + private Map> itemAttributes = new EnumMap<>(Attribute.class); @Expose private List potionEffects = new ArrayList<>(); @Expose private Inventory inventory = null; @@ -177,18 +178,18 @@ public class SRPlayer { public void setItemAttributes( @NotNull Attribute attribute, @NotNull ItemStack item, @NotNull Double value) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); if (itemAttributes.containsKey(attribute)) { itemAttributes.get(attribute).put(item, value); } else { - HashMap map = new HashMap<>(); + Map map = new HashMap<>(); map.put(item, value); itemAttributes.put(attribute, map); } } public void removeItemAttributes(@NotNull Attribute attribute, @NotNull ItemStack item) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); if (itemAttributes.containsKey(attribute)) { itemAttributes.get(attribute).remove(item); } @@ -196,7 +197,7 @@ public class SRPlayer { @SuppressWarnings("unused") public @Nullable Double getItemAttributes(@NotNull Attribute attribute, @NotNull ItemStack item) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); if (itemAttributes.containsKey(attribute)) { return itemAttributes.get(attribute).get(item); } @@ -205,20 +206,20 @@ public class SRPlayer { @SuppressWarnings("unused") public @NotNull Map getItemAttributes(@NotNull Attribute attribute) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); return itemAttributes.getOrDefault(attribute, new HashMap<>()); } @SuppressWarnings("unused") public @NotNull Map getItemAttributes(Item item) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); HashMap map = new HashMap<>(); itemAttributes.forEach((k, v) -> map.put(k, v.getOrDefault(item.toItemStack(), 0d))); return map; } public @NotNull Double getTotalItemAttribute(@NotNull Attribute attribute) { - if (itemAttributes == null) itemAttributes = new HashMap<>(); + if (itemAttributes == null) itemAttributes = new EnumMap<>(Attribute.class); return itemAttributes.getOrDefault(attribute, new HashMap<>()).values().stream() .reduce(0.0, Double::sum); } diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/gson/ClientBuildDeserializer.java b/src/main/java/me/unurled/sacredrealms/sr/data/gson/ClientBuildDeserializer.java index 93ff96b..a194ac9 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/gson/ClientBuildDeserializer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/gson/ClientBuildDeserializer.java @@ -41,7 +41,7 @@ public class ClientBuildDeserializer implements JsonDeserializer { World world = Bukkit.getWorld(spl[0]); if (world == null) { error("World " + spl[0] + " does not exist"); - continue; + return build; } Location loc; BlockData bData; diff --git a/src/main/java/me/unurled/sacredrealms/sr/events/player/PlayerLevelUpEvent.java b/src/main/java/me/unurled/sacredrealms/sr/events/player/PlayerLevelUpEvent.java index 67d9b28..485b477 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/events/player/PlayerLevelUpEvent.java +++ b/src/main/java/me/unurled/sacredrealms/sr/events/player/PlayerLevelUpEvent.java @@ -4,8 +4,6 @@ import static me.unurled.sacredrealms.sr.utils.Component.comp; import me.unurled.sacredrealms.sr.components.player.SRPlayer; import net.kyori.adventure.text.Component; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -21,7 +19,6 @@ public class PlayerLevelUpEvent extends Event { super(true); this.p = p; this.previousLevel = previousLevel; - OfflinePlayer pa = Bukkit.getOfflinePlayer(p.getUuid()); /* * -------------------------------------------------- * diff --git a/src/main/java/me/unurled/sacredrealms/sr/utils/SRPlayerUtils.java b/src/main/java/me/unurled/sacredrealms/sr/utils/SRPlayerUtils.java index 50068ed..8da2e86 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/utils/SRPlayerUtils.java +++ b/src/main/java/me/unurled/sacredrealms/sr/utils/SRPlayerUtils.java @@ -73,7 +73,7 @@ public class SRPlayerUtils { * href="https://github.com/DragonL0508/D-Damage-Indicators/blob/master/src/main/java/me/dragonl/damageIndicators/GlobalListener.java">author */ public static @NotNull TextDisplay spawnIndicator( - @NotNull Entity eventEntity, @NotNull Boolean isHeal, double number) { + @NotNull Entity eventEntity, boolean isHeal, double number) { // vector operation Vector location = eventEntity.getLocation().toVector(); Vector facingVector = eventEntity.getFacing().getDirection();