Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex
This commit is contained in:
commit
a0b7870acc
@ -16,10 +16,10 @@ public class NBSReader
|
|||||||
{
|
{
|
||||||
public static NoteSong loadSong(String fileName) throws FileNotFoundException
|
public static NoteSong loadSong(String fileName) throws FileNotFoundException
|
||||||
{
|
{
|
||||||
return loadSong(new DataInputStream(new FileInputStream(new File(fileName))));
|
return loadSong(new DataInputStream(new FileInputStream(new File(fileName))), fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static NoteSong loadSong(DataInputStream stream)
|
public static NoteSong loadSong(DataInputStream stream, String defaultName)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -41,6 +41,9 @@ public class NBSReader
|
|||||||
int blocksRemoved = readInt(stream);
|
int blocksRemoved = readInt(stream);
|
||||||
String midiFileName = readString(stream);
|
String midiFileName = readString(stream);
|
||||||
|
|
||||||
|
if ((name == null || name.length() == 0) && defaultName != null)
|
||||||
|
name = defaultName;
|
||||||
|
|
||||||
HashMap<Integer, NoteLayer> layerMap = new HashMap<Integer, NoteLayer>();
|
HashMap<Integer, NoteLayer> layerMap = new HashMap<Integer, NoteLayer>();
|
||||||
|
|
||||||
// Note Block Information
|
// Note Block Information
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
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;
|
||||||
@ -43,7 +40,12 @@ public class NotePlayer
|
|||||||
|
|
||||||
private void startThread()
|
private void startThread()
|
||||||
{
|
{
|
||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
while (!_finished)
|
while (!_finished)
|
||||||
{
|
{
|
||||||
_tick++;
|
_tick++;
|
||||||
@ -57,9 +59,14 @@ public class NotePlayer
|
|||||||
{
|
{
|
||||||
_finished = true;
|
_finished = true;
|
||||||
|
|
||||||
_plugin.getServer().getScheduler().runTask(_plugin, () -> {
|
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
|
||||||
|
{
|
||||||
|
@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;
|
||||||
@ -77,23 +84,34 @@ public class NotePlayer
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void playNote(Note note, float volume, Collection<? extends Player> players)
|
|
||||||
{
|
|
||||||
players.stream().filter(_verifier::shouldPlay).forEach((player) ->
|
|
||||||
player.playSound(player.getEyeLocation(), UtilNote.getInstrumentSound(note.getInstrument()), volume, (float) UtilNote.getPitch(note.getNote() - 33)));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playTick(int tick)
|
private void playTick(int tick)
|
||||||
{
|
{
|
||||||
Collection<? extends Player> players = UtilServer.getPlayersCollection();
|
Player[] playerArray = UtilServer.getPlayers();
|
||||||
|
List<Player> players = new ArrayList<>(playerArray.length);
|
||||||
|
for (Player player : playerArray)
|
||||||
|
{
|
||||||
|
if (_verifier.shouldPlay(player))
|
||||||
|
players.add(player);
|
||||||
|
}
|
||||||
|
|
||||||
float volume = _volumeMult * 1F;
|
for (NoteLayer layer : _song.getLayers())
|
||||||
_song.getLayers().stream().map(layer -> layer.getNote(tick)).filter(Objects::nonNull).forEach((note) -> playNote(note, volume, players));
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancel()
|
public void cancel()
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package mineplex.core.playerCount;
|
||||||
|
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import mineplex.core.MiniPlugin;
|
||||||
|
import mineplex.core.updater.UpdateType;
|
||||||
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.data.BungeeServer;
|
||||||
|
import mineplex.serverdata.data.DataRepository;
|
||||||
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
|
import mineplex.serverdata.servers.ConnectionData;
|
||||||
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
|
||||||
|
public class PlayerCountManager extends MiniPlugin
|
||||||
|
{
|
||||||
|
private Region _region;
|
||||||
|
private DataRepository<BungeeServer> _repository;
|
||||||
|
private DataRepository<BungeeServer> _secondRepository;
|
||||||
|
|
||||||
|
private volatile int _playerCount;
|
||||||
|
|
||||||
|
public PlayerCountManager(JavaPlugin plugin)
|
||||||
|
{
|
||||||
|
super("PlayerCount", plugin);
|
||||||
|
|
||||||
|
_region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
|
||||||
|
|
||||||
|
_repository = new RedisDataRepository<BungeeServer>(ServerManager.getConnection(true, ServerManager.SERVER_STATUS_LABEL), ServerManager.getConnection(false, ServerManager.SERVER_STATUS_LABEL),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
|
||||||
|
if (_region == Region.US)
|
||||||
|
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.81.1.156", 6379, ConnectionData.ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.81.1.156", 6377, ConnectionData.ConnectionType.SLAVE, "ServerStatus"),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
else
|
||||||
|
_secondRepository = new RedisDataRepository<BungeeServer>(new ConnectionData("10.33.53.16", 6379, ConnectionData.ConnectionType.MASTER, "ServerStatus"), new ConnectionData("10.33.53.16", 6377, ConnectionData.ConnectionType.SLAVE, "ServerStatus"),
|
||||||
|
Region.ALL, BungeeServer.class, "bungeeServers");
|
||||||
|
|
||||||
|
updatePlayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePlayerCount()
|
||||||
|
{
|
||||||
|
int totalPlayers = 0;
|
||||||
|
for (BungeeServer server : _repository.getElements())
|
||||||
|
{
|
||||||
|
totalPlayers += server.getPlayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BungeeServer server : _secondRepository.getElements())
|
||||||
|
{
|
||||||
|
totalPlayers += server.getPlayerCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
_playerCount = totalPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlayerCount()
|
||||||
|
{
|
||||||
|
return _playerCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void refresh(UpdateEvent event)
|
||||||
|
{
|
||||||
|
if (event.getType() != UpdateType.SEC)
|
||||||
|
return;
|
||||||
|
|
||||||
|
runAsync(this::updatePlayerCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -261,7 +261,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
|||||||
if (file.getName().endsWith(".nbs"))
|
if (file.getName().endsWith(".nbs"))
|
||||||
{
|
{
|
||||||
System.out.println("Loading Song " + file.getPath());
|
System.out.println("Loading Song " + file.getPath());
|
||||||
NoteSong song = NBSReader.loadSong(new DataInputStream(new FileInputStream(file)));
|
NoteSong song = NBSReader.loadSong(new DataInputStream(new FileInputStream(file)), file.getName().replace("_", " ").replace(".nbs", ""));
|
||||||
if (song != null)
|
if (song != null)
|
||||||
{
|
{
|
||||||
_songs.add(song);
|
_songs.add(song);
|
||||||
|
Loading…
Reference in New Issue
Block a user