optimize import and code reformat

This commit is contained in:
unurled 2024-02-27 21:00:24 +01:00
parent 36f8e3f6f0
commit 64ef73f7e0
Signed by: unurled
GPG key ID: FDBC9CBE1F82423F
15 changed files with 379 additions and 371 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;
/* <b><color of the rarity>rarity
* <dark_gray>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<Attribute, Double> attributes;
@NotNull private Rarity rarity;
private HashMap<Enchantment, Integer> enchantments;
@NotNull private HashMap<Attribute, Double> attributes;
private List<Ability> abilities;
@NotNull private HashMap<Enchantment, Integer> enchantments;
public Item(String ID, String name, Material material) {
this.ID = ID;
this.name = name;
this.material = material;
@NotNull private List<Ability> 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<Attribute, Double> getAttributes() {
return attributes;
}
public void setAttributes(HashMap<Attribute, Double> 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<Enchantment, Integer> getEnchantments() {
return enchantments;
}
public void setEnchantments(HashMap<Enchantment, Integer> 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<Ability> getAbilities() {
return abilities;
}
public void setAbilities(List<Ability> 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<Attribute, Double> getAttributes() {
return attributes;
}
public Double getAttribute(Attribute attribute) {
return attributes.get(attribute);
}
public void setAttributes(HashMap<Attribute, Double> 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<Enchantment, Integer> getEnchantments() {
return enchantments;
}
public void setEnchantments(HashMap<Enchantment, Integer> 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<Ability> getAbilities() {
return abilities;
}
public void setAbilities(List<Ability> 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
+ "}";
}
}

View file

@ -13,7 +13,10 @@ public enum Rarity {
SPECIAL("<red>Special", "SPECIAL", 7, NamedTextColor.RED),
UNIQUE("<yellow>Unique", "UNIQUE", 8, NamedTextColor.YELLOW),
ADMIN(
"<color:#800000><obf>aa</obf><dark_red>Admin</dark_red><obf>aa</obf></color>", "ADMIN", 100, NamedTextColor.DARK_RED);
"<color:#800000><obf>aa</obf><dark_red>Admin</dark_red><obf>aa</obf></color>",
"ADMIN",
100,
NamedTextColor.DARK_RED);
private final String name;
private final String ID;

View file

@ -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;
}
}

View file

@ -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<Attribute, Double> attributes;
@Expose
private final List<PotionEffect> potionEffects;
@Expose private final UUID uuid;
@Expose private final HashMap<Attribute, Double> attributes;
@Expose private final List<PotionEffect> 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<Attribute, Double> 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<PotionEffect> effects) {
potionEffects.clear();
potionEffects.addAll(effects);
}
@NotNull
public List<PotionEffect> getPotionEffects() {
return potionEffects;
}
public void setPotionEffects(@NotNull List<PotionEffect> effects) {
potionEffects.clear();
potionEffects.addAll(effects);
}
}

View file

@ -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;

View file

@ -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<Inventory> {
@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;
}
}

View file

@ -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<Inventory> {
@Override
public JsonElement serialize(Inventory itemStacks, Type type,
JsonSerializationContext jsonSerializationContext) {
List<String> 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<String> 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);
}
}

View file

@ -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<ItemStack> {
@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;
}
}

View file

@ -14,24 +14,25 @@ import org.bukkit.potion.PotionEffectType;
public class PotionEffectDeserializer implements JsonDeserializer<PotionEffect> {
@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;
}
}

View file

@ -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<PotionEffect> {
@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);
}
}

View file

@ -53,31 +53,20 @@ public class Items {
return 0.0;
}
/** <b><color of the rarity>rarity
* <dark_gray>Description: blablabla
* <dark_gray>blabbla
* <dark_gray>blabla
* <gray>Attributes:
* <gray> Health: <green>+100
* <gray> Strength: <red>+10
* <gray> Mana: <dark_aqua>+10
* <gray>Abilities:
* <gray> Ability 1,<yellow> On Rightclick unleash a powerful attack
* <dark_gray>cooldown: 10s,
* <dark_gray>damage: 100,
* <dark_gray>mana cost: <dark_aqua>50
* <gray> Ability 2,<yellow> On Rightclick unleash a powerful attack
* <dark_gray>cooldown: 10s,
* <dark_gray>damage: 100,
* <dark_gray>mana cost: <dark_aqua>50
* <dark_purple>Enchantments:
* <blue> Enchantment <if max level gold>1
* <blue> Enchantment <if max level gold>2
/**
* <b><color of the rarity>rarity <dark_gray>Description: blablabla <dark_gray>blabbla
* <dark_gray>blabla <gray>Attributes: <gray> Health: <green>+100 <gray> Strength: <red>+10
* <gray> Mana: <dark_aqua>+10 <gray>Abilities: <gray> Ability 1,<yellow> On Rightclick unleash
* a powerful attack <dark_gray>cooldown: 10s, <dark_gray>damage: 100, <dark_gray>mana cost:
* <dark_aqua>50 <gray> Ability 2,<yellow> On Rightclick unleash a powerful attack
* <dark_gray>cooldown: 10s, <dark_gray>damage: 100, <dark_gray>mana cost: <dark_aqua>50
* <dark_purple>Enchantments: <blue> Enchantment <if max level gold>1 <blue> Enchantment <if max
* level gold>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("<dark_gray>" + item.getDescription()));
if (!item.getAttributes().isEmpty()) {
lore.add(comp("<gray>Attributes:"));
item.getAttributes().forEach((k, v) -> lore.add(comp(" <gray>➤ " + k.getName() + ": " + (v < 0 ? "<red>" : "<green>") +
"+" + v)));
item.getAttributes()
.forEach(
(k, v) ->
lore.add(
comp(
" <gray>➤ "
+ k.getName()
+ ": "
+ (v < 0 ? "<red>" : "<green>")
+ "+"
+ v)));
}
if (!item.getAbilities().isEmpty()) {
if (!item.getAbilities().isEmpty()) {
lore.add(comp("<gray>Abilities:"));
item.getAbilities().forEach(a -> {
lore.add(comp(" <gray>➤ " + a.getName() + ",<yellow> " + a.getDescription()));
lore.add(comp(" <dark_gray>cooldown: " + a.getCooldown() + "s,"));
lore.add(comp(" <dark_gray>damage: " + a.getDamage() + ","));
lore.add(comp(" <dark_gray>mana cost: <dark_aqua>" + a.getManaCost()));
});
item.getAbilities()
.forEach(
a -> {
lore.add(comp(" <gray>➤ " + a.getName() + ",<yellow> " + a.getDescription()));
lore.add(comp(" <dark_gray>cooldown: " + a.getCooldown() + "s,"));
lore.add(comp(" <dark_gray>damage: " + a.getDamage() + ","));
lore.add(comp(" <dark_gray>mana cost: <dark_aqua>" + a.getManaCost()));
});
}
if (!item.getEnchantments().isEmpty()) {
lore.add(comp("<dark_purple>Enchantments:"));
item.getEnchantments().forEach((k, v) -> lore.add(comp(" <blue>➤ " + k.getName() + " <if "
+ "max level gold>" + v)));
item.getEnchantments()
.forEach(
(k, v) ->
lore.add(comp(" <blue>➤ " + k.getName() + " <if " + "max level gold>" + v)));
}
stack.lore(lore);

View file

@ -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);
}
}
}

View file

@ -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<PotionEffect>) p.getActivePotionEffects());
public static void syncPlayerToSR(Player p, SRPlayer sr) {
sr.setInventory(p.getInventory());
sr.setPotionEffects((List<PotionEffect>) 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();
}
}