Nearing completion.
This commit is contained in:
parent
43eb2b2b38
commit
3f8f29d9f8
|
@ -19,7 +19,7 @@ public class Team {
|
|||
private Set<String> players;
|
||||
|
||||
public Collection<String> getPlayers() {
|
||||
return (Collection<String>) Collections.unmodifiableSet((Set<?>) this.players);
|
||||
return (Collection<String>) (Collection<?>) Collections.unmodifiableSet((Set<?>) this.players);
|
||||
}
|
||||
|
||||
public void addPlayer(final String name) {
|
||||
|
|
|
@ -9,11 +9,22 @@ import java.util.Map;
|
|||
|
||||
public class ExpiringSet<T> extends HashSet<T> {
|
||||
private final long expiration;
|
||||
private final ExpiringEvent<T> event;
|
||||
|
||||
private final Map<T, Long> timestamps = new HashMap<>();
|
||||
|
||||
public ExpiringSet(long expiration) {
|
||||
this.expiration = expiration;
|
||||
this.event = null;
|
||||
}
|
||||
|
||||
public ExpiringSet(long expiration, ExpiringEvent<T> event) {
|
||||
this.expiration = expiration;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public interface ExpiringEvent<T> {
|
||||
void onExpiration(T item);
|
||||
}
|
||||
|
||||
public void checkForExpirations() {
|
||||
|
@ -23,6 +34,7 @@ public class ExpiringSet<T> extends HashSet<T> {
|
|||
T element = iterator.next();
|
||||
if (super.contains(element)) {
|
||||
if (this.timestamps.get(element) + this.expiration < now) {
|
||||
if (this.event != null) this.event.onExpiration(element);
|
||||
iterator.remove();
|
||||
super.remove(element);
|
||||
}
|
||||
|
|
108922
javascript/classes.js
108922
javascript/classes.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -132,7 +132,7 @@ window.initializeVoiceClient = (() => {
|
|||
this.descriptionHandler = null;
|
||||
this.peerTrackHandler = null;
|
||||
this.peerDisconnectHandler = null;
|
||||
this.microphoneVolumeAudioContext = new AudioContext();
|
||||
this.microphoneVolumeAudioContext = null;
|
||||
}
|
||||
|
||||
voiceClientSupported() {
|
||||
|
@ -177,6 +177,7 @@ window.initializeVoiceClient = (() => {
|
|||
this.taskState = TASKSTATE_LOADING;
|
||||
const self = this;
|
||||
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then((stream) => {
|
||||
self.microphoneVolumeAudioContext = new AudioContext();
|
||||
self.localRawMediaStream = stream;
|
||||
self.localRawMediaStream.getAudioTracks()[0].enabled = false;
|
||||
self.localMediaStream = self.microphoneVolumeAudioContext.createMediaStreamDestination();
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>eagler</title>
|
||||
<script type="text/javascript" src="classes.js"></script>
|
||||
<script type="text/javascript" src="eagswebrtc.js"></script>
|
||||
<script type="text/javascript" src="classes.js"></script>
|
||||
<script type="text/javascript">
|
||||
if(document.location.href.startsWith("file:")) {
|
||||
alert("You're not supposed to 'open' this file in your browser. Please upload this folder to your HTTP(s) server and access it via the internet. This is not a bug, please read the documentation");
|
||||
|
|
|
@ -13,6 +13,11 @@ public class ExpiringSet<T> extends HashSet<T> {
|
|||
|
||||
private final Map<T, Long> timestamps = new HashMap<>();
|
||||
|
||||
public ExpiringSet(long expiration) {
|
||||
this.expiration = expiration;
|
||||
this.event = null;
|
||||
}
|
||||
|
||||
public ExpiringSet(long expiration, ExpiringEvent<T> event) {
|
||||
this.expiration = expiration;
|
||||
this.event = event;
|
||||
|
@ -29,7 +34,7 @@ public class ExpiringSet<T> extends HashSet<T> {
|
|||
T element = iterator.next();
|
||||
if (super.contains(element)) {
|
||||
if (this.timestamps.get(element) + this.expiration < now) {
|
||||
this.event.onExpiration(element);
|
||||
if (this.event != null) this.event.onExpiration(element);
|
||||
iterator.remove();
|
||||
super.remove(element);
|
||||
}
|
||||
|
|
|
@ -1125,18 +1125,19 @@ public class Minecraft implements Runnable {
|
|||
|
||||
if (EaglerAdapter.getVoiceChannel() == Voice.VoiceChannel.PROXIMITY) {
|
||||
if (this.theWorld != null && this.thePlayer != null) {
|
||||
HashSet<String> seenPlayers = new HashSet<>();
|
||||
for (Object playerObject : this.theWorld.playerEntities) {
|
||||
EntityPlayer player = (EntityPlayer) playerObject;
|
||||
if (player == this.thePlayer) continue;
|
||||
EaglerAdapter.updateVoicePosition(player.username, player.posX, player.posY + player.getEyeHeight(), player.posZ);
|
||||
int prox = EaglerAdapter.getVoiceProximity();
|
||||
// cube
|
||||
if (Math.abs(thePlayer.posX - player.posX) < prox && Math.abs(thePlayer.posY - player.posY) < prox && Math.abs(thePlayer.posZ - player.posZ) < prox) {
|
||||
if (Math.abs(thePlayer.posX - player.posX) <= prox && Math.abs(thePlayer.posY - player.posY) <= prox && Math.abs(thePlayer.posZ - player.posZ) <= prox) {
|
||||
EaglerAdapter.addNearbyPlayer(player.username);
|
||||
} else {
|
||||
EaglerAdapter.removeNearbyPlayer(player.username);
|
||||
seenPlayers.add(player.username);
|
||||
}
|
||||
}
|
||||
EaglerAdapter.cleanupNearbyPlayers(seenPlayers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.*;
|
|||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,6 +15,7 @@ import java.util.LinkedList;
|
|||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.lax1dude.eaglercraft.*;
|
||||
import org.json.JSONObject;
|
||||
|
@ -2118,13 +2118,16 @@ public class EaglerAdapterImpl2 {
|
|||
});
|
||||
|
||||
public static final void removeNearbyPlayer(String username) {
|
||||
// todo: add 5-10s disconnect delay
|
||||
if (nearbyPlayers.remove(username)) {
|
||||
if (getVoiceStatus() == Voice.VoiceStatus.DISCONNECTED || getVoiceStatus() == Voice.VoiceStatus.UNAVAILABLE) return;
|
||||
recentlyNearbyPlayers.add(username);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void cleanupNearbyPlayers(HashSet<String> existingPlayers) {
|
||||
nearbyPlayers.stream().filter(un -> !existingPlayers.contains(un)).collect(Collectors.toSet()).forEach(EaglerAdapterImpl2::removeNearbyPlayer);
|
||||
}
|
||||
|
||||
public static final void updateVoicePosition(String username, double x, double y, double z) {
|
||||
if (voicePanners.containsKey(username)) voicePanners.get(username).setPosition((float) x, (float) y, (float) z);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user