utils
This commit is contained in:
parent
241feba114
commit
932a74dc42
4 changed files with 144 additions and 14 deletions
|
@ -4,8 +4,8 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||
|
||||
public class Component {
|
||||
|
||||
public static net.kyori.adventure.text.Component comp(String msg) {
|
||||
MiniMessage mm = MiniMessage.miniMessage();
|
||||
return mm.deserialize(msg);
|
||||
}
|
||||
public static net.kyori.adventure.text.Component comp(String msg) {
|
||||
MiniMessage mm = MiniMessage.miniMessage();
|
||||
return mm.deserialize(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package me.unurled.sacredrealms.sr.utils;
|
||||
|
||||
import static me.unurled.sacredrealms.sr.utils.Component.comp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import me.unurled.sacredrealms.sr.components.attributes.Attribute;
|
||||
import me.unurled.sacredrealms.sr.components.item.Item;
|
||||
|
@ -24,17 +28,12 @@ public class Items {
|
|||
|
||||
AtomicReference<Double> total = new AtomicReference<>(0.0);
|
||||
|
||||
Arrays.stream(inv.getArmorContents()).toList().forEach(item ->
|
||||
total.updateAndGet(
|
||||
v -> (v + getAttribute(item,
|
||||
attribute))));
|
||||
Arrays.stream(inv.getArmorContents())
|
||||
.toList()
|
||||
.forEach(item -> total.updateAndGet(v -> (v + getAttribute(item, attribute))));
|
||||
|
||||
total.updateAndGet(
|
||||
v -> (v + getAttribute(inv.getItemInMainHand(),
|
||||
attribute)));
|
||||
total.updateAndGet(
|
||||
v -> (v + getAttribute(inv.getItemInOffHand(),
|
||||
attribute)));
|
||||
total.updateAndGet(v -> (v + getAttribute(inv.getItemInMainHand(), attribute)));
|
||||
total.updateAndGet(v -> (v + getAttribute(inv.getItemInOffHand(), attribute)));
|
||||
|
||||
return total.get();
|
||||
}
|
||||
|
@ -53,4 +52,68 @@ 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
|
||||
*
|
||||
* @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);
|
||||
if (im == null) return stack;
|
||||
if (stack == null) return stack;
|
||||
if (stack.getType().equals(Material.AIR)) return stack;
|
||||
PersistentDataContainer p = stack.getItemMeta().getPersistentDataContainer();
|
||||
if (!p.has(ItemManager.ID, PersistentDataType.STRING)) return stack;
|
||||
Item item = im.getItem(p.get(ItemManager.ID, PersistentDataType.STRING));
|
||||
|
||||
List<net.kyori.adventure.text.Component> lore = new ArrayList<>();
|
||||
|
||||
lore.add(comp("<b>" + item.getRarity().getName()));
|
||||
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)));
|
||||
}
|
||||
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()));
|
||||
});
|
||||
}
|
||||
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)));
|
||||
}
|
||||
|
||||
stack.lore(lore);
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
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.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 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();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue