diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/attributes/Attribute.java b/src/main/java/me/unurled/sacredrealms/sr/components/attributes/Attribute.java index c08b875..3b04d07 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/attributes/Attribute.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/attributes/Attribute.java @@ -4,49 +4,13 @@ import org.bukkit.NamespacedKey; import org.bukkit.persistence.PersistentDataType; public enum Attribute { - HEALTH( - "HEALTH", - "Health", - 100, - 100000, - 0, - new NamespacedKey("sr", "health")), - STRENGTH( - "STRENGTH", - "Strength", - 10, - 10000, - 0, - new NamespacedKey("sr", "strength")), - DEFENSE( - "DEFENSE", - "Defense", - 10, - 10000, - 0, - new NamespacedKey("sr", "defense")), - AGILITY( - "AGILITY", - "Agility", - 100, - 10000, - 0, - new NamespacedKey("sr", "agility")), - LUCK( - "LUCK", - "Luck", - 100, - 99999, - -99999, - new NamespacedKey("sr", "luck")), + HEALTH("HEALTH", "Health", 100, 100000, 0, new NamespacedKey("sr", "health")), + STRENGTH("STRENGTH", "Strength", 10, 10000, 0, new NamespacedKey("sr", "strength")), + DEFENSE("DEFENSE", "Defense", 10, 10000, 0, new NamespacedKey("sr", "defense")), + AGILITY("AGILITY", "Agility", 100, 10000, 0, new NamespacedKey("sr", "agility")), + LUCK("LUCK", "Luck", 100, 99999, -99999, new NamespacedKey("sr", "luck")), MANA("MANA", "Mana", 100, 10000, 0, new NamespacedKey("sr", "mana")), - CHARISMA( - "CHARISMA", - "Charisma", - 0, - 10000, - -10000, - new NamespacedKey("sr", "charisma")), + CHARISMA("CHARISMA", "Charisma", 0, 10000, -10000, new NamespacedKey("sr", "charisma")), ; private final String name; @@ -57,12 +21,7 @@ public enum Attribute { private final NamespacedKey key; Attribute( - String ID, - String name, - int defaultValue, - int maxValue, - int minValue, - NamespacedKey key) { + String ID, String name, int defaultValue, int maxValue, int minValue, NamespacedKey key) { this.ID = ID; this.name = name; this.defaultValue = defaultValue; diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/combat/CombatManager.java b/src/main/java/me/unurled/sacredrealms/sr/components/combat/CombatManager.java index bb11bf5..92051ba 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/combat/CombatManager.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/combat/CombatManager.java @@ -34,7 +34,8 @@ public class CombatManager extends Manager { public void onDamage(EntityDamageByEntityEvent e) { e.setDamage(0.0); - if (!(e.getDamager() instanceof LivingEntity damager) || !(e.getEntity() instanceof LivingEntity entity)) { + if (!(e.getDamager() instanceof LivingEntity damager) + || !(e.getEntity() instanceof LivingEntity entity)) { return; } PlayerManager pm = (PlayerManager) PlayerManager.getInstance(PlayerManager.class); 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 79efd30..af0a714 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 @@ -1,5 +1,8 @@ package me.unurled.sacredrealms.sr.components.item; +import static me.unurled.sacredrealms.sr.utils.Component.comp; +import static me.unurled.sacredrealms.sr.utils.Items.lore; + import java.util.HashMap; import java.util.List; import me.unurled.sacredrealms.sr.components.attributes.Attribute; @@ -7,6 +10,10 @@ import me.unurled.sacredrealms.sr.components.item.abilities.Ability; import me.unurled.sacredrealms.sr.components.item.enchantments.Enchantment; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; +import org.jetbrains.annotations.NotNull; /* rarity * Description: blablabla @@ -31,119 +38,175 @@ import org.bukkit.inventory.ItemStack; * */ public class Item { - private final String ID; + @NotNull private final String ID; - private String name; + @NotNull private String name; - private Material material; + @NotNull private Material material; - private String description; + @NotNull private String description; - private Rarity rarity; + @NotNull private Integer customModelData; - private HashMap attributes; + @NotNull private Rarity rarity; - private HashMap enchantments; + @NotNull private HashMap attributes; - private List abilities; + @NotNull private HashMap enchantments; - public Item(String ID, String name, Material material) { - this.ID = ID; - this.name = name; - this.material = material; + @NotNull private List abilities; + + public Item(@NotNull String ID, @NotNull String name, @NotNull Material material) { + this.ID = ID; + this.name = name; + this.material = material; + this.description = ""; + this.rarity = Rarity.COMMON; + this.customModelData = 0; + this.abilities = List.of(); + this.attributes = new HashMap<>(); + this.enchantments = new HashMap<>(); + } + + public @NotNull String getID() { + return ID; + } + + public @NotNull String getName() { + return name; + } + + public void setName(@NotNull String name) { + this.name = name; + } + + public Material getMaterial() { + return material; + } + + public void setMaterial(@NotNull Material material) { + this.material = material; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Rarity getRarity() { + return rarity; + } + + public void setRarity(Rarity rarity) { + this.rarity = rarity; + } + + public HashMap getAttributes() { + return attributes; + } + + public void setAttributes(HashMap attributes) { + this.attributes = attributes; + } + + public Double getAttribute(Attribute attribute) { + return attributes.get(attribute); + } + + public void addAttribute(Attribute attribute, double value) { + attributes.put(attribute, value); + } + + public void removeAttribute(Attribute attribute) { + attributes.remove(attribute); + } + + public HashMap getEnchantments() { + return enchantments; + } + + public void setEnchantments(HashMap enchantments) { + this.enchantments = enchantments; + } + + public void addEnchantment(Enchantment enchantment, int level) { + enchantments.put(enchantment, level); + } + + public void removeEnchantment(Enchantment enchantment) { + enchantments.remove(enchantment); + } + + public List getAbilities() { + return abilities; + } + + public void setAbilities(List abilities) { + this.abilities = abilities; + } + + public void addAbility(Ability ability) { + abilities.add(ability); + } + + public void removeAbility(Ability ability) { + abilities.remove(ability); + } + + public Integer getCustomModelData() { + return customModelData; + } + + public void setCustomModelData(Integer customModelData) { + this.customModelData = customModelData; + } + + public ItemStack toItemStack() { + ItemStack item = new ItemStack(material); + ItemMeta meta = item.getItemMeta(); + if (meta == null) { + return null; } - public String getID() { - return ID; + PersistentDataContainer p = meta.getPersistentDataContainer(); + p.set(ItemManager.ID, PersistentDataType.STRING, ID); + + meta.displayName(comp(name).color(rarity.getColor())); + + if (customModelData != 0) { + meta.setCustomModelData(customModelData); } - public String getName() { - return name; - } + lore(item); - public void setName(String name) { - this.name = name; - } + item.setItemMeta(meta); + return item; + } - public Material getMaterial() { - return material; - } - - public void setMaterial(Material material) { - this.material = material; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Rarity getRarity() { - return rarity; - } - - public void setRarity(Rarity rarity) { - this.rarity = rarity; - } - - public HashMap getAttributes() { - return attributes; - } - - public Double getAttribute(Attribute attribute) { - return attributes.get(attribute); - } - - public void setAttributes(HashMap attributes) { - this.attributes = attributes; - } - - public void addAttribute(Attribute attribute, double value) { - attributes.put(attribute, value); - } - - public void removeAttribute(Attribute attribute) { - attributes.remove(attribute); - } - - public HashMap getEnchantments() { - return enchantments; - } - - public void setEnchantments(HashMap enchantments) { - this.enchantments = enchantments; - } - - public void addEnchantment(Enchantment enchantment, int level) { - enchantments.put(enchantment, level); - } - - public void removeEnchantment(Enchantment enchantment) { - enchantments.remove(enchantment); - } - - public List getAbilities() { - return abilities; - } - - public void setAbilities(List abilities) { - this.abilities = abilities; - } - - public void addAbility(Ability ability) { - abilities.add(ability); - } - - public void removeAbility(Ability ability) { - abilities.remove(ability); - } - - public ItemStack toItemStack() { - ItemStack item = new ItemStack(material); - // set item meta - return item; - } + @Override + public String toString() { + return "{" + + "ID: " + + ID + + ", name: " + + name + + ", material: " + + material + + ", description: " + + description + + ", customModelData: " + + customModelData + + ", rarity: " + + rarity + + ", attributes: " + + attributes + + ", enchantments: " + + enchantments + + ", abilities: " + + abilities + + "}"; + } } 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 6e868da..85b7d9c 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 @@ -13,7 +13,10 @@ public enum Rarity { SPECIAL("Special", "SPECIAL", 7, NamedTextColor.RED), UNIQUE("Unique", "UNIQUE", 8, NamedTextColor.YELLOW), ADMIN( - "aaAdminaa", "ADMIN", 100, NamedTextColor.DARK_RED); + "aaAdminaa", + "ADMIN", + 100, + NamedTextColor.DARK_RED); private final String name; private final String ID; diff --git a/src/main/java/me/unurled/sacredrealms/sr/components/item/abilities/Ability.java b/src/main/java/me/unurled/sacredrealms/sr/components/item/abilities/Ability.java index 6214e44..f48e79f 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/components/item/abilities/Ability.java +++ b/src/main/java/me/unurled/sacredrealms/sr/components/item/abilities/Ability.java @@ -1,42 +1,40 @@ package me.unurled.sacredrealms.sr.components.item.abilities; -/** - * Represents an ability that an item can have. - * TODO: Implement this class - */ +/** Represents an ability that an item can have. TODO: Implement this class */ public class Ability { - private final String name; - private final String description; - private final Integer cooldown; - private final Integer manaCost; - private final Integer damage; + private final String name; + private final String description; + private final Integer cooldown; + private final Integer manaCost; + private final Integer damage; - public Ability(String name, String description, Integer cooldown, Integer manaCost, Integer damage) { - this.name = name; - this.description = description; - this.cooldown = cooldown; - this.manaCost = manaCost; - this.damage = damage; - } + public Ability( + String name, String description, Integer cooldown, Integer manaCost, Integer damage) { + this.name = name; + this.description = description; + this.cooldown = cooldown; + this.manaCost = manaCost; + this.damage = damage; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public Integer getCooldown() { - return cooldown; - } + public Integer getCooldown() { + return cooldown; + } - public Integer getManaCost() { - return manaCost; - } + public Integer getManaCost() { + return manaCost; + } - public Integer getDamage() { - return damage; - } + public Integer getDamage() { + return damage; + } } 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 666093f..baa78b7 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 @@ -19,17 +19,10 @@ import org.jetbrains.annotations.Nullable; public class SRPlayer { - @Expose - private final UUID uuid; - - @Expose - private Inventory inventory; - - @Expose - private final HashMap attributes; - - @Expose - private final List potionEffects; + @Expose private final UUID uuid; + @Expose private final HashMap attributes; + @Expose private final List potionEffects; + @Expose private Inventory inventory; public SRPlayer(@NotNull Player player) { this.uuid = player.getUniqueId(); @@ -43,15 +36,15 @@ public class SRPlayer { return uuid; } - public void setInventory(Inventory inventory) { - this.inventory = inventory; - } - @NotNull public Inventory getInventory() { return inventory; } + public void setInventory(Inventory inventory) { + this.inventory = inventory; + } + @NotNull public HashMap getAttributes() { return attributes; @@ -80,11 +73,12 @@ public class SRPlayer { if (p == null) { return null; } - Object o = p.getInventory() - .getItemInMainHand() - .getItemMeta() - .getPersistentDataContainer() - .get(attribute.getKey(), attribute.getType()); + Object o = + p.getInventory() + .getItemInMainHand() + .getItemMeta() + .getPersistentDataContainer() + .get(attribute.getKey(), attribute.getType()); if (o == null) { setHandItemAttribute(attribute, attribute.getDefaultValue()); return attribute.getDefaultValue(); @@ -97,23 +91,20 @@ public class SRPlayer { if (p == null) { return; } - if (checkIfValueIsOutOfBoundsForAttribute(attribute, value, p)) - return; + if (checkIfValueIsOutOfBoundsForAttribute(attribute, value, p)) return; ItemStack i = p.getInventory().getItemInMainHand(); ItemMeta im = i.getItemMeta(); - im.getPersistentDataContainer() - .set(attribute.getKey(), PersistentDataType.DOUBLE, value); + im.getPersistentDataContainer().set(attribute.getKey(), PersistentDataType.DOUBLE, value); im.lore(); } - private boolean checkIfValueIsOutOfBoundsForAttribute(@NotNull Attribute attribute, - @NotNull Double value, - Player p) { + private boolean checkIfValueIsOutOfBoundsForAttribute( + @NotNull Attribute attribute, @NotNull Double value, Player p) { if (!attribute.getType().getComplexType().isInstance(value)) { return true; } if (attribute.getType().equals(PersistentDataType.DOUBLE)) { - double d = (double) value; + double d = value; if (d < attribute.getMinValue() || d > attribute.getMaxValue()) { warn( "(Player " @@ -157,13 +148,13 @@ public class SRPlayer { potionEffects.clear(); } - public void setPotionEffects(@NotNull List effects) { - potionEffects.clear(); - potionEffects.addAll(effects); - } - @NotNull public List getPotionEffects() { return potionEffects; } + + public void setPotionEffects(@NotNull List effects) { + potionEffects.clear(); + potionEffects.addAll(effects); + } } diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/DataManager.java b/src/main/java/me/unurled/sacredrealms/sr/data/DataManager.java index 605b90e..785c286 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/DataManager.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/DataManager.java @@ -5,8 +5,6 @@ import static me.unurled.sacredrealms.sr.utils.Logger.error; import java.io.File; import java.io.IOException; import me.unurled.sacredrealms.sr.SR; -import me.unurled.sacredrealms.sr.data.DataHandler; -import me.unurled.sacredrealms.sr.data.Redis; import me.unurled.sacredrealms.sr.managers.Manager; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventoryDeserializer.java b/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventoryDeserializer.java index 9967a67..55b8d2c 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventoryDeserializer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventoryDeserializer.java @@ -1,7 +1,5 @@ package me.unurled.sacredrealms.sr.data.gson; -import static me.unurled.sacredrealms.sr.utils.Logger.log; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -9,7 +7,6 @@ import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import java.lang.reflect.Type; -import java.util.Arrays; import org.bukkit.Bukkit; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; @@ -17,26 +14,26 @@ import org.bukkit.inventory.ItemStack; public class InventoryDeserializer implements JsonDeserializer { - @Override - public Inventory deserialize(JsonElement jsonElement, Type type, - JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - Inventory inv = Bukkit.createInventory(null, InventoryType.PLAYER); - // parse from a string, to a list of string - String[] contents = jsonElement.getAsString().split(";"); + @Override + public Inventory deserialize( + JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + Inventory inv = Bukkit.createInventory(null, InventoryType.PLAYER); + // parse from a string, to a list of string + String[] contents = jsonElement.getAsString().split(";"); // iterate through the list of strings and create ItemStacks with deserialize() Gson gson = new GsonBuilder() .registerTypeAdapter(ItemStack.class, new ItemStackDeserializer()) .create(); - for (int i = 0; i < contents.length; i++) { - if (contents[i].equals("null")) { - inv.setItem(i, null); - } else { - ItemStack item = gson.fromJson(contents[i], ItemStack.class); - if (item != null) - inv.setItem(i, item); - } - } - return inv; + for (int i = 0; i < contents.length; i++) { + if (contents[i].equals("null")) { + inv.setItem(i, null); + } else { + ItemStack item = gson.fromJson(contents[i], ItemStack.class); + if (item != null) inv.setItem(i, item); + } } + return inv; + } } diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventorySerializer.java b/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventorySerializer.java index f73fdab..2b3381a 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventorySerializer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/gson/InventorySerializer.java @@ -1,27 +1,26 @@ package me.unurled.sacredrealms.sr.data.gson; -import static me.unurled.sacredrealms.sr.utils.Logger.error; - import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import java.lang.reflect.Type; import java.util.Arrays; -import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import org.bukkit.inventory.Inventory; public class InventorySerializer implements JsonSerializer { - @Override - public JsonElement serialize(Inventory itemStacks, Type type, - JsonSerializationContext jsonSerializationContext) { - List collect = Arrays.stream(itemStacks.getContents()) - .map(item -> item == null ? "null" : Arrays.toString(item.serializeAsBytes())).collect(Collectors.toList()); + @Override + public JsonElement serialize( + Inventory itemStacks, Type type, JsonSerializationContext jsonSerializationContext) { + List collect = + Arrays.stream(itemStacks.getContents()) + .map(item -> item == null ? "null" : Arrays.toString(item.serializeAsBytes())) + .collect(Collectors.toList()); - String s = String.join(";", collect); - return new JsonPrimitive(s); - } + String s = String.join(";", collect); + return new JsonPrimitive(s); + } } diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/gson/ItemStackDeserializer.java b/src/main/java/me/unurled/sacredrealms/sr/data/gson/ItemStackDeserializer.java index 98abd90..5d6e2e6 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/gson/ItemStackDeserializer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/gson/ItemStackDeserializer.java @@ -1,26 +1,24 @@ package me.unurled.sacredrealms.sr.data.gson; -import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; import java.lang.reflect.Type; -import java.util.Map; -import org.bukkit.Material; import org.bukkit.inventory.ItemStack; public class ItemStackDeserializer implements JsonDeserializer { - @Override - public ItemStack deserialize(JsonElement jsonElement, Type type, - JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - Gson gson = new Gson(); - byte[] mm = gson.fromJson(jsonElement, byte[].class); - if (mm != null) { - return ItemStack.deserializeBytes(mm); - } - return null; + @Override + public ItemStack deserialize( + JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + Gson gson = new Gson(); + byte[] mm = gson.fromJson(jsonElement, byte[].class); + if (mm != null) { + return ItemStack.deserializeBytes(mm); } + return null; + } } diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectDeserializer.java b/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectDeserializer.java index cbb71dc..41e26a6 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectDeserializer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectDeserializer.java @@ -14,24 +14,25 @@ import org.bukkit.potion.PotionEffectType; public class PotionEffectDeserializer implements JsonDeserializer { - @Override - public PotionEffect deserialize(JsonElement jsonElement, Type type, - JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { - try { - String pot = jsonElement.getAsString(); - pot = pot.replace("{", "").replace("}", ""); - String[] parts = pot.split(","); - // find the potion effect type from the string part[0] is a key - PotionEffectType pet = Registry.POTION_EFFECT_TYPE.get(new NamespacedKey("minecraft", - parts[0])); - int duration = Integer.parseInt(parts[1]); - int amplifier = Integer.parseInt(parts[2]); - boolean particles = Boolean.parseBoolean(parts[3]); + @Override + public PotionEffect deserialize( + JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) + throws JsonParseException { + try { + String pot = jsonElement.getAsString(); + pot = pot.replace("{", "").replace("}", ""); + String[] parts = pot.split(","); + // find the potion effect type from the string part[0] is a key + PotionEffectType pet = + Registry.POTION_EFFECT_TYPE.get(new NamespacedKey("minecraft", parts[0])); + int duration = Integer.parseInt(parts[1]); + int amplifier = Integer.parseInt(parts[2]); + boolean particles = Boolean.parseBoolean(parts[3]); - return new PotionEffect(pet, duration, amplifier, false, particles, false); - } catch(Exception e) { - error("Error deserializing potion effect: " + e.getMessage()); - } - return null; + return new PotionEffect(pet, duration, amplifier, false, particles, false); + } catch (Exception e) { + error("Error deserializing potion effect: " + e.getMessage()); } + return null; + } } diff --git a/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectSerializer.java b/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectSerializer.java index ddc4b48..0712b9f 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectSerializer.java +++ b/src/main/java/me/unurled/sacredrealms/sr/data/gson/PotionEffectSerializer.java @@ -1,6 +1,5 @@ package me.unurled.sacredrealms.sr.data.gson; -import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; @@ -10,18 +9,17 @@ import org.bukkit.potion.PotionEffect; public class PotionEffectSerializer implements JsonSerializer { - @Override - public JsonElement serialize(PotionEffect potionEffect, Type type, - JsonSerializationContext jsonSerializationContext) { - StringBuilder sb = new StringBuilder(); - sb.append("{"); - sb.append(potionEffect.getType().key()); - sb.append(","); - sb.append(potionEffect.getDuration()); - sb.append(","); - sb.append(potionEffect.getAmplifier()); - sb.append(",").append(potionEffect.hasParticles()); - sb.append("}"); - return new JsonPrimitive(sb.toString()); - } + @Override + public JsonElement serialize( + PotionEffect potionEffect, Type type, JsonSerializationContext jsonSerializationContext) { + String sb = "{" + + potionEffect.getType().key() + + "," + + potionEffect.getDuration() + + "," + + potionEffect.getAmplifier() + + "," + potionEffect.hasParticles() + + "}"; + return new JsonPrimitive(sb); + } } diff --git a/src/main/java/me/unurled/sacredrealms/sr/utils/Items.java b/src/main/java/me/unurled/sacredrealms/sr/utils/Items.java index c5ae754..1771d36 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/utils/Items.java +++ b/src/main/java/me/unurled/sacredrealms/sr/utils/Items.java @@ -53,31 +53,20 @@ public class Items { return 0.0; } - /** rarity - * Description: blablabla - * blabbla - * blabla - * Attributes: - * ➤ Health: +100 - * ➤ Strength: +10 - * ➤ Mana: +10 - * Abilities: - * ➤ Ability 1, On Rightclick unleash a powerful attack - * cooldown: 10s, - * damage: 100, - * mana cost: 50 - * ➤ Ability 2, On Rightclick unleash a powerful attack - * cooldown: 10s, - * damage: 100, - * mana cost: 50 - * Enchantments: - * ➤ Enchantment 1 - * ➤ Enchantment 2 + /** + * rarity Description: blablabla blabbla + * blabla Attributes: ➤ Health: +100 ➤ Strength: +10 + * ➤ Mana: +10 Abilities: ➤ Ability 1, On Rightclick unleash + * a powerful attack cooldown: 10s, damage: 100, mana cost: + * 50 ➤ Ability 2, On Rightclick unleash a powerful attack + * cooldown: 10s, damage: 100, mana cost: 50 + * Enchantments: ➤ Enchantment 1 ➤ Enchantment 2 * * @param item the item * @param stack the itemstack * @return the itemstack with lore - * */ + */ public static ItemStack lore(ItemStack stack) { ItemManager im = (ItemManager) ItemManager.getInstance(ItemManager.class); @@ -94,22 +83,35 @@ public class Items { lore.add(comp("" + item.getDescription())); if (!item.getAttributes().isEmpty()) { lore.add(comp("Attributes:")); - item.getAttributes().forEach((k, v) -> lore.add(comp(" ➤ " + k.getName() + ": " + (v < 0 ? "" : "") + - "+" + v))); + item.getAttributes() + .forEach( + (k, v) -> + lore.add( + comp( + " ➤ " + + k.getName() + + ": " + + (v < 0 ? "" : "") + + "+" + + v))); } - if (!item.getAbilities().isEmpty()) { + if (!item.getAbilities().isEmpty()) { lore.add(comp("Abilities:")); - item.getAbilities().forEach(a -> { - lore.add(comp(" ➤ " + a.getName() + ", " + a.getDescription())); - lore.add(comp(" cooldown: " + a.getCooldown() + "s,")); - lore.add(comp(" damage: " + a.getDamage() + ",")); - lore.add(comp(" mana cost: " + a.getManaCost())); - }); + item.getAbilities() + .forEach( + a -> { + lore.add(comp(" ➤ " + a.getName() + ", " + a.getDescription())); + lore.add(comp(" cooldown: " + a.getCooldown() + "s,")); + lore.add(comp(" damage: " + a.getDamage() + ",")); + lore.add(comp(" mana cost: " + a.getManaCost())); + }); } if (!item.getEnchantments().isEmpty()) { lore.add(comp("Enchantments:")); - item.getEnchantments().forEach((k, v) -> lore.add(comp(" ➤ " + k.getName() + " " + v))); + item.getEnchantments() + .forEach( + (k, v) -> + lore.add(comp(" ➤ " + k.getName() + " " + v))); } stack.lore(lore); diff --git a/src/main/java/me/unurled/sacredrealms/sr/utils/NumberParser.java b/src/main/java/me/unurled/sacredrealms/sr/utils/NumberParser.java index f99ddfe..a5196b8 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/utils/NumberParser.java +++ b/src/main/java/me/unurled/sacredrealms/sr/utils/NumberParser.java @@ -1,33 +1,33 @@ package me.unurled.sacredrealms.sr.utils; public class NumberParser { - public static double parse(String input) { - input = input.toLowerCase().trim(); - double multiplier = 1.0; + public static double parse(String input) { + input = input.toLowerCase().trim(); + double multiplier = 1.0; - if (input.endsWith("k")) { - multiplier = 1e3; - input = input.substring(0, input.length() - 1); - } else if (input.endsWith("m")) { - multiplier = 1e6; - input = input.substring(0, input.length() - 1); - } else if (input.endsWith("b")) { - multiplier = 1e9; - input = input.substring(0, input.length() - 1); - } - - return Double.parseDouble(input) * multiplier; + if (input.endsWith("k")) { + multiplier = 1e3; + input = input.substring(0, input.length() - 1); + } else if (input.endsWith("m")) { + multiplier = 1e6; + input = input.substring(0, input.length() - 1); + } else if (input.endsWith("b")) { + multiplier = 1e9; + input = input.substring(0, input.length() - 1); } - public static String format(double number) { - if (number >= 1e9) { - return String.format("%.2fb", number / 1e9); - } else if (number >= 1e6) { - return String.format("%.2fm", number / 1e6); - } else if (number >= 1e3) { - return String.format("%.2fk", number / 1e3); - } else { - return String.format("%.2f", number); - } + return Double.parseDouble(input) * multiplier; + } + + public static String format(double number) { + if (number >= 1e9) { + return String.format("%.2fb", number / 1e9); + } else if (number >= 1e6) { + return String.format("%.2fm", number / 1e6); + } else if (number >= 1e3) { + return String.format("%.2fk", number / 1e3); + } else { + return String.format("%.2f", number); } + } } 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 e5b903a..fb28742 100644 --- a/src/main/java/me/unurled/sacredrealms/sr/utils/SRPlayerUtils.java +++ b/src/main/java/me/unurled/sacredrealms/sr/utils/SRPlayerUtils.java @@ -7,28 +7,28 @@ import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; public class SRPlayerUtils { - public static void syncPlayerToSR(Player p, SRPlayer sr) { - sr.setInventory(p.getInventory()); - sr.setPotionEffects((List) p.getActivePotionEffects()); + public static void syncPlayerToSR(Player p, SRPlayer sr) { + sr.setInventory(p.getInventory()); + sr.setPotionEffects((List) p.getActivePotionEffects()); + } + + public static void syncSRToPlayer(SRPlayer sr, Player p) { + p.getInventory().setContents(sr.getInventory().getContents()); + + // agility (speed) + // default is 100 so 0.2 + float value = (float) (sr.getAttribute(Attribute.AGILITY) / 500.0); + p.setFlySpeed(value); + p.setWalkSpeed(value); + + for (PotionEffect pe : sr.getPotionEffects()) { + p.addPotionEffect(pe); } - public static void syncSRToPlayer(SRPlayer sr, Player p) { - p.getInventory().setContents(sr.getInventory().getContents()); - - // agility (speed) - // default is 100 so 0.2 - float value = (float) (sr.getAttribute(Attribute.AGILITY) / 500.0); - p.setFlySpeed(value); - p.setWalkSpeed(value); - - for (PotionEffect pe : sr.getPotionEffects()) { - p.addPotionEffect(pe); - } - - // health - // default is 100 so 20 - p.setHealth(sr.getAttribute(Attribute.HEALTH) / 5); - p.sendHealthUpdate(); - p.updateInventory(); - } + // health + // default is 100 so 20 + p.setHealth(sr.getAttribute(Attribute.HEALTH) / 5); + p.sendHealthUpdate(); + p.updateInventory(); + } }