Remove some lombok usage from the api package

This commit is contained in:
KennyTV 2020-03-10 13:22:22 +01:00
parent 467adbd3ed
commit dd73ba4f72
14 changed files with 215 additions and 86 deletions

View File

@ -1,6 +1,5 @@
package us.myles.ViaVersion.bungee.storage;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.myles.ViaVersion.api.data.StoredObject;
@ -10,7 +9,6 @@ import java.lang.reflect.Field;
import java.util.Set;
import java.util.UUID;
@Data
@EqualsAndHashCode(callSuper = true)
public class BungeeStorage extends StoredObject {
private static Field bossField;
@ -27,7 +25,7 @@ public class BungeeStorage extends StoredObject {
}
}
private ProxiedPlayer player;
private final ProxiedPlayer player;
private String currentServer;
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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,12 +1,41 @@
package us.myles.ViaVersion.api.minecraft.metadata;
import lombok.AllArgsConstructor;
import lombok.Data;
@AllArgsConstructor
@Data
public class Metadata {
private int id;
private MetaType metaType;
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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -1,13 +1,10 @@
package us.myles.ViaVersion.api.type.types;
import lombok.AllArgsConstructor;
import lombok.Data;
import us.myles.ViaVersion.api.type.Type;
import java.util.LinkedList;
import java.util.List;
@Data
public class Particle {
private int id;
private List<ParticleData> arguments = new LinkedList<>();
@ -16,10 +13,45 @@ public class Particle {
this.id = id;
}
@lombok.Data
@AllArgsConstructor
public int getId() {
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 {
private Type type;
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;
}
}
}

View File

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

View File

@ -4,7 +4,6 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
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.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14;

View File

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