Error with string and integers

Discussion in 'Plugin Development' started by thechrisanator, Nov 29, 2018.

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

    thechrisanator

    Code:
    public class CreateRequest implements Listener {
      
        public GrandMinechange main; //initialize the main variable as Type main class
        public CreateRequest(GrandMinechange plugin) {
            this.main = plugin; //set it equal to an instance of main
        }
      
        public Inventory createInventory() {
          
          
            Inventory crinv = Bukkit.getServer().createInventory(null, 54, ChatColor.GREEN + "Create A Request");
          
          
            ItemStack reqstack = new ItemStack(Material.BLACK_CONCRETE, 1);
            ItemMeta reqmeta = reqstack.getItemMeta();
            reqmeta.setDisplayName(ChatColor.GREEN.toString() + ChatColor.BOLD.toString() + "Drag Desired Item Here"); //Placeholder item
            reqstack.setItemMeta(reqmeta);
            crinv.setItem(13, reqstack);
          
          
            (LINE 34) -> System.out.println(main.maxRequestAmount());
            List<String> lore = Arrays.asList(ChatColor.YELLOW.toString() + "Maximum is ".toString());
    error:
    Code:
    [19:05:05 ERROR]: Could not pass event InventoryClickEvent to TheGrandMinechange v1.0.0
    org.bukkit.event.EventException: null
            at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:72) ~[patched_1.13.2.jar:git-Paper-448]
            at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78) ~[patched_1.13.2.jar:git-Paper-448]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[patched_1.13.2.jar:git-Paper-448]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:513) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:2280) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.PacketPlayInWindowClick.a(SourceFile:33) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.PacketPlayInWindowClick.a(SourceFile:10) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:12) ~[patched_1.13.2.jar:git-Paper-448]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_191]
            at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_191]
            at net.minecraft.server.v1_13_R2.SystemUtils.a(SystemUtils.java:109) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:1016) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:439) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:943) ~[patched_1.13.2.jar:git-Paper-448]
            at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:841) ~[patched_1.13.2.jar:git-Paper-448]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: java.lang.NullPointerException
            at me.Darkolythe.GrandMinechange.CreateRequest.createInventory(CreateRequest.java:34) ~[?:?]
            at me.Darkolythe.GrandMinechange.Menu.onInventoryClick(Menu.java:63) ~[?:?]
            at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor141.execute(Unknown Source) ~[?:?]
            at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:70) ~[patched_1.13.2.jar:git-Paper-448]
            ... 15 more
     
    Last edited: Nov 29, 2018
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    thechrisanator

    in main:

    Code:
    public class GrandMinechange extends JavaPlugin {
    
        public String prefix = new String(ChatColor.WHITE.toString() + ChatColor.BOLD.toString() + "[" + ChatColor.BLUE.toString() + "Minechange" + ChatColor.WHITE.toString() + ChatColor.BOLD.toString() + "] ");
        public HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
       
        public static GrandMinechange plugin;
        public Menu menu = new Menu(this); //get the Menu class
        public CreateRequest createrequest = new CreateRequest(this);
        public int maxrequestamount = getConfig().getInt("maxrequestamount");
     
  4. Online

    timtower Administrator Administrator Moderator

  5. Offline

    thechrisanator

    move them there and keep them there right?

    Code:
    public class GrandMinechange extends JavaPlugin {
    
        public String prefix = new String(ChatColor.WHITE.toString() + ChatColor.BOLD.toString() + "[" + ChatColor.BLUE.toString() + "Minechange" + ChatColor.WHITE.toString() + ChatColor.BOLD.toString() + "] ");
        public HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
       
        public static GrandMinechange plugin;
        public Menu menu = new Menu(this); //get the Menu class
        public CreateRequest createrequest = new CreateRequest(this);
        public int maxrequestamount = getConfig().getInt("maxrequestamount");
       
        @Override
        public void onEnable() {
            menu = new Menu(this); //get other classes
            plugin = this;
           
            Menu menu = new Menu(this); //get the Menu class
            CreateRequest createrequest = new CreateRequest(this);
            maxrequestamount = getConfig().getInt("maxrequestamount");
           
            getServer().getPluginManager().registerEvents(menu, this); //register events from other classes
            getServer().getPluginManager().registerEvents(createrequest, this);
            getCommand("minechange").setExecutor(new MinechangeCommand());
           
            getConfig().addDefault("maxrequestamount", 10000);
            getConfig().options().copyDefaults(true);
            saveConfig();
           
            System.out.println(prefix + ChatColor.GREEN + "The Grand Minechange Enabled!");
        }
     
  6. Online

    timtower Administrator Administrator Moderator

  7. Offline

    thechrisanator

    doing this is still causing errors

    Code:
    public class GrandMinechange extends JavaPlugin {
    
        public String prefix = new String(ChatColor.WHITE.toString() + ChatColor.BOLD.toString() + "[" + ChatColor.BLUE.toString() + "Minechange" + ChatColor.WHITE.toString() + ChatColor.BOLD.toString() + "] ");
        public HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
     
        public static GrandMinechange plugin;
        public Menu menu;
        public CreateRequest createrequest;
        public int maxrequestamount;
     
        @Override
        public void onEnable() {
            menu = new Menu(this); //get other classes
            plugin = this;
         
            getConfig().addDefault("maxrequestamount", 10000); //if this value is missing from the config, it will put it back
            getConfig().options().copyDefaults(true);
            saveConfig();
         
            maxrequestamount = getConfig().getInt("maxrequestamount");
            menu = new Menu(plugin); //get the Menu class
            createrequest = new CreateRequest(plugin);
         
            getServer().getPluginManager().registerEvents(menu, this); //register events from other classes
            getServer().getPluginManager().registerEvents(createrequest, this);
            getCommand("minechange").setExecutor(new MinechangeCommand());
         
            System.out.println(prefix + ChatColor.GREEN + "The Grand Minechange Enabled!");
        }
    the weird thing, is that main.maxrequestamount is accessible in CreateRequest, just not in that method.
    It's accessible in both event handlers
     
  8. Offline

    KarimAKL

    @thechrisanator What are the errors? Would probably help more knowing that.
     
  9. Offline

    AdamDev

    @thechrisanator
    I may have a feeling that possibly it's picking up "main" as null.
    1. Try removing the construct from CreateRequest class and follow the next steps.
    2. Create a static getInstance() returning your plugin variable in your main class.
    3. In CreateRequest, change "public GrandMinechange main;" to "public GrandMinechange main = GrandMinechange.getInstance();"
    4. Try adding another variable to your CreateRequest class with the maxrequestamount as a variable and add it to your existing constructor. Looking like:
      Code:
       public GrandMinechange main; //initialize the main variable as Type main class
      public int maxrequestamount;
          public CreateRequest(GrandMinechange plugin,int maxrequests) {
              this.main = plugin; //set it equal to an instance of main
              this.maxrequestamount = maxrequests; //set it equal to amount of maxrequests
          }
    If nothing works;
    1. Try debugging your code, such as looking for errors or misplaced code or undefined variables or variables that can't be used
    2. Make sure that everything is being set upon enable
     
Thread Status:
Not open for further replies.

Share This Page