optimize import and code reformat
This commit is contained in:
parent
36f8e3f6f0
commit
64ef73f7e0
15 changed files with 379 additions and 371 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
+ "}";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue