Помогите Данные не записываются в конфиг + эвент не работает

Tildik

Участник
Баллы
31
У меня есть плагин, который при съедании еды с определенным названием выдает эффект, который указан в конфиге для еды с этим названием
Проблема: данные не записываются в конфиг + во время съедания еды с определенным эффектом ничего не происходит
------------Эвент---------------------
Код:
public class events implements Listener {
    public void onInteract(PlayerInteractEvent e) {
        if(e.getAction() != Action.RIGHT_CLICK_AIR && e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
        int num_config = Integer.parseInt(Main.getInstance().getConfig().getString("settings.count"));
        int num = 1;
        String effect = "none", durability = "none", sila = "none", name = "none";
        ItemStack itemStack = e.getItem();
        ItemMeta itemMeta = itemStack.getItemMeta();
        while(num > num_config) {
            String path = "eats." + num + ".name";
            if (Main.getInstance().getConfig().getString(path).equalsIgnoreCase(itemMeta.getDisplayName())) {

                effect = Main.getInstance().getConfig().getString("eats." + num + ".effect");
                durability = Main.getInstance().getConfig().getString("eats." + num + ".durability");
                sila = Main.getInstance().getConfig().getString("eats." + num + ".sila");
                name = Main.getInstance().getConfig().getString("eats." + num + ".name");
            }
            else{
                num++;
            }

        }
        if (effect.equalsIgnoreCase("none")) {
            return;
        }
        else {
            Player p = e.getPlayer();
            e.setCancelled(true);
            onRemoveItem(p);
            int sila1 = 1, durability1 = 15;
            try{
                durability = Main.getInstance().getConfig().getString("eats." + num + ".durability");
                sila = Main.getInstance().getConfig().getString("eats." + num + ".sila");
                sila1 = Integer.parseInt(sila);
                durability1 = Integer.parseInt(durability);
            }
            catch(NumberFormatException exception) {
                p.sendMessage("Продолжительность и сила указаны неверно!");
            }
            effect = Main.getInstance().getConfig().getString("eats." + num + ".effect");
            giveEffect(p, effect, durability1, sila1);
        }
    }
    private void onRemoveItem(Player p)
    {
        ItemStack item = p.getInventory().getItemInMainHand();
        item.setAmount(item.getAmount() - 1);
        p.getInventory().setItemInMainHand(item);
    }
    private void giveEffect(Player p, String effect, int durability, int sila) {
        if (effect.equalsIgnoreCase("POISON")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.POISON, durability, sila));
        }
        else if (effect.equalsIgnoreCase("SPEED")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, durability, sila));
        }
        else if (effect.equalsIgnoreCase("REGENERATION")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, durability, sila));
        }
        else if (effect.equalsIgnoreCase("BLINDNESS")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, durability, sila));
        }
        else if (effect.equalsIgnoreCase("NIGHT_VISION")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, durability, sila));
        }
        else if (effect.equalsIgnoreCase("HUNGER")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, durability, sila));
        }
        else if (effect.equalsIgnoreCase("GLOWING")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.GLOWING, durability, sila));
        }
        else if (effect.equalsIgnoreCase("SATURATION")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, durability, sila));
        }
        else if (effect.equalsIgnoreCase("LEVITATION")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, durability, sila));
        }
        else if (effect.equalsIgnoreCase("HEALTH_BOOST")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, durability, sila));
        }
        else if (effect.equalsIgnoreCase("INVISIBILITY")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, durability, sila));
        }
        else if (effect.equalsIgnoreCase("ABSORPTION")) {
            p.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, durability, sila));
        }



    }
}
----------Команда/Запись данных в конфиг---------------

Код:
public class EffectEat implements CommandExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        Player player = (Player) sender;
        ItemStack itemInMainHand = player.getInventory().getItemInMainHand();
        if(args.length == 0){
            player.sendMessage(ChatColor.RED + Main.getInstance().getConfig().getString("messages.noRequiredArgument"));
            return true;
        }
        else {
            if(itemInMainHand.getType() != Material.AIR) {
                try {
                    int a, b, c;
                    a = Integer.parseInt(args[1]);
                    a = Integer.parseInt(args[2]);

                } catch (NumberFormatException e) {
                    player.sendMessage(ChatColor.RED + Main.getInstance().getConfig().getString("message.NumberFormatException"));
                }
                ItemStack itemStack = player.getInventory().getItemInMainHand();
                int num_config = Integer.parseInt(Main.getInstance().getConfig().getString("settings.count"));
                num_config++;

                Main.getInstance().getConfig().set("settings.count", num_config);
                ItemMeta itemMeta = itemStack.getItemMeta();
                String name = itemMeta.getDisplayName();
                String path1 = "eats." + num_config + ".name";
                String path2 = "eats." + num_config + ".effect";
                String path3 = "eats." + num_config + ".durability";
                String path4 = "eats." + num_config + ".sila";

                Main.getInstance().getConfig().set(path1, name);
                Main.getInstance().getConfig().set(path2, args[0]);
                Main.getInstance().getConfig().set(path3, args[1]);
                Main.getInstance().getConfig().set(path4, args[2]);

                player.sendMessage(ChatColor.GREEN + Main.getInstance().getConfig().getString("messages.success"));

            }
            else{
                player.sendMessage(ChatColor.RED + Main.getInstance().getConfig().getString("messages.MaterialAIR"));
            }
        }

    return true;
    }
}
---------Конфиг---------------

Код:
settings:
  count: 1
# Переменную выше изменять нельзя! Его изменяет сам плагин
messages:
  MaterialAIR: 'Зачем мне выдавать эффект воздуху. ВОЗЬМИ ПРЕДМЕТ В РУКУ!'
  noRequiredArgument: 'Не хватает какого то из аргументов! Правильное использование команды: /effecteat <название эффекта на англ.> <длительность> <сила>'
  NumberFormatException: 'Я не смог преобразовать некоторые аргументы в числа! Правильное использование команды: /effecteat <название эффекта на англ.> <длительность> <сила>'
  success: 'Успех!'

eats:
  1:
    name: 'Тест'
    effect: 'POISON'
    durability: 10
    sila: 10
 
Назад
Верх