Play Effect.

Discussion in 'Plugin Development' started by Scratchytheitchy, May 25, 2013.

Thread Status:
Not open for further replies.
  1. I'm not having any luck on producing "redstone particles" on a hit location,
    Here's my code for it.

    Code:
    @EventHandler
    public void onEntityDamageEvent(EntityDamageEvent event){
    Player hitted = (Player) event.getEntity();
    hitted.getLocation().getWorld().playEffect(hitted.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE);
        }
    Not sure if im using the correct Event or my location is wrong.

    Thanks for reading.

    Or is it my effect ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Im still getting no luck on this :/

    Anyone got a clue what im doing wrong ?
     
  3. Offline

    fromgate

    Hello,
    Effect.STEP_SOUND is not a visual effect. So I think is not possible to play restone particles effect. Visual effect are: SMOKE, POTION_BREAK (include bottle break sound too :(), ENDER_SIGNAL, MOBSPAWNER_FLAMES.
     
  4. Ah i see :/

    Well thanks for the help anyways, much appreicated :)
     
  5. Actually it is a visual effect..It's the effect when a block breaks and when you sprint over a block.
    Scratchytheitchy it probably doesn't work because you didn't registered the listener. Try adding debug messages to see if the event get fired properly.
     
    fromgate likes this.
  6. I always forget about something, thanks CaptainBern :)

    Ill get back if my problem still occurs.
     
  7. You're welcome!
     
  8. Offline

    fromgate

    CaptainBern Ohhh! You opened my eyes! I will check this effect again :) Thank you :)
     
    Programmer213 likes this.
  9. You're welcome!
     
  10. Code:
    package com.gmail.scott.mess16;
     
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class BloodEffect extends JavaPlugin implements Listener{
     
     
       
       
        public final Listener entityListener =(this);
     
        public void OnEnable() {
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(this.entityListener, this);}
        public void OnDisable() {
        }
       
        @EventHandler
        public void onEntityDamage(EntityDamageEvent event){
        Player hitted = (Player) event.getEntity();
        hitted.getLocation().getWorld().playEffect(hitted.getLocation(), Effect.STEP_SOUND, Material.REDSTONE);
        }      
        }
        
    I have watched and read about listeners, and i still dont fully understand them :p

    This code doesnt work, but its got to do with my horrible (embaressing) attempt with Listeners.

    Thanks for reading.
     
  11. Offline

    Wingzzz

    Okay so this wouldn't work as you don't make a Listener, you make a variable of the type class that implements it (I believe) so if you were to do it that way you would not do:
    Code:java
    1. public final Listener entityListener =(this);

    You would do this:
    Code:java
    1. public BloodEffect entityListener = this;

    Although it's very, very unnecessary... So let's get rid of that shall we? Instead we'll replace it with the keyword 'this' (which is just a reference to the class it is used in):
    Code:java
    1. package com.gmail.scott.mess16;
    2.  
    3. import org.bukkit.Effect;
    4. import org.bukkit.Material;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.entity.EntityDamageEvent;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class BloodEffect extends JavaPlugin implements Listener {
    13.  
    14. @Override
    15. public void OnEnable() {
    16. PluginManager pm = getServer().getPluginManager();
    17. // no need to make an instance of the class when you can just say 'this'
    18. pm.registerEvents(this, this);
    19. }
    20.  
    21. @Override
    22. public void OnDisable() {
    23. }
    24.  
    25. @EventHandler
    26. public void onEntityDamage(EntityDamageEvent event){
    27. Player hitted = (Player) event.getEntity();
    28. hitted.getLocation().getWorld().playEffect(hitted.getLocation(), Effect.STEP_SOUND, Material.REDSTONE);
    29. }
    30.  
    31. }

    Once you get your listener and everything going and if it still doesn't work try:
    Code:java
    1. hitted.getLocation().getWorld().playEffect(hitted.getLocation(), Effect.STEP_SOUND, Material.REDSTONE.getID());

    Great reference for the Bukkit Event API: http://wiki.bukkit.org/Event_API_Reference
     
  12. Ah i see.

    Thanks for taking your time to explain it and help.
    Ill test this later when i have time :)
     
  13. Offline

    Wingzzz

    Sounds great! Let me know how it turns out eh
     
  14. Sure, will do!
     
  15. Offline

    DarkBladee12

    WiredWingzzz Scratchytheitchy You should make a check if the entity is a player first and then cast it into a player, because otherwise it'll throw a lot of errors ;)
     
  16. Offline

    Wingzzz

    That's very true.
     
  17. I see, thanks for the heads up.
     
  18. Offline

    Wingzzz

    I believe if you only want it for players, otherwise just use Entity (or perhaps LivingEntity) and do it that way.
    Code:java
    1. LivingEntity hitted = (LivingEntity) event.getEntity();

    This way any LivingEntity ie: zombie, player, skeleton can have the blood come out. Although you may want to get a bit specific like make skeletons perhaps have bones spurt out or white wool STEP_SOUND or something of the sort (Like sorting what item/animation per mob, just a thought).
     
  19. Code:
    package com.gmail.scott.mess16;
     
    import org.bukkit.Effect;
    import org.bukkit.Material;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class BloodEffect extends JavaPlugin implements Listener{
     
        public void OnEnable() {
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(this, this);}
       
       
        public void OnDisable() {
        }
       
        @EventHandler
        public void onEntityDamage(EntityDamageEvent event){
        LivingEntity hitted = (LivingEntity) event.getEntity();
        hitted.getLocation().getWorld().playEffect(hitted.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_WIRE);
        }
       
        }
        
    Its still not working, ive tried Material.REDSTONE_WIRE, Material.REDSTONE and Material.REDSTONE.getId

    Any suggestions ?

    Thanks.
     
  20. Offline

    Wingzzz

    Errors or anything? Not sure what you mean by not working exactly, mind letting us know a little bit more detail?
     
  21. No redstone particles are prodouced when attacking, and theres no errors :/
     
  22. Offline

    FuZioN720

    I think you need an action try this.

    Code:java
    1.  
    2. if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
    3. hitted.getLocation().getWorld().playEffect(hitted.getLocation(), Effect.STEP_SOUND, Material.REDSTONE.getID());
    4. }
    5.  


    Also Check this out: LINK

    You can'y have the Material.REDSTONE.getID() there it goes like this:

    Find from the Bukkit API

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  23. Alright, ill try that and play about with it.
    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page