java.lang.IllegalArgumentException: Plugin already initialized. What's going on? - java

When I'm testing my new plugin an exception keeps getting thrown: java.lang.IllegalArgumentException: Plugin already initialized! Please help! Here's the code:
package me.plugin.example;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class Main extends JavaPlugin implements Listener {
#Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new Main(), this);
}
#EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player p = event.getPlayer();
event.setJoinMessage(ChatColor.AQUA + p.getPlayerListName() + " has joined the game.");
p.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Welcome to the server!");
p.setGameMode(GameMode.ADVENTURE);
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("example")) {
player.sendMessage(ChatColor.BOLD + ""+ ChatColor.ITALIC + "Hello! Hope you like to be set on fire. lol :P");
player.setFireTicks(20);
}
return true;
}
#Override
public void onDisable() {
}
}
I know that you're only supposed to declare one JavaPlugin class per plugin, which I think I'm doing. But it keeps saying:
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
at me.plugin.example.Main.onEnable(Main.java:27) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_201]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_201]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_201]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
... 2 more
I really need to test this plugin to see if it works, and any help would be greatly appreciated! Thank you!

I would really recommend you to put your event handler in a separate class.
Try removing the below line
getServer().getPluginManager().registerEvents(new Main(), this);
and please don't ask your question several times.

The stacktrace clearly tells where is the problem. What is a stack trace, and how can I use it to debug my application errors?
The error:
java.lang.IllegalArgumentException: Plugin already initialized!
...
Caused by: java.lang.IllegalStateException: Initial initialization
...
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
Your code:
#Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new Main(), this);
} //<-- 19th line
And the problem is when you register your event you are creating a new instance of your Main class. So replace new Main()
getServer().getPluginManager().registerEvents(new Main(), this);
with this
getServer().getPluginManager().registerEvents(this, this);

PluginAlreadyInitialized error occours when the .jar file contains more than one subclass of JavaPlugin class. Use the JavaPlugin class only once in all plugins from.

Related

java.lang.IllegalArgumentException: Plugin already initialized [duplicate]

When I'm testing my new plugin an exception keeps getting thrown: java.lang.IllegalArgumentException: Plugin already initialized! Please help! Here's the code:
package me.plugin.example;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.event.Listener;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class Main extends JavaPlugin implements Listener {
#Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new Main(), this);
}
#EventHandler
public void onPlayerJoinEvent(PlayerJoinEvent event) {
Player p = event.getPlayer();
event.setJoinMessage(ChatColor.AQUA + p.getPlayerListName() + " has joined the game.");
p.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Welcome to the server!");
p.setGameMode(GameMode.ADVENTURE);
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
Player player = (Player) sender;
if (cmd.getName().equalsIgnoreCase("example")) {
player.sendMessage(ChatColor.BOLD + ""+ ChatColor.ITALIC + "Hello! Hope you like to be set on fire. lol :P");
player.setFireTicks(20);
}
return true;
}
#Override
public void onDisable() {
}
}
I know that you're only supposed to declare one JavaPlugin class per plugin, which I think I'm doing. But it keeps saying:
java.lang.IllegalArgumentException: Plugin already initialized!
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
at me.plugin.example.Main.onEnable(Main.java:27) ~[?:?]
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
Caused by: java.lang.IllegalStateException: Initial initialization
at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_201]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_201]
at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_201]
at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_201]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
... 2 more
I really need to test this plugin to see if it works, and any help would be greatly appreciated! Thank you!
I would really recommend you to put your event handler in a separate class.
Try removing the below line
getServer().getPluginManager().registerEvents(new Main(), this);
and please don't ask your question several times.
The stacktrace clearly tells where is the problem. What is a stack trace, and how can I use it to debug my application errors?
The error:
java.lang.IllegalArgumentException: Plugin already initialized!
...
Caused by: java.lang.IllegalStateException: Initial initialization
...
at me.plugin.example.Main.<init>(Main.java:19) ~[?:?]
Your code:
#Override
public void onEnable() {
getServer().getPluginManager().registerEvents(new Main(), this);
} //<-- 19th line
And the problem is when you register your event you are creating a new instance of your Main class. So replace new Main()
getServer().getPluginManager().registerEvents(new Main(), this);
with this
getServer().getPluginManager().registerEvents(this, this);
PluginAlreadyInitialized error occours when the .jar file contains more than one subclass of JavaPlugin class. Use the JavaPlugin class only once in all plugins from.

Can't find main class in plugin.yml

[04:48:05 ERROR]: Could not load 'plugins\HelloWorld.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.spoonle.helloworld.Main'
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:66) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugins(CraftServer.java:291) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:152) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:505) [spigot.jar:git-Spigot-c3c767f-33d5de3]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: java.lang.ClassNotFoundException: me.spoonle.helloworld.Main
at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_211]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_211]
at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_211]
at java.lang.Class.forName0(Native Method) ~[?:1.8.0_211]
at java.lang.Class.forName(Unknown Source) ~[?:1.8.0_211]
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:64) ~[spigot.jar:git-Spigot-c3c767f-33d5de3]
... 7 more
I keep getting this error while loading my plugin onto my test server.
(I did check the other posts and they didn't help me)
plugin.yml file:
name: HelloWorld
version: 1.0
author: Spoonle
main: me.spoonle.helloworld.Main
commands:
hello:
alias: [hi]
do I need to add something? Those are spaces and not tabs. I saw that using TAB can break the yml file so I used spaces instead.
Code:
package me.spoonle.helloworld.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.spoonle.helloworld.Main;
public class HelloCommand implements CommandExecutor {
private Main plugin;
public HelloCommand(Main plugin) {
this.plugin = plugin;
plugin.getCommand("hello").setExecutor(this);
}
#Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players may execute this command!");
return true;
}
Player p = (Player) sender;
if (p.hasPermission("hello.use")) {
p.sendMessage("Hello!");
return true;
} else {
p.sendMessage("You do not have permissions to use this command!");
}
return false;
}
}
This is just what I want the plugin to do. I don't know if this helps but its here if you need it.
Why can't I load my plugin??
Edit: I fixed the invalid plugin.yml. Now it is saying it can't find the main class. As stated above in the plugin.yml code, its me.spoonle.helloworld.Main and thats where my main file is located. How do I fix that now??
Is the plugin.yml file in the same folder as the Main file?
If so, you just have to write
main: Main
Your main class must extend JavaPlugin
Your plugin.yml must state "main: " and then your main class.
There should be a class called Main in the package me.spoonle.helloworld. If so, your main class is in the correct location.
Also, it is not good practice to use Main as your main class. Use the name of your program instead.
Example
Main:
package me.spoonle.helloworld;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
// Initialise HelloCommand here and set the executor of "hello" command
}
#Override
public void onDisable() {
}
}
Plugin.yml:
name: HelloWorld
version: 1.0
author: Spoonle
main: me.spoonle.helloworld.Main

Error when trying to set Players displayname on chat event (Minecraft, Spigot)

I am fairly new to Java and programming Minecraft plugins. I would like the chat listener to check it the player's name is in the config and then set the display name to that, but if the player's name is not in the config, then I would like it to just set the players name.
This is my Chat Listener:
package me.purp.servercore.listeners;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import me.purp.servercore.Main;
import me.purp.servercore.utils.Utils;
public class ServerChat implements Listener
{
private Main plugin;
public ServerChat(Main plugin)
{
Bukkit.getPluginManager().registerEvents(this, plugin);
}
#EventHandler
public void Chat(AsyncPlayerChatEvent event)
{
String message = event.getMessage();
Player player = event.getPlayer();
if (!plugin.getConfig().contains(player.getName())) {
event.setFormat(Utils.color("&7" + player.getDisplayName() + " &7&l» &r" + message));
} else if (plugin.getConfig().contains(player.getName())) {
event.setFormat(Utils.color("&7" + plugin.getConfig().getString(player.getName()) + " &7&l» &r" + message));
}
}
}
This is my nickname class:
package me.purp.servercore.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import me.purp.servercore.Main;
import me.purp.servercore.utils.Utils;
public class PlayerNick implements CommandExecutor
{
private Main plugin;
public PlayerNick(Main plugin)
{
this.plugin = plugin;
plugin.getCommand("nick").setExecutor(this);
}
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
FileConfiguration config = plugin.getConfig();
if (!(sender instanceof Player))
{
sender.sendMessage(Utils.color(config.getString("PlayerEntityFalse")));
return true;
}
Player player = (Player) sender;
if (player.hasPermission("core.nick"))
{
if (args.length == 0)
{
player.sendMessage(Utils.color("&cYou cannot have a blank nickname!"));
return true;
}
String nick = "";
for (String arg : args)
{
nick += arg + " ";
}
player.sendMessage(Utils.color("&7Your nickname is now: " + nick));
config.set(player.getName(), nick);
plugin.saveConfig();
}
return false;
}
}
This is my error:
Could not pass event AsyncPlayerChatEvent to Core v0.2
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:482) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at net.minecraft.server.v1_12_R1.PlayerConnection.chat(PlayerConnection.java:1319) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1257) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at net.minecraft.server.v1_12_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) [spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:?]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
at java.lang.Thread.run(Unknown Source) [?:?]
Caused by: java.lang.NullPointerException
at me.purp.servercore.listeners.ServerChat.Chat(ServerChat.java:29) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot-1.12.2.jar:git-Spigot-2cf50f0-8166d17]
... 11 more
Like said in the comment from Carlos under this post:
You haven't set this.plugin = plugin in your ServerChat class.
Caused by: java.lang.NullPointerException
at me.purp.servercore.listeners.ServerChat.Chat(ServerChat.java:29)
At line 29:
if (!plugin.getConfig().contains(player.getName())) {
so either
plugin or
plugin.getConfig() or
player
is null. Try to print out these variables and tell us which one is null.
My toughts:
Maybe you dont have your config saved with saveDefaultConfig() in the onEnable method. plugin shouldn't be null because then there should be a problem at the constructor when registering the listener. Also the player normally isn't null so the problem should be at the config.

Minecraft NPC not spawning and attacking me on server: null pointer error [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 5 years ago.
When I join my server "testing" is printed as expected but the npc is not spawned and does not attack me. Here is the plugin.yml:
main: com.megacrafting.MegaParty
version: 1.0
name: Megaparty
depend: [Citizens]
Here is the error:
[20:58:24 ERROR]: Could not pass event PlayerJoinEvent to Megaparty v1.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-b78586d-f3356f1]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-b78586d-f3356f1]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499) [spigot.jar:git-Spigot-b78586d-f3356f1]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.PlayerList.onPlayerJoin(PlayerList.java:342) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.PlayerList.a(PlayerList.java:162) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.LoginListener.b(LoginListener.java:159) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.LoginListener.e(LoginListener.java:57) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:842) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:405) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-b78586d-f3356f1]
at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-b78586d-f3356f1]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
Caused by: java.lang.NullPointerException
at com.megacrafting.MegaParty.onJoin(MegaParty.java:35) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[spigot.jar:git-Spigot-b78586d-f3356f1]
... 14 more
Here is the code:
package com.megacrafting;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
public class MegaParty extends JavaPlugin implements Listener {
private NPCRegistry registry;
public void onEnable() {
NPCRegistry registry = CitizensAPI.getNPCRegistry();
getServer().getPluginManager().registerEvents(this, this);
}
#EventHandler
public void onJoin(PlayerJoinEvent event) {
Player p = event.getPlayer();
p.sendMessage("testing");
Location loc = p.getLocation();
NPC npc = registry.createNPC(EntityType.PLAYER, "keys9");
npc.spawn(loc);
npc.getNavigator().setTarget(p, true);
}
}
Your field registry is NULL because you never set it in your onEnable.
Change your onEnable to
public void onEnable() {
this.registry = CitizensAPI.getNPCRegistry();
getServer().getPluginManager().registerEvents(this, this);
}

How to load video in java FX

I want to insert video into javaFX. Insert video from computer - Not from youtube or something.
Play/pause/minimize buttons, borders are not needed.
import java.io.FileNotFoundException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
public class MediaMP4 extends Application {
Stage window;
Scene scene1;
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws FileNotFoundException {
window = primaryStage;
primaryStage.setTitle("Moves");
Media media = new Media ("pr.mp4");
MediaPlayer player = new MediaPlayer (media);
MediaView view = new MediaView (player);
Group full = new Group ();
full.getChildren().addAll(view);
scene1 = new Scene (full,600,600);
primaryStage.setScene(scene1);
window.show();
player.play();
}
}
My pr.mp4 file is inside project, not in package.
Stack trace:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'pr.mp4'
at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:211)
at javafx.scene.media.Media.<init>(Media.java:393)
at vv.MediaMP4.start(MediaMP4.java:27)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
Exception running application vv.MediaMP4
The relevant line in your stack trace is:
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'pr.mp4'.
You need to specify an URI string with a scheme as a construtor argument, as specified here.
So change your line from this:
Media media = new Media ("pr.mp4");
to something like this:
Media media = new Media("file://c:/myproject/pr.mp4"));
Have a look at this question for more details: How to target a file (a path to it) in Java/JavaFX

Categories

Resources