Hi all, I’m having an issue where my Minecraft server has stopped logging in-game events. Here are the key details of my setup: Java Version: 21 Minecraft Version: 1.21.1 Server Host: Shockbyte (Paper Server, version 1.21.1, Java 21) I suspect the issue might be related to my plugin configuration. Below, I’ve included the contents of my `pom.xml` and `plugin.yml` files. If anyone could take a look and let me know if something seems off, I would really appreciate it! Thanks in advance Pom.xml Code: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>newestfile.here</groupId> <artifactId>newestplugin</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>plugin.yml</include> </includes> <filtering>true</filtering> </resource> </resources> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.10.1</version> <configuration> <release>21</release> </configuration> </plugin> </plugins> </pluginManagement> </build> <repositories> <repository> <id>papermc-repo</id> <url>https://papermc.io/repo/repository/maven-public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>io.papermc.paper</groupId> <artifactId>paper-api</artifactId> <version>1.21.1-R0.1-SNAPSHOT</version> <scope>provided</scope> </dependency> </dependencies> </project> Plugin.yml Code: name: newestplugin main: newestfile.here.newestplugin.Main version: 0.0.1-SNAPSHOT api-version: 1.21.1
What precisely is the issue? Are you saying that none of your listeners are working? Are you receiving any errors?
Thanks for your support! Yes, events are no longer being registered. I thus checked the log file and I received the message below, which suggests something with the specification in the plugin.yml and pom.xml files (pasted above) may be an issue? [10:55:49] [Server thread/ERROR]: Error occurred while enabling newestplugin v0.0.1-SNAPSHOT (Is it up to date?)
@caledonian26 The lines around that highlighted error say what is wrong. Please post your full server log using https://pastebin.com or similar
Thanks for your support! The full error: Code: [10:55:49] [Server thread/INFO]: [newestplugin] HELLO! WELCOME TO THE TRACKER PLUGIN [10:55:49] [Server thread/ERROR]: Error occurred while enabling newestplugin v0.0.1-SNAPSHOT (Is it up to date?) java.lang.NullPointerException: Cannot invoke "org.bukkit.entity.Player.getWorld()" because "player" is null at newestplugin-0.0.1-SNAPSHOT.jar/newestfile.here.newestplugin.Main.startLampTask(Main.java:77) ~[newestplugin-0.0.1-SNAPSHOT.jar:?] at newestplugin-0.0.1-SNAPSHOT.jar/newestfile.here.newestplugin.Main.onEnable(Main.java:50) ~[newestplugin-0.0.1-SNAPSHOT.jar:?] at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:288) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?] at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:202) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:109) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:520) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?] at org.bukkit.craftbukkit.CraftServer.enablePlugin(CraftServer.java:640) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:589) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:754) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:516) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:329) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1215) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:330) ~[paper-1.21.1.jar:1.21.1-77-4ff58c4] at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?] [10:55:49] [Server thread/INFO]: [newestplugin] Disabling newestplugin v0.0.1-SNAPSHOT [10:55:49] [Server thread/INFO]: [Geyser-Spigot] Enabling Geyser-Spigot v2.4.2-SNAPSHOT
Yes, I do - I see it says player is null. But, surely the code should still work/continue reading even if that one line returns null? Or does one line == null result in the whole code being aborted? (Which would explain why the log files are not being saved) Perhaps I need add an 'exception' somewhere?
Hey all, My issue is now resolved! I realise I needed to add a 'try' and 'exception' to my code (within my .java file containing my code) as follows: Code: public void startLampTask() { try { Player player = Bukkit.getPlayer("caledonian26"); if (player != null) { World world = player.getWorld(); Location lampPosition = new Location(world, -16, -60, 82); getServer().getScheduler().runTaskTimer(this, new BukkitRunnable() { @Override public void run() { tickCounter++; if (tickCounter >= PULSE_INTERVAL) { tickCounter = 0; lampState = !lampState; Block block = lampPosition.clone().subtract(0, 1, 0).getBlock(); if (lampState) { block.setType(Material.REDSTONE_BLOCK); } else { block.setType(Material.AIR); } getLogger().info("Lamp State: " + (lampState ? "On" : "Off")); } } }, 0L, 1L); } else { getLogger().warning("Player 'caledonian26' is not online."); } } catch (Exception e) { e.printStackTrace(); getLogger().severe("An error occurred while starting the lamp task."); } } Thanks for all your help!
You don't need the try/catch if you have the if(player != null) statement. Also, clean code tip here. Notice how you have if(player != null) which is encompassing a huge portion of the code? The {} of the huge conditional makes it harder to read because the developer needs to look for the ending '}' to understand what's happening. To clean it up, try this: Code: Player player = Bukkit.getPlayer("caledonian26"); if(player == null) getLogger().warning("Player 'caledonian26' is not online."); else { World world = player.getWorld(); Location lampPosition = new Location(world, -16, -60, 82); new BukkitRunnable() { int tickCounter = 0; int PULSE_INTERVAL = 10; // Change value here public void run() { tickCounter++; if (tickCounter >= PULSE_INTERVAL) { tickCounter = 0; lampState = !lampState; Block block = lampPosition.clone().subtract(0, 1, 0).getBlock(); if (lampState) { block.setType(Material.REDSTONE_BLOCK); } else { block.setType(Material.AIR); } getLogger().info("Lamp State: " + (lampState ? "On" : "Off")); } } }.runTaskTimer(plugin, 0L, 0L); } I also made the runnable use the BukkitRunnable class, which looks cleaner. And I removed the try/catch. Happy programming!