Large spekars

This commit is contained in:
Minecon724 2024-12-20 11:14:42 +01:00
commit d83b1dbcd1
No known key found for this signature in database
GPG key ID: 3CCC4D267742C8E8
7 changed files with 50 additions and 10 deletions

View file

@ -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);
}
}

View file

@ -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;
}
}
}

View file

@ -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);
}
}

View file

@ -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 {}
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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);
}
}