Solved Plugin is executing an event that never existed, why?

Discussion in 'Plugin Development' started by xpaintall, May 15, 2021.

  1. Offline

    xpaintall

    I tried so hard to find this stupid peice of code, but it never existed. It just came out of nowhere. This is the only PlayerRespawnEvent in both custom made plugins and the error occured when I booted up my computer again, was not there before I shut it down.
    Code:
    @EventHandler
        public void onRespawn(PlayerRespawnEvent event) {
            Player player = event.getPlayer();
    
            if(player.getWorld() == Bukkit.getWorld("arena-flow")) {
                player.setGameMode(GameMode.SPECTATOR);
                new BukkitRunnable() {
    
                    int countdown = 5;
    
                    @Override
                    public void run() {
                        player.setGameMode(GameMode.SPECTATOR);
    
                        if(countdown == 5) {
                            player.teleport(new Location(Bukkit.getWorld("arena-flow"), -18.500, 90, -2.500));
                        }
    
                        if(countdown > 0) {
                            player.sendMessage(ChatColor.YELLOW + "Respawning in: " + ChatColor.GREEN + countdown);
                            countdown--;
                        }
                        if(countdown == 0) {
                            countdown--;
                        }
                        if(countdown < 0) {
                            cancel();
                            f.joinArena(player);
                            player.setGameMode(GameMode.ADVENTURE);
                            player.sendMessage(ChatColor.GREEN + "Respawned!");
                        }
    
                    }
    
    
                }.runTaskTimer(f, 0, 20);
            }
    
    
        }
    Now what should happen is I get into spectator mode, it counts down to 1 and teleports me back (f#JoinArena(player); method). But what happens now is I get into adventure mode, get Items that I should get when I join into the server, get into spectator mode whilst allowing me to use these items. WHY.
    Edit: In case you're wondering, the "f" is an instance to my Main class (
    ArenaMainClass f = ArenaMainClass#getPlugin(ArenaMainClass#class);
    )
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    xpaintall

    @timtower My apologies that I used the word error incorrectly, there was no error whilst respawning.
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    xpaintall

    @timtower Yes, absolutely, but the problem isn't this event, it is something being executed that does not exist
     
  6. Offline

    davidclue

    Can you share the entire listener class or at least all the events.
     
  7. Offline

    timtower Administrator Administrator Moderator

    Then remove all other plugins and only run this one.
     
  8. Offline

    xpaintall

    @timtower It works basically the same, I get into adventure mode which shouldn't happen and get different items that I am supposed to get when the BukkitRunnable is over. Does this have any connection to the /gamerule keepInventory ? I could do
    Code:
    player.getInventory().clear();
    but I feel like that wouldn't solve anything because it can break other plugins. Also, the items I am getting are from a different plugin that I made.
     
  9. Offline

    davidclue

    @xpaintall You realize we can't help you if we don't have the other plugins code... You said code that does not exist is running and then tell us that another plugin you made has an event firing that gives you those items. Try and remove your other plugin and test if it works.
     
  10. Offline

    timtower Administrator Administrator Moderator

    @xpaintall If they are from a different plugin then you did not remove all other plugins.
     
  11. Offline

    xpaintall

    Alright, I know that what I am saying is a bit confusing, so I made a short video explaining my problem.
     
  12. Offline

    davidclue

    @xpaintall Share every method in your plugin where you give the player the items, then it will be easy to determine the problem. I know you made your video showing most of your code but I do not want to go back and forth trying to read the entire plugin's code so just share all the methods that give the player the items.
     
  13. Offline

    xpaintall

    @davidclue No problem, I will do that later today

    @davidclue Ok, I can show you the code.

    I just want you to let you know that these items are mentioned items in the video.

    Code:
    player.getInventory().setItem(0, compass.lobbyCompass);
    player.getInventory().setItem(1, Profile.profileItem);
    player.getInventory().setItem(4, cosmeticItemBox.cosmeticItemBox);
    player.getInventory().setItem(8, updates.updateItem);
    
    Code:
    @EventHandler
        public void onChange(PlayerChangedWorldEvent event) {
            Player player = event.getPlayer();
            if(player.getWorld() == Bukkit.getWorld("lobby")) {
    
                    player.teleport(new Location(Bukkit.getWorld("lobby"), 292.500, 11, 1920.500, 180, 0));
                    player.getInventory().clear();
    
                    player.getInventory().setItem(0, compass.lobbyCompass);
                    player.getInventory().setItem(1, Profile.profileItem);
                    player.getInventory().setItem(4, cosmeticItemBox.cosmeticItemBox);
                    player.getInventory().setItem(8, updates.updateItem);
    
    
                ScoreboardManager m = Bukkit.getScoreboardManager();
                Scoreboard board = m.getNewScoreboard();
    
                Objective empty = board.registerNewObjective("test", "dummy");
                empty.setDisplaySlot(DisplaySlot.SIDEBAR);
                empty.setDisplayName("");
    
                player.setScoreboard(board);
    
            }
        }
    And my Join listener class:
    Code:
    @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
             event.setJoinMessage("");
                    player.teleport(new Location(Bukkit.getWorld("lobby"), 292.500, 11, 1920.500, 180, 0));
                    player.getInventory().clear();
    
                    player.getInventory().setItem(0, compass.lobbyCompass);
                    player.getInventory().setItem(1, Profile.profileItem);
                    player.getInventory().setItem(4,cosmeticItemBox.cosmeticItemBox);
                    player.getInventory().setItem(8,updates.updateItem);
    
    
    }
    That is it. Every single one of these classes are registered in my main.

    EDIT: One thing, when I try to change something, i get this error (an actual error now):
    Code:
    [10:55:48 ERROR]: Could not pass event PlayerRespawnEvent to MctallArena v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[ser.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[ser.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [ser.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerList.moveToWorld(PlayerList.java:568) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerList.moveToWorld(PlayerList.java:507) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:1393) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInClientCommand.a(SourceFile:31) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PacketPlayInClientCommand.a(SourceFile:8) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [ser.jar:git-Spigot-db6de12-18fbb24]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_261]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_261]
            at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [ser.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [ser.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_261]
    Caused by: java.lang.NoClassDefFoundError: com/xpaintall/ArenaMain/ArenaListeners/RespawnLIstener$1
            at com.xpaintall.ArenaMain.ArenaListeners.RespawnLIstener.onRespawn(RespawnLIstener.java:25) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_261]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[ser.jar:git-Spigot-db6de12-18fbb24]
            ... 17 more
    Caused by: java.lang.ClassNotFoundException: com.xpaintall.ArenaMain.ArenaListeners.RespawnLIstener$1
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_261]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[ser.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[ser.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_261]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_261]
            at com.xpaintall.ArenaMain.ArenaListeners.RespawnLIstener.onRespawn(RespawnLIstener.java:25) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_261]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[ser.jar:git-Spigot-db6de12-18fbb24]
            ... 17 more
    To fix it, I used to take the plugin out and back in, but I ain't sure what does the error mean, because it says that my BukkitRunnable() isn't valid or something, I am not really sure.
     
    Last edited: May 18, 2021
  14. Offline

    xpaintall

    @davidclue I did more investigation and found out that my PlayerChangedWorldEvent is manipulating the PlayerRespawnEvent. Not sure why.
     
  15. Offline

    davidclue

    PlayerChangeWorldEvent happens when a player switches a world, I don't know if it's a bug but it will trigger when a player respawns just as if you go through the end portal back to the overworld it triggers as a PlayerRespawnEvent for some reason, not a PlayerPortalEvent. What is line 25 in your onRespawn method? The one from the error.
     
  16. Offline

    xpaintall

    @davidclue It is the "new BukkitRunnable()"
    Code:
             new BukkitRunnable() {
    
                    int countdown = 5;
    
                    @Override
                    public void run() {
                        player.setGameMode(GameMode.SPECTATOR);
    
                        if(countdown < 0) {
                            cancel();
                            f.joinArena(player);
                            player.setGameMode(GameMode.ADVENTURE);
                            player.sendMessage(ChatColor.GREEN + "Respawned!");
                        }
    
                        if(countdown == 0) {
                            countdown--;
                        }
    
                        if(countdown == 5) {
                            player.teleport(new Location(Bukkit.getWorld("arena-flow"), -18.500, 90, -2.500));
                        }
    
                        if(countdown > 0) {
                            player.sendMessage(ChatColor.GREEN + "Respawning in: " + ChatColor.YELLOW + countdown);
                            countdown--;
                        }
    
    
                    }
    
    
                }.runTaskTimer(f, 0, 20);
     
  17. Offline

    davidclue

    Try using a scheduled delay task with a runnable instead maybe that will work better, your code looks fine I don't understand why you would be getting an error if you are in your arena world because the PlayerChangeWorldEvent will only run if they are in the lobby world. You're calling it somewhere else or you are dying in your lobby world.
     
  18. Offline

    xpaintall

    @davidclue I tested some things out and found out that I am not respawning just in my arena world, which means that I'm respawning in my "arena-flow" and in the "lobby" world simultaneously. Then, I get teleported in the "arena-flow" world. I don't know why I'm automatically teleported to the lobby world which triggers the
    PlayerChangedWorldEvent. The reason I know this is because I took out the arena plugin and killed myself in the "arena-flow" world and got teleported to the lobby.
     
  19. Offline

    davidclue

    @xpaintall Because the players spawn is in the lobby world... It's how the game works, you will need to change the players spawn in your plugin.
     
  20. Offline

    xpaintall

    @davidclue I thought about what you said, used the player#setRespawnLocation and it works! THANK YOU SO MUCH!
     

Share This Page