Вопрос hasCustomEffect в PotionMeta

Destroy

Разработчик
Пользователь
Сообщения
777
Решения
30
Веб-сайт
destroydevs.ru
Java:
            if(e.getSlot() == Menu.getMixedPotionSlot() && e.getInventory().getItem(Menu.getMixedPotionSlot()) != null) {
                e.getWhoClicked().sendMessage("6");
                e.setCancelled(true);
                int chance = (int) (Math.random() * 100);
                if(e.getInventory().getItem(Menu.getFirstPotionSlot()) == null || e.getInventory().getItem(Menu.getSecondPotionSlot()) == null) {
                    // положите 2 зелья чтобы скрестить их
                    e.getWhoClicked().sendMessage("7");
                    return;
                }
                if(chance <= Storage.chance.get(e.getWhoClicked().getUniqueId())) {
                    ItemStack item = new ItemStack(Material.POTION);
                    PotionMeta meta = (PotionMeta) item.getItemMeta();
                    ItemStack item1 = e.getInventory().getItem(Menu.getFirstPotionSlot());
                    ItemStack item2 = e.getInventory().getItem(Menu.getSecondPotionSlot());
                    if(item1 == null || item2 == null) {
                        e.getWhoClicked().sendMessage("null items");
                        return;
                    }
                    PotionMeta meta1 = (PotionMeta) item1.getItemMeta();
                    PotionMeta meta2 = (PotionMeta) item2.getItemMeta();
                    if(meta == null || meta1 == null || meta2 == null) {
                        e.getWhoClicked().sendMessage("null meta");
                        return;
                    }

                    if(meta1.hasCustomEffects()) {
                        for (PotionEffect effect : meta1.getCustomEffects()) {
                            meta.addCustomEffect(effect, true);
                        }
                    }

                    if(meta2.hasCustomEffects()) {
                        for (PotionEffect effect : meta2.getCustomEffects()) {
                            meta.addCustomEffect(effect, true);
                        }
                    }

                    meta.setColor(Color.ORANGE);

                    item.setItemMeta(meta);
                    e.getInventory().setItem(Menu.getFirstPotionSlot(), new ItemStack(Material.AIR));
                    e.getInventory().setItem(Menu.getSecondPotionSlot(), new ItemStack(Material.AIR));
                    Storage.price.put(e.getWhoClicked().getUniqueId(), Menu.getChanceGiverPrice());
                    Storage.chance.put(e.getWhoClicked().getUniqueId(), Menu.getStandardChance());
                    e.getWhoClicked().getInventory().addItem(item);
                    Alchemist.update((Player) e.getWhoClicked(), e.getInventory());
                    // УСПЕХ
                    e.getWhoClicked().sendMessage("8");
                } else {
                    e.getInventory().setItem(Menu.getFirstPotionSlot(), new ItemStack(Material.AIR));
                    e.getInventory().setItem(Menu.getSecondPotionSlot(), new ItemStack(Material.AIR));
                    Storage.price.put(e.getWhoClicked().getUniqueId(), Menu.getChanceGiverPrice());
                    Storage.chance.put(e.getWhoClicked().getUniqueId(), Menu.getStandardChance());
                    Alchemist.update((Player) e.getWhoClicked(), e.getInventory());
                    // НЕУДАЧА
                    e.getWhoClicked().sendMessage("9");
                }
            }

в начале идёт проверка на зелья без эффектов (она проваливается хотя я беру зелья исключительно с эффектами)
Java:
            if(e.getCurrentItem() != null && e.getCurrentItem().getType() == Material.POTION) {
                PotionMeta meta = (PotionMeta) e.getCurrentItem().getItemMeta();

                if(meta == null) {
                    e.getWhoClicked().sendMessage("null meta1");
                    return;
                }

                if(!meta.hasCustomEffects()) {
                    // можно брать только зелья с эффектами
                    e.getWhoClicked().sendMessage("5");
                    e.setCancelled(true);
                    return;
                }
            }
выводит цифру 5. Повторюсь, нажимаю я исключительно на зелья с эффектами.

Так-же если каким-то образом получится положить предмет в слоты для зелий и нажать на смешивание их - получается "Несоздаваемое зелье" без эффектов.
При этом зелья так-же с эффектами.

Как можно заменить getCustomPotionEffects?
 
hasCustomEffects() выводит именно кастомные эффекты, а не вообще все. Как то сам тоже потратил много времени из-за этого.

Вот мой итоговый код для теста зелий на наличие эффектов
 

Вложения

  • 2023-01-23_23-56-13.png
    2023-01-23_23-56-13.png
    44.7 KB · Просмотры: 22
hasCustomEffects() выводит именно кастомные эффекты, а не вообще все. Как то сам тоже потратил много времени из-за этого.

Вот мой итоговый код для теста зелий на наличие эффектов
Java:
                    if(meta1.hasCustomEffects()) {
                        for(PotionEffect effect : meta1.getCustomEffects()) {
                            meta.addCustomEffect(effect, true);
                        }
                    } else if(meta1.getBasePotionData().getType().getEffectType() != null) {
                        PotionEffect potionEffect;
                        PotionData data = meta1.getBasePotionData();
                        if(data.isUpgraded()) {
                            potionEffect = new PotionEffect(data.getType().getEffectType(), 90*20, 1);
                            if(pt4.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 22*20, 1);
                            }
                        } else {
                            potionEffect = new PotionEffect(data.getType().getEffectType(), 3*60*20, 0);
                            if(pt2.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 2*60*20, 0);
                            }
                            if(pt4.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 45*20, 0);
                            }
                        }
                        if(data.isExtended()) {
                            potionEffect = new PotionEffect(data.getType().getEffectType(), 8*60*20, 0);
                            if(pt2.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 4*60*20, 0);
                            }
                            if(pt4.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 30*3*20, 1);
                            }
                        }
                        if(pt3.contains(data.getType())) {
                            if(data.isUpgraded()) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 0, 1);
                            } else {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 0, 0);
                            }
                        }
                        if(pt.contains(data.getType())) {
                            if(data.isExtended()) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 8 * 60 * 20, 0);
                            } else {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 3 * 60 * 20, 0);
                            }
                        }
                        if(data.getType() == PotionType.TURTLE_MASTER) {
                            PotionEffect potionEffect1;
                            PotionEffect potionEffect2;
                            if(data.isUpgraded()) {
                                potionEffect1 = new PotionEffect(PotionEffectType.SLOW, 20 * 20, 3);
                                potionEffect2 = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20 * 20, 3);
                            } else if(data.isExtended()) {
                                potionEffect1 = new PotionEffect(PotionEffectType.SLOW, 40 * 20, 3);
                                potionEffect2 = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 40 * 20, 2);
                            } else {
                                potionEffect1 = new PotionEffect(PotionEffectType.SLOW, 20 * 20, 3);
                                potionEffect2 = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20 * 20, 2);
                            }
                            meta.addCustomEffect(potionEffect1, true);
                            meta.addCustomEffect(potionEffect2, true);
                        } else {
                            meta.addCustomEffect(potionEffect, true);
                        }
                    }

                    if(meta2.hasCustomEffects()) {
                        for(PotionEffect effect : meta2.getCustomEffects()) {
                            meta.addCustomEffect(effect, true);
                        }
                    } else if(meta2.getBasePotionData().getType().getEffectType() != null) {
                        PotionEffect potionEffect;
                        PotionData data = meta2.getBasePotionData();
                        if(data.isUpgraded()) {
                            potionEffect = new PotionEffect(data.getType().getEffectType(), 90*20, 1);
                            if(pt4.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 22*20, 1);
                            }
                        } else {
                            potionEffect = new PotionEffect(data.getType().getEffectType(), 3*60*20, 0);
                            if(pt2.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 2*60*20, 0);
                            }
                            if(pt4.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 45*20, 0);
                            }
                        }
                        if(data.isExtended()) {
                            potionEffect = new PotionEffect(data.getType().getEffectType(), 8*60*20, 0);
                            if(pt2.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 4*60*20, 0);
                            }
                            if(pt4.contains(data.getType())) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 30*3*20, 1);
                            }
                        }
                        if(pt3.contains(data.getType())) {
                            if(data.isUpgraded()) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 0, 1);
                            } else {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 0, 0);
                            }
                        }
                        if(pt.contains(data.getType())) {
                            if(data.isExtended()) {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 8 * 60 * 20, 0);
                            } else {
                                potionEffect = new PotionEffect(data.getType().getEffectType(), 3 * 60 * 20, 0);
                            }
                        }
                        if(data.getType() == PotionType.TURTLE_MASTER) {
                            PotionEffect potionEffect1;
                            PotionEffect potionEffect2;
                            if(data.isUpgraded()) {
                                potionEffect1 = new PotionEffect(PotionEffectType.SLOW, 20 * 20, 3);
                                potionEffect2 = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20 * 20, 3);
                            } else if(data.isExtended()) {
                                potionEffect1 = new PotionEffect(PotionEffectType.SLOW, 40 * 20, 3);
                                potionEffect2 = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 40 * 20, 2);
                            } else {
                                potionEffect1 = new PotionEffect(PotionEffectType.SLOW, 20 * 20, 3);
                                potionEffect2 = new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 20 * 20, 2);
                            }
                            meta.addCustomEffect(potionEffect1, true);
                            meta.addCustomEffect(potionEffect2, true);
                        } else {
                            meta.addCustomEffect(potionEffect, true);
                        }
                    }
 
Назад
Сверху Снизу