This commit is contained in:
parent
1380e7479a
commit
5ffb921150
7 changed files with 174 additions and 78 deletions
|
@ -1,6 +1,7 @@
|
|||
package me.unurled.sacredrealms.sr.utils;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
import static me.unurled.sacredrealms.sr.utils.SRPlayerUtils.syncSRToPlayer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -9,6 +10,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.item.Item;
|
||||
import me.unurled.sacredrealms.sr.components.item.ItemManager;
|
||||
import me.unurled.sacredrealms.sr.components.player.PlayerManager;
|
||||
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
|
@ -19,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
|||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public class Items {
|
||||
public static @NotNull Double getTotalAttribute(Player player, Attribute attribute) {
|
||||
public static @NotNull Double getTotalAttribute(@NotNull Player player, Attribute attribute) {
|
||||
return getTotalAttribute(player.getEquipment(), attribute);
|
||||
}
|
||||
|
||||
|
@ -51,18 +54,17 @@ public class Items {
|
|||
return i.getAttribute(attribute);
|
||||
}
|
||||
}
|
||||
if (p.has(attribute.getKey(), PersistentDataType.DOUBLE)) {
|
||||
try {
|
||||
return p.get(attribute.getKey(), PersistentDataType.DOUBLE);
|
||||
} catch (Exception e) {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
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
|
||||
*
|
||||
* @param stack the itemstack
|
||||
* @return the itemstack with lore
|
||||
|
@ -118,4 +120,36 @@ public class Items {
|
|||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static void updatePlayer(@NotNull Player player, ItemStack oldItem, ItemStack newItem) {
|
||||
PlayerManager pm = (PlayerManager) PlayerManager.getInstance(PlayerManager.class);
|
||||
if (pm == null) {
|
||||
return;
|
||||
}
|
||||
SRPlayer p = pm.getPlayer(player.getUniqueId());
|
||||
if (p == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemManager im = (ItemManager) ItemManager.getInstance(ItemManager.class);
|
||||
if (im == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove status of old Item
|
||||
if (oldItem != null && !oldItem.getType().equals(Material.AIR)) {
|
||||
for (Attribute a : Attribute.values()) {
|
||||
p.removeItemAttributes(a, oldItem);
|
||||
}
|
||||
}
|
||||
|
||||
// add status of new Item
|
||||
if (newItem != null && !newItem.getType().equals(Material.AIR)) {
|
||||
for (Attribute a : Attribute.values()) {
|
||||
p.setItemAttributes(a, newItem, getAttribute(newItem, a));
|
||||
}
|
||||
}
|
||||
|
||||
syncSRToPlayer(p, player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package me.unurled.sacredrealms.sr.utils;
|
||||
|
||||
public class NumberParser {
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package me.unurled.sacredrealms.sr.utils;
|
|||
import java.util.List;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.player.SRPlayer;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
|
@ -17,7 +18,17 @@ public class SRPlayerUtils {
|
|||
|
||||
// agility (speed)
|
||||
// default is 100 so 0.2
|
||||
float value = (float) (sr.getAttribute(Attribute.AGILITY) / 500.0);
|
||||
double items = sr.getTotalItemAttribute(Attribute.AGILITY);
|
||||
double speed = sr.getAttribute(Attribute.AGILITY);
|
||||
float value = (float) ((speed + items) / 500.0f);
|
||||
value = Math.min(value, 1.0f);
|
||||
value = Math.max(value, 0f);
|
||||
AttributeInstance attribute1 =
|
||||
p.getAttribute(org.bukkit.attribute.Attribute.GENERIC_MOVEMENT_SPEED);
|
||||
if (attribute1 != null) attribute1.setBaseValue(value);
|
||||
AttributeInstance attribute2 =
|
||||
p.getAttribute(org.bukkit.attribute.Attribute.GENERIC_FLYING_SPEED);
|
||||
if (attribute2 != null) attribute2.setBaseValue(value);
|
||||
p.setFlySpeed(value);
|
||||
p.setWalkSpeed(value);
|
||||
|
||||
|
@ -27,7 +38,10 @@ public class SRPlayerUtils {
|
|||
|
||||
// health
|
||||
// default is 100 so 20
|
||||
p.setHealth(sr.getAttribute(Attribute.HEALTH) / 5);
|
||||
double health =
|
||||
(sr.getAttribute(Attribute.HEALTH) + sr.getTotalItemAttribute(Attribute.HEALTH)) / 5;
|
||||
AttributeInstance attribute = p.getAttribute(org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH);
|
||||
if (attribute != null) attribute.setBaseValue(health);
|
||||
p.sendHealthUpdate();
|
||||
p.updateInventory();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue