3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-09 01:30:13 +01:00

Merge pull request #1674 from KennyTV/abstraction

Remove some lombok usage from the api package
Dieser Commit ist enthalten in:
Myles 2020-03-10 22:36:45 +00:00 committet von GitHub
Commit ef88be547b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
14 geänderte Dateien mit 215 neuen und 86 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.bungee.storage; package us.myles.ViaVersion.bungee.storage;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
@ -10,7 +9,6 @@ import java.lang.reflect.Field;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class BungeeStorage extends StoredObject { public class BungeeStorage extends StoredObject {
private static Field bossField; private static Field bossField;
@ -27,7 +25,7 @@ public class BungeeStorage extends StoredObject {
} }
} }
private ProxiedPlayer player; private final ProxiedPlayer player;
private String currentServer; private String currentServer;
private Set<UUID> bossbar; private Set<UUID> bossbar;
@ -45,4 +43,20 @@ public class BungeeStorage extends StoredObject {
} }
} }
} }
public ProxiedPlayer getPlayer() {
return player;
}
public String getCurrentServer() {
return currentServer;
}
public void setCurrentServer(String currentServer) {
this.currentServer = currentServer;
}
public Set<UUID> getBossbar() {
return bossbar;
}
} }

Datei anzeigen

@ -1,18 +1,18 @@
package us.myles.ViaVersion.api; package us.myles.ViaVersion.api;
import lombok.*;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.UUID; import java.util.UUID;
@Getter(AccessLevel.PROTECTED)
@Setter(AccessLevel.PROTECTED)
@RequiredArgsConstructor
public abstract class ViaListener { public abstract class ViaListener {
private final Class<? extends Protocol> requiredPipeline; private final Class<? extends Protocol> requiredPipeline;
private boolean registered = false; private boolean registered;
public ViaListener(Class<? extends Protocol> requiredPipeline) {
this.requiredPipeline = requiredPipeline;
}
/** /**
* Get the UserConnection from an UUID * Get the UserConnection from an UUID
@ -20,7 +20,7 @@ public abstract class ViaListener {
* @param uuid UUID object * @param uuid UUID object
* @return The UserConnection * @return The UserConnection
*/ */
protected UserConnection getUserConnection(@NonNull UUID uuid) { protected UserConnection getUserConnection(UUID uuid) {
return Via.getManager().getConnection(uuid); return Via.getManager().getConnection(uuid);
} }
@ -40,4 +40,16 @@ public abstract class ViaListener {
* Register the event * Register the event
*/ */
public abstract void register(); public abstract void register();
protected Class<? extends Protocol> getRequiredPipeline() {
return requiredPipeline;
}
protected boolean isRegistered() {
return registered;
}
protected void setRegistered(boolean registered) {
this.registered = registered;
}
} }

Datei anzeigen

@ -1,10 +1,13 @@
package us.myles.ViaVersion.api.data; package us.myles.ViaVersion.api.data;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class StoredObject { public class StoredObject {
private final UserConnection user; private final UserConnection user;
public StoredObject(UserConnection user) {
this.user = user;
}
public UserConnection getUser() {
return user;
}
} }

Datei anzeigen

@ -1,12 +1,12 @@
package us.myles.ViaVersion.api.data; package us.myles.ViaVersion.api.data;
import com.google.common.base.Preconditions;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import lombok.Data; import lombok.Data;
import lombok.NonNull;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -23,7 +23,6 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
@Data @Data
public class UserConnection { public class UserConnection {
@NonNull
private final Channel channel; private final Channel channel;
Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>(); Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>();
private boolean active = true; private boolean active = true;
@ -41,6 +40,7 @@ public class UserConnection {
private ReadWriteLock velocityLock = new ReentrantReadWriteLock(); private ReadWriteLock velocityLock = new ReentrantReadWriteLock();
public UserConnection(Channel channel) { public UserConnection(Channel channel) {
Preconditions.checkNotNull(channel);
this.channel = channel; this.channel = channel;
} }
@ -93,12 +93,7 @@ public class UserConnection {
if (currentThread) { if (currentThread) {
channel.pipeline().context(handler).writeAndFlush(packet); channel.pipeline().context(handler).writeAndFlush(packet);
} else { } else {
channel.eventLoop().submit(new Runnable() { channel.eventLoop().submit(() -> channel.pipeline().context(handler).writeAndFlush(packet));
@Override
public void run() {
channel.pipeline().context(handler).writeAndFlush(packet);
}
});
} }
} }
@ -110,8 +105,7 @@ public class UserConnection {
*/ */
public ChannelFuture sendRawPacketFuture(final ByteBuf packet) { public ChannelFuture sendRawPacketFuture(final ByteBuf packet) {
final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName()); final ChannelHandler handler = channel.pipeline().get(Via.getManager().getInjector().getEncoderName());
ChannelFuture future = channel.pipeline().context(handler).writeAndFlush(packet); return channel.pipeline().context(handler).writeAndFlush(packet);
return future;
} }
/** /**
@ -155,26 +149,26 @@ public class UserConnection {
ViaVersionConfig conf = Via.getConfig(); ViaVersionConfig conf = Via.getConfig();
// Max PPS Checker // Max PPS Checker
if (conf.getMaxPPS() > 0) { if (conf.getMaxPPS() > 0) {
if (getPacketsPerSecond() >= conf.getMaxPPS()) { if (packetsPerSecond >= conf.getMaxPPS()) {
disconnect(conf.getMaxPPSKickMessage().replace("%pps", Long.toString(getPacketsPerSecond()))); disconnect(conf.getMaxPPSKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
return true; // don't send current packet return true; // don't send current packet
} }
} }
// Tracking PPS Checker // Tracking PPS Checker
if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) { if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) {
if (getSecondsObserved() > conf.getTrackingPeriod()) { if (secondsObserved > conf.getTrackingPeriod()) {
// Reset // Reset
setWarnings(0); setWarnings(0);
setSecondsObserved(1); setSecondsObserved(1);
} else { } else {
setSecondsObserved(getSecondsObserved() + 1); setSecondsObserved(secondsObserved + 1);
if (getPacketsPerSecond() >= conf.getWarningPPS()) { if (packetsPerSecond >= conf.getWarningPPS()) {
setWarnings(getWarnings() + 1); setWarnings(warnings + 1);
} }
if (getWarnings() >= conf.getMaxWarnings()) { if (warnings >= conf.getMaxWarnings()) {
disconnect(conf.getMaxWarningsKickMessage().replace("%pps", Long.toString(getPacketsPerSecond()))); disconnect(conf.getMaxWarningsKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
return true; // don't send current packet return true; // don't send current packet
} }
} }
@ -188,21 +182,17 @@ public class UserConnection {
* @param reason The reason to use, not used if player is not active. * @param reason The reason to use, not used if player is not active.
*/ */
public void disconnect(final String reason) { public void disconnect(final String reason) {
if (!getChannel().isOpen()) return; if (!channel.isOpen()) return;
if (pendingDisconnect) return; if (pendingDisconnect) return;
pendingDisconnect = true; pendingDisconnect = true;
if (get(ProtocolInfo.class).getUuid() != null) { if (get(ProtocolInfo.class).getUuid() != null) {
final UUID uuid = get(ProtocolInfo.class).getUuid(); final UUID uuid = get(ProtocolInfo.class).getUuid();
Via.getPlatform().runSync(new Runnable() { Via.getPlatform().runSync(() -> {
@Override
public void run() {
if (!Via.getPlatform().kickPlayer(uuid, ChatColor.translateAlternateColorCodes('&', reason))) { if (!Via.getPlatform().kickPlayer(uuid, ChatColor.translateAlternateColorCodes('&', reason))) {
getChannel().close(); // =) channel.close(); // =)
}
} }
}); });
} }
} }
/** /**
@ -222,23 +212,20 @@ public class UserConnection {
} }
buf.writeBytes(packet); buf.writeBytes(packet);
final ChannelHandlerContext context = PipelineUtil final ChannelHandlerContext context = PipelineUtil
.getPreviousContext(Via.getManager().getInjector().getDecoderName(), getChannel().pipeline()); .getPreviousContext(Via.getManager().getInjector().getDecoderName(), channel.pipeline());
if (currentThread) { if (currentThread) {
if (context != null) { if (context != null) {
context.fireChannelRead(buf); context.fireChannelRead(buf);
} else { } else {
getChannel().pipeline().fireChannelRead(buf); channel.pipeline().fireChannelRead(buf);
} }
} else { } else {
try { try {
channel.eventLoop().submit(new Runnable() { channel.eventLoop().submit(() -> {
@Override
public void run() {
if (context != null) { if (context != null) {
context.fireChannelRead(buf); context.fireChannelRead(buf);
} else { } else {
getChannel().pipeline().fireChannelRead(buf); channel.pipeline().fireChannelRead(buf);
}
} }
}); });
} catch (Throwable t) { } catch (Throwable t) {

Datei anzeigen

@ -1,8 +1,6 @@
package us.myles.ViaVersion.api.minecraft.chunks; package us.myles.ViaVersion.api.minecraft.chunks;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;

Datei anzeigen

@ -1,12 +1,41 @@
package us.myles.ViaVersion.api.minecraft.metadata; package us.myles.ViaVersion.api.minecraft.metadata;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class Metadata { public class Metadata {
private int id; private int id;
private MetaType metaType; private MetaType metaType;
private Object value; private Object value;
public Metadata(int id, MetaType metaType, Object value) {
this.id = id;
this.metaType = metaType;
this.value = value;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public MetaType getMetaType() {
return metaType;
}
public void setMetaType(MetaType metaType) {
this.metaType = metaType;
}
public Object getValue() {
return value;
}
public <T> T getCastedValue() {
return (T) value;
}
public void setValue(Object value) {
this.value = value;
}
} }

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.protocol; package us.myles.ViaVersion.api.protocol;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -205,12 +203,33 @@ public abstract class Protocol {
return "Protocol:" + getClass().getSimpleName(); return "Protocol:" + getClass().getSimpleName();
} }
@AllArgsConstructor
@Getter
public static class ProtocolPacket { public static class ProtocolPacket {
State state; private final State state;
int oldID; private final int oldID;
int newID; private final int newID;
PacketRemapper remapper; private final PacketRemapper remapper;
public ProtocolPacket(State state, int oldID, int newID, PacketRemapper remapper) {
this.state = state;
this.oldID = oldID;
this.newID = newID;
this.remapper = remapper;
}
public State getState() {
return state;
}
public int getOldID() {
return oldID;
}
public int getNewID() {
return newID;
}
public PacketRemapper getRemapper() {
return remapper;
}
} }
} }

Datei anzeigen

@ -1,13 +1,9 @@
package us.myles.ViaVersion.api.protocol; package us.myles.ViaVersion.api.protocol;
import lombok.AllArgsConstructor; import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.NonNull;
import java.util.*; import java.util.*;
@AllArgsConstructor
@Getter
public class ProtocolVersion { public class ProtocolVersion {
private static final Map<Integer, ProtocolVersion> versions = new HashMap<>(); private static final Map<Integer, ProtocolVersion> versions = new HashMap<>();
private static final List<ProtocolVersion> versionList = new ArrayList<>(); private static final List<ProtocolVersion> versionList = new ArrayList<>();
@ -89,7 +85,13 @@ public class ProtocolVersion {
register(unknown = new ProtocolVersion(-1, "UNKNOWN")); register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
} }
public static void register(@NonNull ProtocolVersion protocol) { public ProtocolVersion(int id, String name) {
this.id = id;
this.name = name;
}
public static void register(ProtocolVersion protocol) {
Preconditions.checkNotNull(protocol);
versions.put(protocol.getId(), protocol); versions.put(protocol.getId(), protocol);
versionList.add(protocol); versionList.add(protocol);
} }
@ -133,6 +135,14 @@ public class ProtocolVersion {
return null; return null;
} }
public int getId() {
return id;
}
public String getName() {
return name;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

Datei anzeigen

@ -1,12 +1,10 @@
package us.myles.ViaVersion.api.remapper; package us.myles.ViaVersion.api.remapper;
import lombok.Getter;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.InformativeException; import us.myles.ViaVersion.exception.InformativeException;
public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> { public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
@Getter
private final Type<T1> inputType; private final Type<T1> inputType;
private final Type<T2> outputType; private final Type<T2> outputType;
@ -38,4 +36,12 @@ public abstract class ValueTransformer<T1, T2> implements ValueWriter<T1> {
throw e; throw e;
} }
} }
public Type<T1> getInputType() {
return inputType;
}
public Type<T2> getOutputType() {
return outputType;
}
} }

Datei anzeigen

@ -2,7 +2,6 @@ package us.myles.ViaVersion.api.type;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.Getter;
import us.myles.ViaVersion.api.minecraft.*; import us.myles.ViaVersion.api.minecraft.*;
import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.types.*; import us.myles.ViaVersion.api.type.types.*;
@ -10,7 +9,6 @@ import us.myles.ViaVersion.api.type.types.minecraft.*;
import java.util.UUID; import java.util.UUID;
@Getter
public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> { public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
/* Defined Types */ /* Defined Types */
public static final Type<Byte> BYTE = new ByteType(); public static final Type<Byte> BYTE = new ByteType();
@ -144,12 +142,20 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
this.typeName = typeName; this.typeName = typeName;
} }
public Class<? super T> getOutputClass() {
return outputClass;
}
public String getTypeName() {
return typeName;
}
public Class<? extends Type> getBaseClass() { public Class<? extends Type> getBaseClass() {
return this.getClass(); return this.getClass();
} }
@Override @Override
public String toString() { public String toString() {
return "Type|" + getTypeName(); return "Type|" + typeName;
} }
} }

Datei anzeigen

@ -1,13 +1,10 @@
package us.myles.ViaVersion.api.type.types; package us.myles.ViaVersion.api.type.types;
import lombok.AllArgsConstructor;
import lombok.Data;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@Data
public class Particle { public class Particle {
private int id; private int id;
private List<ParticleData> arguments = new LinkedList<>(); private List<ParticleData> arguments = new LinkedList<>();
@ -16,10 +13,45 @@ public class Particle {
this.id = id; this.id = id;
} }
@lombok.Data public int getId() {
@AllArgsConstructor return id;
}
public void setId(int id) {
this.id = id;
}
public List<ParticleData> getArguments() {
return arguments;
}
public void setArguments(List<ParticleData> arguments) {
this.arguments = arguments;
}
public static class ParticleData { public static class ParticleData {
private Type type; private Type type;
private Object value; private Object value;
public ParticleData(Type type, Object value) {
this.type = type;
this.value = value;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Object getValue() {
return value;
}
public void setValue(Object value) {
this.value = value;
}
} }
} }

Datei anzeigen

@ -24,5 +24,5 @@ public class Types1_13 {
/** /**
* Particle type for 1.13 * Particle type for 1.13
*/ */
public static Type<Particle> PARTICLE = new Particle1_13Type(); public static final Type<Particle> PARTICLE = new Particle1_13Type();
} }

Datei anzeigen

@ -4,7 +4,6 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.velocity.storage; package us.myles.ViaVersion.velocity.storage;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -12,10 +11,9 @@ import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class VelocityStorage extends StoredObject { public class VelocityStorage extends StoredObject {
private Player player; private final Player player;
private String currentServer; private String currentServer;
private List<UUID> cachedBossbar; private List<UUID> cachedBossbar;
private static Method getServerBossBars; private static Method getServerBossBars;
@ -58,4 +56,20 @@ public class VelocityStorage extends StoredObject {
} }
return cachedBossbar; return cachedBossbar;
} }
public Player getPlayer() {
return player;
}
public String getCurrentServer() {
return currentServer;
}
public void setCurrentServer(final String currentServer) {
this.currentServer = currentServer;
}
public List<UUID> getCachedBossbar() {
return cachedBossbar;
}
} }