Large spekars
This commit is contained in:
parent
3053110a1a
commit
d83b1dbcd1
7 changed files with 50 additions and 10 deletions
|
@ -7,6 +7,6 @@ import java.util.HashSet;
|
|||
public class BlockChecker extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
new HashSet<>(BlockSpeaker.speakers.values()).forEach(BlockSpeaker::check);
|
||||
new HashSet<>(BlockSpeaker.speakers.values()).forEach(BlockSpeaker::tick);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
package eu.m724.musicPlugin.item.speaker;
|
||||
|
||||
import eu.m724.musicPlugin.Statics;
|
||||
import eu.m724.musicPlugin.player.MovingMusicPlayer;
|
||||
import eu.m724.musicPlugin.player.MusicPlayer;
|
||||
import eu.m724.musicPlugin.player.StaticMusicPlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import org.bukkit.metadata.MetadataValueAdapter;
|
||||
import org.checkerframework.checker.units.qual.N;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class BlockSpeaker extends Speaker {
|
||||
static final Map<Location, BlockSpeaker> speakers = new HashMap<>();
|
||||
|
@ -31,6 +27,7 @@ public class BlockSpeaker extends Speaker {
|
|||
/* */
|
||||
|
||||
private final Location location;
|
||||
private boolean large;
|
||||
|
||||
public BlockSpeaker(Location location) {
|
||||
super(new StaticMusicPlayer(location));
|
||||
|
@ -43,13 +40,34 @@ public class BlockSpeaker extends Speaker {
|
|||
speakers.remove(location);
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
public void tick() {
|
||||
if (location.getBlock().getType() == Material.NOTE_BLOCK && location.getBlock().hasMetadata("t_speaker")) {
|
||||
return true;
|
||||
if (location.clone().add(0, 1, 0).getBlock().getType() == Material.NOTE_BLOCK) {
|
||||
if (!large) {
|
||||
System.out.println("Speaker now large");
|
||||
getMusicPlayer().setDistance(64);
|
||||
this.large = true;
|
||||
}
|
||||
} else {
|
||||
if (large) {
|
||||
System.out.println("Speaker now small");
|
||||
getMusicPlayer().setDistance(32);
|
||||
this.large = false;
|
||||
}
|
||||
}
|
||||
if (getMusicPlayer().isPlaying()) {
|
||||
if (large) {
|
||||
location.getWorld().spawnParticle(Particle.NOTE, location.clone().add(0.6, 0.5, 0), 1, 0, ThreadLocalRandom.current().nextDouble(-1, 0.5), ThreadLocalRandom.current().nextDouble(-0.4, 0.4));
|
||||
location.getWorld().spawnParticle(Particle.NOTE, location.clone().add(-0.6, 0.5, 0), 1, 0, ThreadLocalRandom.current().nextDouble(-1, 0.5), ThreadLocalRandom.current().nextDouble(-0.4, 0.4));
|
||||
location.getWorld().spawnParticle(Particle.NOTE, location.clone().add(0, 0.5, 0.6), 1, ThreadLocalRandom.current().nextDouble(-0.4, 0.4), ThreadLocalRandom.current().nextDouble(-1, 0.5), 0);
|
||||
location.getWorld().spawnParticle(Particle.NOTE, location.clone().add(0, 0.5, -0.6), 1, ThreadLocalRandom.current().nextDouble(-0.4, 0.4), ThreadLocalRandom.current().nextDouble(-1, 0.5), 0);
|
||||
} else {
|
||||
location.getWorld().spawnParticle(Particle.NOTE, location.clone().add(0, 0.7, 0), 1, ThreadLocalRandom.current().nextDouble(-0.4, 0.4), 0, ThreadLocalRandom.current().nextDouble(-0.4, 0.4));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Speaker disaper");
|
||||
destroy();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.m724.musicPlugin.player;
|
||||
|
||||
import de.maxhenkel.voicechat.api.audiochannel.AudioChannel;
|
||||
import de.maxhenkel.voicechat.api.audiochannel.EntityAudioChannel;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -24,4 +25,9 @@ public class EntityMusicPlayer extends MusicPlayer {
|
|||
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistance(int distance) {
|
||||
((EntityAudioChannel)this.channel).setDistance(distance);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,5 +34,8 @@ public class LocalMusicPlayer extends MusicPlayer {
|
|||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistance(int distance) { } // distance doesn't apply to this one
|
||||
|
||||
public static class NotConnectedException extends Exception {}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.m724.musicPlugin.player;
|
||||
|
||||
import de.maxhenkel.voicechat.api.audiochannel.AudioChannel;
|
||||
import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
|
@ -47,4 +48,9 @@ public class MovingMusicPlayer extends MusicPlayer {
|
|||
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistance(int distance) {
|
||||
((LocationalAudioChannel)this.channel).setDistance(distance);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ public abstract class MusicPlayer {
|
|||
private Consumer<TrackAction> onAction = (r) -> {};
|
||||
|
||||
abstract AudioChannel createChannel();
|
||||
abstract public void setDistance(int distance);
|
||||
|
||||
/**
|
||||
* Initializes this music player
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.m724.musicPlugin.player;
|
||||
|
||||
import de.maxhenkel.voicechat.api.audiochannel.AudioChannel;
|
||||
import de.maxhenkel.voicechat.api.audiochannel.LocationalAudioChannel;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.UUID;
|
||||
|
@ -25,4 +26,9 @@ public class StaticMusicPlayer extends MusicPlayer {
|
|||
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDistance(int distance) {
|
||||
((LocationalAudioChannel)this.channel).setDistance(distance);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue