Solved Spamming Console

Discussion in 'Spigot Plugin Development' started by MakingTheMagic, May 30, 2016.

  1. Hey there!

    Does anyone know what is wrong with this or how I could stop this from spamming my console with errors. As I cant find a solution.

    Code (Text):
     @EventHandler(priority = EventPriority.HIGHEST)
      public void EntityChangeBlockEvent (final EntityChangeBlockEvent event) {
             Block b= (Block) event.getEntity();
      if (event.getEntityType() == EntityType.FALLING_BLOCK) {
       event.setCancelled(true);
     
        }
       }
    Thank you,
    Any advice will be appreciated!
     
  2. I can't find any solution either Without an error.
     
  3.  
  4. Code (Java):
    public Entity getEntity()
    Returns the Entity involved in this event
    Code (Java):
    public Block getBlock()
    Gets the block the entity is changing
    how do you cast them ?
    Code (Java):
    Block block = (Block) e.getBlock();
    and

    Code (Java):
    Entity entity = (Entity) e.getEntity();
     
  5. So if I remove the cast about the block, and replace it with Entity. It should stop the error?

    Thanks,
    :)
     
  6. not sure about other errors but the error ClassCastException is the one you've been fixed.
     
  7. Thank you. :)
     
  8. set the thread as solved.
     
  9. Code (Text):
         
    [10:04:05 WARN]: CommandBlock at (526,4,20) failed to handle command
    org.bukkit.command.CommandException: Unhandled exception executing command 'minecartride' in plugin MyPlugin v2.8
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.CommandBlockListenerAbstract.executeCommand(CommandBlockListenerAbstract.java:211) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.CommandBlockListenerAbstract.a(CommandBlockListenerAbstract.java:92) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.BlockCommand.b(BlockCommand.java:48) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:653) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.WorldServer.doTick(WorldServer.java:249) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:770) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_66]
    Caused by: java.lang.IllegalArgumentException: Entity cannot ride itself.
            at com.google.common.base.Preconditions.checkArgument(Preconditions.java:125) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity.setPassenger(CraftEntity.java:313) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            at net.mini.mcd.commands.MinecartRide.onCommand(MinecartRide.java:43) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Spigot-db6de12-18fbb24]
            ... 11 more
    >save-all
    [10:04:54 INFO]: Saving...
    [10:04:55 INFO]: Saved the world
    >
    So this is another error, and this is my code:

    Code (Text):
        if(sender instanceof BlockCommandSender)
                     {
                         if(args.length == 2)
                         {
                              final Player player;

                                try {
                                        player = Bukkit.getPlayer(args[0]);
                                     
                                } catch (Exception e) {
                                        return true;
                                }
                 
                         Location block = ((BlockCommandSender) sender).getBlock().getLocation();
                         for (Entity nearby : getNearbyEntities(block, Integer.parseInt(args[1]))) { // Gets entities within 5 blocks of given location
                            if(nearby instanceof Minecart)
                            {
                                if(nearby.getPassenger() == null)
                                {
                                       System.out.print("Sent player to cart!");
                                      nearby.setPassenger(player);
                                      nearby.getPassenger().setPassenger(player);
                                      if(nearby.getPassenger() == null)
                                      {
                                      nearby.setPassenger(player);
                                      nearby.getPassenger().setPassenger(player);
                                      }
                                }else{        
                     
                               System.out.print("Can not send player to cart!");
                           
                                }
                            }    
                        }
                           


                         }
                   
                     }
                 }
                return false;
             }
               
                   
           
           
       
                 public static Entity[] getNearbyEntities(Location l, int radius) {

                     int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16)) / 16;

                    HashSet <Entity> radiusEntities = new HashSet < Entity > ();


                   for (int chX = 0 - chunkRadius; chX <= chunkRadius; chX++) {

                       for (int chZ = 0 - chunkRadius; chZ <= chunkRadius; chZ++) {
                            int x = (int) l.getX(), y = (int) l.getY(), z = (int) l.getZ();

                        for (Entity e: new Location(l.getWorld(), x + (chX * 16), y, z + (chZ * 16)).getChunk().getEntities()) {

                              if (e.getLocation().distance(l) <= radius && e.getLocation().getBlock() != l.getBlock())

                             radiusEntities.add(e);

                     }
                       }
        }

               

                        return radiusEntities.toArray(new Entity[radiusEntities.size()]);

                 }
    }






     
    Any ideas? Thanks! :D
     
  10. you're using try and catch exception wrong. just simply removed them and set the value of player player in to Server#getPlayer(args[0])
     
  11. this is another error :p

    it will caused by :
    Code (Java):
    java.lang.IllegalArgumentException: Entity cannot ride itself.
     
  12. I removed try and catch - now I have this:

    Code (Text):
            if(sender instanceof BlockCommandSender)
                     {
                         if(args.length == 2)
                         {
                                       
                              Player player = Bukkit.getPlayer(args[0]);
                   
                         Location block = ((BlockCommandSender) sender).getBlock().getLocation();
                         for (Entity nearby : getNearbyEntities(block, Integer.parseInt(args[1]))) { // Gets entities within 5 blocks of given location
                            if(nearby instanceof Minecart)
                            {
                                if(nearby.getPassenger() == null)
                                {
                                     
                                //      nearby.setPassenger(player);
                                      nearby.getPassenger().setPassenger(player);
                                      if(nearby.getPassenger() == null)
                                      {
                                          System.out.print("[Plugin] Sent player to cart!");
                                //      nearby.setPassenger(player);
                                      nearby.getPassenger().setPassenger(player);
                                      }
                                }else{        
                       
                               System.out.print("[Plugin] Can not send player to cart!");
                             
                                }
                            }    
                        }
                             
    but now it doesn't run and shows an error still in Console.
     
  13. oohh what you did ?

    Code (Java):
    nearby.setPassenger(player);
    // and remove this
    nearby.getPassenger().setPassenger(player);
     
  14. Remove this line:
    nearby.getPassenger().setPassenger(player);
     
    • Like Like x 1
  15. Thanks for lending a hand I'll give him to you. I have many works to do.
     
    • Friendly Friendly x 1
  16. Thanks!
     
  17. Code (Text):
    [15:37:07] [Server thread/ERROR]: Could not pass event PlayerDropItemEvent to McDiscoveryCore v2.8
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.EntityHuman.a(EntityHuman.java:556) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.EntityHuman.drop(EntityHuman.java:513) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:2032) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.PacketPlayInSetCreativeSlot.a(SourceFile:23) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.PacketPlayInSetCreativeSlot.a(SourceFile:9) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_72]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_72]
        at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
    Caused by: java.lang.NullPointerException
        at net.mini.mcd.join.Inventory.drop(Inventory.java:87) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_72]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_72]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_72]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_72]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.jar:git-Spigot-104c8c8-00d3334]
        ... 17 more
     
    That's my error, and this is my code:

    Code (Text):
         @EventHandler
         public void drop(PlayerDropItemEvent e)
         {
             if(e.getItemDrop().getItemStack().getItemMeta().getDisplayName().equalsIgnoreCase("item1"))
                     {
                 e.setCancelled(true);
                     
                     }
             if(e.getItemDrop().getItemStack().getItemMeta().getDisplayName().equalsIgnoreCase("item2"))
                     {
                 e.setCancelled(true);
                     }
             if(e.getItemDrop().getItemStack().getItemMeta().getDisplayName().equalsIgnoreCase("item3"))
             {
                 e.setCancelled(true);
             }
       

         }
     
    Thanks for this help! :D
     

  18. well first of all create a new post for this topic so we can't get confused.

    second check if the Item that's been dropped has ItemMeta or null.
     
  19. Thanks, and sorry! :D