#Problem with plugin logic, can't figure it out

1 messages · Page 1 of 1 (latest)

shut depot
austere birch
#

what ChatColor.stripColor("Waffen verzaubern")

#

i guess you want to strip the title name

wooden cave
#

Could you describe what the problem is exactly? What's not working?

shut depot
shut depot
austere birch
#

yes

shut depot
#

thanks

#

can I strip the title?

austere birch
#

yes

shut depot
#

how?

#

there is no chatcolor.stripstring or something

austere birch
#

literally what you used ChatColor.stripColor

shut depot
#

wait

#

then I was correct

#

but then why isn't it working

austere birch
#

if (ChatColor.stripColor(title).equals("smth"))

shut depot
#

yea thats what I did

#

if (!title.equals(ChatColor.stripColor("Werkzeuge verzaubern"))) return;

wooden cave
shut depot
#

it doesn't apply the enchantment

austere birch
shut depot
#

no the other way around+

#

I detect if the menu im in is the right one by checking the title

wooden cave
#

When is the error happening? If you put an item in, does it work or is the problem when you try and click a book?

shut depot
#

if I put Main.log.info("test"); below all my checks it doesn't show up in the console

austere birch
#

bruh you're literally checking if the title equals Waffen verzaubern, where it will be something like §cWaffen verzaubern so you're not stripping the color codes from the title before comparing it

shut depot
#

that means even if I do everything right the checks arent passed

shut depot
#

ChatColor.stripColor removes all colors

austere birch
#

the string you're passing doesnt have any color codes

shut depot
shut depot
#

OH

#

I am stripping the wrong string...

austere birch
#

yes

shut depot
#

if it works now I am quitting spigot development and becoming a professional fortnite youtuber

wooden cave
#

By the way, when making custom enchantments, I'd really recommend using PDC instead of the enchantment API, as pdc's are more resilient and enchantments can be buggy, especially when loading/unloading them.

shut depot
#

PDC?

wooden cave
#

persistent data container

#

I see you aren't making custom enchants and just applying vanilla ones, maybe you should use a hashmap linking the enchanted book displayNames to an actual enchantment object and applying that object, it'd be simpler than building your own wrapper.

austere birch
shut depot
#

I am not doing custom enchantments

shut depot
wooden cave
#
public class linkedEnchants{
public static HashMap<String, Enchantment> linkEnchants{
HashMap<> ench = new HashMap<String, Enchantment>;
ench.add("Unbreaking", Enchantment.DURABILITY)
// etc...
}}```

then, when applying enchantments:

switch (ChatColor.stripColor(e.getCurrentItem().getItemMeta().getDisplayName())) {
case "Unbreaking" -> {
e.setCancelled(true);
Enchantment ench = linkedEnchants.linkEnchants.get("Unbreaking");
item.addEnchantment(ench);
}```

#

I think something like this could be better lol