#Plugin no workie please help.

1 messages · Page 1 of 1 (latest)

lost gust
#

getting away from the busy chat

scarlet relic
#

this.getServer().getPluginManager().registerEvents(this, new stats_gui(// requires an argument \\)); was supposed to this.getServer().getPluginManager().registerEvents(new stats_gui(this), this);

#

do you see?

lost gust
#

yeah thanks

#

i will test right away

scarlet relic
#

👍 🤓

lost gust
#

sadly didn't work

scarlet relic
#

show the error

lost gust
scarlet relic
#

Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.Inventory.getType()" because "inventory" is null

lost gust
#

yeah see that no clue what the fuck its talking about though 😂

scarlet relic
#

at me.helix.atlasstats.commands.stats.onCommand(stats.java:24) ~[?:?]

#

show this

lost gust
#

p.openInventory(Main.instance.Inventory);

#

thats the line its referring to

#

line 21 in the paste

scarlet relic
#

show this metod

lost gust
#

which method?

scarlet relic
#

Main.instance.Inventory

lost gust
#

its not a method its a var its in the main class

#

public Inventory Inventory;

#

thats all it is

scarlet relic
#

then this vair is null?

lost gust
#

so i see the issue

#

if (cmd.getName().equalsIgnoreCase("stats")) {
p.openInventory(Main.instance.Inventory);
}

this is to open the menu

#

this.getServer().getPluginManager().registerEvents(new stats_gui(this), this);

this is to create the menu on plugin enable

#

public void build (Player p) {

    main.Inventory = Bukkit.createInventory(null, 9, Main.color("            &e&lStats Menu"));

    World worldd = p.getWorld();

    ItemStack world = new ItemStack(Material.MAP);
    ItemMeta worldmera = world.getItemMeta();
    worldmera.setDisplayName(Main.color("&cWorld Stats"));
    ArrayList<String> lore1 = new ArrayList();
    lore1.add(Main.color("&6&l* &e&lInformation"));
    lore1.add("");
    lore1.add(Main.color("&c● &eSpawn Location &8&l» &7X:&a" + worldd.getSpawnLocation().getBlockX() + " &7Y:&c" + worldd.getSpawnLocation().getBlockY() + " &7Z:&b" + worldd.getSpawnLocation().getBlockZ()));
    lore1.add(Main.color("&c● &eYour Location &8&l» &7X:&a" + p.getLocation().getBlockX() + " &7Y:&c" + p.getLocation().getBlockY() + " &7Z:&b" + p.getLocation().getBlockZ()));

// lore1.add(Main.color("&c● &eBed Location &8&l» &7X:&a" + p.getBedLocation().getBlockX() + " &7Y:&c" + p.getBedLocation().getBlockY() + " &7Z:&b" + p.getBedLocation().getBlockZ()));
lore1.add(Main.color("&c● &eWorld Name &8&l» &a" + worldd.getName()));
lore1.add(Main.color("&c● &eBiome Name &8&l» &a" + p.getLocation().getBlock().getBiome()));
worldmera.setLore(lore1);
world.setItemMeta(worldmera);

all of this gets pushed into the inventory so you can do the first line of code i sent allowing you to open it

#

however it is not generating the inventory onEnable

scarlet relic
#

try this

public class stats implements CommandExecutor, Listener{

    private Main main;
    public stats(Main main) {
        this.main = main;
    }
    
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

        if(sender instanceof Player) {
            Player p = (Player) sender;

            if (cmd.getName().equalsIgnoreCase("stats")) {
                if (Main.instance.Inventory == null) {
                    System.out.println("Inventory is null");
                } else {
                    p.openInventory(Main.instance.Inventory);
                }
            }

            return true;
        }
        return false;
    }
}

#

and see if the console print "Inventory is null"

lost gust
#

so it should be going Main.java

this.getServer().getPluginManager().registerEvents(new stats_gui(this), this);

then it should go stats_gui.java

public class stats_gui implements Listener {

      private Main main;
    public stats_gui(Main main) {
        this.main = main;
    }

    public void build (Player p) {

        main.Inventory = Bukkit.createInventory(null, 9, Main.color("            &e&lStats Menu"));

        World worldd = p.getWorld();

        ItemStack world = new ItemStack(Material.MAP);
        ItemMeta worldmera = world.getItemMeta();
        worldmera.setDisplayName(Main.color("&cWorld Stats"));
        ArrayList<String> lore1 = new ArrayList();
        lore1.add(Main.color("&6&l* &e&lInformation"));
        lore1.add("");
        lore1.add(Main.color("&c● &eSpawn Location &8&l» &7X:&a" + worldd.getSpawnLocation().getBlockX() + " &7Y:&c" + worldd.getSpawnLocation().getBlockY() + " &7Z:&b" + worldd.getSpawnLocation().getBlockZ()));
        lore1.add(Main.color("&c● &eYour Location &8&l» &7X:&a" + p.getLocation().getBlockX() + " &7Y:&c" + p.getLocation().getBlockY() + " &7Z:&b" + p.getLocation().getBlockZ()));
//        lore1.add(Main.color("&c● &eBed Location &8&l» &7X:&a" + p.getBedLocation().getBlockX() + " &7Y:&c" + p.getBedLocation().getBlockY() + " &7Z:&b" + p.getBedLocation().getBlockZ()));
        lore1.add(Main.color("&c● &eWorld Name &8&l» &a" + worldd.getName()));
        lore1.add(Main.color("&c● &eBiome Name &8&l» &a" + p.getLocation().getBlock().getBiome()));
        worldmera.setLore(lore1);
        world.setItemMeta(worldmera);

and then i should be able to run the command in stats.java

if (cmd.getName().equalsIgnoreCase("stats")) {
                p.openInventory(Main.instance.Inventory);
            }
#

if that all makes sense

scarlet relic
#

oh

#

ok i see the error

#

youre using the public class stats_gui implements Listener { as a listener

#

but youre not using event on there

#

youre using the method public void build (Player p) {

#

but the method isnt called

lost gust
#

yeah so it printed Inventory is null

scarlet relic
#

yes

#

ill show you how to fix it

lost gust
#

[02:40:02] [Server thread/INFO]: _Ghillie issued server command: /stats
[02:40:02] [Server thread/INFO]: Inventory is null

#

alright

scarlet relic
#

you dont need to implements Listener

public class stats_gui {

      private Main main;
    public stats_gui(Main main) {
        this.main = main;
    }

    public void build (Player p) {
     .....

    }

}```
#
private stats_gui statsGui;

@Override
    public void onEnable() {

        instance = this;

        File file = new File(getDataFolder(), "config.yml");
        if (!file.exists()) {
            saveDefaultConfig();
        }
        this.stats_gui = new stats_gui(this);
        ...
    }
#
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

            if(sender instanceof Player) {
                Player p = (Player) sender;

                if (cmd.getName().equalsIgnoreCase("stats")) {
                    Main.instance.stats_gui.build(p);
                    p.openInventory(Main.instance.Inventory);
                }

                return true;
            }
            return false;
        }
#

and try it

scarlet relic
lost gust
scarlet relic
#

How so?

#

oh

#

this.statsGui = new stats_gui(this);

#

try

lost gust
#

yep that fixed it however new issue lol

lost gust
scarlet relic
#

Main.instance.statsGui.build(p);

#

im making mistakes

lost gust
#

no your good don't worry

scarlet relic
#

it works?

lost gust
#

technical difficulties right now sorry.

#

Thank you the menu now opens but for some reason it allows me to take the items out of it lol

#

@scarlet relic you have been more than helpful!

scarlet relic
#

and about camelCase