Solved Problems with LeftClick (Adding support from 1.8 to 1.13)

Discussion in 'Spigot Plugin Development' started by HotDoctor, Apr 25, 2019.

Thread Status:
Not open for further replies.
  1. Error:
    Code (Text):

    [00:49:09] [Server thread/ERROR]: Could not pass event PlayerInteractEvent to UltraParkour v1.0
    org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:309) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:299) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:266) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:262) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.PlayerConnection.a(PlayerConnection.java:1673) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.PacketPlayInArmAnimation.a(SourceFile:32) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.PacketPlayInArmAnimation.a(SourceFile:9) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.PlayerConnectionUtils.a(SourceFile:10) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_201]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_201]
        at net.minecraft.server.v1_13_R2.SystemUtils.a(SourceFile:199) [spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:896) [spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.NullPointerException
        at hotdoctor.plugin.ultraparkour.events.MyEvents.Salir(MyEvents.java:1165) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_201]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_201]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot-1.13.2.jar:git-Spigot-f56e2e7-4385562]
        ... 18 more
     

    Code of the error:
    Code (Text):

        @EventHandler
        public void Salir(PlayerInteractEvent e) {
            if(playing.containsKey(e.getPlayer())) {
                Player player = e.getPlayer();
                if(player.getItemInHand() == null) {
                    return;
                }
                if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
                    return;
    (HERE IS THE ERROR) }if(e.getClickedBlock().getType() != Material.valueOf(main.getConfig().getString("parkour-options.items.Cancel.ID")) || e.getClickedBlock().getType() != Material.valueOf(main.getConfig().getString("parkour-options.items.Restart.ID")) || e.getClickedBlock().getType() != Material.valueOf(main.getConfig().getString("parkour-options.items.Checkpoint.ID"))) {
                    return;
                }
               //more of my stuff
     
    Code (Text):

    version: 1.0
    name: UltraParkour
    author: HotDoctor
    api-version: 1.13
     

    Code (Text):

      items:
        enabled: true
        Checkpoint:
          ID: BEACON
          name: '&9Back to last Checkpoint &7(Right Click)'
          lore:
          - '&9Example lore'
          - '&cExample lore'
          - '&1Example lore'
          slot: 3
          amount: 1
          use-delay: true
          delay: 5
          delay-message: '<prefix> &4Error: &cYou will have to wait &b<delay> &cSeconds
            to do this again!'
        Restart:
          ID: RED_BED
          name: '&cRestart Parkour &7(Right Click)'
          lore:
          - '&9Example lore'
          - '&cExample lore'
          - '&1Example lore'
          slot: 4
          amount: 1
          use-delay: true
          delay: 5
          delay-message: '<prefix> &4Error: &cYou will have to wait &b<delay> &cSeconds
            to do this again!'
        Cancel:
          ID: IRON_DOOR
          name: '&4Stop playing &7(Right Click)'
          lore:
          - '&9Example lore'
          - '&cExample lore'
          - '&1Example lore'
          slot: 5
          amount: 1
     


    What Im trying to do?

    Well practically I do not need to say it xd, The error is simply that every time I use the Left Click (Especially without having an item in my hand) I always generate that error, without exception and I do not know what to do, it's super strange

    It also happens if I use another type of item
     
    #1 HotDoctor, Apr 25, 2019
    Last edited: Apr 25, 2019
  2. Many things can be null on that line, like the config which returns "Main.getconfig" or the config path itself
     
  3. Hello,

    In addition to @MrMaurice211, it can also be the e.getBlockClicked(), which return null if the player left/right click in air.
    This wouldn't be the case if your IF condition was correct:
    Code (Java):
    If(e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)
        // your code
    }
    Also, you shouldn't use a Map<Player, ...>, it doesn't work as the Player object change at any time. Use a more constant variable, like the p.getUniqueId(): Map<UUID,...>.
     
  4. so what should I do exactly? ;w;
     
  5. just stop using the action <action>_CLICK_AIR?
     
  6. Show your entire class and the config.
     
  7. All code:
    Code (Text):

    [QUOTE="spatziempire, post: 3379378, member: 620222"]Show your entire class and the config.[/QUOTE]

        @EventHandler
        public void Salir(PlayerInteractEvent e) {
            if(playing.containsKey(e.getPlayer())) {
                Player player = e.getPlayer();
                if(player.getItemInHand() == null) {
                    return;
               
                }if(e.getClickedBlock().getType() != Material.valueOf(main.getConfig().getString("parkour-options.items.Cancel.ID")) || e.getClickedBlock().getType() != Material.valueOf(main.getConfig().getString("parkour-options.items.Restart.ID")) || e.getClickedBlock().getType() != Material.valueOf(main.getConfig().getString("parkour-options.items.Checkpoint.ID"))) {
                    return;
                }
                if(!(e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)){
                    return;
                }
                String name = e.getItem().getItemMeta().getDisplayName();
                String nameconfig = main.getConfig().getString("parkour-options.items.Cancel.name");
                String colored = ChatColor.translateAlternateColorCodes('&', nameconfig);
                if(colored.equalsIgnoreCase(name)) {
                    if(main.getConfig().getString("parkour-options.items.enabled").equalsIgnoreCase("true")) {
                        if(playing.containsKey(player)) {
                            e.setCancelled(true);
                            String tpto = playing.get(player);
                            String message = ChatColor.translateAlternateColorCodes('&', main.getConfig().getString("parkour-options.items.messages.Cancel.done"));
                            String replaced = message.replaceAll("<prefix>", main.prefix);
                            player.sendMessage(replaced);
                            if(main.getConfig().getString("parkours."+tpto+".rewards.final.use-vault.enabled").equalsIgnoreCase("true")) {
                                if(main.dependency == true) {
                                    double playerbal = playermoney.get(player);
                                    @SuppressWarnings("static-access")
                                    Economy econ = main.getEconomy();
                                    econ.withdrawPlayer(player, playerbal);
                                    playermoney.remove(player);
                                   
                                }else {
                                    if(playermoney.containsKey(player)) {
                                        playermoney.remove(player);
                                    }
                                   
                                }
                            }
                            if(playermoney.containsKey(player)) {
                                playermoney.remove(player);
                            }
                            playercheckpoint.remove(player);
                            playing.remove(player);
                            if(playerwaiting.containsKey(player)) {
                                this.playerwaiting.remove(player);
                            }
                            this.playertime.remove(player);
                            this.playerhours.remove(player);
                            this.playerminutes.remove(player);
                            if(playerwaiting2.containsKey(player)) {
                                this.playerwaiting2.remove(player);
                            }
                            player.getInventory().clear();
                            if(main.getConfig().getString("parkour-options.save-inventory").equalsIgnoreCase("true")) {
                                try {
                                    restoreInventory(player);
                                } catch (IOException e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                               
                            }
                            if(reward.containsKey(player)) {
                                RewardStorage playerre = reward.get(player);
                                playerre.deleteStorage();
                                reward.remove(player);
                            }
                           
                           
                        }
                    }
                }
            }
           
        }
     

    The config is already avaible xd look the first thread
     
  8. I told you what to do.
    First, check if e.getClickedBlock() isn't null.

    Next, replace if (!(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)) {
    by
    If(e.getAction() == Action.LEFT_CLICK_BLOCK || e.getAction() == Action.RIGHT_CLICK_BLOCK)

    And replace Player by UUID in your playing map: don't forget to convert also in your methods "getPlayer()" by "getPlayer().getUniqueId()"
     
    • Friendly Friendly x 1
  9. I will test it, thank you so much
     
  10. You should really take a look at Java conventions. I thought "main" would be an object since it is lower case.
     
    • Agree Agree x 1
  11. It works now, tysm! really.
     
Thread Status:
Not open for further replies.