Development Assistance Teleporting items on EntityExplodeEvent (error)

Discussion in 'Plugin Help/Development/Requests' started by DNABomb, Jun 11, 2015.

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

    DNABomb

    im getting the error "org.bukkit.craftbukkit.v1_8_R3.entity.CraftItem cannot be cast to org.bukkit.entity.Player"

    My goal is that whenever there is an explosion event the dropped items (from chests and destroyed blocks) get teleported to a Player (if the player is withing 20 blocks of the explosion)

    Here is my code

    Code:
    @EventHandler
        public void onEntityExplode(EntityExplodeEvent event) {
            final Entity entity = event.getEntity();
            if (entity instanceof Creeper || entity instanceof TNTPrimed) {
                int X = entity.getLocation().getBlock().getX();
                int Z = entity.getLocation().getBlock().getZ();
                int Y = entity.getLocation().getBlock().getY();
                Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "say The block location of the Explosion = " + X + " " + Z + " " + Y);
                this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                      public void run() {
                          for (Entity e : entity.getNearbyEntities(20, 20, 20))
                                 if (e.getType().equals(EntityType.DROPPED_ITEM)) {
                                     Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), "say the entities in the region are : " + ((e instanceof Player ? ((Player) e).getName() : e.getType().name())));
                                     Location location = ((Player) e).getLocation();
                                     e.teleport(location);
                                 }
                      }
                    }, 2);
            }
        }
     
  2. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  3. Offline

    Markyroson

    Are you getting any errors or stack traces that you could provide to better help the community assist you?
     
  4. Offline

    I Al Istannen

    @DNABomb Line 11 passes through, if the Entity is an Item. Then later you cast the entity to an Player (line 14,13). That can't work.
    And why would you use "Bukkit.getServer().dispatchCommand("say");"? This way the whole server will read the messages.
     
Thread Status:
Not open for further replies.

Share This Page