first commit
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
Build AsminVoicechat / prepare-release (push) Successful in 14s
Build AsminVoicechat / build-and-test (17) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (18) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (19) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (20) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (21) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (22) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (23) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (24) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (25) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (26) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (27-ea) (push) Canceled after 0s
Build AsminVoicechat / build-and-test (16) (push) Canceled after 38s
This commit is contained in:
commit
bbccd4a815
454 files changed
+45050
No files matched your search
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*
|
||||
* Could not load the following classes:
|
||||
* javax.annotation.Nullable
|
||||
* org.bukkit.Bukkit
|
||||
* org.bukkit.Location
|
||||
* org.bukkit.World
|
||||
* org.bukkit.entity.Player
|
||||
* org.bukkit.event.EventHandler
|
||||
* org.bukkit.event.Listener
|
||||
* org.bukkit.event.player.PlayerJoinEvent
|
||||
* org.bukkit.event.player.PlayerQuitEvent
|
||||
* org.bukkit.plugin.Plugin
|
||||
*/
|
||||
package de.maxhenkel.voicechat.voice.server;
|
||||
|
||||
import de.maxhenkel.voicechat.Voicechat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
import javax.annotation.Nullable;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class ServerPlayerManager
|
||||
implements Listener {
|
||||
private static final long REFRESH_INTERVAL_TICKS = 600L;
|
||||
public static final ServerPlayerManager INSTANCE = new ServerPlayerManager();
|
||||
private volatile Set<Player> players = Collections.emptySet();
|
||||
|
||||
public static void init(Plugin plugin) {
|
||||
if (!Voicechat.SERVER_CONFIG.threadedServerSupport.get().booleanValue()) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getPluginManager().registerEvents((Listener)INSTANCE, plugin);
|
||||
Voicechat.compatibility.scheduleSyncRepeatingTask(INSTANCE::refresh, 0L, 600L);
|
||||
}
|
||||
|
||||
private ServerPlayerManager() {
|
||||
}
|
||||
|
||||
private synchronized void refresh() {
|
||||
this.players = new HashSet<Player>(Bukkit.getOnlinePlayers());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public synchronized void onPlayerJoin(PlayerJoinEvent event) {
|
||||
HashSet<Player> newPlayers = new HashSet<Player>(this.players);
|
||||
newPlayers.add(event.getPlayer());
|
||||
this.players = newPlayers;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public synchronized void onPlayerQuit(PlayerQuitEvent event) {
|
||||
HashSet<Player> newPlayers = new HashSet<Player>(this.players);
|
||||
newPlayers.remove(event.getPlayer());
|
||||
this.players = newPlayers;
|
||||
}
|
||||
|
||||
public static Collection<Player> getPlayersInRange(World level, Location pos, double range, @Nullable Predicate<Player> filter) {
|
||||
return INSTANCE.getPlayersInRangeInternal(level, pos, range, filter);
|
||||
}
|
||||
|
||||
private Collection<Player> getPlayersInRangeInternal(World world, Location pos, double range, @Nullable Predicate<Player> filter) {
|
||||
if (!Voicechat.SERVER_CONFIG.threadedServerSupport.get().booleanValue()) {
|
||||
return ServerPlayerManager.getPlayersInRangeDirect(world, pos, range, filter);
|
||||
}
|
||||
ArrayList<Player> nearbyPlayers = new ArrayList<Player>();
|
||||
for (Player player : this.players) {
|
||||
if (!world.equals((Object)player.getWorld()) || !ServerPlayerManager.isInRange(player.getLocation(), pos, range) || filter != null && !filter.test(player)) continue;
|
||||
nearbyPlayers.add(player);
|
||||
}
|
||||
return nearbyPlayers;
|
||||
}
|
||||
|
||||
private static Collection<Player> getPlayersInRangeDirect(World world, Location pos, double range, @Nullable Predicate<Player> filter) {
|
||||
ArrayList<Player> nearbyPlayers = new ArrayList<Player>();
|
||||
List worldPlayers = world.getPlayers();
|
||||
for (int i = 0; i < worldPlayers.size(); ++i) {
|
||||
Player player = (Player)worldPlayers.get(i);
|
||||
if (!ServerPlayerManager.isInRange(player.getLocation(), pos, range) || filter != null && !filter.test(player)) continue;
|
||||
nearbyPlayers.add(player);
|
||||
}
|
||||
return nearbyPlayers;
|
||||
}
|
||||
|
||||
public static boolean isInRange(Location pos1, Location pos2, double range) {
|
||||
return ServerPlayerManager.square(pos1.getX() - pos2.getX()) + ServerPlayerManager.square(pos1.getY() - pos2.getY()) + ServerPlayerManager.square(pos1.getZ() - pos2.getZ()) <= ServerPlayerManager.square(range);
|
||||
}
|
||||
|
||||
private static double square(double value) {
|
||||
return value * value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user