Can not use my classes from other plugins

Discussion in 'Plugin Development' started by mr_nice1107, Oct 13, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    mr_nice1107

    Hey,
    I have a problem.

    The plugin is running on a Spigot 1.14.4 server
    I use the IntelliJ IDEA 2019.2.1 (Community Edition)

    I created a plugin with some basic features.
    And now I wand to access to it from a nother plugin.

    I already did this cind of stuff in the past so I add the the .jar file as a new dictunary from my base plugin and I thought if should be fine?
    The I go in the new plugin and imported the stuff from the base plugin.
    That worked so far and I got no errors while building
    now I started the server and get this error:

    Error (open)

    java.lang.NullPointerException: null
    at ...base.Utils.<init>(Utils.java:29) ~[?:?]
    at ...chestlock.listener.BlockListener.<init>(BlockListener.java:14) ~[?:?]
    at ...chestlock.Main.loadListener(Main.java:36) ~[?:?]
    at ...chestlock.Main.onEnable(Main.java:21) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:810) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.Bukkit.reload(Bukkit.java:576) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:433) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:397) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:971) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:816) [spigot-1.14.4.jar:git-Spigot-9de398a-9c887d4]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]


    Utils.java:29
    Code:
    private final File help = new File(plugin.getDataFolder().getPath(), "help.yml");
    BlockListener.java:14
    Code:
    private Utils utils = new Utils(prefix);
    so what can I do now and where is the issue?
     
  2. Online

    timtower Administrator Administrator Moderator

    @mr_nice1107 Please post the full classes.
    My bet is that you are accessing variables that aren't set yet.
     
  3. Offline

    Dai_Kunai

    At least post main.java class in chestlock line 21.
     
  4. Offline

    mr_nice1107

    Ok at first thank you for replys.

    My classes are looking like this:
    Code:
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin {
    private String prefix;
    private static Main instance;
    
    @Override
    public void onEnable() {
      prefix = "§7[§dChestLock§7]: ";
      instance = this;
      loadListener(); // <-- line 21 in main
      Bukkit.getConsoleSender().sendMessage(prefix+"§aEnabled");
    }
    
    private void loadListener() {
      Bukkit.getPluginManager().registerEvents(new BlockListener(), this);
    }
    public String getPrefix() {
      return prefix;
    }
    private Main getInstance() {
      return instance;
    }
    }
    Code:
    import ...chestlock.Main;
    import ...base.Utils;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    public class listenerChest implements Listener {
    private Main plugin = Main.getInstance(); // I don't have to import the Main class because it is in the same package
    private Utils utils = new Utils(plugin.getPrefix());
    
    @EventHandler
    public void onTest(BlockBreakEvent e) {
      e.setCancelled(true)
    }
    }
    Code:
    import ...base.Main;
    
    public class Utils {
    private final Main plugin = Main.getInstance();
    private final String prefix;
    private final File help = new File(plugin.getDataFolder().getPath(), "help.yml");
    private final File player = new File(plugin.getDataFolder().getPath(), "player.yml");
    private final File log = new File(plugin.getDataFolder().getPath(), "log.yml");
    public Utils(String prefix) { this.prefix = prefix; }
    }
    That are the involved classes I think
     
    Last edited by a moderator: Oct 14, 2019
  5. Offline

    mr_nice1107

    Ok I now tryed to update my InteliJ but it still don't work
    Now I just put the chestLock stuff in the core plugin... that worked but that is not a good solution because I want to make many plugins that all based of the core plugin instead of one big one

    So thank you for the support till now I cind of solved the issue but I would be realy happy if someone can help me with this problem so I can make independent smal plugins that all just need the core plugin instead of one big one that have many features but not all needed...
     
Thread Status:
Not open for further replies.

Share This Page