From dd73ba4f7204423918777621277d3b10a656aac7 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 10 Mar 2020 13:22:22 +0100 Subject: [PATCH] Remove some lombok usage from the api package --- .../bungee/storage/BungeeStorage.java | 20 ++++++- .../us/myles/ViaVersion/api/ViaListener.java | 24 ++++++-- .../ViaVersion/api/data/StoredObject.java | 13 ++-- .../ViaVersion/api/data/UserConnection.java | 59 ++++++++----------- .../api/minecraft/chunks/ChunkSection.java | 2 - .../api/minecraft/metadata/Metadata.java | 39 ++++++++++-- .../ViaVersion/api/protocol/Protocol.java | 35 ++++++++--- .../api/protocol/ProtocolVersion.java | 22 +++++-- .../api/remapper/ValueTransformer.java | 10 +++- .../us/myles/ViaVersion/api/type/Type.java | 12 +++- .../ViaVersion/api/type/types/Particle.java | 42 +++++++++++-- .../api/type/types/version/Types1_13.java | 2 +- .../packets/EntityPackets.java | 1 - .../velocity/storage/VelocityStorage.java | 20 ++++++- 14 files changed, 215 insertions(+), 86 deletions(-) diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java index 907471e86..592ec0f30 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java @@ -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 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 getBossbar() { + return bossbar; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java index 91212eaee..a87aa1026 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java @@ -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 requiredPipeline; - private boolean registered = false; + private boolean registered; + + public ViaListener(Class 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 getRequiredPipeline() { + return requiredPipeline; + } + + protected boolean isRegistered() { + return registered; + } + + protected void setRegistered(boolean registered) { + this.registered = registered; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java b/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java index 3b9f8c3a9..2e700af77 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/StoredObject.java @@ -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; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java b/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java index 1f5e85ee9..a50354e74 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java @@ -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 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) { diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index 156745f06..eb361c41b 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -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; diff --git a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java index 68fdeca43..244ea8423 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java +++ b/common/src/main/java/us/myles/ViaVersion/api/minecraft/metadata/Metadata.java @@ -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 getCastedValue() { + return (T) value; + } + + public void setValue(Object value) { + this.value = value; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index b7711a82b..bcf25e9ea 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -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; + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index d5517ecc9..941cbff1a 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -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 versions = new HashMap<>(); private static final List 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; diff --git a/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java b/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java index 78b73cd98..0c7a2fda6 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java +++ b/common/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java @@ -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 implements ValueWriter { - @Getter private final Type inputType; private final Type outputType; @@ -38,4 +36,12 @@ public abstract class ValueTransformer implements ValueWriter { throw e; } } + + public Type getInputType() { + return inputType; + } + + public Type getOutputType() { + return outputType; + } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java index 6ae163471..32bddc323 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -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 implements ByteBufReader, ByteBufWriter { /* Defined Types */ public static final Type BYTE = new ByteType(); @@ -144,12 +142,20 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { this.typeName = typeName; } + public Class getOutputClass() { + return outputClass; + } + + public String getTypeName() { + return typeName; + } + public Class getBaseClass() { return this.getClass(); } @Override public String toString() { - return "Type|" + getTypeName(); + return "Type|" + typeName; } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/Particle.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/Particle.java index 5a5013935..b202a544a 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/Particle.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/Particle.java @@ -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 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 getArguments() { + return arguments; + } + + public void setArguments(List 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; + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13.java b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13.java index 4bd78bbbf..12c9d854d 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13.java +++ b/common/src/main/java/us/myles/ViaVersion/api/type/types/version/Types1_13.java @@ -24,5 +24,5 @@ public class Types1_13 { /** * Particle type for 1.13 */ - public static Type PARTICLE = new Particle1_13Type(); + public static final Type PARTICLE = new Particle1_13Type(); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java index 30527910f..d38987c79 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_15to1_14_4/packets/EntityPackets.java @@ -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; diff --git a/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java b/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java index 51dd9191c..cc7284f12 100644 --- a/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java +++ b/velocity/src/main/java/us/myles/ViaVersion/velocity/storage/VelocityStorage.java @@ -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 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 getCachedBossbar() { + return cachedBossbar; + } }