Help With Sounds and Effects!

Discussion in 'Plugin Development' started by lme999, Dec 10, 2013.

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

    lme999

    Hey guys, I'm trying to get this to play a sound, and do the 'smoke' effect, whenever a player hits another player inside of my hub

    It should work like this:
    If one player hits the other, the player who got hit, should have the smoke effect happen around them. The one who hit the player, should hear a sound.
    Also, it needs to only work in the 'hubworld'
    How can I do this? This is what I currently have, and it's not working:
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
    3. Player player = (Player) event.getEntity();
    4. if (player.hasPermission("nodrop.no")) {
    5. if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
    6. if (event.getEntity().getWorld().getName() == "hubworld") {
    7. event.getEntity().getWorld().playEffect(event.getEntity().getLocation(), Effect.SMOKE, 0);
    8. Bukkit.getWorld("hubworld").playSound(player.getLocation(), Sound.VILLAGER_HAGGLE, 1, 0);
    9. }
    10. }
    11. }
    12. }
     
  2. Offline

    MOMOTHEREAL

    Your code seems fine. Maybe try outputing something in the console (debug line). Events registered correctly?
     
  3. Offline

    lme999

    How do I do that?
    Someone mentioned adding a left click interact type thing? Which I also do not know how to do.
     
  4. Offline

    JRL1004

    lme999 event.getEntity().getWorld().getName().equals("hubworld");
     
  5. Offline

    Wingzzz

    The listener is being registered, correct?
     
  6. Offline

    lme999

    Setting it up in the world seems to work for me, on my other events that I have working, it's just I cannot figure out how to make the sound/effects actually happen.
     
  7. Offline

    JRL1004

    lme999 One thing I recommend when testing w/ sounds and particles is to make sure your sounds are up and your particles are set to all (respectively).
    also, I made it (sorta):
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
    3. if (!(e.getEntity() instanceof Player)) return; // Return out if a player was not hurt
    4. if (!(e.getDamager() instanceof Player)) return; // Return out if a player was not the attacker
    5. Player player = (Player) e.getEntity();
    6. if (!player.getWorld().getName().equals("hubworld")) return; // You need to use .equals, it will not work otherwise
    7. if (!player.hasPermission("nodrop.no")) return; //No permission
    8. World w = player.getWorld();
    9. w.playEffect(player.getLocation(), Effect.SMOKE, null); // No data bit needed for smoke
    10. w.playSound(player.getLocation(), Sound.VILLAGER_HAGGLE, 1, 0);
    11. }

    This exactly what you have, I just cleaned it up
     
  8. Offline

    Wingzzz

    Code:java
    1. player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 0, 20);
    2. player.gerWorld().playSound(player.getLocation(), Sound.SOMETHING, 1F, 1F);


    These methods are from World-

    Methods:
    void playEffect (Location location, Effect effect, int data, int radius)
    Plays an effect to all players within a given radius around a location.

    void playSound (Location location, Sound sound, float volume, float pitch)
    Play a Sound at the provided Location in the World.
     
    jthort likes this.
  9. Offline

    lme999

    Okay, thanks guys, I've got it working mostly now. Except that I have another event that cancels all player damage, from drowning, hitting other people, falling etc.. (EntityDamageEvent). So what I need now, is a new event I think, that will make the smoke/sound happen when the person hits the player (but no damage gets taken). Anyone know of anything?
     
  10. Offline

    MOMOTHEREAL

    I think you shall use EntityDamageByEntityEvent instead.
     
  11. Offline

    lme999

    That seems to have worked, I can't hit mobs in the hubworld now, but that world will have mobs disabled anyway, thanks so much for everyone's help, I really appreciate it.
     
Thread Status:
Not open for further replies.

Share This Page