3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-30 18:10:12 +01:00

Merge pull request #1743 from KennyTV/cache

Uncache UserConnection on channel close, say farewell to lombok
Dieser Commit ist enthalten in:
Myles 2020-04-25 12:24:44 +01:00 committet von GitHub
Commit d96b88b967
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
35 geänderte Dateien mit 592 neuen und 200 gelöschten Zeilen

Datei anzeigen

@ -27,7 +27,7 @@ public class PlayerSneakListener extends ViaBukkitListener {
private final boolean is1_14Fix; private final boolean is1_14Fix;
private Map<Player, Boolean> sneaking; // true = 1.14+, else false private Map<Player, Boolean> sneaking; // true = 1.14+, else false
private Set<UUID> sneakingUuids; private Set<UUID> sneakingUuids;
private Method getHandle; private final Method getHandle;
private Method setSize; private Method setSize;
private boolean useCache; private boolean useCache;

Datei anzeigen

@ -2,10 +2,8 @@ package us.myles.ViaVersion.bukkit.platform;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import us.myles.ViaVersion.ViaVersionPlugin; import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -73,13 +71,6 @@ public class BukkitViaLoader implements ViaPlatformLoader {
// Add ProtocolSupport ConnectListener if necessary. // Add ProtocolSupport ConnectListener if necessary.
ClassGenerator.registerPSConnectListener(plugin); ClassGenerator.registerPSConnectListener(plugin);
registerListener(new Listener() {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e) {
Via.getManager().handleDisconnect(e.getPlayer().getUniqueId());
}
});
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) { if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
storeListener(new ArmorListener(plugin)).register(); storeListener(new ArmorListener(plugin)).register();

Datei anzeigen

@ -2,31 +2,34 @@ package us.myles.ViaVersion;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.protocol.ProtocolConstants; import net.md_5.bungee.protocol.ProtocolConstants;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaConnectionManager; import us.myles.ViaVersion.api.platform.ViaConnectionManager;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.bungee.commands.BungeeCommand; import us.myles.ViaVersion.bungee.commands.BungeeCommand;
import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler; import us.myles.ViaVersion.bungee.commands.BungeeCommandHandler;
import us.myles.ViaVersion.bungee.commands.BungeeCommandSender; import us.myles.ViaVersion.bungee.commands.BungeeCommandSender;
import us.myles.ViaVersion.bungee.platform.*; import us.myles.ViaVersion.bungee.platform.BungeeTaskId;
import us.myles.ViaVersion.bungee.platform.BungeeViaAPI;
import us.myles.ViaVersion.bungee.platform.BungeeViaConfig;
import us.myles.ViaVersion.bungee.platform.BungeeViaInjector;
import us.myles.ViaVersion.bungee.platform.BungeeViaLoader;
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.GsonUtil;
import java.util.*; import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>, Listener { public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>, Listener {
@ -193,16 +196,4 @@ public class BungeePlugin extends Plugin implements ViaPlatform<ProxiedPlayer>,
public ViaConnectionManager getConnectionManager() { public ViaConnectionManager getConnectionManager() {
return connectionManager; return connectionManager;
} }
@EventHandler
public void onQuit(PlayerDisconnectEvent e) {
UserConnection userConnection = getConnectionManager().getConnectedClient(e.getPlayer().getUniqueId());
if (userConnection != null) {
// Only remove if the connection is disconnected (eg. relogin)
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
Via.getManager().handleDisconnect(e.getPlayer().getUniqueId());
}
}
}
} }

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.bungee.platform; package us.myles.ViaVersion.bungee.platform;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import lombok.NonNull;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -20,8 +19,9 @@ import java.util.TreeSet;
import java.util.UUID; import java.util.UUID;
public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> { public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
@Override @Override
public int getPlayerVersion(@NonNull ProxiedPlayer player) { public int getPlayerVersion(ProxiedPlayer player) {
UserConnection conn = Via.getManager().getConnection(player.getUniqueId()); UserConnection conn = Via.getManager().getConnection(player.getUniqueId());
if (conn == null) { if (conn == null) {
return player.getPendingConnection().getVersion(); return player.getPendingConnection().getVersion();
@ -30,7 +30,7 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
} }
@Override @Override
public int getPlayerVersion(@NonNull UUID uuid) { public int getPlayerVersion(UUID uuid) {
return getPlayerVersion(ProxyServer.getInstance().getPlayer(uuid)); return getPlayerVersion(ProxyServer.getInstance().getPlayer(uuid));
} }

Datei anzeigen

@ -1,6 +1,5 @@
package us.myles.ViaVersion.bungee.service; package us.myles.ViaVersion.bungee.service;
import lombok.Getter;
import net.md_5.bungee.api.Callback; import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
@ -15,9 +14,8 @@ import java.util.concurrent.ConcurrentHashMap;
public class ProtocolDetectorService implements Runnable { public class ProtocolDetectorService implements Runnable {
private static final Map<String, Integer> detectedProtocolIds = new ConcurrentHashMap<>(); private static final Map<String, Integer> detectedProtocolIds = new ConcurrentHashMap<>();
private BungeePlugin plugin;
@Getter
private static ProtocolDetectorService instance; private static ProtocolDetectorService instance;
private final BungeePlugin plugin;
public ProtocolDetectorService(BungeePlugin plugin) { public ProtocolDetectorService(BungeePlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -84,4 +82,11 @@ public class ProtocolDetectorService implements Runnable {
return new HashMap<>(detectedProtocolIds); return new HashMap<>(detectedProtocolIds);
} }
public static ProtocolDetectorService getInstance() {
return instance;
}
public BungeePlugin getPlugin() {
return plugin;
}
} }

Datei anzeigen

@ -1,15 +1,14 @@
package us.myles.ViaVersion.bungee.storage; package us.myles.ViaVersion.bungee.storage;
import lombok.EqualsAndHashCode;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@EqualsAndHashCode(callSuper = true)
public class BungeeStorage extends StoredObject { public class BungeeStorage extends StoredObject {
private static Field bossField; private static Field bossField;
@ -59,4 +58,22 @@ public class BungeeStorage extends StoredObject {
public Set<UUID> getBossbar() { public Set<UUID> getBossbar() {
return bossbar; return bossbar;
} }
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
BungeeStorage that = (BungeeStorage) o;
if (!Objects.equals(player, that.player)) return false;
if (!Objects.equals(currentServer, that.currentServer)) return false;
return Objects.equals(bossbar, that.bossbar);
}
@Override
public int hashCode() {
int result = player != null ? player.hashCode() : 0;
result = 31 * result + (currentServer != null ? currentServer.hashCode() : 0);
result = 31 * result + (bossbar != null ? bossbar.hashCode() : 0);
return result;
}
} }

Datei anzeigen

@ -1,8 +1,9 @@
package us.myles.ViaVersion; package us.myles.ViaVersion;
import lombok.Builder;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaConnectionManager;
import us.myles.ViaVersion.api.platform.ViaInjector; import us.myles.ViaVersion.api.platform.ViaInjector;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.platform.ViaPlatformLoader; import us.myles.ViaVersion.api.platform.ViaPlatformLoader;
@ -27,9 +28,9 @@ public class ViaManager {
private final ViaCommandHandler commandHandler; private final ViaCommandHandler commandHandler;
private final ViaPlatformLoader loader; private final ViaPlatformLoader loader;
private final Set<String> subPlatforms = new HashSet<>(); private final Set<String> subPlatforms = new HashSet<>();
private TaskId mappingLoadingTask;
private boolean debug; private boolean debug;
@Builder
public ViaManager(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) { public ViaManager(ViaPlatform<?> platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
this.platform = platform; this.platform = platform;
this.injector = injector; this.injector = injector;
@ -37,6 +38,10 @@ public class ViaManager {
this.loader = loader; this.loader = loader;
} }
public static ViaManagerBuilder builder() {
return new ViaManagerBuilder();
}
public void init() { public void init() {
if (System.getProperty("ViaVersion") != null) { if (System.getProperty("ViaVersion") != null) {
// Reload? // Reload?
@ -83,6 +88,12 @@ public class ViaManager {
// Load Platform // Load Platform
loader.load(); loader.load();
// Common tasks // Common tasks
mappingLoadingTask = Via.getPlatform().runRepeatingSync(() -> {
if (ProtocolRegistry.checkForMappingCompletion()) {
platform.cancelTask(mappingLoadingTask);
mappingLoadingTask = null;
}
}, 10L);
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) { if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {
if (Via.getConfig().isSimulatePlayerTick()) { if (Via.getConfig().isSimulatePlayerTick()) {
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L); Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
@ -128,6 +139,9 @@ public class ViaManager {
return platform.getConnectionManager().getConnectedClients(); return platform.getConnectionManager().getConnectedClients();
} }
/**
* @see ViaConnectionManager#isClientConnected(UUID)
*/
public boolean isClientConnected(UUID player) { public boolean isClientConnected(UUID player) {
return platform.getConnectionManager().isClientConnected(player); return platform.getConnectionManager().isClientConnected(player);
} }
@ -136,17 +150,6 @@ public class ViaManager {
platform.getConnectionManager().onLoginSuccess(info); platform.getConnectionManager().onLoginSuccess(info);
} }
public void handleDisconnect(UUID id) {
UserConnection connection = getConnection(id);
if (connection != null) {
handleDisconnect(connection);
}
}
public void handleDisconnect(UserConnection info) {
platform.getConnectionManager().onDisconnect(info);
}
public ViaPlatform<?> getPlatform() { public ViaPlatform<?> getPlatform() {
return platform; return platform;
} }
@ -185,7 +188,41 @@ public class ViaManager {
return subPlatforms; return subPlatforms;
} }
/**
* @see ViaConnectionManager#getConnectedClient(UUID)
*/
public UserConnection getConnection(UUID playerUUID) { public UserConnection getConnection(UUID playerUUID) {
return platform.getConnectionManager().getConnectedClient(playerUUID); return platform.getConnectionManager().getConnectedClient(playerUUID);
} }
public static final class ViaManagerBuilder {
private ViaPlatform<?> platform;
private ViaInjector injector;
private ViaCommandHandler commandHandler;
private ViaPlatformLoader loader;
public ViaManagerBuilder platform(ViaPlatform<?> platform) {
this.platform = platform;
return this;
}
public ViaManagerBuilder injector(ViaInjector injector) {
this.injector = injector;
return this;
}
public ViaManagerBuilder loader(ViaPlatformLoader loader) {
this.loader = loader;
return this;
}
public ViaManagerBuilder commandHandler(ViaCommandHandler commandHandler) {
this.commandHandler = commandHandler;
return this;
}
public ViaManager build() {
return new ViaManager(platform, injector, commandHandler, loader);
}
}
} }

Datei anzeigen

@ -7,7 +7,6 @@ import us.myles.ViaVersion.api.platform.ViaPlatform;
public class Via { public class Via {
private static ViaPlatform platform; private static ViaPlatform platform;
private static ViaManager manager; private static ViaManager manager;
private static boolean cacheJsonMappings;
/** /**
* Register the ViaManager associated with the platform. * Register the ViaManager associated with the platform.

Datei anzeigen

@ -38,8 +38,8 @@ public interface ViaAPI<T> {
* *
* @param playerUUID UUID of a player * @param playerUUID UUID of a player
* @return true if Via has a cached userconnection for this player * @return true if Via has a cached userconnection for this player
* @deprecated as of 0.9.9, because all players are ported use {@link #getPlayerVersion(UUID)}, * @deprecated use {@link #isInjected(UUID)}
* or use {@link #isInjected(UUID)} * @see #isInjected(UUID)
*/ */
@Deprecated @Deprecated
default boolean isPorted(UUID playerUUID) { default boolean isPorted(UUID playerUUID) {
@ -66,18 +66,18 @@ public interface ViaAPI<T> {
* *
* @param player Platform player object, eg. Bukkit this is Player * @param player Platform player object, eg. Bukkit this is Player
* @param packet The packet, you need a VarInt ID then the packet contents. * @param packet The packet, you need a VarInt ID then the packet contents.
* @throws IllegalArgumentException If not on 1.9 throws IllegalArg * @throws IllegalArgumentException if the player is not injected by Via
*/ */
void sendRawPacket(T player, ByteBuf packet) throws IllegalArgumentException; void sendRawPacket(T player, ByteBuf packet);
/** /**
* Send a raw packet to the player (Use new IDs) * Send a raw packet to the player (Use new IDs)
* *
* @param uuid The uuid from the player to send packet * @param uuid The uuid from the player to send packet
* @param packet The packet, you need a VarInt ID then the packet contents. * @param packet The packet, you need a VarInt ID then the packet contents.
* @throws IllegalArgumentException If not on 1.9 throws IllegalArg * @throws IllegalArgumentException if the player is not injected by Via
*/ */
void sendRawPacket(UUID uuid, ByteBuf packet) throws IllegalArgumentException; void sendRawPacket(UUID uuid, ByteBuf packet);
/** /**
* Create a new bossbar instance * Create a new bossbar instance

Datei anzeigen

@ -5,7 +5,6 @@ import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import lombok.Data;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
@ -17,23 +16,25 @@ import us.myles.ViaVersion.util.PipelineUtil;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
@Data
public class UserConnection { public class UserConnection {
private static final AtomicLong IDS = new AtomicLong();
private final long id = IDS.incrementAndGet();
private final Channel channel; private final Channel channel;
Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>(); Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>();
private boolean active = true; private boolean active = true;
private boolean pendingDisconnect = false; private boolean pendingDisconnect;
private Object lastPacket; private Object lastPacket;
private long sentPackets = 0L; private long sentPackets;
private long receivedPackets = 0L; private long receivedPackets;
// Used for tracking pps // Used for tracking pps
private long startTime = 0L; private long startTime;
private long intervalPackets = 0L; private long intervalPackets;
private long packetsPerSecond = -1L; private long packetsPerSecond = -1L;
// Used for handling warnings (over time) // Used for handling warnings (over time)
private int secondsObserved = 0; private int secondsObserved;
private int warnings = 0; private int warnings;
public UserConnection(Channel channel) { public UserConnection(Channel channel) {
this.channel = channel; this.channel = channel;
@ -242,4 +243,109 @@ public class UserConnection {
public void sendRawPacketToServer(ByteBuf packet) { public void sendRawPacketToServer(ByteBuf packet) {
sendRawPacketToServer(packet, false); sendRawPacketToServer(packet, false);
} }
public long getId() {
return id;
}
public Channel getChannel() {
return channel;
}
public Map<Class, StoredObject> getStoredObjects() {
return storedObjects;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public boolean isPendingDisconnect() {
return pendingDisconnect;
}
public void setPendingDisconnect(boolean pendingDisconnect) {
this.pendingDisconnect = pendingDisconnect;
}
public Object getLastPacket() {
return lastPacket;
}
public void setLastPacket(Object lastPacket) {
this.lastPacket = lastPacket;
}
public long getSentPackets() {
return sentPackets;
}
public void setSentPackets(long sentPackets) {
this.sentPackets = sentPackets;
}
public long getReceivedPackets() {
return receivedPackets;
}
public void setReceivedPackets(long receivedPackets) {
this.receivedPackets = receivedPackets;
}
public long getStartTime() {
return startTime;
}
public void setStartTime(long startTime) {
this.startTime = startTime;
}
public long getIntervalPackets() {
return intervalPackets;
}
public void setIntervalPackets(long intervalPackets) {
this.intervalPackets = intervalPackets;
}
public long getPacketsPerSecond() {
return packetsPerSecond;
}
public void setPacketsPerSecond(long packetsPerSecond) {
this.packetsPerSecond = packetsPerSecond;
}
public int getSecondsObserved() {
return secondsObserved;
}
public void setSecondsObserved(int secondsObserved) {
this.secondsObserved = secondsObserved;
}
public int getWarnings() {
return warnings;
}
public void setWarnings(int warnings) {
this.warnings = warnings;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
UserConnection that = (UserConnection) o;
return id == that.id;
}
@Override
public int hashCode() {
return Long.hashCode(id);
}
} }

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -27,8 +25,6 @@ public class Entity1_10Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
ENTITY(-1), ENTITY(-1),
DROPPED_ITEM(1, ENTITY), DROPPED_ITEM(1, ENTITY),
@ -126,6 +122,11 @@ public class Entity1_10Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);
@ -137,10 +138,18 @@ public class Entity1_10Types {
return Optional.empty(); return Optional.empty();
return Optional.ofNullable(TYPES.get(id)); return Optional.ofNullable(TYPES.get(id));
} }
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
} }
@AllArgsConstructor
@Getter
public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType { public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM), ITEM(2, EntityType.DROPPED_ITEM),
@ -179,6 +188,21 @@ public class Entity1_10Types {
} }
} }
ObjectType(int id, EntityType type) {
this.id = id;
this.type = type;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getType() {
return type;
}
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.empty(); return Optional.empty();

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -27,8 +25,6 @@ public class Entity1_11Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
ENTITY(-1), ENTITY(-1),
DROPPED_ITEM(1, ENTITY), DROPPED_ITEM(1, ENTITY),
@ -154,6 +150,21 @@ public class Entity1_11Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);
@ -167,8 +178,6 @@ public class Entity1_11Types {
} }
} }
@AllArgsConstructor
@Getter
public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType { public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM), ITEM(2, EntityType.DROPPED_ITEM),
@ -209,6 +218,21 @@ public class Entity1_11Types {
} }
} }
ObjectType(int id, EntityType type) {
this.id = id;
this.type = type;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getType() {
return type;
}
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.empty(); return Optional.empty();

Datei anzeigen

@ -10,8 +10,6 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -37,8 +35,6 @@ public class Entity1_12Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
ENTITY(-1), ENTITY(-1),
DROPPED_ITEM(1, ENTITY), DROPPED_ITEM(1, ENTITY),
@ -167,6 +163,21 @@ public class Entity1_12Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);
@ -180,8 +191,6 @@ public class Entity1_12Types {
} }
} }
@AllArgsConstructor
@Getter
public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType { public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.DROPPED_ITEM), ITEM(2, EntityType.DROPPED_ITEM),
@ -222,6 +231,21 @@ public class Entity1_12Types {
} }
} }
ObjectType(int id, EntityType type) {
this.id = id;
this.type = type;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getType() {
return type;
}
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.empty(); return Optional.empty();

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -27,8 +25,6 @@ public class Entity1_13Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
// Auto generated // Auto generated
@ -209,6 +205,21 @@ public class Entity1_13Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);
@ -222,8 +233,6 @@ public class Entity1_13Types {
} }
} }
@AllArgsConstructor
@Getter
public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType { public enum ObjectType implements us.myles.ViaVersion.api.entities.ObjectType {
BOAT(1, EntityType.BOAT), BOAT(1, EntityType.BOAT),
ITEM(2, EntityType.ITEM), ITEM(2, EntityType.ITEM),
@ -265,6 +274,21 @@ public class Entity1_13Types {
} }
} }
ObjectType(int id, EntityType type) {
this.id = id;
this.type = type;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getType() {
return type;
}
public static Optional<ObjectType> findById(int id) { public static Optional<ObjectType> findById(int id) {
if (id == -1) if (id == -1)
return Optional.empty(); return Optional.empty();

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -22,8 +20,6 @@ public class Entity1_14Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
// Auto generated // Auto generated
@ -211,6 +207,21 @@ public class Entity1_14Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -22,9 +20,6 @@ public class Entity1_15Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
ENTITY(-1), ENTITY(-1),
@ -211,6 +206,21 @@ public class Entity1_15Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.api.entities; package us.myles.ViaVersion.api.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import java.util.HashMap; import java.util.HashMap;
@ -22,9 +20,6 @@ public class Entity1_16Types {
return type.get(); return type.get();
} }
@AllArgsConstructor
@Getter
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType { public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
ENTITY(-1), ENTITY(-1),
@ -216,6 +211,21 @@ public class Entity1_16Types {
this.parent = null; this.parent = null;
} }
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static { static {
for (EntityType type : EntityType.values()) { for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type); TYPES.put(type.id, type);

Datei anzeigen

@ -1,12 +1,8 @@
package us.myles.ViaVersion.api.minecraft.metadata.types; package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@RequiredArgsConstructor
@Getter
public enum MetaType1_12 implements MetaType { public enum MetaType1_12 implements MetaType {
Byte(0, Type.BYTE), Byte(0, Type.BYTE),
VarInt(1, Type.VAR_INT), VarInt(1, Type.VAR_INT),
@ -27,8 +23,22 @@ public enum MetaType1_12 implements MetaType {
private final int typeID; private final int typeID;
private final Type type; private final Type type;
MetaType1_12(int typeID, Type type) {
this.typeID = typeID;
this.type = type;
}
public static MetaType1_12 byId(int id) { public static MetaType1_12 byId(int id) {
return values()[id]; return values()[id];
} }
@Override
public int getTypeID() {
return typeID;
}
@Override
public Type getType() {
return type;
}
} }

Datei anzeigen

@ -1,13 +1,9 @@
package us.myles.ViaVersion.api.minecraft.metadata.types; package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13;
@RequiredArgsConstructor
@Getter
public enum MetaType1_13 implements MetaType { public enum MetaType1_13 implements MetaType {
Byte(0, Type.BYTE), Byte(0, Type.BYTE),
VarInt(1, Type.VAR_INT), VarInt(1, Type.VAR_INT),
@ -30,8 +26,22 @@ public enum MetaType1_13 implements MetaType {
private final int typeID; private final int typeID;
private final Type type; private final Type type;
MetaType1_13(int typeID, Type type) {
this.typeID = typeID;
this.type = type;
}
public static MetaType1_13 byId(int id) { public static MetaType1_13 byId(int id) {
return values()[id]; return values()[id];
} }
@Override
public int getTypeID() {
return typeID;
}
@Override
public Type getType() {
return type;
}
} }

Datei anzeigen

@ -1,13 +1,9 @@
package us.myles.ViaVersion.api.minecraft.metadata.types; package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13_2; import us.myles.ViaVersion.api.type.types.version.Types1_13_2;
@RequiredArgsConstructor
@Getter
public enum MetaType1_13_2 implements MetaType { public enum MetaType1_13_2 implements MetaType {
Byte(0, Type.BYTE), Byte(0, Type.BYTE),
VarInt(1, Type.VAR_INT), VarInt(1, Type.VAR_INT),
@ -30,8 +26,22 @@ public enum MetaType1_13_2 implements MetaType {
private final int typeID; private final int typeID;
private final Type type; private final Type type;
MetaType1_13_2(int typeID, Type type) {
this.typeID = typeID;
this.type = type;
}
public static MetaType1_13_2 byId(int id) { public static MetaType1_13_2 byId(int id) {
return values()[id]; return values()[id];
} }
@Override
public int getTypeID() {
return typeID;
}
@Override
public Type getType() {
return type;
}
} }

Datei anzeigen

@ -1,13 +1,9 @@
package us.myles.ViaVersion.api.minecraft.metadata.types; package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; import us.myles.ViaVersion.api.type.types.version.Types1_14;
@RequiredArgsConstructor
@Getter
public enum MetaType1_14 implements MetaType { public enum MetaType1_14 implements MetaType {
Byte(0, Type.BYTE), Byte(0, Type.BYTE),
VarInt(1, Type.VAR_INT), VarInt(1, Type.VAR_INT),
@ -33,8 +29,22 @@ public enum MetaType1_14 implements MetaType {
private final int typeID; private final int typeID;
private final Type type; private final Type type;
MetaType1_14(int typeID, Type type) {
this.typeID = typeID;
this.type = type;
}
public static MetaType1_14 byId(int id) { public static MetaType1_14 byId(int id) {
return values()[id]; return values()[id];
} }
@Override
public int getTypeID() {
return typeID;
}
@Override
public Type getType() {
return type;
}
} }

Datei anzeigen

@ -1,12 +1,8 @@
package us.myles.ViaVersion.api.minecraft.metadata.types; package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@RequiredArgsConstructor
@Getter
public enum MetaType1_8 implements MetaType { public enum MetaType1_8 implements MetaType {
Byte(0, Type.BYTE), Byte(0, Type.BYTE),
Short(1, Type.SHORT), Short(1, Type.SHORT),
@ -21,7 +17,22 @@ public enum MetaType1_8 implements MetaType {
private final int typeID; private final int typeID;
private final Type type; private final Type type;
MetaType1_8(int typeID, Type type) {
this.typeID = typeID;
this.type = type;
}
public static MetaType1_8 byId(int id) { public static MetaType1_8 byId(int id) {
return values()[id]; return values()[id];
} }
@Override
public int getTypeID() {
return typeID;
}
@Override
public Type getType() {
return type;
}
} }

Datei anzeigen

@ -1,12 +1,8 @@
package us.myles.ViaVersion.api.minecraft.metadata.types; package us.myles.ViaVersion.api.minecraft.metadata.types;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.MetaType;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
@RequiredArgsConstructor
@Getter
public enum MetaType1_9 implements MetaType { public enum MetaType1_9 implements MetaType {
Byte(0, Type.BYTE), Byte(0, Type.BYTE),
VarInt(1, Type.VAR_INT), VarInt(1, Type.VAR_INT),
@ -26,8 +22,22 @@ public enum MetaType1_9 implements MetaType {
private final int typeID; private final int typeID;
private final Type type; private final Type type;
MetaType1_9(int typeID, Type type) {
this.typeID = typeID;
this.type = type;
}
public static MetaType1_9 byId(int id) { public static MetaType1_9 byId(int id) {
return values()[id]; return values()[id];
} }
@Override
public int getTypeID() {
return typeID;
}
@Override
public Type getType() {
return type;
}
} }

Datei anzeigen

@ -1,5 +1,6 @@
package us.myles.ViaVersion.api.platform; package us.myles.ViaVersion.api.platform;
import io.netty.channel.ChannelFutureListener;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
@ -18,6 +19,10 @@ public class ViaConnectionManager {
UUID id = connection.get(ProtocolInfo.class).getUuid(); UUID id = connection.get(ProtocolInfo.class).getUuid();
connections.add(connection); connections.add(connection);
clients.put(id, connection); clients.put(id, connection);
if (connection.getChannel() != null) {
connection.getChannel().closeFuture().addListener((ChannelFutureListener) future -> onDisconnect(connection));
}
} }
public void onDisconnect(UserConnection connection) { public void onDisconnect(UserConnection connection) {
@ -42,6 +47,9 @@ public class ViaConnectionManager {
* Returns null when there isn't a server or connection was not found * Returns null when there isn't a server or connection was not found
* When ViaVersion is reloaded, this method may not return some players. * When ViaVersion is reloaded, this method may not return some players.
* May not return ProtocolSupport players. * May not return ProtocolSupport players.
* <p>
* Note that connections are removed as soon as their channel is closed,
* so avoid using this method during player quits for example.
*/ */
public UserConnection getConnectedClient(UUID clientIdentifier) { public UserConnection getConnectedClient(UUID clientIdentifier) {
return clients.get(clientIdentifier); return clients.get(clientIdentifier);
@ -58,6 +66,12 @@ public class ViaConnectionManager {
return Collections.unmodifiableSet(connections); return Collections.unmodifiableSet(connections);
} }
/**
* Returns if Via injected into this player connection.
*
* @param playerId player uuid
* @return true if the player is handled by Via
*/
public boolean isClientConnected(UUID playerId) { public boolean isClientConnected(UUID playerId) {
return clients.containsKey(playerId); return clients.containsKey(playerId);
} }

Datei anzeigen

@ -70,11 +70,10 @@ public class ProtocolRegistry {
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE)); registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
registerBaseProtocol(new BaseProtocol1_7(), Range.all()); registerBaseProtocol(new BaseProtocol1_7(), Range.all());
// Register built in protocols
registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8); registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8);
registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId()); registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9.getId());
registerProtocol(new Protocol1_9_3To1_9_1_2(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_9_2); registerProtocol(new Protocol1_9_3To1_9_1_2(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_9_2);
// Only supported for 1.9.4 server to 1.9 (nothing else)
registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_2); registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_2);
registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId()); registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getId(), ProtocolVersion.v1_9_2.getId()), ProtocolVersion.v1_9_3.getId());
registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3); registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3);
@ -320,15 +319,26 @@ public class ProtocolRegistry {
if (future == null) return; if (future == null) return;
future.get(); future.get();
}
/**
* Shuts down the executor and uncaches mappings if all futures have been completed.
*
* @return true if the executor has now been shut down
*/
public static boolean checkForMappingCompletion() {
synchronized (MAPPING_LOADER_LOCK) { synchronized (MAPPING_LOADER_LOCK) {
if (mappingsLoaded) return; if (mappingsLoaded) return false;
// Remove only after execution to block other potential threads for (CompletableFuture<Void> future : mappingLoaderFutures.values()) {
mappingLoaderFutures.remove(protocolClass); // Return if any future hasn't completed yet
if (mappingLoaderFutures.isEmpty()) { if (!future.isDone()) {
shutdownLoaderExecutor(); return false;
}
} }
shutdownLoaderExecutor();
return true;
} }
} }
@ -336,6 +346,7 @@ public class ProtocolRegistry {
mappingsLoaded = true; mappingsLoaded = true;
mappingLoaderExecutor.shutdown(); mappingLoaderExecutor.shutdown();
mappingLoaderExecutor = null; mappingLoaderExecutor = null;
mappingLoaderFutures.clear();
mappingLoaderFutures = null; mappingLoaderFutures = null;
if (MappingDataLoader.isCacheJsonMappings()) { if (MappingDataLoader.isCacheJsonMappings()) {
MappingDataLoader.getMappingsCache().clear(); MappingDataLoader.getMappingsCache().clear();
@ -349,6 +360,13 @@ public class ProtocolRegistry {
} }
} }
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Class<? extends Protocol> dependsOn, Runnable runnable) {
synchronized (MAPPING_LOADER_LOCK) {
CompletableFuture<Void> future = getMappingLoaderFuture(dependsOn).whenCompleteAsync((v, throwable) -> runnable.run(), mappingLoaderExecutor);
mappingLoaderFutures.put(protocolClass, future);
}
}
public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) { public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) {
synchronized (MAPPING_LOADER_LOCK) { synchronized (MAPPING_LOADER_LOCK) {
if (mappingsLoaded) return null; if (mappingsLoaded) return null;

Datei anzeigen

@ -66,4 +66,15 @@ public class ProtocolInfo extends StoredObject {
public void setPipeline(ProtocolPipeline pipeline) { public void setPipeline(ProtocolPipeline pipeline) {
this.pipeline = pipeline; this.pipeline = pipeline;
} }
@Override
public String toString() {
return "ProtocolInfo{" +
"state=" + state +
", protocolVersion=" + protocolVersion +
", serverProtocolVersion=" + serverProtocolVersion +
", username='" + username + '\'' +
", uuid=" + uuid +
'}';
}
} }

Datei anzeigen

@ -1,7 +1,5 @@
package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage; package us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage;
import lombok.Getter;
import lombok.Setter;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType; import us.myles.ViaVersion.api.entities.Entity1_14Types.EntityType;
@ -18,14 +16,8 @@ public class EntityTracker1_14 extends EntityTracker {
// 0x1 = sleeping, 0x2 = riptide // 0x1 = sleeping, 0x2 = riptide
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>(); private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
private final Map<Integer, Byte> playerEntityFlags = new ConcurrentHashMap<>(); private final Map<Integer, Byte> playerEntityFlags = new ConcurrentHashMap<>();
@Getter
@Setter
private int latestTradeWindowId; private int latestTradeWindowId;
@Getter
@Setter
private boolean forceSendCenterChunk = true; private boolean forceSendCenterChunk = true;
@Getter
@Setter
private int chunkCenterX, chunkCenterZ; private int chunkCenterX, chunkCenterZ;
public EntityTracker1_14(UserConnection user) { public EntityTracker1_14(UserConnection user) {
@ -101,4 +93,36 @@ public class EntityTracker1_14 extends EntityTracker {
public void setEntityFlags(int player, byte data) { public void setEntityFlags(int player, byte data) {
playerEntityFlags.put(player, data); playerEntityFlags.put(player, data);
} }
public int getLatestTradeWindowId() {
return latestTradeWindowId;
}
public void setLatestTradeWindowId(int latestTradeWindowId) {
this.latestTradeWindowId = latestTradeWindowId;
}
public boolean isForceSendCenterChunk() {
return forceSendCenterChunk;
}
public void setForceSendCenterChunk(boolean forceSendCenterChunk) {
this.forceSendCenterChunk = forceSendCenterChunk;
}
public int getChunkCenterX() {
return chunkCenterX;
}
public void setChunkCenterX(int chunkCenterX) {
this.chunkCenterX = chunkCenterX;
}
public int getChunkCenterZ() {
return chunkCenterZ;
}
public void setChunkCenterZ(int chunkCenterZ) {
this.chunkCenterZ = chunkCenterZ;
}
} }

Datei anzeigen

@ -1,9 +1,13 @@
package us.myles.ViaVersion.util; package us.myles.ViaVersion.util;
import lombok.SneakyThrows;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
/** /**
* Created by wea_ondara licensed under MIT * Created by wea_ondara licensed under MIT
@ -54,16 +58,19 @@ public class ConcurrentList<E> extends ArrayList<E> {
} }
@Override @Override
@SneakyThrows
public Object clone() { public Object clone() {
synchronized (lock) { synchronized (lock) {
ConcurrentList<E> clist = (ConcurrentList<E>) super.clone(); try {
clist.modCount = 0; ConcurrentList<E> clist = (ConcurrentList<E>) super.clone();
Field f = ArrayList.class.getDeclaredField("elementData"); clist.modCount = 0;
f.setAccessible(true); Field f = ArrayList.class.getDeclaredField("elementData");
f.set(clist, Arrays.copyOf((Object[]) f.get(this), this.size())); f.setAccessible(true);
f.set(clist, Arrays.copyOf((Object[]) f.get(this), this.size()));
return clist; return clist;
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
} }
} }

Datei anzeigen

@ -73,14 +73,6 @@
</repositories> </repositories>
<dependencies> <dependencies>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<!-- Javassist (Bytecode Library) --> <!-- Javassist (Bytecode Library) -->
<dependency> <dependency>
<groupId>org.javassist</groupId> <groupId>org.javassist</groupId>

Datei anzeigen

@ -23,16 +23,15 @@
</resource> </resource>
</resources> </resources>
<plugins> <plugins>
<!-- We need to disable Sponge's annotation processing -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version> <version>3.8.1</version>
<configuration> <configuration>
<!-- We only run lombok and not sponge in-built mcmod.info generator due to issues with multiversion --> <compilerArgs>
<annotationProcessors> <arg>-proc:none</arg>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor </compilerArgs>
</annotationProcessor>
</annotationProcessors>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

Datei anzeigen

@ -1,12 +0,0 @@
package us.myles.ViaVersion.sponge.listeners;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import us.myles.ViaVersion.api.Via;
public class ClientLeaveListener {
@Listener
public void onDisconnect(ClientConnectionEvent.Disconnect disconnect) {
Via.getManager().handleDisconnect(disconnect.getTargetEntity().getUniqueId());
}
}

Datei anzeigen

@ -1,13 +1,11 @@
package us.myles.ViaVersion.sponge.platform; package us.myles.ViaVersion.sponge.platform;
import lombok.Getter;
import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.living.player.Player;
import us.myles.ViaVersion.api.boss.BossBar; import us.myles.ViaVersion.api.boss.BossBar;
import us.myles.ViaVersion.api.boss.BossColor; import us.myles.ViaVersion.api.boss.BossColor;
import us.myles.ViaVersion.api.boss.BossStyle; import us.myles.ViaVersion.api.boss.BossStyle;
import us.myles.ViaVersion.boss.CommonBoss; import us.myles.ViaVersion.boss.CommonBoss;
@Getter
public class SpongeBossBar extends CommonBoss<Player> { public class SpongeBossBar extends CommonBoss<Player> {
public SpongeBossBar(String title, float health, BossColor color, BossStyle style) { public SpongeBossBar(String title, float health, BossColor color, BossStyle style) {

Datei anzeigen

@ -13,7 +13,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.HandItemProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import us.myles.ViaVersion.sponge.listeners.ClientLeaveListener;
import us.myles.ViaVersion.sponge.listeners.UpdateListener; import us.myles.ViaVersion.sponge.listeners.UpdateListener;
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.BlockListener; import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.BlockListener;
import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.DeathListener; import us.myles.ViaVersion.sponge.listeners.protocol1_9to1_8.DeathListener;
@ -50,8 +49,6 @@ public class SpongeViaLoader implements ViaPlatformLoader {
public void load() { public void load() {
// Update Listener // Update Listener
registerListener(new UpdateListener()); registerListener(new UpdateListener());
/* Base Protocol */
registerListener(new ClientLeaveListener());
/* 1.9 client to 1.8 server */ /* 1.9 client to 1.8 server */
if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) { if (ProtocolRegistry.SERVER_PROTOCOL < ProtocolVersion.v1_9.getId()) {

Datei anzeigen

@ -3,7 +3,6 @@ package us.myles.ViaVersion;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.PluginContainer; import com.velocitypowered.api.plugin.PluginContainer;
@ -18,7 +17,6 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.command.ViaCommandSender; import us.myles.ViaVersion.api.command.ViaCommandSender;
import us.myles.ViaVersion.api.configuration.ConfigurationProvider; import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.MappingDataLoader; import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaConnectionManager; import us.myles.ViaVersion.api.platform.ViaConnectionManager;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
@ -27,13 +25,19 @@ import us.myles.ViaVersion.util.GsonUtil;
import us.myles.ViaVersion.velocity.VersionInfo; import us.myles.ViaVersion.velocity.VersionInfo;
import us.myles.ViaVersion.velocity.command.VelocityCommandHandler; import us.myles.ViaVersion.velocity.command.VelocityCommandHandler;
import us.myles.ViaVersion.velocity.command.VelocityCommandSender; import us.myles.ViaVersion.velocity.command.VelocityCommandSender;
import us.myles.ViaVersion.velocity.platform.*; import us.myles.ViaVersion.velocity.platform.VelocityTaskId;
import us.myles.ViaVersion.velocity.platform.VelocityViaAPI;
import us.myles.ViaVersion.velocity.platform.VelocityViaConfig;
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
import us.myles.ViaVersion.velocity.platform.VelocityViaLoader;
import us.myles.ViaVersion.velocity.service.ProtocolDetectorService; import us.myles.ViaVersion.velocity.service.ProtocolDetectorService;
import us.myles.ViaVersion.velocity.util.LoggerWrapper; import us.myles.ViaVersion.velocity.util.LoggerWrapper;
import java.io.File; import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Plugin( @Plugin(
@ -82,17 +86,6 @@ public class VelocityPlugin implements ViaPlatform<Player> {
Via.getManager().init(); Via.getManager().init();
} }
@Subscribe
public void onQuit(DisconnectEvent e) {
UserConnection userConnection = connectionManager.getConnectedClient(e.getPlayer().getUniqueId());
if (userConnection != null) {
// Only remove if the connection is disconnected (eg. relogin)
if (userConnection.getChannel() == null || !userConnection.getChannel().isOpen()) {
Via.getManager().handleDisconnect(e.getPlayer().getUniqueId());
}
}
}
@Override @Override
public String getPlatformName() { public String getPlatformName() {
String proxyImpl = ProxyServer.class.getPackage().getImplementationTitle(); String proxyImpl = ProxyServer.class.getPackage().getImplementationTitle();

Datei anzeigen

@ -1,7 +1,6 @@
package us.myles.ViaVersion.velocity.storage; package us.myles.ViaVersion.velocity.storage;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import lombok.EqualsAndHashCode;
import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.util.ReflectionUtil; import us.myles.ViaVersion.util.ReflectionUtil;
@ -9,9 +8,9 @@ import us.myles.ViaVersion.util.ReflectionUtil;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@EqualsAndHashCode(callSuper = true)
public class VelocityStorage extends StoredObject { public class VelocityStorage extends StoredObject {
private final Player player; private final Player player;
private String currentServer; private String currentServer;
@ -72,4 +71,22 @@ public class VelocityStorage extends StoredObject {
public List<UUID> getCachedBossbar() { public List<UUID> getCachedBossbar() {
return cachedBossbar; return cachedBossbar;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VelocityStorage that = (VelocityStorage) o;
if (!Objects.equals(player, that.player)) return false;
if (!Objects.equals(currentServer, that.currentServer)) return false;
return Objects.equals(cachedBossbar, that.cachedBossbar);
}
@Override
public int hashCode() {
int result = player != null ? player.hashCode() : 0;
result = 31 * result + (currentServer != null ? currentServer.hashCode() : 0);
result = 31 * result + (cachedBossbar != null ? cachedBossbar.hashCode() : 0);
return result;
}
} }