Search in sources :

Example 1 with PositionSongPlayer

use of com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer in project HitW-plugin by Blackoutburst.

the class HPlayer method setInGame.

public void setInGame(boolean inGame, HGame game) {
    this.inGame = inGame;
    if (!inGame) {
        if (rsp != null) {
            rsp.setPlaying(false);
            rsp.destroy();
        }
        Utils.giveConfigItem(this.player);
    } else {
        if (new File("./plugins/HitW/songs/" + songName + ".nbs").exists()) {
            Location loc = new Location(this.player.getLocation().getWorld(), (game.getArea().x0 + game.getArea().x1) / 2, (game.getArea().y0 + game.getArea().y1) / 2, (game.getArea().z0 + game.getArea().z1) / 2);
            song = NBSDecoder.parse(new File("./plugins/HitW/songs/" + songName + ".nbs"));
            rsp = new PositionSongPlayer(song);
            rsp.setTargetLocation(loc);
            rsp.setDistance(128);
            rsp.setRepeatMode(RepeatMode.ONE);
            rsp.addPlayer(this.getPlayer());
            rsp.setPlaying(true);
        }
    }
}
Also used : PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) File(java.io.File) Location(org.bukkit.Location)

Example 2 with PositionSongPlayer

use of com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer in project Nexus by ProjectEdenGG.

the class JukeboxUser method play.

public void play(JukeboxSong jukeboxSong, int tick) {
    cancel();
    final Song song = jukeboxSong.getSong();
    final PositionSongPlayer songPlayer = new PositionSongPlayer(song);
    updatePlayers(songPlayer);
    songPlayer.setTargetLocation(getLocation());
    songPlayer.setPlaying(true);
    songPlayer.setTick((short) tick);
    songPlayer.setCategory(SoundCategory.RECORDS);
    this.currentSong = jukeboxSong.getName();
    this.songPlayer = songPlayer;
    this.taskIds.add(Tasks.repeat(0, 1, () -> {
        if (!isOnline()) {
            cancel();
            return;
        }
        songPlayer.setTargetLocation(getLocation());
        updatePlayers(songPlayer);
    }));
}
Also used : PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) Song(com.xxmicloxx.NoteBlockAPI.model.Song)

Example 3 with PositionSongPlayer

use of com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer in project Nexus by ProjectEdenGG.

the class Listeners method onSongNext.

@EventHandler
public void onSongNext(SongNextEvent event) {
    SongPlayer songPlayer = event.getSongPlayer();
    Song song = songPlayer.getSong();
    Set<UUID> UUIDList = songPlayer.getPlayerUUIDs();
    for (UUID uuid : UUIDList) {
        Player player = Bukkit.getPlayer(uuid);
        if (player == null || !player.isOnline())
            continue;
        if (songPlayer instanceof PositionSongPlayer) {
            Radio radio = RadioUtils.getRadio(songPlayer);
            if (radio != null) {
                if (RadioUtils.isInRangeOfRadiusRadio(player, radio))
                    RadioUtils.actionBar(player, song, true);
            }
        } else
            RadioUtils.actionBar(player, song, true);
    }
}
Also used : PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) Song(com.xxmicloxx.NoteBlockAPI.model.Song) RadioUtils.removePlayer(gg.projecteden.nexus.features.radio.RadioUtils.removePlayer) SongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer) RadioUtils.addPlayer(gg.projecteden.nexus.features.radio.RadioUtils.addPlayer) Player(org.bukkit.entity.Player) PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) SongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer) PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) Radio(gg.projecteden.nexus.models.radio.RadioConfig.Radio) UUID(java.util.UUID) EventHandler(org.bukkit.event.EventHandler)

Example 4 with PositionSongPlayer

use of com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer in project Nexus by ProjectEdenGG.

the class RadioFeature method createSongPlayer.

public static void createSongPlayer(Radio radio, Playlist playlist) {
    playlist = RadioUtils.shufflePlaylist(playlist);
    if (radio.getType().equals(RadioType.RADIUS)) {
        Location location = radio.getLocation();
        int radius = radio.getRadius();
        PositionSongPlayer positionSongPlayer = new PositionSongPlayer(playlist);
        positionSongPlayer.setTargetLocation(location);
        positionSongPlayer.setDistance(radius);
        setRadioDefaults(positionSongPlayer);
        radio.setSongPlayer(positionSongPlayer);
    } else {
        RadioSongPlayer radioSongPlayer = new RadioSongPlayer(playlist);
        setRadioDefaults(radioSongPlayer);
        radio.setSongPlayer(radioSongPlayer);
    }
}
Also used : PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) RadioSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer) Location(org.bukkit.Location)

Example 5 with PositionSongPlayer

use of com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer in project Nexus by ProjectEdenGG.

the class RadioFeature method onStart.

@Override
public void onStart() {
    allSongs = new ArrayList<>();
    new Listeners();
    Tasks.async(() -> {
        File[] songs = songsDirectory.listFiles();
        if (songs != null) {
            for (File file : songs) allSongs.add(new RadioSong(file.getName(), file));
        }
        setupRadios();
        // Rejoin radios
        for (Player player : OnlinePlayers.getAll()) {
            RadioUser user = userService.get(player);
            if (user.getLastServerRadio() != null)
                RadioUtils.addPlayer(player, user.getLastServerRadio());
        }
        // Radio Particles Task
        Tasks.repeat(0, TickTime.TICK.x(5), () -> {
            for (Radio radio : getRadios()) {
                if (!radio.getType().equals(RadioType.RADIUS))
                    continue;
                if (!radio.isEnabled())
                    continue;
                if (!radio.isParticles())
                    continue;
                if (radio.getLocation() == null)
                    continue;
                new ParticleBuilder(Particle.NOTE).count(RandomUtils.randomInt(1, 3)).offset(0.25, 0.25, 0.25).location(radio.getLocation().add(0, RandomUtils.randomDouble(0.45, 0.75), 0)).spawn();
            }
        });
        // Radius Radio User Task
        RadioUserService service = new RadioUserService();
        Tasks.repeat(0, TickTime.SECOND.x(2), () -> {
            for (Radio radio : getRadios()) {
                if (!(radio.getSongPlayer() instanceof PositionSongPlayer))
                    continue;
                for (Player player : OnlinePlayers.getAll()) {
                    RadioUser user = service.get(player);
                    if (user.isMute())
                        continue;
                    if (user.getLeftRadiusRadios().contains(radio.getId()))
                        continue;
                    boolean isInRange = isInRangeOfRadiusRadio(player, radio);
                    boolean isListening = isListening(player, radio);
                    if (isInRange && !isListening) {
                        if (user.getServerRadio() != null)
                            removePlayer(player, user.getServerRadio());
                        addPlayer(player, radio);
                    } else if (!isInRange && isListening) {
                        removePlayer(player, radio);
                        if (user.getLastServerRadio() != null)
                            addPlayer(player, user.getLastServerRadio());
                    }
                }
            }
        });
    });
}
Also used : PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) RadioUtils.removePlayer(gg.projecteden.nexus.features.radio.RadioUtils.removePlayer) Player(org.bukkit.entity.Player) PositionSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer) SongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer) RadioUtils.addPlayer(gg.projecteden.nexus.features.radio.RadioUtils.addPlayer) RadioSongPlayer(com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer) RadioUser(gg.projecteden.nexus.models.radio.RadioUser) Radio(gg.projecteden.nexus.models.radio.RadioConfig.Radio) RadioUtils.isInRangeOfRadiusRadio(gg.projecteden.nexus.features.radio.RadioUtils.isInRangeOfRadiusRadio) File(java.io.File) RadioSong(gg.projecteden.nexus.models.radio.RadioConfig.RadioSong) ParticleBuilder(com.destroystokyo.paper.ParticleBuilder) RadioUserService(gg.projecteden.nexus.models.radio.RadioUserService)

Aggregations

PositionSongPlayer (com.xxmicloxx.NoteBlockAPI.songplayer.PositionSongPlayer)5 Song (com.xxmicloxx.NoteBlockAPI.model.Song)2 RadioSongPlayer (com.xxmicloxx.NoteBlockAPI.songplayer.RadioSongPlayer)2 SongPlayer (com.xxmicloxx.NoteBlockAPI.songplayer.SongPlayer)2 RadioUtils.addPlayer (gg.projecteden.nexus.features.radio.RadioUtils.addPlayer)2 RadioUtils.removePlayer (gg.projecteden.nexus.features.radio.RadioUtils.removePlayer)2 Radio (gg.projecteden.nexus.models.radio.RadioConfig.Radio)2 File (java.io.File)2 Location (org.bukkit.Location)2 Player (org.bukkit.entity.Player)2 ParticleBuilder (com.destroystokyo.paper.ParticleBuilder)1 RadioUtils.isInRangeOfRadiusRadio (gg.projecteden.nexus.features.radio.RadioUtils.isInRangeOfRadiusRadio)1 RadioSong (gg.projecteden.nexus.models.radio.RadioConfig.RadioSong)1 RadioUser (gg.projecteden.nexus.models.radio.RadioUser)1 RadioUserService (gg.projecteden.nexus.models.radio.RadioUserService)1 UUID (java.util.UUID)1 EventHandler (org.bukkit.event.EventHandler)1