Bonjour, je suis actuellement en train de crée un plugin qui permet d'avoir une bossbar différente pour chaque joueur (un systeme de mana) mais je suis confronté à une erreur que j'arrive pas à resoudre. (je suis avec spigot 1.13)
Voici le code de ma class Mana :
Code (cpp):
package fr.cercus.magic;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import fr.cercus.magic.utils.Bossbar;
public class Mana implements Listener{
private FileConfiguration config;
public static Map<Player, Bossbar> Pboss = new HashMap<>();
public Bossbar boss;
public Mana(Main main) {
this.config = main.getConfig();
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
if(config.contains(p.getName())) {
//Set la progression de la bossbar en fonction du mana dans le config.yml ?
double manas = config.getDouble(p.getName()+".manas");
if(Pboss.containsKey(p)) {
Pboss.replace(p, (Bossbar) boss.setBossbar(manas));
return;
}
// on ajoute le player a la hashmap
Pboss.put(p, (Bossbar) boss.setBossbar(manas));
return;
}
Pboss.put(p, (Bossbar) boss.getBossBar());
config.addDefault(p.getName()+".manas", 100.0);
return;
}
@EventHandler
public void onPlace(BlockPlaceEvent e) {
}
}
Mon code de ma classe Bossbar :
Code (cpp):
package fr.cercus.magic.utils;
import org.bukkit.Bukkit;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.boss.BossBar;
public class Bossbar {
private BossBar bossBar;
public Bossbar() {
bossBar = Bukkit.createBossBar("§aVotre mana", BarColor.GREEN, BarStyle.SOLID);
}
public BossBar getBossBar() {
return bossBar;
}
public Bossbar setBossbar(double progress) {
this.getBossBar().setProgress(progress);
return this;
}
}
Et voici l'erreur en question :
Code (cpp):
[12:26:39 ERROR]: Could not pass event PlayerJoinEvent to AdventSpells v1.0
org.bukkit.event.EventException: null
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:308) ~[spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.PlayerList.onPlayerJoin(PlayerList.java:343) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.PlayerList.a(PlayerList.java:163) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.LoginListener.b(LoginListener.java:150) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.LoginListener.Y_(LoginListener.java:54) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.NetworkManager.a(NetworkManager.java:231) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.ServerConnection.c(ServerConnection.java:120) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.MinecraftServer.w(MinecraftServer.java:984) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.DedicatedServer.w(DedicatedServer.java:411) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.MinecraftServer.v(MinecraftServer.java:819) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at net.minecraft.server.v1_13_R1.MinecraftServer.run(MinecraftServer.java:717) [spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
Caused by: java.lang.NullPointerException
at fr.cercus.magic.Mana.onJoin(Mana.java:48) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_161]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304) ~[spigot-1.13.jar:git-Spigot-ed1cec9-1c7adf7]
... 14 more