Merge branch 'abstraction' of https://github.com/ViaVersion/ViaVersion into portedplayerschange

This commit is contained in:
creeper123123321 2020-04-15 11:39:13 -03:00
commit dd5cbb0e4c
64 changed files with 940 additions and 278 deletions

63
bukkit-legacy/pom.xml Normal file
View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>viaversion-bukkit-legacy</artifactId>
<properties>
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
</properties>
<build>
<resources>
<resource>
<targetPath>.</targetPath>
<filtering>true</filtering>
<directory>src/main/resources/</directory>
<includes>
<include>*</include>
</includes>
</resource>
</resources>
</build>
<dependencies>
<!-- Common Module -->
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion-common</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<!-- Bukkit API, http://www.spigotmc.org/ or http://bukkit.org/ -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>${bukkitVersion}</version>
<scope>provided</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>junit</groupId>
</exclusion>
<exclusion>
<artifactId>gson</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>persistence-api</artifactId>
<groupId>javax.persistence</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>

View File

@ -1,21 +1,16 @@
package us.myles.ViaVersion.bukkit.listeners;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaListener;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
@Getter(AccessLevel.PROTECTED)
public class ViaBukkitListener extends ViaListener implements Listener {
private final Plugin plugin;
public ViaBukkitListener(ViaVersionPlugin plugin, Class<? extends Protocol> requiredPipeline) {
public ViaBukkitListener(Plugin plugin, Class<? extends Protocol> requiredPipeline) {
super(requiredPipeline);
this.plugin = plugin;
}
@ -26,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());
}
@ -50,4 +45,8 @@ public class ViaBukkitListener extends ViaListener implements Listener {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
setRegistered(true);
}
public Plugin getPlugin() {
return plugin;
}
}

View File

@ -14,7 +14,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.ItemStack;
import us.myles.ViaVersion.ViaVersionPlugin;
import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.type.Type;
@ -28,7 +28,7 @@ public class ArmorListener extends ViaBukkitListener {
private static final UUID ARMOR_ATTRIBUTE = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150");
public ArmorListener(ViaVersionPlugin plugin) {
public ArmorListener(Plugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}
@ -36,7 +36,6 @@ public class ArmorListener extends ViaBukkitListener {
// Ensure that the player is on our pipe
if (!isOnPipe(player)) return;
int armor = 0;
for (ItemStack stack : player.getInventory().getArmorContents()) {
armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
@ -82,12 +81,7 @@ public class ArmorListener extends ViaBukkitListener {
if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
final Player player = e.getPlayer();
// Due to odd bugs it's 3 ticks later
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable() {
@Override
public void run() {
sendArmorUpdate(player);
}
}, 3L);
Bukkit.getScheduler().scheduleSyncDelayedTask(getPlugin(), () -> sendArmorUpdate(player), 3L);
}
}
}
@ -114,11 +108,6 @@ public class ArmorListener extends ViaBukkitListener {
public void sendDelayedArmorUpdate(final Player player) {
if (!isOnPipe(player)) return; // Don't start a task if the player is not on the pipe
Via.getPlatform().runSync(new Runnable() {
@Override
public void run() {
sendArmorUpdate(player);
}
});
Via.getPlatform().runSync(() -> sendArmorUpdate(player));
}
}

View File

@ -4,7 +4,7 @@ import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
@ -12,7 +12,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
public class BlockListener extends ViaBukkitListener {
public BlockListener(ViaVersionPlugin plugin) {
public BlockListener(Plugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.PlayerDeathEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
@ -14,7 +14,8 @@ import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
public class DeathListener extends ViaBukkitListener {
public DeathListener(ViaVersionPlugin plugin) {
public DeathListener(Plugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}

View File

@ -13,6 +13,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class HandItemCache extends BukkitRunnable {
private final Map<UUID, Item> handCache = new ConcurrentHashMap<>();
@Override

View File

@ -6,13 +6,13 @@ import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import us.myles.ViaVersion.ViaVersionPlugin;
import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
public class PaperPatch extends ViaBukkitListener {
public PaperPatch(ViaVersionPlugin plugin) {
public PaperPatch(Plugin plugin) {
super(plugin, Protocol1_9To1_8.class);
}

View File

@ -13,7 +13,7 @@
<properties>
<!-- Change Bukkit Version HERE! -->
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
<bukkitVersion>1.15.2-R0.1-SNAPSHOT</bukkitVersion>
</properties>
<build>
@ -60,5 +60,13 @@
</exclusion>
</exclusions>
</dependency>
<!-- Legacy Support -->
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion-bukkit-legacy</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

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

@ -0,0 +1,68 @@
package us.myles.ViaVersion.bukkit.listeners.protocol1_15to1_14_4;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.potion.PotionEffectType;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.bukkit.listeners.ViaBukkitListener;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import java.util.Arrays;
public class EntityToggleGlideListener extends ViaBukkitListener {
public EntityToggleGlideListener(ViaVersionPlugin plugin) {
super(plugin, Protocol1_15To1_14_4.class);
}
@EventHandler(priority = EventPriority.MONITOR)
public void entityToggleGlide(EntityToggleGlideEvent event) {
if (!(event.getEntity() instanceof Player)) return;
Player player = (Player) event.getEntity();
if (!isOnPipe(player)) return;
// Cancelling can only be done by updating the player's metadata
if (event.isGliding() && event.isCancelled()) {
PacketWrapper packet = new PacketWrapper(0x44, null, getUserConnection(player));
try {
packet.write(Type.VAR_INT, player.getEntityId());
byte bitmask = 0;
// Collect other metadata for the mitmask
if (player.getFireTicks() > 0) {
bitmask |= 0x01;
}
if (player.isSneaking()) {
bitmask |= 0x02;
}
// 0x04 is unused
if (player.isSprinting()) {
bitmask |= 0x08;
}
if (player.isSwimming()) {
bitmask |= 0x10;
}
if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) {
bitmask |= 0x20;
}
if (player.isGlowing()) {
bitmask |= 0x40;
}
// leave 0x80 as 0 to stop gliding
packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, MetaType1_14.Byte, bitmask)));
packet.send(Protocol1_15To1_14_4.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

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;
@ -28,12 +27,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 (!isInjected(uuid))
return getExternalVersion(Bukkit.getPlayer(uuid));
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();

View File

@ -17,7 +17,12 @@ import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.bukkit.listeners.UpdateListener;
import us.myles.ViaVersion.bukkit.listeners.multiversion.PlayerSneakListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.*;
import us.myles.ViaVersion.bukkit.listeners.protocol1_15to1_14_4.EntityToggleGlideListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.ArmorListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.BlockListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.DeathListener;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.HandItemCache;
import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.PaperPatch;
import us.myles.ViaVersion.bukkit.providers.BukkitBlockConnectionProvider;
import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider;
import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator;
@ -99,6 +104,14 @@ public class BukkitViaLoader implements ViaPlatformLoader {
}
}
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_15.getId()) {
try {
Class.forName("org.bukkit.event.entity.EntityToggleGlideEvent");
storeListener(new EntityToggleGlideListener(plugin)).register();
} catch (ClassNotFoundException ignored) {
}
}
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco")
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch"))

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

@ -291,8 +291,8 @@ public class WorldPackets {
wrapper.clearInputBuffer();
// First set this packet ID to Block placement
wrapper.setId(0x08);
wrapper.write(Type.LONG, -1L);
wrapper.write(Type.BYTE, (byte) 255);
wrapper.write(Type.POSITION, new Position(-1, (short) -1, -1));
wrapper.write(Type.UNSIGNED_BYTE, (short) 255);
// Write item in hand
Item item = Protocol1_9To1_8.getHandItem(wrapper.user());
// Blocking patch
@ -315,9 +315,9 @@ public class WorldPackets {
}
wrapper.write(Type.ITEM, item);
wrapper.write(Type.BYTE, (byte) 0);
wrapper.write(Type.BYTE, (byte) 0);
wrapper.write(Type.BYTE, (byte) 0);
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
wrapper.write(Type.UNSIGNED_BYTE, (short) 0);
}
});

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();
}
}

13
pom.xml
View File

@ -18,6 +18,7 @@
<modules>
<module>common</module>
<module>bukkit</module>
<module>bukkit-legacy</module>
<module>bungee</module>
<module>fabric</module>
<module>sponge</module>
@ -52,6 +53,18 @@
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<!-- Velocity repository -->
<repository>
<id>velocity</id>
<url>https://repo.velocitypowered.com/snapshots</url>
</repository>
<!-- Sponge repository -->
<repository>
<id>sponge</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
<!-- ViaVersion Repository -->
<repository>
<id>viaversion-repo</id>

View File

@ -12,13 +12,6 @@
<artifactId>viaversion-sponge-legacy</artifactId>
<packaging>jar</packaging>
<repositories>
<repository>
<id>sponge</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
</repositories>
<build>
<resources>
<resource>

View File

@ -11,13 +11,6 @@
<artifactId>viaversion-sponge</artifactId>
<repositories>
<repository>
<id>sponge</id>
<url>https://repo.spongepowered.org/maven</url>
</repository>
</repositories>
<build>
<resources>
<resource>

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;
@ -19,12 +18,12 @@ import java.util.UUID;
public class SpongeViaAPI 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 (!isInjected(uuid))
return ProtocolRegistry.SERVER_PROTOCOL;
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();

View File

@ -11,13 +11,6 @@
<artifactId>viaversion-velocity</artifactId>
<repositories>
<repository>
<id>velocity</id>
<url>https://repo.velocitypowered.com/snapshots</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>

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

@ -2,7 +2,6 @@ package us.myles.ViaVersion.velocity.platform;
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;
@ -20,15 +19,16 @@ import java.util.UUID;
public class VelocityViaAPI implements ViaAPI<Player> {
@Override
public int getPlayerVersion(@NonNull Player player) {
public int getPlayerVersion(Player player) {
if (!isInjected(player.getUniqueId()))
return player.getProtocolVersion().getProtocol();
return Via.getManager().getConnection(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
}
@Override
public int getPlayerVersion(@NonNull UUID uuid) {
public int getPlayerVersion(UUID uuid) {
return getPlayerVersion(VelocityPlugin.PROXY.getPlayer(uuid).orElseThrow(NoSuchElementException::new));
}
@Override

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;
}
}