Jukebox getPlaying

Discussion in 'Plugin Development' started by KaBob, Aug 14, 2011.

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

    KaBob

    I'm trying to use the following code to check what a jukebox is playing, but it returns gold record even if its playing a green record.
    BlockState b=player.getTargetBlock(null, 100).getState();
    and then
    ((Jukebox)b.getData()).getPlaying()
    But as far as I can tell, both the code and the minecraft wiki incorrectly assume that the jukebox stores the record in the data value. From what I've seen, the data value just says 1 if theres a disc in it. Which is why the code always outputs gold record.
    Anyway, is there some other way to check which record is inside a jukebox?
     
  2. Offline

    kroltan

    I think you could try to raise a flag when a player "inserts" the disc in the jukebox, containing the disc that was inserted. Then you could check if the jukebox is playing, and check that variable, then do your code
    Code:java
    1. BlockState b = player.getTargetBlock(null, 100).getState();
    2. if (((Jukebox)b.getData()).getPlaying() && theVarIToldYou == 1) { //1=green, 2=gold, for example
    3. do.something();
    4. }

    Edit: i didn't test this.
     
  3. Offline

    Acrobot

    Experimental, you will need CraftBukkit:
    Code:java
    1.  
    2. Location l = player.getLocation();
    3. TileEntityRecordPlayer recordplayer =(TileEntityRecordPlayer) ((CraftWorld) player.getWorld()).getHandle().getTileEntity(l.getBlockX(), l.getBlockY(), l.getBlockZ());
    4. int typeOfRecord = recordplayer.a;
    5.  


    BTW, 0 means no disk.
     
Thread Status:
Not open for further replies.

Share This Page