if statement for Entity touch water

Discussion in 'Plugin Development' started by Asgernohns, Jul 22, 2013.

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

    Asgernohns

    hello all java programers :)

    i wanna make a plugin that can do so cats gonna be hurt if they touch water.
    i can only make this for a player entity. Anyone who knows how to turn that entity over to
    a cat or ocelot :)

    Here is the player code:
    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e){
    3. Player p = e.getPlayer();
    4.  
    5. if ((e.getTo().getBlock().getType() == Material.STATIONARY_WATER) || (e.getTo().getBlock().getType() == Material.WATER)){
    6. p.addPotionEffect(new PotionEffect(PotionEffectType.HARM, 1000000, 1));
    7.  
    8. }
    9.  
    10. }
     
  2. Offline

    etaxi341

    Asgernohns You could use a Sheduler that checks every 20 Ticks for every Entity Cat if it is in the Water. This could cause lagg but I am note sure. But there is no EntityMoveEvent so I don't know any other Method.
     
  3. Offline

    Asgernohns

  4. Offline

    etaxi341

    put an Scheduler into your onEnable part. for Schedulers are many Tutorials online at YouTube.
     
  5. Offline

    phips99

    Asgernohns You shouldn't kill the player with potions. Do:
    Code:java
    1. player.damage(20D);
     
  6. Offline

    Asgernohns

    i don't wan't it to be a player phips99 but an ocelot

    etaxi341 how do you wanna dectect that the ocelot entity is in the water? :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  7. Offline

    phips99

    Asgernohns Oops. But doesn't matter:
    Code:java
    1. ocelot.damage(20D);
    It's the same...
     
  8. Offline

    Asgernohns

    you're right phips99 but how do i dectect that the ocelot is in water? :)
     
  9. Offline

    etaxi341

    Asgernohns
    You need to define ocelot and then:
    Code:java
    1. if (ocelot.getLocation().getBlock().getType() == Material.WATER){
    2. //STUFF
    3. }
     
  10. Offline

    xTrollxDudex

     
  11. Offline

    Asgernohns

    i tried and i tried and i tried, but i can't figure out how to define ocelot.
    Please help me etaxi341. I know im a noob but i like doing this.
     
  12. Offline

    etaxi341

    Asgernohns
    Code:java
    1. List<Entity> entList = world.getEntities();
    2. for(Entity current : entList){
    3. if (current instanceof Ocelot){
    4. //now is Current your defined ocelot
    5. }
    6. }
     
  13. Offline

    Asgernohns

    etaxi341 i gets a lot of errors in my code

    Here is my onEnable():
    Code:java
    1. @Override
    2. public void onEnable() {
    3. PluginDescriptionFile pdfFile = this.getDescription();
    4. this.Logger.info(pdfFile.getName()+" v"+pdfFile.getVersion()+" has been enabled!");
    5. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    6. public void run(){
    7. List<Entity> entList = world.getEntities();
    8. for(Entity current : entList){
    9. if(current instanceof Ocelot){
    10. if(Ocelot.getLocation().getBlock().getType() == Material.WATER){
    11. Ocelot.damage(1d);
    12. }
    13. }
    14. }
    15. }
    16. }, 1, 20);
    17. }
     
  14. Offline

    etaxi341

    what are the Errors and where are them?
     
  15. Offline

    Asgernohns

    //dfsfsdfsfgh = errors etaxi341

    //dfsdfsdfdsfgh = just code
    //1 error
    world.Entities();
    //world can not be resolved

    //2 error
    if(Ocelot.getLocation().getBlock().getType() == Material.WATER){
    Ocelot.damage(1d);
     
  16. Offline

    etaxi341

    Sorry forgot to send you defined world:
    Code:java
    1. World world = this.getServer().getWorld("world");
     
Thread Status:
Not open for further replies.

Share This Page