Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Merge pull request #1689 from KennyTV/abstraction
Asynchronously load mapping data
Dieser Commit ist enthalten in:
Commit
3c9c61056d
@ -10,6 +10,7 @@ import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
||||
import us.myles.ViaVersion.api.platform.TaskId;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
|
||||
@ -82,6 +83,10 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
|
||||
compatSpigotBuild = false;
|
||||
}
|
||||
|
||||
if (getServer().getPluginManager().getPlugin("ViaBackwards") != null) {
|
||||
MappingDataLoader.enableMappingsCache();
|
||||
}
|
||||
|
||||
// Generate classes needed (only works if it's compat or ps)
|
||||
ClassGenerator.generate();
|
||||
lateBind = !BukkitViaInjector.isBinded();
|
||||
|
@ -12,6 +12,7 @@ import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.ViaAPI;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
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.ViaPlatform;
|
||||
@ -37,7 +38,7 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
@Override
|
||||
public void onLoad() {
|
||||
try {
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_14_4");
|
||||
ProtocolConstants.class.getField("MINECRAFT_1_15_2");
|
||||
} catch (NoSuchFieldException e) {
|
||||
getLogger().warning(" / \\");
|
||||
getLogger().warning(" / \\");
|
||||
@ -47,10 +48,12 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
getLogger().warning(" / o \\");
|
||||
getLogger().warning("/_____________\\");
|
||||
}
|
||||
|
||||
api = new BungeeViaAPI();
|
||||
config = new BungeeViaConfig(getDataFolder());
|
||||
commandHandler = new BungeeCommandHandler();
|
||||
ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCommand(commandHandler));
|
||||
|
||||
// Init platform
|
||||
Via.init(ViaManager.builder()
|
||||
.platform(this)
|
||||
@ -62,6 +65,10 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (ProxyServer.getInstance().getPluginManager().getPlugin("ViaBackwards") != null) {
|
||||
MappingDataLoader.enableMappingsCache();
|
||||
}
|
||||
|
||||
// Inject
|
||||
Via.getManager().init();
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
package us.myles.ViaVersion;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.ViaInjector;
|
||||
@ -48,7 +46,7 @@ public class ViaManager {
|
||||
if (platform.getConf().isCheckForUpdates())
|
||||
UpdateUtil.sendUpdateMessage();
|
||||
// Force class load
|
||||
ProtocolRegistry.getSupportedVersions();
|
||||
ProtocolRegistry.init();
|
||||
// Inject
|
||||
try {
|
||||
injector.inject();
|
||||
|
@ -7,6 +7,7 @@ import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
public class Via {
|
||||
private static ViaPlatform platform;
|
||||
private static ViaManager manager;
|
||||
private static boolean cacheJsonMappings;
|
||||
|
||||
/**
|
||||
* Register the ViaManager associated with the platform.
|
||||
|
@ -1,14 +1,52 @@
|
||||
package us.myles.ViaVersion.api.data;
|
||||
|
||||
import com.google.gson.*;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class MappingDataLoader {
|
||||
|
||||
private static final Map<String, JsonObject> MAPPINGS_CACHE = new ConcurrentHashMap<>();
|
||||
private static boolean cacheJsonMappings;
|
||||
|
||||
/**
|
||||
* Returns true if a selected number of mappings should be cached.
|
||||
* If enabled, cleanup should be done after the cache is no longer needed.
|
||||
*
|
||||
* @return true if mappings should be cached
|
||||
*/
|
||||
public static boolean isCacheJsonMappings() {
|
||||
return cacheJsonMappings;
|
||||
}
|
||||
|
||||
public static void enableMappingsCache() {
|
||||
cacheJsonMappings = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cached mappings. Cleared after Via has been fully loaded.
|
||||
*
|
||||
* @see #isCacheJsonMappings()
|
||||
*/
|
||||
public static Map<String, JsonObject> getMappingsCache() {
|
||||
return MAPPINGS_CACHE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the file from the plugin folder if present, else from the bundled resources.
|
||||
*/
|
||||
public static JsonObject loadFromDataDir(String name) {
|
||||
File file = new File(Via.getPlatform().getDataFolder(), name);
|
||||
if (!file.exists()) return loadData(name);
|
||||
@ -26,11 +64,34 @@ public class MappingDataLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the file from the bundled resources. Uses the cache if enabled.
|
||||
*/
|
||||
public static JsonObject loadData(String name) {
|
||||
return loadData(name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the file from the bundled resources. Uses the cache if enabled.
|
||||
*
|
||||
* @param cacheIfEnabled whether loaded files should be cached
|
||||
*/
|
||||
public static JsonObject loadData(String name, boolean cacheIfEnabled) {
|
||||
if (cacheJsonMappings) {
|
||||
JsonObject cached = MAPPINGS_CACHE.get(name);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
}
|
||||
|
||||
InputStream stream = getResource(name);
|
||||
InputStreamReader reader = new InputStreamReader(stream);
|
||||
try {
|
||||
return GsonUtil.getGson().fromJson(reader, JsonObject.class);
|
||||
JsonObject object = GsonUtil.getGson().fromJson(reader, JsonObject.class);
|
||||
if (cacheIfEnabled && cacheJsonMappings) {
|
||||
MAPPINGS_CACHE.put(name, object);
|
||||
}
|
||||
return object;
|
||||
} finally {
|
||||
try {
|
||||
reader.close();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.platform.providers.ViaProviders;
|
||||
@ -13,16 +12,20 @@ import us.myles.ViaVersion.packets.State;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public abstract class Protocol {
|
||||
private final Map<Pair<State, Integer>, ProtocolPacket> incoming = new HashMap<>();
|
||||
private final Map<Pair<State, Integer>, ProtocolPacket> outgoing = new HashMap<>();
|
||||
|
||||
private final Map<Class, Object> storedObjects = new ConcurrentHashMap<>();
|
||||
private final Map<Packet, ProtocolPacket> incoming = new HashMap<>();
|
||||
private final Map<Packet, ProtocolPacket> outgoing = new HashMap<>();
|
||||
private final Map<Class, Object> storedObjects = new HashMap<>(); // currently only used for MetadataRewriters
|
||||
private final boolean hasMappingDataToLoad;
|
||||
|
||||
public Protocol() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public Protocol(boolean hasMappingDataToLoad) {
|
||||
this.hasMappingDataToLoad = hasMappingDataToLoad;
|
||||
registerPackets();
|
||||
}
|
||||
|
||||
@ -50,26 +53,38 @@ public abstract class Protocol {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle protocol registration phase, use this to register providers / tasks.
|
||||
*
|
||||
* @param providers The current providers
|
||||
*/
|
||||
protected void register(ViaProviders providers) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the packets for this protocol
|
||||
* Register the packets for this protocol.
|
||||
*/
|
||||
protected abstract void registerPackets();
|
||||
|
||||
/**
|
||||
* Load mapping data for the protocol.
|
||||
* <p>
|
||||
* To be overridden if needed.
|
||||
*/
|
||||
protected void loadMappingData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle protocol registration phase, use this to register providers / tasks.
|
||||
* <p>
|
||||
* To be overridden if needed.
|
||||
*
|
||||
* @param providers The current providers
|
||||
*/
|
||||
protected void register(ViaProviders providers) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise a user for this protocol setting up objects.
|
||||
* /!\ WARNING - May be called more than once in a single {@link UserConnection}
|
||||
* <p>
|
||||
* To be overridden if needed.
|
||||
*
|
||||
* @param userConnection The user to initialise
|
||||
*/
|
||||
public abstract void init(UserConnection userConnection);
|
||||
public void init(UserConnection userConnection) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an incoming packet, with simple id transformation.
|
||||
@ -96,12 +111,12 @@ public abstract class Protocol {
|
||||
|
||||
public void registerIncoming(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||
Pair<State, Integer> pair = new Pair<>(state, newPacketID);
|
||||
if (!override && incoming.containsKey(pair)) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
|
||||
Packet packet = new Packet(state, newPacketID);
|
||||
if (!override && incoming.containsKey(packet)) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" +
|
||||
" If this override is intentional, set override to true. Stacktrace: ", new Exception());
|
||||
}
|
||||
incoming.put(pair, protocolPacket);
|
||||
incoming.put(packet, protocolPacket);
|
||||
}
|
||||
|
||||
public void cancelIncoming(State state, int oldPacketID, int newPacketID) {
|
||||
@ -142,12 +157,12 @@ public abstract class Protocol {
|
||||
|
||||
public void registerOutgoing(State state, int oldPacketID, int newPacketID, PacketRemapper packetRemapper, boolean override) {
|
||||
ProtocolPacket protocolPacket = new ProtocolPacket(state, oldPacketID, newPacketID, packetRemapper);
|
||||
Pair<State, Integer> pair = new Pair<>(state, oldPacketID);
|
||||
if (!override && outgoing.containsKey(pair)) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, pair + " already registered!" +
|
||||
Packet packet = new Packet(state, oldPacketID);
|
||||
if (!override && outgoing.containsKey(packet)) {
|
||||
Via.getPlatform().getLogger().log(Level.WARNING, packet + " already registered!" +
|
||||
" If override is intentional, set override to true. Stacktrace: ", new Exception());
|
||||
}
|
||||
outgoing.put(pair, protocolPacket);
|
||||
outgoing.put(packet, protocolPacket);
|
||||
}
|
||||
|
||||
public void cancelOutgoing(State state, int oldPacketID, int newPacketID) {
|
||||
@ -163,6 +178,10 @@ public abstract class Protocol {
|
||||
cancelOutgoing(state, oldPacketID, -1);
|
||||
}
|
||||
|
||||
public boolean hasMappingDataToLoad() {
|
||||
return hasMappingDataToLoad;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a packet using this protocol
|
||||
*
|
||||
@ -172,12 +191,13 @@ public abstract class Protocol {
|
||||
* @throws Exception Throws exception if it fails to transform
|
||||
*/
|
||||
public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception {
|
||||
Pair<State, Integer> statePacket = new Pair<>(state, packetWrapper.getId());
|
||||
Map<Pair<State, Integer>, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming);
|
||||
Packet statePacket = new Packet(state, packetWrapper.getId());
|
||||
Map<Packet, ProtocolPacket> packetMap = (direction == Direction.OUTGOING ? outgoing : incoming);
|
||||
ProtocolPacket protocolPacket = packetMap.get(statePacket);
|
||||
if (protocolPacket == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// write packet id
|
||||
int newID = direction == Direction.OUTGOING ? protocolPacket.getNewID() : protocolPacket.getOldID();
|
||||
packetWrapper.setId(newID);
|
||||
@ -203,6 +223,44 @@ public abstract class Protocol {
|
||||
return "Protocol:" + getClass().getSimpleName();
|
||||
}
|
||||
|
||||
public static class Packet {
|
||||
private final State state;
|
||||
private final int packetId;
|
||||
|
||||
public Packet(State state, int packetId) {
|
||||
this.state = state;
|
||||
this.packetId = packetId;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public int getPacketId() {
|
||||
return packetId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Packet{" + "state=" + state + ", packetId=" + packetId + '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Packet that = (Packet) o;
|
||||
return packetId == that.packetId && state == that.state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = state != null ? state.hashCode() : 0;
|
||||
result = 31 * result + packetId;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ProtocolPacket {
|
||||
private final State state;
|
||||
private final int oldID;
|
||||
|
@ -2,9 +2,9 @@ package us.myles.ViaVersion.api.protocol;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.collect.Sets;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
||||
import us.myles.ViaVersion.protocols.base.BaseProtocol;
|
||||
import us.myles.ViaVersion.protocols.base.BaseProtocol1_7;
|
||||
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
|
||||
@ -31,8 +31,21 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.Protocol1_9_3To1_9_1
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||
import us.myles.ViaVersion.protocols.protocol1_9to1_9_1.Protocol1_9To1_9_1;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ProtocolRegistry {
|
||||
public static final Protocol BASE_PROTOCOL = new BaseProtocol();
|
||||
@ -40,11 +53,19 @@ public class ProtocolRegistry {
|
||||
// Input Version -> Output Version & Protocol (Allows fast lookup)
|
||||
private static final Map<Integer, Map<Integer, Protocol>> registryMap = new ConcurrentHashMap<>();
|
||||
private static final Map<Pair<Integer, Integer>, List<Pair<Integer, Protocol>>> pathCache = new ConcurrentHashMap<>();
|
||||
private static final List<Protocol> registerList = Lists.newCopyOnWriteArrayList();
|
||||
private static final Set<Integer> supportedVersions = Sets.newConcurrentHashSet();
|
||||
private static final List<Protocol> registerList = new ArrayList<>();
|
||||
private static final Set<Integer> supportedVersions = new HashSet<>();
|
||||
private static final List<Pair<Range<Integer>, Protocol>> baseProtocols = Lists.newCopyOnWriteArrayList();
|
||||
|
||||
private static final Object MAPPING_LOADER_LOCK = new Object();
|
||||
private static Map<Class<? extends Protocol>, CompletableFuture<Void>> mappingLoaderFutures = new HashMap<>();
|
||||
private static ThreadPoolExecutor mappingLoaderExecutor;
|
||||
private static boolean mappingsLoaded;
|
||||
|
||||
static {
|
||||
mappingLoaderExecutor = new ThreadPoolExecutor(5, 16, 45L, TimeUnit.SECONDS, new SynchronousQueue<>());
|
||||
mappingLoaderExecutor.allowCoreThreadTimeOut(true);
|
||||
|
||||
// Base Protocol
|
||||
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
|
||||
registerBaseProtocol(new BaseProtocol1_7(), Range.all());
|
||||
@ -82,6 +103,10 @@ public class ProtocolRegistry {
|
||||
registerProtocol(new Protocol1_16To1_15_2(), ProtocolVersion.v1_16, ProtocolVersion.v1_15_2);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
// Empty method to trigger static initializer once
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a protocol
|
||||
*
|
||||
@ -102,15 +127,13 @@ public class ProtocolRegistry {
|
||||
*/
|
||||
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
|
||||
// Clear cache as this may make new routes.
|
||||
if (!pathCache.isEmpty())
|
||||
if (!pathCache.isEmpty()) {
|
||||
pathCache.clear();
|
||||
}
|
||||
|
||||
for (Integer version : supported) {
|
||||
if (!registryMap.containsKey(version)) {
|
||||
registryMap.put(version, new HashMap<>());
|
||||
}
|
||||
|
||||
registryMap.get(version).put(output, protocol);
|
||||
Map<Integer, Protocol> protocolMap = registryMap.computeIfAbsent(version, k -> new HashMap<>());
|
||||
protocolMap.put(output, protocol);
|
||||
}
|
||||
|
||||
if (Via.getPlatform().isPluginEnabled()) {
|
||||
@ -119,6 +142,16 @@ public class ProtocolRegistry {
|
||||
} else {
|
||||
registerList.add(protocol);
|
||||
}
|
||||
|
||||
if (protocol.hasMappingDataToLoad()) {
|
||||
if (mappingLoaderExecutor != null) {
|
||||
// Submit mapping data loading
|
||||
addMappingLoaderFuture(protocol.getClass(), protocol::loadMappingData);
|
||||
} else {
|
||||
// Late protocol adding - just do it on the current thread
|
||||
protocol.loadMappingData();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,8 +180,9 @@ public class ProtocolRegistry {
|
||||
List<Pair<Integer, Protocol>> paths = getProtocolPath(versions.getId(), ProtocolRegistry.SERVER_PROTOCOL);
|
||||
if (paths == null) continue;
|
||||
supportedVersions.add(versions.getId());
|
||||
for (Pair<Integer, Protocol> path : paths)
|
||||
for (Pair<Integer, Protocol> path : paths) {
|
||||
supportedVersions.add(path.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +282,7 @@ public class ProtocolRegistry {
|
||||
return protocolList;
|
||||
}
|
||||
// Generate path
|
||||
List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<Pair<Integer, Protocol>>(), clientVersion, serverVersion);
|
||||
List<Pair<Integer, Protocol>> outputPath = getProtocolPath(new ArrayList<>(), clientVersion, serverVersion);
|
||||
// If it found a path, cache it.
|
||||
if (outputPath != null) {
|
||||
pathCache.put(protocolKey, outputPath);
|
||||
@ -274,4 +308,51 @@ public class ProtocolRegistry {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that mapping data for that protocol has already been loaded, completes it otherwise.
|
||||
*
|
||||
* @param protocolClass protocol class
|
||||
*/
|
||||
public static void completeMappingDataLoading(Class<? extends Protocol> protocolClass) throws Exception {
|
||||
if (mappingsLoaded) return;
|
||||
|
||||
CompletableFuture<Void> future = getMappingLoaderFuture(protocolClass);
|
||||
if (future == null) return;
|
||||
|
||||
future.get();
|
||||
|
||||
synchronized (MAPPING_LOADER_LOCK) {
|
||||
if (mappingsLoaded) return;
|
||||
|
||||
// Remove only after execution to block other potential threads
|
||||
mappingLoaderFutures.remove(protocolClass);
|
||||
if (mappingLoaderFutures.isEmpty()) {
|
||||
shutdownLoaderExecutor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void shutdownLoaderExecutor() {
|
||||
mappingsLoaded = true;
|
||||
mappingLoaderExecutor.shutdown();
|
||||
mappingLoaderExecutor = null;
|
||||
mappingLoaderFutures = null;
|
||||
if (MappingDataLoader.isCacheJsonMappings()) {
|
||||
MappingDataLoader.getMappingsCache().clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addMappingLoaderFuture(Class<? extends Protocol> protocolClass, Runnable runnable) {
|
||||
synchronized (MAPPING_LOADER_LOCK) {
|
||||
CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, mappingLoaderExecutor);
|
||||
mappingLoaderFutures.put(protocolClass, future);
|
||||
}
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> getMappingLoaderFuture(Class<? extends Protocol> protocolClass) {
|
||||
synchronized (MAPPING_LOADER_LOCK) {
|
||||
if (mappingsLoaded) return null;
|
||||
return mappingLoaderFutures.get(protocolClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ public class BaseProtocol extends Protocol {
|
||||
if (protocols != null) {
|
||||
for (Pair<Integer, Protocol> prot : protocols) {
|
||||
pipeline.add(prot.getValue());
|
||||
// Ensure mapping data has already been loaded
|
||||
ProtocolRegistry.completeMappingDataLoading(prot.getValue().getClass());
|
||||
}
|
||||
wrapper.set(Type.VAR_INT, 0, protocol);
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import net.md_5.bungee.api.ChatColor;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Pair;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
|
||||
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
|
||||
@ -190,11 +189,6 @@ public class BaseProtocol1_7 extends Protocol {
|
||||
registerIncoming(State.LOGIN, 0x02, 0x02); // Plugin Response (1.13)
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
|
||||
public static String addDashes(String trimmedUUID) {
|
||||
StringBuilder idBuff = new StringBuilder(trimmedUUID);
|
||||
idBuff.insert(20, '-');
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_11_1to1_11;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
|
||||
public class Protocol1_11_1To1_11 extends Protocol {
|
||||
@ -8,9 +7,4 @@ public class Protocol1_11_1To1_11 extends Protocol {
|
||||
protected void registerPackets() {
|
||||
// Only had metadata changes, see wiki.vg for full info.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_12_1to1_12;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
@ -87,9 +86,4 @@ public class Protocol1_12_1To1_12 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_12_2to1_12_1;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
@ -26,9 +25,4 @@ public class Protocol1_12_2To1_12_1 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_13_2to1_13_1;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
@ -71,9 +70,4 @@ public class Protocol1_13_2To1_13_1 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -42,14 +42,15 @@ import java.util.Map;
|
||||
|
||||
public class Protocol1_13To1_12_2 extends Protocol {
|
||||
|
||||
public static final PacketHandler POS_TO_3_INT = new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
Position position = wrapper.read(Type.POSITION);
|
||||
wrapper.write(Type.INT, position.getX());
|
||||
wrapper.write(Type.INT, (int) position.getY());
|
||||
wrapper.write(Type.INT, position.getZ());
|
||||
}
|
||||
public Protocol1_13To1_12_2() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
public static final PacketHandler POS_TO_3_INT = wrapper -> {
|
||||
Position position = wrapper.read(Type.POSITION);
|
||||
wrapper.write(Type.INT, position.getX());
|
||||
wrapper.write(Type.INT, (int) position.getY());
|
||||
wrapper.write(Type.INT, position.getZ());
|
||||
};
|
||||
|
||||
public static final PacketHandler SEND_DECLARE_COMMANDS_AND_TAGS =
|
||||
@ -132,11 +133,6 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.UNDERLINE, ':');
|
||||
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.ITALIC, ';');
|
||||
SCOREBOARD_TEAM_NAME_REWRITE.put(ChatColor.RESET, '/');
|
||||
|
||||
MappingData.init();
|
||||
ConnectionData.init();
|
||||
RecipeData.init();
|
||||
BlockIdData.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1151,6 +1147,14 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
||||
registerIncoming(State.PLAY, 0x20, 0x2A);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadMappingData() {
|
||||
MappingData.init();
|
||||
ConnectionData.init();
|
||||
RecipeData.init();
|
||||
BlockIdData.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
userConnection.put(new EntityTracker1_13(userConnection));
|
||||
|
@ -195,7 +195,7 @@ public class ConnectionData {
|
||||
public static void init() {
|
||||
if (!Via.getConfig().isServersideBlockConnections()) return;
|
||||
Via.getPlatform().getLogger().info("Loading block connection mappings ...");
|
||||
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json");
|
||||
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);
|
||||
JsonObject blocks1_13 = mapping1_13.getAsJsonObject("blocks");
|
||||
for (Entry<String, JsonElement> blockState : blocks1_13.entrySet()) {
|
||||
Integer id = Integer.parseInt(blockState.getKey());
|
||||
|
@ -33,23 +33,19 @@ public class MappingData {
|
||||
public static Mappings blockMappings;
|
||||
|
||||
public static void init() {
|
||||
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json");
|
||||
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json");
|
||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 mappings...");
|
||||
JsonObject mapping1_12 = MappingDataLoader.loadData("mapping-1.12.json", true);
|
||||
JsonObject mapping1_13 = MappingDataLoader.loadData("mapping-1.13.json", true);
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 block mapping...");
|
||||
blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 item mapping...");
|
||||
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
|
||||
Via.getPlatform().getLogger().info("Loading new 1.13 tags...");
|
||||
loadTags(blockTags, mapping1_13.getAsJsonObject("block_tags"));
|
||||
loadTags(itemTags, mapping1_13.getAsJsonObject("item_tags"));
|
||||
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 enchantment mapping...");
|
||||
|
||||
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
|
||||
enchantmentMappings = new Mappings(72, mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 sound mapping...");
|
||||
soundMappings = new Mappings(662, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.12.2 -> 1.13 plugin channel mappings...");
|
||||
|
||||
JsonObject object = MappingDataLoader.loadFromDataDir("channelmappings-1.13.json");
|
||||
if (object != null) {
|
||||
@ -64,7 +60,6 @@ public class MappingData {
|
||||
}
|
||||
}
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading translation mappping");
|
||||
Map<String, String> translateData = GsonUtil.getGson().fromJson(
|
||||
new InputStreamReader(MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/mapping-lang-1.12-1.13.json")),
|
||||
new TypeToken<Map<String, String>>() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_3to1_14_2;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
@ -43,8 +42,4 @@ public class Protocol1_14_3To1_14_2 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_14_4to1_14_3;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
@ -40,8 +39,4 @@ public class Protocol1_14_4To1_14_3 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
public class Protocol1_14To1_13_2 extends Protocol {
|
||||
|
||||
static {
|
||||
MappingData.init();
|
||||
public Protocol1_14To1_13_2() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -254,6 +254,14 @@ public class Protocol1_14To1_13_2 extends Protocol {
|
||||
registerIncoming(State.PLAY, 0x2A, 0x2D);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadMappingData() {
|
||||
MappingData.init();
|
||||
WorldPackets.air = MappingData.blockStateMappings.getNewId(0);
|
||||
WorldPackets.voidAir = MappingData.blockStateMappings.getNewId(8591);
|
||||
WorldPackets.caveAir = MappingData.blockStateMappings.getNewId(8592);
|
||||
}
|
||||
|
||||
public static int getNewSoundId(int id) {
|
||||
int newId = MappingData.soundMappings.getNewId(id);
|
||||
if (newId == -1) {
|
||||
|
@ -23,26 +23,21 @@ public class MappingData {
|
||||
public static Set<Integer> nonFullBlocks;
|
||||
|
||||
public static void init() {
|
||||
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json");
|
||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
|
||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 mappings...");
|
||||
JsonObject mapping1_13_2 = MappingDataLoader.loadData("mapping-1.13.2.json", true);
|
||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 blockstate mapping...");
|
||||
blockStateMappings = new Mappings(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 block mapping...");
|
||||
blockMappings = new Mappings(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 item mapping...");
|
||||
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_13_2.getAsJsonObject("items"), mapping1_14.getAsJsonObject("items"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 sound mapping...");
|
||||
soundMappings = new Mappings(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.14 blockstates...");
|
||||
JsonObject blockStates = mapping1_14.getAsJsonObject("blockstates");
|
||||
Map<String, Integer> blockStateMap = new HashMap<>(blockStates.entrySet().size());
|
||||
for (Map.Entry<String, JsonElement> entry : blockStates.entrySet()) {
|
||||
blockStateMap.put(entry.getValue().getAsString(), Integer.parseInt(entry.getKey()));
|
||||
}
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.14 heightmap data...");
|
||||
JsonObject heightMapData = MappingDataLoader.loadData("heightMapData-1.14.json");
|
||||
JsonArray motionBlocking = heightMapData.getAsJsonArray("MOTION_BLOCKING");
|
||||
us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData.motionBlocking = new HashSet<>(motionBlocking.size());
|
||||
|
@ -28,11 +28,11 @@ import us.myles.ViaVersion.util.CompactArrayUtil;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class WorldPackets {
|
||||
private static final int AIR = MappingData.blockStateMappings.getNewId(0);
|
||||
private static final int VOID_AIR = MappingData.blockStateMappings.getNewId(8591);
|
||||
private static final int CAVE_AIR = MappingData.blockStateMappings.getNewId(8592);
|
||||
public static final int SERVERSIDE_VIEW_DISTANCE = 64;
|
||||
private static final byte[] FULL_LIGHT = new byte[2048];
|
||||
public static int air;
|
||||
public static int voidAir;
|
||||
public static int caveAir;
|
||||
|
||||
static {
|
||||
Arrays.fill(FULL_LIGHT, (byte) 0xff);
|
||||
@ -156,7 +156,7 @@ public class WorldPackets {
|
||||
for (int i = 0; i < section.getPaletteSize(); i++) {
|
||||
int old = section.getPaletteEntry(i);
|
||||
int newId = Protocol1_14To1_13_2.getNewBlockStateId(old);
|
||||
if (!hasBlock && newId != AIR && newId != VOID_AIR && newId != CAVE_AIR) { // air, void_air, cave_air
|
||||
if (!hasBlock && newId != air && newId != voidAir && newId != caveAir) { // air, void_air, cave_air
|
||||
hasBlock = true;
|
||||
}
|
||||
section.setPaletteEntry(i, newId);
|
||||
@ -171,7 +171,7 @@ public class WorldPackets {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int id = section.getFlatBlock(x, y, z);
|
||||
if (id != AIR && id != VOID_AIR && id != CAVE_AIR) {
|
||||
if (id != air && id != voidAir && id != caveAir) {
|
||||
nonAirBlockCount++;
|
||||
worldSurface[x + z * 16] = y + s * 16 + 1; // +1 (top of the block)
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_15_1to1_15;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
|
||||
public class Protocol1_15_1To1_15 extends Protocol {
|
||||
@ -8,8 +7,4 @@ public class Protocol1_15_1To1_15 extends Protocol {
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_15_2to1_15_1;
|
||||
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
|
||||
public class Protocol1_15_2To1_15_1 extends Protocol {
|
||||
@ -8,8 +7,4 @@ public class Protocol1_15_2To1_15_1 extends Protocol {
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
}
|
||||
}
|
||||
|
@ -21,11 +21,16 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||
|
||||
public class Protocol1_15To1_14_4 extends Protocol {
|
||||
|
||||
private TagRewriter tagRewriter;
|
||||
|
||||
public Protocol1_15To1_14_4() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
new MetadataRewriter1_15To1_14_4(this);
|
||||
|
||||
MappingData.init();
|
||||
EntityPackets.register(this);
|
||||
PlayerPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
@ -115,13 +120,7 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
});
|
||||
|
||||
// Tags
|
||||
TagRewriter tagRewriter = new TagRewriter(this, Protocol1_15To1_14_4::getNewBlockId, InventoryPackets::getNewItemId, EntityPackets::getNewEntityId);
|
||||
int[] shulkerBoxes = new int[17];
|
||||
int shulkerBoxOffset = 501;
|
||||
for (int i = 0; i < 17; i++) {
|
||||
shulkerBoxes[i] = shulkerBoxOffset + i;
|
||||
}
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:shulker_boxes", shulkerBoxes);
|
||||
tagRewriter = new TagRewriter(this, Protocol1_15To1_14_4::getNewBlockId, InventoryPackets::getNewItemId, EntityPackets::getNewEntityId);
|
||||
tagRewriter.register(0x5B, 0x5C);
|
||||
|
||||
registerOutgoing(State.PLAY, 0x08, 0x09);
|
||||
@ -203,6 +202,18 @@ public class Protocol1_15To1_14_4 extends Protocol {
|
||||
registerOutgoing(State.PLAY, 0x59, 0x5A);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadMappingData() {
|
||||
MappingData.init();
|
||||
|
||||
int[] shulkerBoxes = new int[17];
|
||||
int shulkerBoxOffset = 501;
|
||||
for (int i = 0; i < 17; i++) {
|
||||
shulkerBoxes[i] = shulkerBoxOffset + i;
|
||||
}
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:shulker_boxes", shulkerBoxes);
|
||||
}
|
||||
|
||||
public static int getNewBlockStateId(int id) {
|
||||
int newId = MappingData.blockStateMappings.getNewId(id);
|
||||
if (newId == -1) {
|
||||
|
@ -14,17 +14,14 @@ public class MappingData {
|
||||
public static Mappings soundMappings;
|
||||
|
||||
public static void init() {
|
||||
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 mappings...");
|
||||
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.14to1.15.json");
|
||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
|
||||
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json");
|
||||
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json", true);
|
||||
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 blockstate mapping...");
|
||||
blockStateMappings = new Mappings(mapping1_14.getAsJsonObject("blockstates"), mapping1_15.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 block mapping...");
|
||||
blockMappings = new Mappings(mapping1_14.getAsJsonObject("blocks"), mapping1_15.getAsJsonObject("blocks"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 item mapping...");
|
||||
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_14.getAsJsonObject("items"), mapping1_15.getAsJsonObject("items"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.14.4 -> 1.15 sound mapping...");
|
||||
soundMappings = new Mappings(mapping1_14.getAsJsonArray("sounds"), mapping1_15.getAsJsonArray("sounds"), false);
|
||||
}
|
||||
}
|
||||
|
@ -20,25 +20,21 @@ import java.util.UUID;
|
||||
|
||||
public class Protocol1_16To1_15_2 extends Protocol {
|
||||
|
||||
private TagRewriter tagRewriter;
|
||||
|
||||
public Protocol1_16To1_15_2() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
MetadataRewriter1_16To1_15_2 metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
|
||||
|
||||
MappingData.init();
|
||||
EntityPackets.register(this);
|
||||
WorldPackets.register(this);
|
||||
InventoryPackets.register(this);
|
||||
|
||||
TagRewriter tagRewriter = new TagRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId);
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:beacon_base_blocks", 133, 134, 148, 265);
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:climbable", 160, 241, 658);
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:fire", 142);
|
||||
tagRewriter.addTag(TagType.ITEM, "minecraft:beacon_payment_items", 529, 530, 531, 760);
|
||||
// The client crashes if we don't send all tags it may use
|
||||
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:soul_speed_blocks");
|
||||
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:soul_fire_base_blocks");
|
||||
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:non_flammable_wood");
|
||||
tagRewriter.addEmptyTag(TagType.ITEM, "minecraft:non_flammable_wood");
|
||||
tagRewriter = new TagRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId);
|
||||
tagRewriter.register(0x5C, 0x5C);
|
||||
|
||||
// Login Success
|
||||
@ -132,6 +128,21 @@ public class Protocol1_16To1_15_2 extends Protocol {
|
||||
registerOutgoing(State.PLAY, 0x4E, 0x43);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadMappingData() {
|
||||
MappingData.init();
|
||||
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:beacon_base_blocks", 133, 134, 148, 265);
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:climbable", 160, 241, 658);
|
||||
tagRewriter.addTag(TagType.BLOCK, "minecraft:fire", 142);
|
||||
tagRewriter.addTag(TagType.ITEM, "minecraft:beacon_payment_items", 529, 530, 531, 760);
|
||||
// The client crashes if we don't send all tags it may use
|
||||
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:soul_speed_blocks");
|
||||
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:soul_fire_base_blocks");
|
||||
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:non_flammable_wood");
|
||||
tagRewriter.addEmptyTag(TagType.ITEM, "minecraft:non_flammable_wood");
|
||||
}
|
||||
|
||||
public static int getNewBlockStateId(int id) {
|
||||
int newId = MappingData.blockStateMappings.getNewId(id);
|
||||
if (newId == -1) {
|
||||
|
@ -18,17 +18,14 @@ public class MappingData {
|
||||
public static Mappings soundMappings;
|
||||
|
||||
public static void init() {
|
||||
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 mappings...");
|
||||
JsonObject diffmapping = MappingDataLoader.loadData("mappingdiff-1.15to1.16.json");
|
||||
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json");
|
||||
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json");
|
||||
JsonObject mapping1_15 = MappingDataLoader.loadData("mapping-1.15.json", true);
|
||||
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true);
|
||||
|
||||
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 blockstate mapping...");
|
||||
blockStateMappings = new Mappings(mapping1_15.getAsJsonObject("blockstates"), mapping1_16.getAsJsonObject("blockstates"), diffmapping.getAsJsonObject("blockstates"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 block mapping...");
|
||||
blockMappings = new Mappings(mapping1_15.getAsJsonObject("blocks"), mapping1_16.getAsJsonObject("blocks"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 item mapping...");
|
||||
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_15.getAsJsonObject("items"), mapping1_16.getAsJsonObject("items"), diffmapping.getAsJsonObject("items"));
|
||||
Via.getPlatform().getLogger().info("Loading 1.15 -> 1.16 sound mapping...");
|
||||
soundMappings = new Mappings(mapping1_15.getAsJsonArray("sounds"), mapping1_16.getAsJsonArray("sounds"), diffmapping.getAsJsonObject("sounds"));
|
||||
|
||||
attributeMappings.put("generic.maxHealth", "minecraft:generic.max_health");
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9_1to1_9;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
@ -45,9 +44,4 @@ public class Protocol1_9_1To1_9 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package us.myles.ViaVersion.protocols.protocol1_9to1_9_1;
|
||||
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
@ -47,9 +46,4 @@ public class Protocol1_9To1_9_1 extends Protocol {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import org.spongepowered.api.text.serializer.TextSerializers;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
import us.myles.ViaVersion.api.data.MappingDataLoader;
|
||||
import us.myles.ViaVersion.api.platform.TaskId;
|
||||
import us.myles.ViaVersion.api.platform.ViaPlatform;
|
||||
import us.myles.ViaVersion.dump.PluginInfo;
|
||||
@ -68,7 +69,8 @@ public class SpongePlugin implements ViaPlatform {
|
||||
conf = new SpongeViaConfig(container, defaultConfig.getParentFile());
|
||||
SpongeCommandHandler commandHandler = new SpongeCommandHandler();
|
||||
game.getCommandManager().register(this, commandHandler, "viaversion", "viaver", "vvsponge");
|
||||
getLogger().info("ViaVersion " + getPluginVersion() + " is now loaded!");
|
||||
logger.info("ViaVersion " + getPluginVersion() + " is now loaded!");
|
||||
|
||||
// Init platform
|
||||
Via.init(ViaManager.builder()
|
||||
.platform(this)
|
||||
@ -80,6 +82,10 @@ public class SpongePlugin implements ViaPlatform {
|
||||
|
||||
@Listener
|
||||
public void onServerStart(GameAboutToStartServerEvent event) {
|
||||
if (game.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
|
||||
MappingDataLoader.enableMappingsCache();
|
||||
}
|
||||
|
||||
// Inject!
|
||||
logger.info("ViaVersion is injecting!");
|
||||
Via.getManager().init();
|
||||
|
@ -18,6 +18,7 @@ import org.slf4j.Logger;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.command.ViaCommandSender;
|
||||
import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
|
||||
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.ViaPlatform;
|
||||
@ -73,6 +74,11 @@ public class VelocityPlugin implements ViaPlatform<Player> {
|
||||
.commandHandler(commandHandler)
|
||||
.loader(new VelocityViaLoader())
|
||||
.injector(new VelocityViaInjector()).build());
|
||||
|
||||
if (proxy.getPluginManager().getPlugin("ViaBackwards").isPresent()) {
|
||||
MappingDataLoader.enableMappingsCache();
|
||||
}
|
||||
|
||||
Via.getManager().init();
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren