geforkt von Mirrors/Velocity
Checkstyle, CappedCollection -> CappedSet
Dieser Commit ist enthalten in:
Ursprung
74afcee9ba
Commit
5f0470fb0b
@ -46,10 +46,14 @@ import com.velocitypowered.proxy.protocol.packet.TitlePacket;
|
|||||||
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
|
||||||
import com.velocitypowered.proxy.tablist.VelocityTabList;
|
import com.velocitypowered.proxy.tablist.VelocityTabList;
|
||||||
import com.velocitypowered.proxy.util.VelocityMessages;
|
import com.velocitypowered.proxy.util.VelocityMessages;
|
||||||
import com.velocitypowered.proxy.util.collect.CappedCollection;
|
import com.velocitypowered.proxy.util.collect.CappedSet;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.CompletionException;
|
import java.util.concurrent.CompletionException;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
@ -103,7 +107,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
this.virtualHost = virtualHost;
|
this.virtualHost = virtualHost;
|
||||||
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
|
this.permissionFunction = PermissionFunction.ALWAYS_UNDEFINED;
|
||||||
this.connectionPhase = minecraftConnection.getType().getInitialClientPhase();
|
this.connectionPhase = minecraftConnection.getType().getInitialClientPhase();
|
||||||
this.knownChannels = CappedCollection.newCappedSet(MAX_PLUGIN_CHANNELS);
|
this.knownChannels = CappedSet.newCappedSet(MAX_PLUGIN_CHANNELS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -650,8 +654,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
|||||||
* @return {@code true} if the message can be forwarded, {@code false} otherwise
|
* @return {@code true} if the message can be forwarded, {@code false} otherwise
|
||||||
*/
|
*/
|
||||||
public boolean canForwardPluginMessage(PluginMessage message) {
|
public boolean canForwardPluginMessage(PluginMessage message) {
|
||||||
// If we're forwarding a plugin message onto the client, that implies that we have a backend connection
|
// If we're forwarding a plugin message onto the client, that implies that we have a backend
|
||||||
// already.
|
// connection already.
|
||||||
MinecraftConnection mc = ensureBackendConnection();
|
MinecraftConnection mc = ensureBackendConnection();
|
||||||
|
|
||||||
boolean minecraftOrFmlMessage;
|
boolean minecraftOrFmlMessage;
|
||||||
|
@ -1,20 +1,21 @@
|
|||||||
package com.velocitypowered.proxy.util.collect;
|
package com.velocitypowered.proxy.util.collect;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.ForwardingCollection;
|
import com.google.common.collect.ForwardingSet;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An unsynchronized collection that puts an upper bound on the size of the collection.
|
* An unsynchronized collection that puts an upper bound on the size of the collection.
|
||||||
*/
|
*/
|
||||||
public class CappedCollection<T> extends ForwardingCollection<T> {
|
public class CappedSet<T> extends ForwardingSet<T> {
|
||||||
|
|
||||||
private final Collection<T> delegate;
|
private final Set<T> delegate;
|
||||||
private final int upperSize;
|
private final int upperSize;
|
||||||
|
|
||||||
private CappedCollection(Collection<T> delegate, int upperSize) {
|
private CappedSet(Set<T> delegate, int upperSize) {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
this.upperSize = upperSize;
|
this.upperSize = upperSize;
|
||||||
}
|
}
|
||||||
@ -25,12 +26,12 @@ public class CappedCollection<T> extends ForwardingCollection<T> {
|
|||||||
* @param <T> the type of elements in the collection
|
* @param <T> the type of elements in the collection
|
||||||
* @return the new collection
|
* @return the new collection
|
||||||
*/
|
*/
|
||||||
public static <T> Collection<T> newCappedSet(int maxSize) {
|
public static <T> Set<T> newCappedSet(int maxSize) {
|
||||||
return new CappedCollection<>(new HashSet<>(), maxSize);
|
return new CappedSet<>(new HashSet<>(), maxSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<T> delegate() {
|
protected Set<T> delegate() {
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
@ -2,17 +2,16 @@ package com.velocitypowered.proxy.util.collect;
|
|||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class CappedCollectionTest {
|
class CappedSetTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void basicVerification() {
|
void basicVerification() {
|
||||||
Collection<String> coll = CappedCollection.newCappedSet(1);
|
Collection<String> coll = CappedSet.newCappedSet(1);
|
||||||
assertTrue(coll.add("coffee"), "did not add single item");
|
assertTrue(coll.add("coffee"), "did not add single item");
|
||||||
assertThrows(IllegalStateException.class, () -> coll.add("tea"),
|
assertThrows(IllegalStateException.class, () -> coll.add("tea"),
|
||||||
"item was added to collection although it is too full");
|
"item was added to collection although it is too full");
|
||||||
@ -25,7 +24,7 @@ class CappedCollectionTest {
|
|||||||
Set<String> doesFill2 = ImmutableSet.of("chocolate");
|
Set<String> doesFill2 = ImmutableSet.of("chocolate");
|
||||||
Set<String> overfill = ImmutableSet.of("Coke", "Pepsi");
|
Set<String> overfill = ImmutableSet.of("Coke", "Pepsi");
|
||||||
|
|
||||||
Collection<String> coll = CappedCollection.newCappedSet(3);
|
Collection<String> coll = CappedSet.newCappedSet(3);
|
||||||
assertTrue(coll.addAll(doesFill1), "did not add items");
|
assertTrue(coll.addAll(doesFill1), "did not add items");
|
||||||
assertTrue(coll.addAll(doesFill2), "did not add items");
|
assertTrue(coll.addAll(doesFill2), "did not add items");
|
||||||
assertThrows(IllegalStateException.class, () -> coll.addAll(overfill),
|
assertThrows(IllegalStateException.class, () -> coll.addAll(overfill),
|
||||||
@ -39,7 +38,7 @@ class CappedCollectionTest {
|
|||||||
Set<String> doesFill2 = ImmutableSet.of("coffee", "chocolate");
|
Set<String> doesFill2 = ImmutableSet.of("coffee", "chocolate");
|
||||||
Set<String> overfill = ImmutableSet.of("coffee", "Coke", "Pepsi");
|
Set<String> overfill = ImmutableSet.of("coffee", "Coke", "Pepsi");
|
||||||
|
|
||||||
Collection<String> coll = CappedCollection.newCappedSet(3);
|
Collection<String> coll = CappedSet.newCappedSet(3);
|
||||||
assertTrue(coll.addAll(doesFill1), "did not add items");
|
assertTrue(coll.addAll(doesFill1), "did not add items");
|
||||||
assertTrue(coll.addAll(doesFill2), "did not add items");
|
assertTrue(coll.addAll(doesFill2), "did not add items");
|
||||||
assertThrows(IllegalStateException.class, () -> coll.addAll(overfill),
|
assertThrows(IllegalStateException.class, () -> coll.addAll(overfill),
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren