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