Bai bai to more lombok usage once more

This commit is contained in:
KennyTV 2020-04-13 20:58:24 +02:00
parent fdb6137339
commit 8f08a32c5a
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
49 changed files with 750 additions and 224 deletions

View File

@ -1,6 +1,5 @@
package us.myles.ViaVersion.bukkit.listeners;
import lombok.NonNull;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
@ -22,7 +21,7 @@ public class ViaBukkitListener extends ViaListener implements Listener {
* @param player Player object
* @return The UserConnection
*/
protected UserConnection getUserConnection(@NonNull Player player) {
protected UserConnection getUserConnection(Player player) {
return getUserConnection(player.getUniqueId());
}

View File

@ -1,12 +1,10 @@
package us.myles.ViaVersion.boss;
import lombok.Getter;
import org.bukkit.entity.Player;
import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle;
@Getter
public class ViaBossBar extends CommonBoss<Player> {
public ViaBossBar(String title, float health, BossColor color, BossStyle style) {

View File

@ -1,16 +1,18 @@
package us.myles.ViaVersion.bukkit.commands;
import lombok.AllArgsConstructor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID;
@AllArgsConstructor
public class BukkitCommandSender implements ViaCommandSender {
private final CommandSender sender;
public BukkitCommandSender(CommandSender sender) {
this.sender = sender;
}
@Override
public boolean hasPermission(String permission) {
return sender.hasPermission(permission);

View File

@ -1,11 +1,16 @@
package us.myles.ViaVersion.bukkit.platform;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.platform.TaskId;
@Getter
@AllArgsConstructor
public class BukkitTaskId implements TaskId {
private final Integer object;
public BukkitTaskId(Integer object) {
this.object = object;
}
@Override
public Integer getObject() {
return object;
}
}

View File

@ -1,7 +1,6 @@
package us.myles.ViaVersion.bukkit.platform;
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import us.myles.ViaVersion.ViaVersionPlugin;
@ -29,12 +28,12 @@ public class BukkitViaAPI implements ViaAPI<Player> {
}
@Override
public int getPlayerVersion(@NonNull Player player) {
public int getPlayerVersion(Player player) {
return getPlayerVersion(player.getUniqueId());
}
@Override
public int getPlayerVersion(@NonNull UUID uuid) {
public int getPlayerVersion(UUID uuid) {
if (!isPorted(uuid))
return getExternalVersion(Bukkit.getPlayer(uuid));
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();

View File

@ -1,15 +1,17 @@
package us.myles.ViaVersion.bungee.commands;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID;
@AllArgsConstructor
public class BungeeCommandSender implements ViaCommandSender {
private CommandSender sender;
private final CommandSender sender;
public BungeeCommandSender(CommandSender sender) {
this.sender = sender;
}
@Override
public boolean hasPermission(String permission) {

View File

@ -2,15 +2,12 @@ package us.myles.ViaVersion.bungee.handlers;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import lombok.Getter;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import java.lang.reflect.Method;
public class BungeeChannelInitializer extends ChannelInitializer<Channel> {
@Getter
private final ChannelInitializer<Channel> original;
private Method method;
@ -40,6 +37,9 @@ public class BungeeChannelInitializer extends ChannelInitializer<Channel> {
socketChannel.pipeline().addBefore("packet-encoder", "via-encoder", encoder);
socketChannel.pipeline().addBefore("packet-decoder", "via-decoder", decoder);
}
public ChannelInitializer<Channel> getOriginal() {
return original;
}
}

View File

@ -1,11 +1,16 @@
package us.myles.ViaVersion.bungee.platform;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.platform.TaskId;
@Getter
@AllArgsConstructor
public class BungeeTaskId implements TaskId {
private Integer object;
private final Integer object;
public BungeeTaskId(Integer object) {
this.object = object;
}
@Override
public Integer getObject() {
return object;
}
}

View File

@ -17,8 +17,6 @@ import us.myles.ViaVersion.util.PipelineUtil;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@Data
public class UserConnection {
@ -156,12 +154,12 @@ public class UserConnection {
if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) {
if (secondsObserved > conf.getTrackingPeriod()) {
// Reset
setWarnings(0);
setSecondsObserved(1);
warnings = 0;
secondsObserved = 1;
} else {
setSecondsObserved(secondsObserved + 1);
secondsObserved++;
if (packetsPerSecond >= conf.getWarningPPS()) {
setWarnings(warnings + 1);
warnings++;
}
if (warnings >= conf.getMaxWarnings()) {

View File

@ -2,11 +2,7 @@ package us.myles.ViaVersion.api.minecraft.item;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
public class Item {
@SerializedName(value = "identifier", alternate = "id")
private int identifier;
@ -14,6 +10,16 @@ public class Item {
private short data;
private CompoundTag tag;
public Item() {
}
public Item(int identifier, byte amount, short data, CompoundTag tag) {
this.identifier = identifier;
this.amount = amount;
this.data = data;
this.tag = tag;
}
public Item(Item toCopy) {
this(toCopy.getIdentifier(), toCopy.getAmount(), toCopy.getData(), toCopy.getTag());
}

View File

@ -1,8 +1,6 @@
package us.myles.ViaVersion.boss;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.NonNull;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.boss.BossBar;
@ -14,9 +12,12 @@ import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
@Getter
public abstract class CommonBoss<T> extends BossBar<T> {
private final UUID uuid;
private String title;
@ -42,7 +43,8 @@ public abstract class CommonBoss<T> extends BossBar<T> {
}
@Override
public BossBar setTitle(@NonNull String title) {
public BossBar setTitle(String title) {
Preconditions.checkNotNull(title);
this.title = title;
sendPacket(CommonBoss.UpdateAction.UPDATE_TITLE);
return this;
@ -62,14 +64,16 @@ public abstract class CommonBoss<T> extends BossBar<T> {
}
@Override
public BossBar setColor(@NonNull BossColor color) {
public BossBar setColor(BossColor color) {
Preconditions.checkNotNull(color);
this.color = color;
sendPacket(CommonBoss.UpdateAction.UPDATE_STYLE);
return this;
}
@Override
public BossBar setStyle(@NonNull BossStyle style) {
public BossBar setStyle(BossStyle style) {
Preconditions.checkNotNull(style);
this.style = style;
sendPacket(CommonBoss.UpdateAction.UPDATE_STYLE);
return this;
@ -98,7 +102,8 @@ public abstract class CommonBoss<T> extends BossBar<T> {
}
@Override
public BossBar addFlag(@NonNull BossFlag flag) {
public BossBar addFlag(BossFlag flag) {
Preconditions.checkNotNull(flag);
if (!hasFlag(flag))
flags.add(flag);
sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
@ -106,7 +111,8 @@ public abstract class CommonBoss<T> extends BossBar<T> {
}
@Override
public BossBar removeFlag(@NonNull BossFlag flag) {
public BossBar removeFlag(BossFlag flag) {
Preconditions.checkNotNull(flag);
if (hasFlag(flag))
flags.remove(flag);
sendPacket(CommonBoss.UpdateAction.UPDATE_FLAGS);
@ -114,7 +120,8 @@ public abstract class CommonBoss<T> extends BossBar<T> {
}
@Override
public boolean hasFlag(@NonNull BossFlag flag) {
public boolean hasFlag(BossFlag flag) {
Preconditions.checkNotNull(flag);
return flags.contains(flag);
}
@ -145,6 +152,29 @@ public abstract class CommonBoss<T> extends BossBar<T> {
return uuid;
}
public UUID getUuid() {
return uuid;
}
@Override
public String getTitle() {
return title;
}
@Override
public float getHealth() {
return health;
}
@Override
public BossStyle getStyle() {
return style;
}
public Set<BossFlag> getFlags() {
return flags;
}
private void setVisible(boolean value) {
if (visible != value) {
visible = value;

View File

@ -1,7 +1,6 @@
package us.myles.ViaVersion.commands;
import com.google.common.base.Preconditions;
import lombok.NonNull;
import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender;
@ -24,7 +23,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
}
@Override
public void registerSubCommand(@NonNull ViaSubCommand command) throws Exception {
public void registerSubCommand(ViaSubCommand command) throws Exception {
Preconditions.checkArgument(command.name().matches("^[a-z0-9_-]{3,15}$"), command.name() + " is not a valid sub-command name.");
if (hasSubCommand(command.name()))
throw new Exception("ViaSubCommand " + command.name() + " does already exists!"); //Maybe another exception later.
@ -163,7 +162,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
* @param message The message
* @param args The objects to replace
*/
public static void sendMessage(@NonNull ViaCommandSender sender, String message, Object... args) {
public static void sendMessage(ViaCommandSender sender, String message, Object... args) {
sender.sendMessage(color(args == null ? message : String.format(message, args)));
}
}

View File

@ -1,16 +1,35 @@
package us.myles.ViaVersion.dump;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Map;
@Data
@AllArgsConstructor
public class DumpTemplate {
private VersionInfo versionInfo;
private Map<String, Object> configuration;
private JsonObject platformDump;
private JsonObject injectionDump;
private final VersionInfo versionInfo;
private final Map<String, Object> configuration;
private final JsonObject platformDump;
private final JsonObject injectionDump;
public DumpTemplate(VersionInfo versionInfo, Map<String, Object> configuration, JsonObject platformDump, JsonObject injectionDump) {
this.versionInfo = versionInfo;
this.configuration = configuration;
this.platformDump = platformDump;
this.injectionDump = injectionDump;
}
public VersionInfo getVersionInfo() {
return versionInfo;
}
public Map<String, Object> getConfiguration() {
return configuration;
}
public JsonObject getPlatformDump() {
return platformDump;
}
public JsonObject getInjectionDump() {
return injectionDump;
}
}

View File

@ -1,16 +1,39 @@
package us.myles.ViaVersion.dump;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.List;
@Data
@AllArgsConstructor
public class PluginInfo {
private boolean enabled;
private String name;
private String version;
private String main;
private List<String> authors;
private final boolean enabled;
private final String name;
private final String version;
private final String main;
private final List<String> authors;
public PluginInfo(boolean enabled, String name, String version, String main, List<String> authors) {
this.enabled = enabled;
this.name = name;
this.version = version;
this.main = main;
this.authors = authors;
}
public boolean isEnabled() {
return enabled;
}
public String getName() {
return name;
}
public String getVersion() {
return version;
}
public String getMain() {
return main;
}
public List<String> getAuthors() {
return authors;
}
}

View File

@ -1,19 +1,52 @@
package us.myles.ViaVersion.dump;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Set;
@Data
@AllArgsConstructor
public class VersionInfo {
private String javaVersion;
private String operatingSystem;
private int serverProtocol;
private Set<Integer> enabledProtocols;
private String platformName;
private String platformVersion;
private String pluginVersion;
private final String javaVersion;
private final String operatingSystem;
private final int serverProtocol;
private final Set<Integer> enabledProtocols;
private final String platformName;
private final String platformVersion;
private final String pluginVersion;
public VersionInfo(String javaVersion, String operatingSystem, int serverProtocol, Set<Integer> enabledProtocols, String platformName, String platformVersion, String pluginVersion) {
this.javaVersion = javaVersion;
this.operatingSystem = operatingSystem;
this.serverProtocol = serverProtocol;
this.enabledProtocols = enabledProtocols;
this.platformName = platformName;
this.platformVersion = platformVersion;
this.pluginVersion = pluginVersion;
}
public String getJavaVersion() {
return javaVersion;
}
public String getOperatingSystem() {
return operatingSystem;
}
public int getServerProtocol() {
return serverProtocol;
}
public Set<Integer> getEnabledProtocols() {
return enabledProtocols;
}
public String getPlatformName() {
return platformName;
}
public String getPlatformVersion() {
return platformVersion;
}
public String getPluginVersion() {
return pluginVersion;
}
}

View File

@ -1,7 +1,5 @@
package us.myles.ViaVersion.protocols.base;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
@ -9,8 +7,6 @@ import us.myles.ViaVersion.packets.State;
import java.util.UUID;
@Getter
@Setter
public class ProtocolInfo extends StoredObject {
private State state = State.HANDSHAKE;
private int protocolVersion = -1;
@ -22,4 +18,52 @@ public class ProtocolInfo extends StoredObject {
public ProtocolInfo(UserConnection user) {
super(user);
}
public State getState() {
return state;
}
public void setState(State state) {
this.state = state;
}
public int getProtocolVersion() {
return protocolVersion;
}
public void setProtocolVersion(int protocolVersion) {
this.protocolVersion = protocolVersion;
}
public int getServerProtocolVersion() {
return serverProtocolVersion;
}
public void setServerProtocolVersion(int serverProtocolVersion) {
this.serverProtocolVersion = serverProtocolVersion;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public UUID getUuid() {
return uuid;
}
public void setUuid(UUID uuid) {
this.uuid = uuid;
}
public ProtocolPipeline getPipeline() {
return pipeline;
}
public void setPipeline(ProtocolPipeline pipeline) {
this.pipeline = pipeline;
}
}

View File

@ -1,18 +1,27 @@
package us.myles.ViaVersion.protocols.protocol1_10to1_9_3.storage;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
@Getter
@Setter
@ToString
public class ResourcePackTracker extends StoredObject {
private String lastHash = "";
public ResourcePackTracker(UserConnection user) {
super(user);
}
public String getLastHash() {
return lastHash;
}
public void setLastHash(String lastHash) {
this.lastHash = lastHash;
}
@Override
public String toString() {
return "ResourcePackTracker{" +
"lastHash='" + lastHash + '\'' +
'}';
}
}

View File

@ -1,14 +1,34 @@
package us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
@AllArgsConstructor
@ToString
@Getter
public class ItemTransaction {
private short windowId;
private short slotId;
private short actionId;
private final short windowId;
private final short slotId;
private final short actionId;
public ItemTransaction(short windowId, short slotId, short actionId) {
this.windowId = windowId;
this.slotId = slotId;
this.actionId = actionId;
}
public short getWindowId() {
return windowId;
}
public short getSlotId() {
return slotId;
}
public short getActionId() {
return actionId;
}
@Override
public String toString() {
return "ItemTransaction{" +
"windowId=" + windowId +
", slotId=" + slotId +
", actionId=" + actionId +
'}';
}
}

View File

@ -1,7 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
@ -162,18 +160,27 @@ public class ParticleRewriter {
Particle handler(Particle particle, Integer[] data);
}
@Data
@RequiredArgsConstructor
private static class NewParticle {
private final int id;
private final ParticleDataHandler handler;
public NewParticle(int id, ParticleDataHandler handler) {
this.id = id;
this.handler = handler;
}
public Particle handle(Particle particle, Integer[] data) {
if (handler != null)
return handler.handler(particle, data);
return particle;
}
public int getId() {
return id;
}
public ParticleDataHandler getHandler() {
return handler;
}
}
}

View File

@ -1,8 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import com.google.gson.reflect.TypeToken;
import lombok.Data;
import lombok.NonNull;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.util.GsonUtil;
@ -33,9 +31,7 @@ public class RecipeData {
}
}
@Data
public static class Recipe {
@NonNull
private String type;
private String group;
private int width;
@ -45,5 +41,77 @@ public class RecipeData {
private Item[] ingredient;
private Item[][] ingredients;
private Item result;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getGroup() {
return group;
}
public void setGroup(String group) {
this.group = group;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public float getExperience() {
return experience;
}
public void setExperience(float experience) {
this.experience = experience;
}
public int getCookingTime() {
return cookingTime;
}
public void setCookingTime(int cookingTime) {
this.cookingTime = cookingTime;
}
public Item[] getIngredient() {
return ingredient;
}
public void setIngredient(Item[] ingredient) {
this.ingredient = ingredient;
}
public Item[][] getIngredients() {
return ingredients;
}
public void setIngredients(Item[][] ingredients) {
this.ingredients = ingredients;
}
public Item getResult() {
return result;
}
public void setResult(Item result) {
this.result = result;
}
}
}

View File

@ -1,12 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Optional;
@Getter
@AllArgsConstructor
public enum SoundSource {
MASTER("master", 0),
MUSIC("music", 1),
@ -22,10 +17,23 @@ public enum SoundSource {
private final String name;
private final int id;
SoundSource(String name, int id) {
this.name = name;
this.id = id;
}
public static Optional<SoundSource> findBySource(String source) {
for (SoundSource item : SoundSource.values())
if (item.name.equalsIgnoreCase(source))
return Optional.of(item);
return Optional.empty();
}
public String getName() {
return name;
}
public int getId() {
return id;
}
}

View File

@ -1,7 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
import lombok.AllArgsConstructor;
import lombok.Data;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
@ -68,11 +66,29 @@ public class BlockStorage extends StoredObject {
return blocks.remove(position);
}
@Data
@AllArgsConstructor
public static class ReplacementData {
private int original;
private int replacement;
}
public ReplacementData(int original, int replacement) {
this.original = original;
this.replacement = replacement;
}
public int getOriginal() {
return original;
}
public void setOriginal(int original) {
this.original = original;
}
public int getReplacement() {
return replacement;
}
public void setReplacement(int replacement) {
this.replacement = replacement;
}
}
}

View File

@ -1,15 +1,11 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
@Getter
@Setter
public class TabCompleteTracker extends StoredObject {
private int transactionId;
private String input;
@ -33,4 +29,36 @@ public class TabCompleteTracker extends StoredObject {
}
lastTabComplete = null;
}
public int getTransactionId() {
return transactionId;
}
public void setTransactionId(int transactionId) {
this.transactionId = transactionId;
}
public String getInput() {
return input;
}
public void setInput(final String input) {
this.input = input;
}
public String getLastTabComplete() {
return lastTabComplete;
}
public void setLastTabComplete(String lastTabComplete) {
this.lastTabComplete = lastTabComplete;
}
public long getTimeToSend() {
return timeToSend;
}
public void setTimeToSend(long timeToSend) {
this.timeToSend = timeToSend;
}
}

View File

@ -1,11 +1,9 @@
package us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage;
import lombok.Getter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Environment;
@Getter
public class ClientWorld extends StoredObject {
private Environment environment;
@ -13,6 +11,10 @@ public class ClientWorld extends StoredObject {
super(user);
}
public Environment getEnvironment() {
return environment;
}
public void setEnvironment(int environmentId) {
this.environment = getEnvFromId(environmentId);
}

View File

@ -1,13 +1,8 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.HashMap;
import java.util.Map;
@RequiredArgsConstructor
@Getter
public enum ArmorType {
LEATHER_HELMET(1, 298, "minecraft:leather_helmet"),
@ -32,7 +27,7 @@ public enum ArmorType {
GOLD_BOOTS(1, 317, "minecraft:gold_boots"),
NONE(0, 0, "none");
private static Map<Integer, ArmorType> armor;
private static final Map<Integer, ArmorType> armor;
static {
armor = new HashMap<>();
@ -45,6 +40,20 @@ public enum ArmorType {
private final int id;
private final String type;
ArmorType(int armorPoints, int id, String type) {
this.armorPoints = armorPoints;
this.id = id;
this.type = type;
}
public int getArmorPoints() {
return armorPoints;
}
public String getType() {
return type;
}
/**
* Find an armour type by the item id
*

View File

@ -1,10 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.chat;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public enum GameMode {
SURVIVAL(0, "Survival Mode"),
CREATIVE(1, "Creative Mode"),
@ -14,6 +9,19 @@ public enum GameMode {
private final int id;
private final String text;
GameMode(int id, String text) {
this.id = id;
this.text = text;
}
public int getId() {
return id;
}
public String getText() {
return text;
}
public static GameMode getById(int id) {
for (GameMode gm : GameMode.values())
if (gm.getId() == id)

View File

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata;
import lombok.Getter;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.entities.Entity1_10Types;
import us.myles.ViaVersion.api.entities.EntityType;
@ -12,7 +11,6 @@ import java.util.Optional;
import static us.myles.ViaVersion.api.entities.Entity1_10Types.EntityType.*;
@Getter
public enum MetaIndex {
// entity
@ -172,6 +170,26 @@ public enum MetaIndex {
this.newType = newType;
}
public Entity1_10Types.EntityType getClazz() {
return clazz;
}
public int getNewIndex() {
return newIndex;
}
public MetaType1_9 getNewType() {
return newType;
}
public MetaType1_8 getOldType() {
return oldType;
}
public int getIndex() {
return index;
}
private static Optional<MetaIndex> getIndex(EntityType type, int index) {
Pair pair = new Pair<>(type, index);
return Optional.ofNullable(metadataRewrites.get(pair));

View File

@ -1,6 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers;
import lombok.Data;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.api.type.Type;
@ -74,7 +73,6 @@ public class BulkChunkTranslatorProvider implements Provider {
return true;
}
@Data
private static class ChunkBulkSection {
private int x;
private int z;
@ -93,5 +91,45 @@ public class BulkChunkTranslatorProvider implements Provider {
return bulkSection;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getZ() {
return z;
}
public void setZ(int z) {
this.z = z;
}
public int getBitMask() {
return bitMask;
}
public void setBitMask(int bitMask) {
this.bitMask = bitMask;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
}
}

View File

@ -1,13 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor
@Getter
public enum SoundCategory {
MASTER("master", 0),
MUSIC("music", 1),
RECORD("record", 2),
@ -22,4 +16,16 @@ public enum SoundCategory {
private final String name;
private final int id;
SoundCategory(String name, int id) {
this.name = name;
this.id = id;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}

View File

@ -1,12 +1,9 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.sounds;
import lombok.Getter;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@Getter
public enum SoundEffect {
MOB_HORSE_ZOMBIE_IDLE("mob.horse.zombie.idle", "entity.zombie_horse.ambient", SoundCategory.NEUTRAL),
@ -261,7 +258,7 @@ public enum SoundEffect {
private final SoundCategory category;
private final boolean breaksound;
private static Map<String, SoundEffect> effects;
private static final Map<String, SoundEffect> effects;
static {
effects = new HashMap<>();
@ -289,4 +286,19 @@ public enum SoundEffect {
return effects.get(name);
}
public String getName() {
return name;
}
public String getNewName() {
return newName;
}
public SoundCategory getCategory() {
return category;
}
public boolean isBreaksound() {
return breaksound;
}
}

View File

@ -1,7 +1,6 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import com.google.common.collect.Sets;
import lombok.Getter;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
@ -10,7 +9,6 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTransla
import java.util.List;
import java.util.Set;
@Getter
public class ClientChunks extends StoredObject {
private final Set<Long> loadedChunks = Sets.newConcurrentHashSet();
private final Set<Long> bulkChunks = Sets.newConcurrentHashSet();
@ -26,4 +24,12 @@ public class ClientChunks extends StoredObject {
public List<Object> transformMapChunkBulk(Object packet) throws Exception {
return Via.getManager().getProviders().get(BulkChunkTranslatorProvider.class).transformMapChunkBulk(packet, this);
}
public Set<Long> getLoadedChunks() {
return loadedChunks;
}
public Set<Long> getBulkChunks() {
return bulkChunks;
}
}

View File

@ -2,8 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.Pair;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
@ -14,9 +12,7 @@ import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
public class CommandBlockStorage extends StoredObject {
private Map<Pair<Integer, Integer>, Map<Position, CompoundTag>> storedCommandBlocks = new ConcurrentHashMap<>();
@Setter
@Getter
private final Map<Pair<Integer, Integer>, Map<Position, CompoundTag>> storedCommandBlocks = new ConcurrentHashMap<>();
private boolean permissions = false;
public CommandBlockStorage(UserConnection user) {
@ -71,4 +67,12 @@ public class CommandBlockStorage extends StoredObject {
public void unloadChunks() {
storedCommandBlocks.clear();
}
public boolean isPermissions() {
return permissions;
}
public void setPermissions(boolean permissions) {
this.permissions = permissions;
}
}

View File

@ -1,10 +1,7 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Sets;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.boss.BossBar;
@ -26,11 +23,15 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@Getter
public class EntityTracker1_9 extends EntityTracker {
private final Map<Integer, UUID> uuidMap = new ConcurrentHashMap<>();
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
@ -43,16 +44,11 @@ public class EntityTracker1_9 extends EntityTracker {
.expireAfterAccess(250, TimeUnit.MILLISECONDS)
.<Position, Boolean>build()
.asMap());
@Setter
private boolean blocking = false;
@Setter
private boolean autoTeam = false;
@Setter
private Position currentlyDigging = null;
private boolean teamExists = false;
@Setter
private GameMode gameMode;
@Setter
private String currentTeam;
public EntityTracker1_9(UserConnection user) {
@ -104,7 +100,7 @@ public class EntityTracker1_9 extends EntityTracker {
}
public boolean interactedBlockRecently(int x, int y, int z) {
return blockInteractions.contains(new Position(x, (short) y , z));
return blockInteractions.contains(new Position(x, (short) y, z));
}
public void addBlockInteraction(Position p) {
@ -308,4 +304,76 @@ public class EntityTracker1_9 extends EntityTracker {
return getClientEntityId();
}
}
public Map<Integer, UUID> getUuidMap() {
return uuidMap;
}
public Map<Integer, List<Metadata>> getMetadataBuffer() {
return metadataBuffer;
}
public Map<Integer, Integer> getVehicleMap() {
return vehicleMap;
}
public Map<Integer, BossBar> getBossBarMap() {
return bossBarMap;
}
public Set<Integer> getValidBlocking() {
return validBlocking;
}
public Set<Integer> getKnownHolograms() {
return knownHolograms;
}
public Set<Position> getBlockInteractions() {
return blockInteractions;
}
public boolean isBlocking() {
return blocking;
}
public void setBlocking(boolean blocking) {
this.blocking = blocking;
}
public boolean isAutoTeam() {
return autoTeam;
}
public void setAutoTeam(boolean autoTeam) {
this.autoTeam = autoTeam;
}
public Position getCurrentlyDigging() {
return currentlyDigging;
}
public void setCurrentlyDigging(Position currentlyDigging) {
this.currentlyDigging = currentlyDigging;
}
public boolean isTeamExists() {
return teamExists;
}
public GameMode getGameMode() {
return gameMode;
}
public void setGameMode(GameMode gameMode) {
this.gameMode = gameMode;
}
public String getCurrentTeam() {
return currentTeam;
}
public void setCurrentTeam(String currentTeam) {
this.currentTeam = currentTeam;
}
}

View File

@ -1,16 +1,20 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
@Getter
@Setter
public class InventoryTracker extends StoredObject {
private String inventory;
public InventoryTracker(UserConnection user) {
super(user);
}
public String getInventory() {
return inventory;
}
public void setInventory(String inventory) {
this.inventory = inventory;
}
}

View File

@ -1,17 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
public class MovementTracker extends StoredObject {
private static final long IDLE_PACKET_DELAY = 50L; // Update every 50ms (20tps)
private static final long IDLE_PACKET_LIMIT = 20; // Max 20 ticks behind
@Getter
private long nextIdlePacket = 0L;
@Getter
@Setter
private boolean ground = true;
public MovementTracker(UserConnection user) {
@ -23,4 +18,16 @@ public class MovementTracker extends StoredObject {
// Allow a maximum lag spike of 1 second (20 ticks/updates)
this.nextIdlePacket = Math.max(nextIdlePacket + IDLE_PACKET_DELAY, System.currentTimeMillis() - IDLE_PACKET_DELAY * IDLE_PACKET_LIMIT);
}
public long getNextIdlePacket() {
return nextIdlePacket;
}
public boolean isGround() {
return ground;
}
public void setGround(boolean ground) {
this.ground = ground;
}
}

View File

@ -1,15 +1,11 @@
package us.myles.ViaVersion.protocols.protocol1_9to1_8.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position;
@Getter
public class PlaceBlockTracker extends StoredObject {
private long lastPlaceTimestamp = 0;
@Setter
private Position lastPlacedPosition = null;
public PlaceBlockTracker(UserConnection user) {
@ -32,4 +28,16 @@ public class PlaceBlockTracker extends StoredObject {
public void updateTime() {
lastPlaceTimestamp = System.currentTimeMillis();
}
public long getLastPlaceTimestamp() {
return lastPlaceTimestamp;
}
public Position getLastPlacedPosition() {
return lastPlacedPosition;
}
public void setLastPlacedPosition(Position lastPlacedPosition) {
this.lastPlacedPosition = lastPlacedPosition;
}
}

View File

@ -2,18 +2,16 @@ package us.myles.ViaVersion.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import lombok.experimental.UtilityClass;
@UtilityClass
public class GsonUtil {
private final Gson gson = getGsonBuilder().create();
public final class GsonUtil {
private static final Gson gson = getGsonBuilder().create();
/**
* Get google's Gson magic
*
* @return Gson instance
*/
public Gson getGson() {
public static Gson getGson() {
return gson;
}
@ -22,8 +20,7 @@ public class GsonUtil {
*
* @return GsonBuilder instance
*/
public GsonBuilder getGsonBuilder() {
public static GsonBuilder getGsonBuilder() {
return new GsonBuilder();
}
}

View File

@ -1,6 +1,5 @@
package us.myles.ViaVersion.sponge.commands;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.spongepowered.api.command.CommandSource;
@ -10,9 +9,12 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID;
@AllArgsConstructor
public class SpongeCommandSender implements ViaCommandSender {
private CommandSource source;
private final CommandSource source;
public SpongeCommandSender(CommandSource source) {
this.source = source;
}
@Override
public boolean hasPermission(String permission) {

View File

@ -5,7 +5,6 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.MessageToByteEncoder;
import lombok.Getter;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
@ -14,7 +13,6 @@ import java.lang.reflect.Method;
public class SpongeChannelInitializer extends ChannelInitializer<Channel> {
@Getter
private final ChannelInitializer<Channel> original;
private Method method;
@ -51,4 +49,8 @@ public class SpongeChannelInitializer extends ChannelInitializer<Channel> {
this.method.invoke(this.original, channel);
}
}
public ChannelInitializer<Channel> getOriginal() {
return original;
}
}

View File

@ -1,6 +1,5 @@
package us.myles.ViaVersion.sponge.listeners;
import lombok.Getter;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.living.player.Player;
import us.myles.ViaVersion.SpongePlugin;
@ -13,7 +12,6 @@ import java.lang.reflect.Field;
public class ViaSpongeListener extends ViaListener {
private static Field entityIdField;
@Getter
private final SpongePlugin plugin;
public ViaSpongeListener(SpongePlugin plugin, Class<? extends Protocol> requiredPipeline) {
@ -46,4 +44,8 @@ public class ViaSpongeListener extends ViaListener {
Via.getPlatform().getLogger().severe("Could not get the entity id, please report this on our Github");
return -1;
}
public SpongePlugin getPlugin() {
return plugin;
}
}

View File

@ -1,12 +1,17 @@
package us.myles.ViaVersion.sponge.platform;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.spongepowered.api.scheduler.Task;
import us.myles.ViaVersion.api.platform.TaskId;
@Getter
@AllArgsConstructor
public class SpongeTaskId implements TaskId {
private Task object;
private final Task object;
public SpongeTaskId(Task object) {
this.object = object;
}
@Override
public Task getObject() {
return object;
}
}

View File

@ -1,7 +1,6 @@
package us.myles.ViaVersion.sponge.platform;
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import org.spongepowered.api.entity.living.player.Player;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
@ -20,14 +19,14 @@ import java.util.UUID;
public class SpongeViaAPI implements ViaAPI<Player> {
@Override
public int getPlayerVersion(@NonNull Player player) {
public int getPlayerVersion(Player player) {
if (!isPorted(player.getUniqueId()))
return ProtocolRegistry.SERVER_PROTOCOL;
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
}
@Override
public int getPlayerVersion(@NonNull UUID uuid) {
public int getPlayerVersion(UUID uuid) {
if (!isPorted(uuid))
return ProtocolRegistry.SERVER_PROTOCOL;
return getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();

View File

@ -2,7 +2,6 @@ package us.myles.ViaVersion.velocity.command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import lombok.AllArgsConstructor;
import net.kyori.text.serializer.gson.GsonComponentSerializer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
@ -10,9 +9,12 @@ import us.myles.ViaVersion.api.command.ViaCommandSender;
import java.util.UUID;
@AllArgsConstructor
public class VelocityCommandSender implements ViaCommandSender {
private CommandSource source;
private final CommandSource source;
public VelocityCommandSender(CommandSource source) {
this.source = source;
}
@Override
public boolean hasPermission(String permission) {

View File

@ -2,17 +2,19 @@ package us.myles.ViaVersion.velocity.handlers;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import lombok.AllArgsConstructor;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
import java.lang.reflect.Method;
@AllArgsConstructor
public class VelocityChannelInitializer extends ChannelInitializer {
private ChannelInitializer original;
private final ChannelInitializer original;
private static Method initChannel;
public VelocityChannelInitializer(ChannelInitializer original) {
this.original = original;
}
static {
try {
initChannel = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);

View File

@ -4,7 +4,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import lombok.AllArgsConstructor;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
@ -16,10 +15,13 @@ import us.myles.ViaVersion.util.PipelineUtil;
import java.util.List;
@ChannelHandler.Sharable
@AllArgsConstructor
public class VelocityDecodeHandler extends MessageToMessageDecoder<ByteBuf> {
private final UserConnection info;
public VelocityDecodeHandler(UserConnection info) {
this.info = info;
}
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {
// use transformers

View File

@ -6,8 +6,6 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.handler.codec.MessageToMessageDecoder;
import io.netty.handler.codec.MessageToMessageEncoder;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
@ -20,11 +18,13 @@ import us.myles.ViaVersion.util.PipelineUtil;
import java.util.List;
@ChannelHandler.Sharable
@RequiredArgsConstructor
public class VelocityEncodeHandler extends MessageToMessageEncoder<ByteBuf> {
@NonNull
private final UserConnection info;
private boolean handledCompression = false;
private boolean handledCompression;
public VelocityEncodeHandler(UserConnection info) {
this.info = info;
}
@Override
protected void encode(final ChannelHandlerContext ctx, ByteBuf bytebuf, List<Object> out) throws Exception {

View File

@ -1,12 +1,17 @@
package us.myles.ViaVersion.velocity.platform;
import com.velocitypowered.api.scheduler.ScheduledTask;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.platform.TaskId;
@Getter
@AllArgsConstructor
public class VelocityTaskId implements TaskId {
private ScheduledTask object;
private final ScheduledTask object;
public VelocityTaskId(ScheduledTask object) {
this.object = object;
}
@Override
public ScheduledTask getObject() {
return object;
}
}

View File

@ -4,7 +4,6 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.proxy.Player;
import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import us.myles.ViaVersion.VelocityPlugin;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
@ -22,14 +21,14 @@ import java.util.UUID;
public class VelocityViaAPI implements ViaAPI<Player> {
@Override
public int getPlayerVersion(@NonNull Player player) {
public int getPlayerVersion(Player player) {
if (!isPorted(player.getUniqueId()))
return player.getProtocolVersion().getProtocol();
return getPortedPlayers().get(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
}
@Override
public int getPlayerVersion(@NonNull UUID uuid) {
public int getPlayerVersion(UUID uuid) {
if (!isPorted(uuid)) {
return VelocityPlugin.PROXY.getPlayer(uuid)
.map(InboundConnection::getProtocolVersion)

View File

@ -1,7 +1,6 @@
package us.myles.ViaVersion.velocity.service;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import lombok.Getter;
import us.myles.ViaVersion.VelocityPlugin;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
@ -13,7 +12,6 @@ import java.util.concurrent.ConcurrentHashMap;
public class ProtocolDetectorService implements Runnable {
private static final Map<String, Integer> detectedProtocolIds = new ConcurrentHashMap<>();
@Getter
private static ProtocolDetectorService instance;
public ProtocolDetectorService() {
@ -79,4 +77,7 @@ public class ProtocolDetectorService implements Runnable {
return new HashMap<>(detectedProtocolIds);
}
public static ProtocolDetectorService getInstance() {
return instance;
}
}