Помогите Не работают оповещения

thematdev

Активный участник
Пользователь
Баллы
46
Имя в Minecraft
thematdev
Проблема в том, что просто никаких оповещений нету, ни в консоль не на сервер игрокам, никуда в общем, ошибок нет. Класс Configuration просто был сделан чтобы сразу получать параметры, тут говнокод, казалось бы напрямую получаем и напрямую создаем обьект класса(в Configuration был метод, который возвращает объект класса).
config:

HTML:
auto:
  notifications:
    chat:
      main:
        delay: 10
        prefix: '[Test]'
        messages:
        - 'Приветствуем Вас на нашем проекте!'
        - 'Тест'
        permission: true
    advancement:
      main:
        delay: 10
        messages:
        - icon: 'minecraft:diamond'
          header: '228'
          footer: '228'
        - icon: 'minecraft:gold_ingot'
          header: 'gay'
          footer: 'gay'
        permission: true
PHP:
package ru.thematdev.cm.config;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import ru.thematdev.cm.auto.notification.AdvancementNotification;
import ru.thematdev.cm.auto.notification.ChatNotification;
import ru.thematdev.cm.main.Main;

public class Configuration {
    
    public FileConfiguration config;
    private ConfigurationSection notificationSection;
    private ConfigurationSection chatSection;
    private ConfigurationSection advSection;
    
    private JavaPlugin plugin;
    
    public Configuration(JavaPlugin plugin) {
        
        this.plugin = plugin;
        
        setConfig(plugin.getConfig());
        this.notificationSection = getConfig().getConfigurationSection("auto.notifications");
        this.chatSection = notificationSection.getConfigurationSection("chat");
        this.advSection = notificationSection.getConfigurationSection("advancement");
        
    }

    public FileConfiguration getConfig() {
        return config;
    }

    public void setConfig(FileConfiguration config) {
        this.config = config;
    }

    public ConfigurationSection getNotificationSection() {
        return notificationSection;
    }
    public ConfigurationSection getChatSection() {
        return chatSection;
    }
    public ConfigurationSection getAdvSection() {
        return advSection;
    }
    
    public ChatNotification getChatNotificationByNode(String node) {
        return new ChatNotification(node, this.config.getDouble(chatSection.getCurrentPath() + "." + node + ".delay"), this.config.getString(chatSection.getCurrentPath() + "." + node + ".prefix"), this.config.getStringList(chatSection.getCurrentPath() + "." + node + ".messages"), this.config.getBoolean(chatSection.getCurrentPath() + "." + node + ".permission"), this.plugin);
    }
    
    public AdvancementNotification getAdvancementNotificationByNode(String node) {
        return new AdvancementNotification(node, this.config.getDouble(advSection.getCurrentPath() + "." + node + ".delay"), this.config.getMapList(advSection.getCurrentPath() + "." + node + ".messages"), this.config.getBoolean(advSection.getCurrentPath() + "." + node + ".permission"), this.plugin);
    }
    
}
PHP:
package ru.thematdev.cm.main;


import java.util.logging.Logger;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

import ru.thematdev.cm.auto.AutoMessage;
import ru.thematdev.cm.auto.join.AMJoinListener;
import ru.thematdev.cm.command.ChatExecutor;
import ru.thematdev.cm.prefix.MessageEditor;

public class Main extends JavaPlugin{
    
    public Logger logger;
    public FileConfiguration config;
    
    public void onEnable() {
        logger = getServer().getLogger();
        logger.info("Cm by thematdev enabled!");
        
        config = getConfig();
        
        config.options().copyDefaults();
        this.saveConfig();
        
        
        new AutoMessage(this);
        
        registerCommands();
        registerEvents();
    }
    
    public void onDisable() {
        logger.info("Cm by thematdev disabled!");
    }
    
    public void registerEvents() {
        
        getServer().getPluginManager().registerEvents(new ChatExecutor(this), this);
        getServer().getPluginManager().registerEvents(new MessageEditor(), this);
        getServer().getPluginManager().registerEvents(new AMJoinListener(), this);
        
    }
    public void registerCommands() {
        
        getCommand("chat").setExecutor(new ChatExecutor(this));
        
    }

}
PHP:
package ru.thematdev.cm.auto;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;

import ru.thematdev.cm.auto.command.AutoMessageExecutor;
import ru.thematdev.cm.auto.notification.AdvancementNotification;
import ru.thematdev.cm.auto.notification.ChatNotification;
import ru.thematdev.cm.config.Configuration;
import ru.thematdev.cm.main.Main;
import ru.thematdev.cm.util.Utils;

public class AutoMessage {
    
    JavaPlugin plugin;
    private Configuration configuration;
    private List<ChatNotification> chatNotifications
    = new ArrayList<>();
    private List<AdvancementNotification> advancementNotifications
    = new ArrayList<>();
            
    public AutoMessage(JavaPlugin plugin) {
        
        this.plugin = plugin;
        
        configuration = new Configuration(plugin);
        
        for (String node : configuration.getChatSection().getKeys(false)) {
            
            ChatNotification notification = new ChatNotification(node, configuration.config.getDouble(configuration.getChatSection().getCurrentPath() + "." + node + ".delay"), configuration.config.getString(configuration.getChatSection().getCurrentPath() + "." + node + ".prefix"), configuration.getChatSection().getStringList(configuration.getChatSection().getCurrentPath() + "." + node + ".messages"), configuration.config.getBoolean(configuration.getChatSection().getCurrentPath() + "." + node + ".permission"), this.plugin);
            chatNotifications.add(notification);
            
        }
        for (String node : configuration.getAdvSection().getKeys(false)) {
            
            AdvancementNotification notification = new AdvancementNotification(node, configuration.config.getDouble(configuration.getChatSection().getCurrentPath() + "." + node + ".delay"), configuration.getChatSection().getMapList(configuration.getChatSection().getCurrentPath() + "." + node + ".messages"), configuration.config.getBoolean(configuration.getChatSection().getCurrentPath() + "." + node + ".permission"), this.plugin);
            advancementNotifications.add(notification);
        
        }
}
}
PHP:
package ru.thematdev.cm.auto.notification;


import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

import ru.thematdev.cm.main.Main;

public abstract class Notification {
    
    public static final String NOTIFICATION_NODE = "cm.auto.notification";

    
    public BukkitTask task;
    public final boolean permission;
    
    private double delay;
    private JavaPlugin plugin;
    
    public Notification(double delay, boolean permission, JavaPlugin plugin) {
        
        
        
        task = Bukkit.getScheduler().runTaskTimer(plugin, this::run, (long) delay * 20, (long) delay * 20);
        this.permission = permission;
        
    }
    
    public void cancel() {
        if (task != null) {
            task.cancel();
        }
    }
    
    public void start() {
        task = Bukkit.getScheduler().runTaskTimer(plugin, this::run, (long) delay * 20, (long) delay * 20);
    }
    
    public abstract void run();

}
package ru.thematdev.cm.auto.notification;
import java.util.List;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import ru.thematdev.cm.main.Main;
import ru.thematdev.cm.refl.Reflection;
public class AdvancementNotification extends Notification{

private static final String PERMISSION_NODE = NOTIFICATION_NODE + "advancement.%s";
private final List<Map<?, ?>> messages;
private final String name;
private JavaPlugin plugin;

private int current = -228;


public AdvancementNotification(String name, double delay, List<Map<?, ?>> messages, boolean permission, JavaPlugin plugin) {
super(delay, permission, plugin);
this.name = name;
this.plugin = plugin;
this.messages = messages;
}
@SuppressWarnings("unchecked")
@Override
public void run() {
if (current < 0 || messages.size() <= ++current) {
current = 0;
}
@SuppressWarnings("all")
AdvancementMessage advancementMessage = new AdvancementMessage((Map<String, String>) messages.get(current), plugin);
Reflection.getOnlinePlayers().stream().filter(player -> permission || player.hasPermission(String.format(PERMISSION_NODE, name))).forEach(advancementMessage::show);

plugin.getLogger().info("Advancement Notification " + name);

}


}
 
Казалось бы у обоих типов Notification в конструкторе обращение к конструктору предка, но почему-то Task не регистрируется.
 
Извините за аутизм... При обновлении билда кора слетел конфиг. Я даун что сказать.
 
Я даун(x2) выдаёт ошибку:
HTML:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_73]
    at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_73]
    at ru.thematdev.cm.auto.notification.ChatNotification.run(ChatNotification.java:36) ~[?:?]
    at org.bukkit.craftbukkit.v1_13_R1.scheduler.CraftTask.run(CraftTask.java:76) ~[spigot-latest.jar:git-Spigot-1503de9-200b239]
    at org.bukkit.craftbukkit.v1_13_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:361) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.MinecraftServer.w(MinecraftServer.java:877) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.DedicatedServer.w(DedicatedServer.java:411) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.MinecraftServer.v(MinecraftServer.java:819) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.MinecraftServer.run(MinecraftServer.java:717) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
ChatNotification
upload_2018-8-8_22-51-54.png
Как вызывается:
hatNotification notification = new ChatNotification(node, configuration.config.getDouble(configuration.getChatSection().getCurrentPath() + "." + node + ".delay"), configuration.config.getString(configuration.getChatSection().getCurrentPath() + "." + node + ".prefix"), configuration.getChatSection().getStringList(configuration.getChatSection().getCurrentPath() + "." + node + ".messages"), configuration.config.getBoolean(configuration.getChatSection().getCurrentPath() + "." + node + ".permission"), this.plugin);
Конфиг:
PHP:
auto:
  notifications:
    chat:
      main:
        delay: 10
        prefix: '[Test]'
        messages:
        - '������������ ��� �� ����� �������!'
        - '����'
        permission: true
    advancement:
      main:
        delay: 10
        messages:
        - icon: minecraft:diamond
          header: '228'
          footer: '228'
        - icon: minecraft:gold_ingot
          header: 'gay'
          footer: 'gay'
        permission: true
 
Я даун(x2) выдаёт ошибку:
HTML:
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.8.0_73]
    at java.util.ArrayList.get(Unknown Source) ~[?:1.8.0_73]
    at ru.thematdev.cm.auto.notification.ChatNotification.run(ChatNotification.java:36) ~[?:?]
    at org.bukkit.craftbukkit.v1_13_R1.scheduler.CraftTask.run(CraftTask.java:76) ~[spigot-latest.jar:git-Spigot-1503de9-200b239]
    at org.bukkit.craftbukkit.v1_13_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:361) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.MinecraftServer.w(MinecraftServer.java:877) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.DedicatedServer.w(DedicatedServer.java:411) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.MinecraftServer.v(MinecraftServer.java:819) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at net.minecraft.server.v1_13_R1.MinecraftServer.run(MinecraftServer.java:717) [spigot-latest.jar:git-Spigot-1503de9-200b239]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_73]
Как вызывается:
hatNotification notification = new ChatNotification(node, configuration.config.getDouble(configuration.getChatSection().getCurrentPath() + "." + node + ".delay"), configuration.config.getString(configuration.getChatSection().getCurrentPath() + "." + node + ".prefix"), configuration.getChatSection().getStringList(configuration.getChatSection().getCurrentPath() + "." + node + ".messages"), configuration.config.getBoolean(configuration.getChatSection().getCurrentPath() + "." + node + ".permission"), this.plugin);
Конфиг:
PHP:
auto:
  notifications:
    chat:
      main:
        delay: 10
        prefix: '[Test]'
        messages:
        - '������������ ��� �� ����� �������!'
        - '����'
        permission: true
    advancement:
      main:
        delay: 10
        messages:
        - icon: minecraft:diamond
          header: '228'
          footer: '228'
        - icon: minecraft:gold_ingot
          header: 'gay'
          footer: 'gay'
        permission: true
Ты из листа messages пытаешься достать данные с несуществующим индексом.
 
Назад
Верх