#Custom Plugin Event Registration
69 messages · Page 1 of 1 (latest)
it seems a variable of yours is null
while you're trying to access it
line: DionFarms.java:214
blockBreakListener is null
can you send the whole method?
the method this is in ^
alsoo
for events you need to annotate the methods with @EventHandler
DionFarms the method that has the blockBreakListener.onBlockBreak(event); in it
hmm
where are you setting the blockBreakListener?
are you setting it to anything?
where are you initializing that variable
that's your issue then
you need to set the variable to something
since its null!
everyone makes mistakes, it happens when you're learning
erm, i'm assuming that's your own class?
this one?
could set it to a new instance of that
aka private final BlockBreakListener blockBreakListener = new BlockBreakListener();
you COULD do something like that
but this way easier imo
haha no worries, you're just learning
gotta start somewhere!
sure
could you send the EconomyManager?
you need to give it the params
or, you said you initialized it in your main class, instead of creating a new variable you can make that one private static and make a getter for it
the new keyword is for the constructor
aka this:
are you making one in your main class?
if so, you could do something like private static EconomyManager economyManager;
in your main
then initialize it in your enable method
okay
so now
make the variable a static
aka private static
ye
then create a getter aka:
public static EconomyManager getEconomyManager() {
return economyManager;
}```
nope
that's fine
then in BlockBreakListener instead of creating another variable aka private EconomyManager economyManager = new EconomyManager(); you can remove that line entirely
then in your break method you can just do EconomyManager economyManager = DionFarms.getEconomyManager();
then you should be set!
(i'm terrible at explaining, if you have any questions just ask haha)
👍 lmk
ye
you would want to do the same
any errors in console?
oh i see your problem
you'll have to do the same thing as we did but with a JavaPlugin or just do:
public static JavaPlugin getInstance() {
return DionFarms.getPlugin(DionFarms.class);
}```
in your main class ^
then in your bukkit runnable use DionFarms.getInstance() instead
Bukkit.getScheduler().runTaskLater(DionFarms.getInstance(), () -> {
block.setType(Material.WHEAT);
BlockData blockData = block.getBlockData();
if (blockData instanceof Ageable) {
Ageable newAgeable = (Ageable) blockData;
newAgeable.setAge(0);
block.setBlockData(newAgeable);
}
}, 1L);```
here
okay, so this ^^
this will go into your main class (DionFarms.java)
then this is in your BlockBreakListener class:
so just replace (Plugin) this with DionFarms.getInstance()
because this would be the current class
which isn't a plugin
which is why you're getting a casting error
haha
no worries
🥳
i'll keep this open for a bit longer if you need anything else
just ping me!