Solved Event started by player (or minecart)

Discussion in 'Plugin Development' started by haamome, Apr 26, 2014.

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

    haamome

    Hi everyone

    First of all you have to know guys that i'm french and my english could be very bad. So i'll try to to write good so u can at least understand me :D

    So my problem is pretty simple :

    I want to play a sound when a player (riding a minecart) cross a specifique location, that i set it in my code java. I did a pretty good job so far when i use "BlockPistonExtendEvent", the sound works prefectly. The problem is i want the sound start when the player riding a minecart is at the location (1146, 96, 25) for example.

    So here's my code you might be understand what i want. I just want to know why the event doesn't start. Thanks by advance :)

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.Location;
    3. import org.bukkit.Sound;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.block.BlockPistonExtendEvent;
    8. import org.bukkit.event.player.PlayerMoveEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class CactusSound extends JavaPlugin implements Listener{
    12.  
    13.  
    14. public void onEnable() {
    15. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    16. }
    17.  
    18.  
    19. @EventHandler
    20. public void onPlayerMoveEvent(PlayerMoveEvent pme) {
    21. Location l = new Location(Bukkit.getWorld("world"), 1146, 133, 28);
    22. Player p = pme.getPlayer();
    23.  
    24. if (p.getPlayer().getLocation() == l) {
    25.  
    26. p.getPlayer().getWorld().playSound(p.getPlayer().getLocation(), Sound.GHAST_SCREAM, 1, 1);
    27. }
    28. }
    29.  
    30. @EventHandler
    31. public void onBlockBreak(BlockPistonExtendEvent e) {
    32.  
    33. if (e.getBlock().isBlockPowered() == true) {
    34. e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.GHAST_SCREAM, 1, 1);
    35. }
    36. }
    37. }
     
  2. Offline

    killerman747

    Untested but should work. Replace in your PlayerMoveEvent
    Code:java
    1. int x = p.getLocation().getBlockX();
    2. int y = p.getLocation().getBlockY();
    3. int z = p.getLocation().getBlockZ();
    4. if(x.equals(YourX) && y.equals(YourY) && z.equals(YourZ)){
    5. Bukkit.getPlayer(p).getWorld().playSound(location,Sound.LEVEL_UP,3, 0);
    6. }
     
    haamome likes this.
  3. Offline

    haamome

    Yup mate thanks for the reply, it works perfectly. Here's my code for ppl who want make the same plugin

    Code:java
    1. import org.bukkit.Bukkit;
    2. import org.bukkit.Sound;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.block.BlockPistonExtendEvent;
    7. import org.bukkit.event.player.PlayerMoveEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class CactusSound extends JavaPlugin implements Listener{
    11.  
    12.  
    13. public void onEnable() {
    14. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    15. }
    16.  
    17. /*Sound played when the player go to the coordinate*/
    18. @EventHandler
    19. public void onPlayerMoveEvent(PlayerMoveEvent pme) {
    20.  
    21. Player p = pme.getPlayer();
    22. int x = p.getLocation().getBlockX();
    23. int y = p.getLocation().getBlockY();
    24. int z = p.getLocation().getBlockZ();
    25. if(x == [your X coordinate] && y == [your Y coordinate] && z == [your Z coordinate]){
    26. p.getWorld().playSound(p.getLocation(),Sound.GHAST_SCREAM, 1, 1);
    27. }
    28. }
    29.  
    30. /*Sound played when Piston is extended*/
    31. @EventHandler
    32. public void onBlockBreak(BlockPistonExtendEvent e) {
    33.  
    34. if (e.getBlock().isBlockPowered() == true) {
    35. e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.GHAST_SCREAM, 1, 1);
    36. }
    37. }
    38. }



    PS: I don't if there is a way to turn the theard to SOLVED. If yes let me know how to do it :p
     
  4. Offline

    LarsNitro

    haamome Thread Tools > Edit Thread > Prefix > Solved
     
  5. Offline

    BillyBobJoe168

    Click thread tools>edit thread>prefix>solved (on phone maybe my words are a bit off XD)
    EDIT: ninja'd XD
     
  6. Offline

    haamome

    Thanks both of you :)
     
Thread Status:
Not open for further replies.

Share This Page