1. Вы находитесь в сообществе Rubukkit. Мы - администраторы серверов Minecraft, разрабатываем собственные плагины и переводим на различные языки плагины наших коллег из других стран.
    Скрыть объявление
Скрыть объявление
В преддверии глобального обновления, мы проводим исследования, которые помогут нам сделать опыт пользования форумом ещё удобнее. Помогите нам, примите участие!

[РЕШЕНО]Error: because "this.plugin" is null

Тема в разделе "Разработка плагинов для новичков", создана пользователем _MRDen3000YT_, 27 сен 2020.

Статус темы:
Закрыта.
  1. Автор темы
    _MRDen3000YT_

    _MRDen3000YT_ Активный участник Пользователь

    Баллы:
    76
    Добрый день столкнулся с проблемой: при запуске плагина ошибка:
    Код:
    [10:02:53 ERROR]: Error occurred while enabling bProtection v1.0 (Is it up to date?)
    java.lang.NullPointerException: Cannot invoke "bProtection.main.bProtection.getDataFolder()" because "this.plugin" is null
            at EventListeners.OnJoinListener.<init>(OnJoinListener.java:23) ~[?:?]
            at bProtection.main.bProtection.onEnable(bProtection.java:47) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot-1.12.2.jar:git-Spigot-dcd1643-e60fc34]
            at java.lang.Thread.run(Thread.java:832) [?:?]
    PHP:
    public class bProtection extends JavaPlugin {
        public static 
    ConcurrentHashMap<PlayerStringtokens = new ConcurrentHashMap<PlayerString>();
        public static List<
    Stringkeys = new ArrayList<>();
        private 
    Permission perm;

        public 
    void onEnable() {
            
    setupPermissions();

            
    CommandProtection cmd = new CommandProtection(permthis);
            
    getCommand("protection").setExecutor(cmd);

            
    File config = new File(getDataFolder() + File.separator "config.yml");
            if (!
    config.exists()) {
                
    getConfig().options().copyDefaults(true);
                
    saveDefaultConfig();

            }
            
    File adminsFile = new File(getDataFolder() + File.separator "admins.yml");
            if (!
    adminsFile.exists()) {
                try {
                    
    adminsFile.createNewFile();
                } catch (
    IOException e) {
                    
    e.printStackTrace();
                }

            }
            
    Bukkit.getPluginManager().registerEvents(new OnJoinListener(this), this);
            
    ConfigurationSection mainSection this.getConfig().getConfigurationSection("main");
            for (
    String key mainSection.getKeys(false)) {
                
    bProtection.keys.add(key);
                
    System.out.println(keys);
            }

        }

        private 
    boolean setupPermissions() {
            
    RegisteredServiceProvider<Permissionrsp getServer().getServicesManager().getRegistration(Permission.class);
            
    perm rsp.getProvider();
            return 
    perm != null;
        }

    }
    PHP:
    public class OnJoinListener implements Listener {


        private 
    bProtection plugin;

        public 
    OnJoinListener(bProtection plugin) {
            
    this.plugin plugin;
        }


        
    File adminsFile = new File(plugin.getDataFolder() + File.separator "admins.yml");
        
    FileConfiguration admins org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(adminsFile);
      

        @
    EventHandler
        
    public void onJoin(PlayerJoinEvent join) {
            
    Player player join.getPlayer();
            if (
    join.getPlayer().hasPermission("bProtection.admin")) {
                
    IPUtil.IPCompare(player);

            }

        }

    }
    23 строчка в OnJoinListener:
    Код:
    File adminsFile = new File(plugin.getDataFolder() + File.separator + "admins.yml"); 
    47 строчка в main class:
    Код:
    Bukkit.getPluginManager().registerEvents(new OnJoinListener(this), this);
    В чем проблема?
     
    Последнее редактирование: 27 сен 2020
  2. Nikolai_Faint

    Nikolai_Faint Активный участник Пользователь

    Баллы:
    96
    Время идёт, участники меняются, но код все такой же как из декомпилятора.

    Инициализацию переменных в конструктор закинь.
     
  3. alexandrage

    alexandrage Старожил Пользователь

    Баллы:
    173
    Прочитай и узнаешь. Ответ написан в ошибке.
    because "this.plugin" is null
     
  4. Автор темы
    _MRDen3000YT_

    _MRDen3000YT_ Активный участник Пользователь

    Баллы:
    76
    Код:
     Bukkit.getPluginManager().registerEvents(new OnJoinListener(this), this);
    Код:
        private bProtection plugin;
    
        public OnJoinListener(bProtection plugin) {
            this.plugin = plugin;
        }
    
     
  5. Nikolai_Faint

    Nikolai_Faint Активный участник Пользователь

    Баллы:
    96
    Крутой, только тебе виртуалка говорит об этом:
    upload_2020-9-28_5-29-24.png
     
  6. Code

    Code Старожил Пользователь

    Баллы:
    123
    Имя в Minecraft:
    _Gizmo
    учи порядок инициализации класса. от того что ты это написал ниже конструктора, оно позднее не выполнится
     
  7. Автор темы
    _MRDen3000YT_

    _MRDen3000YT_ Активный участник Пользователь

    Баллы:
    76
    Спасибо за помощь, учту :good: Решено, закрыто.
     
Статус темы:
Закрыта.

Поделиться этой страницей