Fix binding speaker and other errors
This commit is contained in:
parent
d83b1dbcd1
commit
26963e32ca
3 changed files with 17 additions and 5 deletions
|
@ -52,14 +52,20 @@ public class ItemEvents implements Listener {
|
|||
var block = event.getClickedBlock();
|
||||
if (block != null) {
|
||||
if (block.getType() == Material.NOTE_BLOCK) {
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE)
|
||||
event.setCancelled(true); // prevent accidental break
|
||||
|
||||
var location = block.getLocation().add(0.5, 0.5, 0.5);
|
||||
var speaker = BlockSpeaker.create(location);
|
||||
|
||||
if (speaker == null) {
|
||||
event.getPlayer().sendMessage("This speaker is occupied");
|
||||
return;
|
||||
}
|
||||
|
||||
player.setSpeaker(speaker);
|
||||
block.getWorld().spawnParticle(Particle.HAPPY_VILLAGER, block.getLocation(), 10);
|
||||
|
||||
if (event.getPlayer().getGameMode() == GameMode.CREATIVE)
|
||||
event.setCancelled(true); // prevent accidental break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,8 @@ public class PortableMediaPlayer {
|
|||
|
||||
speaker.setDestroyCallback(c -> {
|
||||
System.out.println("spekar rip");
|
||||
played.pause(); // this one stops the tracker not playback, which is stopped in Speaker
|
||||
if (played != null)
|
||||
played.pause(); // this one stops the tracker not playback, which is stopped in Speaker
|
||||
this.speaker = null;
|
||||
});
|
||||
|
||||
|
|
|
@ -19,9 +19,14 @@ public class BlockSpeaker extends Speaker {
|
|||
}
|
||||
|
||||
public static BlockSpeaker create(Location location) {
|
||||
if (speakers.containsKey(location))
|
||||
var below = location.clone().subtract(0, 1, 0);
|
||||
|
||||
if (speakers.containsKey(location) || speakers.containsKey(below))
|
||||
return null;
|
||||
return speakers.compute(location, (k, v) -> new BlockSpeaker(location));
|
||||
|
||||
var isTopSpeaker = below.getBlock().getType() == Material.NOTE_BLOCK;
|
||||
System.out.println("SPekaer is top: " + isTopSpeaker);
|
||||
return speakers.compute(isTopSpeaker ? below : location, (k, v) -> new BlockSpeaker(k));
|
||||
}
|
||||
|
||||
/* */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue