Solved Console Lag Please Please help!!

Discussion in 'Plugin Development' started by Chintzi, Jul 12, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Chintzi

    Ok so. I have an event in my plugin (PlayerInteractEvent) and i have a method that checks to see if the item a player is holding has a certain lore and if so shoot tnt. So when players right click it all is good and nothing comes up in console but if a player interacts or does anything that registers under the PlayerInteractEvent class that doesnt involve the player right clicking a stick with the lore i mentioned before i get a big console spam ill give you now so to simplify my statement If someone does something else rather than interacting with a item with a certain lore and its to do with the player interacting class my console gets a paragraph of spam

    Thanks in advance guys!

    Code (open)

    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Block block = event.getClickedBlock();
            Player player = event.getPlayer();
            UUID pid = player.getUniqueId();
            List loreList = player.getItemInHand().getItemMeta().getLore();
            if (this.plugin.getConfig().getBoolean("enable_ice")) {
                if (loreList.contains(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("ice.lore")))) {
                    if (player.hasPermission("specitems.power.ice")) {
                        if (event.getAction().equals((Object) Action.RIGHT_CLICK_AIR) || event.getAction().equals((Object) Action.RIGHT_CLICK_BLOCK)) {
                            if (!iceCooldown.contains(pid)) {
                                iceCooldown.add(pid);
                                plugin.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this.plugin, new Runnable() {
    
                                    @Override
                                    public void run() {
                                        iceCooldown.remove(pid);
                                    }
                                }, plugin.getConfig().getInt("ice.cooldown"));
                                Location location = player.getLocation();
                                location.setY(location.getY() + 1);
                                Vector vector = location.getDirection().multiply(plugin.getConfig().getDouble("ice.throw_power"));
    
                                FallingBlock fallingBlock = location.getWorld().spawnFallingBlock(location, Material.ICE, (byte) 0);
                                fallingBlock.setCustomName(ChatColor.AQUA + "Ice Power Ammo");
                                fallingBlock.setVelocity(vector);
                                fallingBlock.setDropItem(false);
    
                                if (this.plugin.getConfig().getBoolean("ice.particles.toggle") == true) {
                                    Particles.send(EnumParticle.valueOf(plugin.getConfig().getString("ice.particles.type").toUpperCase()), location, 0.3F, 0.3F, 0.3F, 0.1F, 20);
                                }
                                if (this.plugin.getConfig().getBoolean("ice.sound.toggle") == true) {
                                    player.getWorld().playSound(location, Sound.valueOf(plugin.getConfig().getString("ice.sound.type")), 1F, 1F);
                                }
                            }
                        }
                    } else {
                        player.sendMessage(pluginPrefix + "You don't have permission to use this power");
                    }
                } else if (loreList.contains(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("lightning.lore")))) {
                    if (player.hasPermission("specitems.power.lightning")) {
                        if (event.getAction().equals((Object) Action.RIGHT_CLICK_AIR) || event.getAction().equals((Object) Action.RIGHT_CLICK_BLOCK)) {
                            if (!lightningCooldown.contains(pid)) {
                                lightningCooldown.add(pid);
                                plugin.getServer().getScheduler().scheduleSyncDelayedTask((Plugin) this.plugin, new Runnable() {
    
                                    @Override
                                    public void run() {
                                        lightningCooldown.remove(pid);
                                    }
                                }, plugin.getConfig().getInt("lightning.cooldown"));
                                for (int n = plugin.getConfig().getInt("lightning.amount"); n > 0; n--) {
                                    block = player.getTargetBlock((HashSet<Byte>) null, plugin.getConfig().getInt("lightning.range"));
                                    block.getWorld().strikeLightning(block.getLocation());
                                }
                                if (plugin.getConfig().getBoolean("lightning.particles.toggle") == true) {
                                    player.getWorld().playSound(player.getLocation(), Sound.valueOf(plugin.getConfig().getString("lightning.sound.type")), 1F, 1F);
                                }
                            }
                        }
                    } else {
                        player.sendMessage(pluginPrefix + "You don't have permission to use this power");
                    }
                } else if (loreList.contains(ChatColor.translateAlternateColorCodes('&', this.plugin.getConfig().getString("tnt.lore")))) {
                    if (player.hasPermission("spectacularitems.power.tnt")) {
                        if (event.getAction().equals((Object) Action.RIGHT_CLICK_AIR) || event.getAction().equals((Object) Action.RIGHT_CLICK_BLOCK)) {
                            Location location = player.getLocation();
                            location.setY(location.getY() + 1);
                            Vector vector = player.getLocation().getDirection().multiply(plugin.getConfig().getInt("tnt.throw_power"));
    
                            TNTPrimed tnt = (TNTPrimed) location.getWorld().spawnEntity(location, EntityType.PRIMED_TNT);
                            tnt.setCustomName(ChatColor.RED + "TNT Power Ammo");
                            tnt.setVelocity(vector);
    
                            if (plugin.getConfig().getBoolean("tnt.particles.toggle") == true) {
                                TNT_Task task = new TNT_Task(plugin);
                                task.setEntity(tnt);
                                task.setId(Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, task, 0, 1));
                            }
                        }
                    } else {
                        player.sendMessage(pluginPrefix + "You don't have permission to use this power");
                    }
                }
            } else if (!this.plugin.getConfig().getBoolean("enable_ice")) {
                player.sendMessage(pluginPrefix + "This power has been disabled in the config.yml");
            }
        }


    Console Log (open)

    Code:
    [21:47:52 ERROR]: Could not pass event PlayerInteractEvent to SpectacularItems v3.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:231) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PlayerInteractManager.a(PlayerInteractManager.java:492) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:890) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PacketPlayInUseItem.a(SourceFile:55) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PacketPlayInUseItem.a(SourceFile:11) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-f630541-a625e45]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
            at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:737) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot.jar:git-Spigot-f630541-a625e45]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
            at specitems.listeners.PlayerListener.onPlayerInteract(PlayerListener.java:50) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-f630541-a625e45]
            ... 17 more
    [21:47:52 ERROR]: Could not pass event PlayerInteractEvent to SpectacularItems v3.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-f630541-a625e45]
            at org.bukkit.craftbukkit.v1_10_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:231) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PlayerInteractManager.a(PlayerInteractManager.java:492) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PlayerConnection.a(PlayerConnection.java:890) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PacketPlayInUseItem.a(SourceFile:55) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PacketPlayInUseItem.a(SourceFile:11) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-f630541-a625e45]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_91]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_91]
            at net.minecraft.server.v1_10_R1.SystemUtils.a(SourceFile:45) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.MinecraftServer.D(MinecraftServer.java:737) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:673) [spigot.jar:git-Spigot-f630541-a625e45]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:572) [spigot.jar:git-Spigot-f630541-a625e45]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
            at specitems.listeners.PlayerListener.onPlayerInteract(PlayerListener.java:50) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-f630541-a625e45]
            ... 17 more
     
    Last edited: Jul 12, 2016
  2. @Chintzi Please put your PlayerListener class in [code=java][/code] tags
     
    Chintzi likes this.
  3. Offline

    Chintzi

  4. Offline

    mine-care

    Chintzi likes this.
  5. Offline

    Chintzi

  6. Offline

    mine-care

    @Chintzi Good luck :)
    Tell me if you need anything.
     
    Chintzi likes this.
  7. Offline

    Chintzi

    @mine-care Hey so i read it thoroughly but im not sure how to apply the fix to my situation, i saw that he checked so see if e was null but im not sure what to check for in my method.

    EDIT: i completely understand now thank you very much for your help finally no console spam! i just checked null for the item in hand and also checked if it wasnt air then etc

    Thx Again
     
    Last edited: Jul 12, 2016
  8. Offline

    mine-care

    @Chintzi No problem ;) Glad the issue was solved! :D
    Also keep in mind that:
    - Item in hand
    - Item metta
    - Item name
    - Item lore
    can all be null, so check before using them ;)
     
Thread Status:
Not open for further replies.

Share This Page