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

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