#Plugin no workie please help.
1 messages · Page 1 of 1 (latest)
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?
👍 🤓
sadly didn't work
show the error
Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.inventory.Inventory.getType()" because "inventory" is null
yeah see that no clue what the fuck its talking about though 😂
p.openInventory(Main.instance.Inventory);
thats the line its referring to
line 21 in the paste
show this metod
which method?
Main.instance.Inventory
its not a method its a var its in the main class
public Inventory Inventory;
thats all it is
then this vair is null?
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
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"
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
okay
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
yeah so it printed Inventory is null
[02:40:02] [Server thread/INFO]: _Ghillie issued server command: /stats
[02:40:02] [Server thread/INFO]: Inventory is null
alright
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
i forgot the constructor
this one doesn't seem to work it wants to change into a hashmap
yep that fixed it however new issue lol
this one wants to replace build with put 😂
no your good don't worry
it works?
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!
you need to learn about the events
and about camelCase