Plugin PlayerRespawnEvent ne fonctionne pas

VG07

Cueilleur de roses
23 Mars 2020
18
1
13
21
Je suis entrain de programmer un plugin spigot et j'ai une erreur mais je n'arrive pas à savoir d'où elle vient si quelqu'un peut m'aider

Voici l'erreur
Code:
Could not pass event PlayerRespawnEvent to PowerBedwars-Power v1.1
org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:319) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerList.moveToWorld(PlayerList.java:695) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerList.moveToWorld(PlayerList.java:599) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:2038) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PacketPlayInClientCommand.a(SourceFile:30) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PacketPlayInClientCommand.a(SourceFile:8) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:942) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:935) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:919) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:851) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_331]
Caused by: java.lang.IllegalStateException: Not scheduled yet
        at org.bukkit.scheduler.BukkitRunnable.checkScheduled(BukkitRunnable.java:156) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.scheduler.BukkitRunnable.getTaskId(BukkitRunnable.java:150) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.scheduler.BukkitRunnable.cancel(BukkitRunnable.java:30) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at fr.plaglefleau.powerbedwarspower.PowerListener.onRespawn(PowerListener.java:95) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_331]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_331]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_331]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_331]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        ... 20 more
[14:26:31] [Server thread/INFO]: test 4
[14:27:17] [Server thread/INFO]: PlagLeFleau issued server command: /kill
[14:27:17] [Server thread/INFO]: PlagLeFleau fell out of the world
[14:27:17] [Server thread/INFO]: [PlagLeFleau: Killed PlagLeFleau]
[14:27:24] [Server thread/ERROR]: Could not pass event PlayerRespawnEvent to PowerBedwars-Power v1.1
org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:319) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerList.moveToWorld(PlayerList.java:695) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerList.moveToWorld(PlayerList.java:599) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:2038) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PacketPlayInClientCommand.a(SourceFile:30) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PacketPlayInClientCommand.a(SourceFile:8) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:942) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:935) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:919) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:851) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_331]
Caused by: java.lang.IllegalStateException: Not scheduled yet
        at org.bukkit.scheduler.BukkitRunnable.checkScheduled(BukkitRunnable.java:156) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.scheduler.BukkitRunnable.getTaskId(BukkitRunnable.java:150) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.scheduler.BukkitRunnable.cancel(BukkitRunnable.java:30) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at fr.plaglefleau.powerbedwarspower.PowerListener.onRespawn(PowerListener.java:95) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_331]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_331]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_331]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_331]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        ... 20 more
et la classe listener
Java:
package fr.plaglefleau.powerbedwarspower;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

import fr.plaglefleau.powerbedwarspower.task.BuilderTask;
import fr.plaglefleau.powerbedwarspower.task.KamikazTask;

public class PowerListener implements Listener {
    public static final ItemStack SELECTION_ITEM = createItem(Material.BLAZE_POWDER, "§l§cSelect your class", 1);
    private final ItemStack INVENTORY_BUILDER_ITEM = createItem(Material.BRICKS, "§eBUILDER", 1);
    private final ItemStack INVENTORY_KAMIKAZE_ITEM = createItem(Material.TNT, "§l§cELECTRIC KAMIKAZE", 1);
    private final ItemStack BRICKS;
    private final String OBJECTIVE = "class";
    private final String IS_DEAD_SCORE = "isDead";
    private final String CLASS_ID = "class";
    private final String NEXT_CLASS = "nextClass";
    private final String IS_SNEAK = "sneak";
    
    private int choicePlacement = 0;
    private Inventory choice = Bukkit.createInventory(null, 9, "§dChoose a class");
    private Main main;
    
    public PowerListener(Main main) {
        this.main = main;
        BRICKS = createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1);
    }

    @EventHandler
    public void onInterract(PlayerInteractEvent event) {
        System.out.println("test 1");
        Player player = event.getPlayer();
        if(event.getItem() == null && (event.getAction() != Action.LEFT_CLICK_AIR || event.getAction() != Action.LEFT_CLICK_BLOCK)) {
            System.out.println("test 2");
            return;
        }
        System.out.println("test 3");
        System.out.println("test 5");
        if(player.getInventory().getItemInMainHand().equals(SELECTION_ITEM)) {
            System.out.println("test 6");
            if((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                System.out.println("test 7");
                player.openInventory(choice);
                System.out.println("test 8");
                addItemInInventory(choice, INVENTORY_BUILDER_ITEM);
                System.out.println("test 9");
                addItemInInventory(choice, INVENTORY_KAMIKAZE_ITEM);
                System.out.println("test 10");
                choicePlacement = 0;
                System.out.println("test 11");
            }
        }
    }
    
    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        if(player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore() == 0)  {
            System.out.println("test 4");
            addPotionEffect(player, PotionEffectType.FAST_DIGGING, 100000, 1, false, false, false);
        }
    }
    
    @EventHandler
    public void onRespawn(PlayerRespawnEvent event) {
        System.out.println("test 12");
        Player player = event.getPlayer();
        player.getScoreboard().getObjective(OBJECTIVE).getScore(IS_DEAD_SCORE).setScore(1);
        System.out.println("test 13");
        player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).setScore(player.getScoreboard().getObjective(OBJECTIVE).getScore(NEXT_CLASS).getScore());
        System.out.println("test 14");
        BuilderTask builderTask = new BuilderTask(player);
        System.out.println("test 15");
        KamikazTask kamikazTask = new KamikazTask(player);
        System.out.println("test 16");
        switch (player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore()) {
            case 0:
                System.out.println("test 17");
                kamikazTask.cancel();
                System.out.println("test 18");
                player.setHealthScale(main.getConfig().getInt("powers.builder.hp"));
                System.out.println("test 19");
                builderTask.runTaskTimer(main, 0, 1200);
                System.out.println("test 20");
                player.getInventory().setItem(main.getConfig().getInt("powers.builder.special-item.slot"), createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1));
                System.out.println("test 21");
                break;
            case 1:
                builderTask.cancel();
                kamikazTask.runTaskTimer(main, 0, 1000);
                player.setHealthScale(main.getConfig().getInt("powers.kamikaze.hp"));
                addPotionEffect(player, PotionEffectType.SPEED, 1000000, main.getConfig().getInt("powers.kamikaze.speed-level"), false, false, false);
                break;
            default:
                player.setHealth(20);
                removeAllPotionEffect(player);
                break;
        }
    }
    
    @EventHandler
    public void onSneak(PlayerToggleSneakEvent event) {
        Player player = event.getPlayer();
        if(player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore() == 0 && !player.isSneaking()) {
            addPotionEffect(player, PotionEffectType.SPEED, 1000000, main.getConfig().getInt("powers.builder.sneak-speed-level"), false, false, false);
        } else if (player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore() == 0 && player.isSneaking()) {
            player.removePotionEffect(PotionEffectType.SPEED);
        }
    }
    
    @EventHandler
    public void onClick(InventoryClickEvent event) {
        Inventory inv = event.getInventory();
        Player player = (Player) event.getWhoClicked();
        ItemStack current = event.getCurrentItem();
        if(current.equals(createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1))) {
            event.setCancelled(true);
        }
        if(inv.equals(choice)) {
            if(current.equals(INVENTORY_BUILDER_ITEM)) {
                setScoreBoard(player, 0);
                player.closeInventory();
            } else if (current.equals(INVENTORY_KAMIKAZE_ITEM)) {
                setScoreBoard(player, 1);
                player.closeInventory();
            }
        }
    }
    
    @EventHandler
    public void onDropp(PlayerDropItemEvent event) {
        ItemStack it = createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1);
        if(event.getItemDrop().getItemStack().equals(it)) {
            event.setCancelled(true);
        }
    }
    
    @SuppressWarnings("unlikely-arg-type")
    @EventHandler
    public void onPlace(BlockPlaceEvent event) {
        Player player = event.getPlayer();
        ItemStack it = createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1);
        if(!player.getInventory().getItem(8).getItemMeta().equals(it)) {
            player.getInventory().setItem(main.getConfig().getInt("powers.builder.special-item.slot"), it);
        }
    }
    
    public static ItemStack createItem(Material material, String dysplayName, int quantity) {
        ItemStack it = new ItemStack(material, quantity);
        ItemMeta im = it.getItemMeta();
        im.setDisplayName(dysplayName);
        it.setItemMeta(im);
        return it;
    }
    
    public static ItemStack createItem(Material material, String dysplayName, boolean isEnchanted) {
        ItemStack it = new ItemStack(material, 1);
        ItemMeta im = it.getItemMeta();
        im.setDisplayName(dysplayName);
        if(isEnchanted) {
            im.addEnchant(Enchantment.ARROW_INFINITE, 1, isEnchanted);
            im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        }
        it.setItemMeta(im);
        return it;
    }
    
    public boolean addItemInInventory(Inventory inv, ItemStack it) {
        if((choicePlacement + 1) <= inv.getSize()) {
            inv.setItem(choicePlacement, it);
            choicePlacement++;
            return true;
        }
        return false;
    }
    
    public void reset(Player player) {
        removeAllPotionEffect(player);
    }
    
    public static void removeAllPotionEffect(Player player) {
        player.removePotionEffect(PotionEffectType.ABSORPTION);
        player.removePotionEffect(PotionEffectType.BAD_OMEN);
        player.removePotionEffect(PotionEffectType.BLINDNESS);
        player.removePotionEffect(PotionEffectType.CONDUIT_POWER);
        player.removePotionEffect(PotionEffectType.CONFUSION);
        player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
        player.removePotionEffect(PotionEffectType.DOLPHINS_GRACE);
        player.removePotionEffect(PotionEffectType.FAST_DIGGING);
        player.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
        player.removePotionEffect(PotionEffectType.GLOWING);
        player.removePotionEffect(PotionEffectType.HARM);
        player.removePotionEffect(PotionEffectType.HEAL);
        player.removePotionEffect(PotionEffectType.HEALTH_BOOST);
        player.removePotionEffect(PotionEffectType.HERO_OF_THE_VILLAGE);
        player.removePotionEffect(PotionEffectType.HUNGER);
        player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
        player.removePotionEffect(PotionEffectType.INVISIBILITY);
        player.removePotionEffect(PotionEffectType.JUMP);
        player.removePotionEffect(PotionEffectType.LEVITATION);
        player.removePotionEffect(PotionEffectType.LUCK);
        player.removePotionEffect(PotionEffectType.NIGHT_VISION);
        player.removePotionEffect(PotionEffectType.POISON);
        player.removePotionEffect(PotionEffectType.REGENERATION);
        player.removePotionEffect(PotionEffectType.SATURATION);
        player.removePotionEffect(PotionEffectType.SLOW);
        player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
        player.removePotionEffect(PotionEffectType.SLOW_FALLING);
        player.removePotionEffect(PotionEffectType.SPEED);
        player.removePotionEffect(PotionEffectType.UNLUCK);
        player.removePotionEffect(PotionEffectType.WATER_BREATHING);
        player.removePotionEffect(PotionEffectType.WEAKNESS);
        player.removePotionEffect(PotionEffectType.WITHER);
    }
    
    public void addPotionEffect(Player player, PotionEffectType potion, int durration, int level, boolean particle, boolean icon, boolean ambient) {
        player.addPotionEffect(new PotionEffect(potion, durration, level, ambient, particle, icon));
    }
    
    public void setScoreBoard(Player player, int scoreClass) {
        Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
        Objective obj = board.registerNewObjective(OBJECTIVE, "dummy", "Classe:");
        obj.getScore(NEXT_CLASS).setScore(scoreClass);
        obj.getScore(IS_DEAD_SCORE).setScore(0);
        obj.getScore(CLASS_ID).setScore(200);
        obj.setDisplaySlot(DisplaySlot.SIDEBAR);
        player.setScoreboard(obj.getScoreboard());
    }

    public ItemStack getBRICKS() {
        return BRICKS;
    }

    public String getIS_SNEAK() {
        return IS_SNEAK;
    }
}

Et ma classe main
Java:
package fr.plaglefleau.powerbedwarspower;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

import fr.plaglefleau.powerbedwarspower.task.BuilderTask;
import fr.plaglefleau.powerbedwarspower.task.KamikazTask;

public class PowerListener implements Listener {
    public static final ItemStack SELECTION_ITEM = createItem(Material.BLAZE_POWDER, "§l§cSelect your class", 1);
    private final ItemStack INVENTORY_BUILDER_ITEM = createItem(Material.BRICKS, "§eBUILDER", 1);
    private final ItemStack INVENTORY_KAMIKAZE_ITEM = createItem(Material.TNT, "§l§cELECTRIC KAMIKAZE", 1);
    private final ItemStack BRICKS;
    private final String OBJECTIVE = "class";
    private final String IS_DEAD_SCORE = "isDead";
    private final String CLASS_ID = "class";
    private final String NEXT_CLASS = "nextClass";
    private final String IS_SNEAK = "sneak";
    
    private int choicePlacement = 0;
    private Inventory choice = Bukkit.createInventory(null, 9, "§dChoose a class");
    private Main main;
    
    public PowerListener(Main main) {
        this.main = main;
        BRICKS = createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1);
    }

    @EventHandler
    public void onInterract(PlayerInteractEvent event) {
        System.out.println("test 1");
        Player player = event.getPlayer();
        if(event.getItem() == null && (event.getAction() != Action.LEFT_CLICK_AIR || event.getAction() != Action.LEFT_CLICK_BLOCK)) {
            System.out.println("test 2");
            return;
        }
        System.out.println("test 3");
        System.out.println("test 5");
        if(player.getInventory().getItemInMainHand().equals(SELECTION_ITEM)) {
            System.out.println("test 6");
            if((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                System.out.println("test 7");
                player.openInventory(choice);
                System.out.println("test 8");
                addItemInInventory(choice, INVENTORY_BUILDER_ITEM);
                System.out.println("test 9");
                addItemInInventory(choice, INVENTORY_KAMIKAZE_ITEM);
                System.out.println("test 10");
                choicePlacement = 0;
                System.out.println("test 11");
            }
        }
    }
    
    @EventHandler
    public void onMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        if(player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore() == 0)  {
            System.out.println("test 4");
            addPotionEffect(player, PotionEffectType.FAST_DIGGING, 100000, 1, false, false, false);
        }
    }
    
    @EventHandler
    public void onRespawn(PlayerRespawnEvent event) {
        System.out.println("test 12");
        Player player = event.getPlayer();
        player.getScoreboard().getObjective(OBJECTIVE).getScore(IS_DEAD_SCORE).setScore(1);
        System.out.println("test 13");
        player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).setScore(player.getScoreboard().getObjective(OBJECTIVE).getScore(NEXT_CLASS).getScore());
        System.out.println("test 14");
        BuilderTask builderTask = new BuilderTask(player);
        System.out.println("test 15");
        KamikazTask kamikazTask = new KamikazTask(player);
        System.out.println("test 16");
        switch (player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore()) {
            case 0:
                System.out.println("test 17");
                kamikazTask.cancel();
                System.out.println("test 18");
                player.setHealthScale(main.getConfig().getInt("powers.builder.hp"));
                System.out.println("test 19");
                builderTask.runTaskTimer(main, 0, 1200);
                System.out.println("test 20");
                player.getInventory().setItem(main.getConfig().getInt("powers.builder.special-item.slot"), createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1));
                System.out.println("test 21");
                break;
            case 1:
                builderTask.cancel();
                kamikazTask.runTaskTimer(main, 0, 1000);
                player.setHealthScale(main.getConfig().getInt("powers.kamikaze.hp"));
                addPotionEffect(player, PotionEffectType.SPEED, 1000000, main.getConfig().getInt("powers.kamikaze.speed-level"), false, false, false);
                break;
            default:
                player.setHealth(20);
                removeAllPotionEffect(player);
                break;
        }
    }
    
    @EventHandler
    public void onSneak(PlayerToggleSneakEvent event) {
        Player player = event.getPlayer();
        if(player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore() == 0 && !player.isSneaking()) {
            addPotionEffect(player, PotionEffectType.SPEED, 1000000, main.getConfig().getInt("powers.builder.sneak-speed-level"), false, false, false);
        } else if (player.getScoreboard().getObjective(OBJECTIVE).getScore(CLASS_ID).getScore() == 0 && player.isSneaking()) {
            player.removePotionEffect(PotionEffectType.SPEED);
        }
    }
    
    @EventHandler
    public void onClick(InventoryClickEvent event) {
        Inventory inv = event.getInventory();
        Player player = (Player) event.getWhoClicked();
        ItemStack current = event.getCurrentItem();
        if(current.equals(createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1))) {
            event.setCancelled(true);
        }
        if(inv.equals(choice)) {
            if(current.equals(INVENTORY_BUILDER_ITEM)) {
                setScoreBoard(player, 0);
                player.closeInventory();
            } else if (current.equals(INVENTORY_KAMIKAZE_ITEM)) {
                setScoreBoard(player, 1);
                player.closeInventory();
            }
        }
    }
    
    @EventHandler
    public void onDropp(PlayerDropItemEvent event) {
        ItemStack it = createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1);
        if(event.getItemDrop().getItemStack().equals(it)) {
            event.setCancelled(true);
        }
    }
    
    @SuppressWarnings("unlikely-arg-type")
    @EventHandler
    public void onPlace(BlockPlaceEvent event) {
        Player player = event.getPlayer();
        ItemStack it = createItem(Material.BRICKS, main.getConfig().getString("power.builder.special-item.name"), 1);
        if(!player.getInventory().getItem(8).getItemMeta().equals(it)) {
            player.getInventory().setItem(main.getConfig().getInt("powers.builder.special-item.slot"), it);
        }
    }
    
    public static ItemStack createItem(Material material, String dysplayName, int quantity) {
        ItemStack it = new ItemStack(material, quantity);
        ItemMeta im = it.getItemMeta();
        im.setDisplayName(dysplayName);
        it.setItemMeta(im);
        return it;
    }
    
    public static ItemStack createItem(Material material, String dysplayName, boolean isEnchanted) {
        ItemStack it = new ItemStack(material, 1);
        ItemMeta im = it.getItemMeta();
        im.setDisplayName(dysplayName);
        if(isEnchanted) {
            im.addEnchant(Enchantment.ARROW_INFINITE, 1, isEnchanted);
            im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        }
        it.setItemMeta(im);
        return it;
    }
    
    public boolean addItemInInventory(Inventory inv, ItemStack it) {
        if((choicePlacement + 1) <= inv.getSize()) {
            inv.setItem(choicePlacement, it);
            choicePlacement++;
            return true;
        }
        return false;
    }
    
    public void reset(Player player) {
        removeAllPotionEffect(player);
    }
    
    public static void removeAllPotionEffect(Player player) {
        player.removePotionEffect(PotionEffectType.ABSORPTION);
        player.removePotionEffect(PotionEffectType.BAD_OMEN);
        player.removePotionEffect(PotionEffectType.BLINDNESS);
        player.removePotionEffect(PotionEffectType.CONDUIT_POWER);
        player.removePotionEffect(PotionEffectType.CONFUSION);
        player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
        player.removePotionEffect(PotionEffectType.DOLPHINS_GRACE);
        player.removePotionEffect(PotionEffectType.FAST_DIGGING);
        player.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
        player.removePotionEffect(PotionEffectType.GLOWING);
        player.removePotionEffect(PotionEffectType.HARM);
        player.removePotionEffect(PotionEffectType.HEAL);
        player.removePotionEffect(PotionEffectType.HEALTH_BOOST);
        player.removePotionEffect(PotionEffectType.HERO_OF_THE_VILLAGE);
        player.removePotionEffect(PotionEffectType.HUNGER);
        player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
        player.removePotionEffect(PotionEffectType.INVISIBILITY);
        player.removePotionEffect(PotionEffectType.JUMP);
        player.removePotionEffect(PotionEffectType.LEVITATION);
        player.removePotionEffect(PotionEffectType.LUCK);
        player.removePotionEffect(PotionEffectType.NIGHT_VISION);
        player.removePotionEffect(PotionEffectType.POISON);
        player.removePotionEffect(PotionEffectType.REGENERATION);
        player.removePotionEffect(PotionEffectType.SATURATION);
        player.removePotionEffect(PotionEffectType.SLOW);
        player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
        player.removePotionEffect(PotionEffectType.SLOW_FALLING);
        player.removePotionEffect(PotionEffectType.SPEED);
        player.removePotionEffect(PotionEffectType.UNLUCK);
        player.removePotionEffect(PotionEffectType.WATER_BREATHING);
        player.removePotionEffect(PotionEffectType.WEAKNESS);
        player.removePotionEffect(PotionEffectType.WITHER);
    }
    
    public void addPotionEffect(Player player, PotionEffectType potion, int durration, int level, boolean particle, boolean icon, boolean ambient) {
        player.addPotionEffect(new PotionEffect(potion, durration, level, ambient, particle, icon));
    }
    
    public void setScoreBoard(Player player, int scoreClass) {
        Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
        Objective obj = board.registerNewObjective(OBJECTIVE, "dummy", "Classe:");
        obj.getScore(NEXT_CLASS).setScore(scoreClass);
        obj.getScore(IS_DEAD_SCORE).setScore(0);
        obj.getScore(CLASS_ID).setScore(200);
        obj.setDisplaySlot(DisplaySlot.SIDEBAR);
        player.setScoreboard(obj.getScoreboard());
    }

    public ItemStack getBRICKS() {
        return BRICKS;
    }

    public String getIS_SNEAK() {
        return IS_SNEAK;
    }
}

Ma verison de spigot est "spigot-1.16.5"
Je code sur java 8

Merci d'avance
 

Detobel36

Créateur de plugins (PhoenixRebirth)
Support
17 Août 2012
10 470
24
2 240
347
26
Bruxelles - Belgique
www.phoenix-rebirth.fr
Salut,

Java:
at fr.plaglefleau.powerbedwarspower.PowerListener.onRespawn(PowerListener.java:95) ~[?:?]

Donc:
Java:
BuilderTask builderTask = new BuilderTask(player);
Donc l'erreur n'est pas du tout dans l'event... Mais dans ton "BuilterTask".


Cordialement,
Detobel36