Some java 8 code
This commit is contained in:
parent
addb2c8c0e
commit
a1915e324c
@ -1,10 +1,12 @@
|
||||
package mineplex.core.common.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
@ -18,6 +20,11 @@ public class UtilServer
|
||||
return getServer().getOnlinePlayers().toArray(new Player[0]);
|
||||
}
|
||||
|
||||
public static Collection<? extends Player> getPlayersCollection()
|
||||
{
|
||||
return getServer().getOnlinePlayers();
|
||||
}
|
||||
|
||||
public static List<Player> getSortedPlayers()
|
||||
{
|
||||
return getSortedPlayers(new Comparator<Player>()
|
||||
|
@ -1,7 +1,10 @@
|
||||
package mineplex.core.noteblock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -40,12 +43,7 @@ public class NotePlayer
|
||||
|
||||
private void startThread()
|
||||
{
|
||||
Thread thread = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
Thread thread = new Thread(() -> {
|
||||
while (!_finished)
|
||||
{
|
||||
_tick++;
|
||||
@ -59,14 +57,9 @@ public class NotePlayer
|
||||
{
|
||||
_finished = true;
|
||||
|
||||
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_plugin.getServer().getScheduler().runTask(_plugin, () -> {
|
||||
SongFinishEvent event = new SongFinishEvent(_song);
|
||||
_plugin.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
@ -84,34 +77,23 @@ public class NotePlayer
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private void playTick(int tick)
|
||||
private void playNote(Note note, float volume, Collection<? extends Player> players)
|
||||
{
|
||||
Player[] playerArray = UtilServer.getPlayers();
|
||||
List<Player> players = new ArrayList<>(playerArray.length);
|
||||
for (Player player : playerArray)
|
||||
{
|
||||
if (_verifier.shouldPlay(player))
|
||||
players.add(player);
|
||||
players.stream().filter(_verifier::shouldPlay).forEach((player) ->
|
||||
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33)));
|
||||
}
|
||||
|
||||
for (NoteLayer layer : _song.getLayers())
|
||||
private void playTick(int tick)
|
||||
{
|
||||
Note note = layer.getNote(tick);
|
||||
if (note != null)
|
||||
{
|
||||
float volume = _volumeMult * (layer.getVolume() / 100F);
|
||||
for (Player player : players)
|
||||
{
|
||||
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33));
|
||||
}
|
||||
}
|
||||
}
|
||||
Collection<? extends Player> players = UtilServer.getPlayersCollection();
|
||||
|
||||
float volume = _volumeMult * 1F;
|
||||
_song.getLayers().stream().map(layer -> layer.getNote(tick)).filter(Objects::nonNull).forEach((note) -> playNote(note, volume, players));
|
||||
}
|
||||
|
||||
public void cancel()
|
||||
|
Loading…
Reference in New Issue
Block a user