Asyncronos Entity add - ERROR :(

Discussion in 'Plugin Development' started by deleted_91027365, May 25, 2015.

Thread Status:
Not open for further replies.
  1. Hey, I wan to make a flying slimeball and if it hits a player the player dies. But if i want to do anything with setHealth() I became an Asyncronos Entity add error for this line. But if i want to send some message, it works fine.

    Here is the Listener:
    Code:
    package de.dunklesToast.rm;
    
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    
    
    @SuppressWarnings("deprecation")
    public class AxeThread implements Runnable {
       
        private Thread thread;
        private Player player;
        private double radius;
        private boolean running;
        private Item item;
    
       
        public AxeThread(Player player, double radius, Item item){
            this.player = player;
            this.radius = radius;
            this.item = item;
            this.thread = new Thread(this);
           
        }
       
        public void start() {
            this.running = true;
            if(running){
                this.thread.start();
            }
        }
       
    
        public void stop() {
            this.running = false;
            this.thread.stop();
        }
       
    
        @Override
        public void run() {
            while(running) {
                for(Entity entity : item.getNearbyEntities(radius, radius, radius)) {
                    if(entity instanceof Player) {
                        Player target = (Player) entity;
                        if(target != player) {
                            target.setHealth(0.0D);
                            target.sendMessage("Hit");
                            this.item.remove();
                            this.stop();
                        }
                       
                    }
                   
               
               
               
                if(item.isOnGround()) {
                    this.item.remove();
                    this.stop();
                }
                if(item == null) {
                    this.stop();
                }
                try {
                    Thread.sleep(25);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }}
    
     
  2. Offline

    Googlelover1234

    @dunklesToast
    I'm not 100% sure on what you are doing, but how come you cast Player to entity, and then check if that entity isn't a player? Anyway, please describe a little bit more on what your goal is, I had a bit of a hard time understanding it.
     
  3. Offline

    Goblom

    Anything have to do world modification cannot be done async (this includes entity related stuff). You will get an error every time you do this because bukkit & Minecraft both prevent it.

    Edit: forgot tag @dunklesToast
     
  4. @Googlelover1234 Do you know the GameMode RageMode? (GommeHD.net). I want that a player can throw an item and it flys (Like an arrow) and if this SlimeBall hits a Player the Player dies.
     
  5. Offline

    mythbusterma

    @dunklesToast

    Doesn't matter what you're trying to do, don't do it asynchronously if you don't have to.
     
  6. Offline

    Zombie_Striker

    @dunklesToast
    Please use Schedular or a BukkitRunnable, don't make a new Thread.

    Also, you need to cast your Entity to a Damageable in order to set their health .
     
Thread Status:
Not open for further replies.

Share This Page