3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-05 07:40:16 +01:00

Merge pull request #1426 from KennyTV/abstraction

MappingData and minor ProtocolRegistry cleanup
Dieser Commit ist enthalten in:
Myles 2019-08-29 21:24:28 +01:00 committet von GitHub
Commit e6e7da89cc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
42 geänderte Dateien mit 281 neuen und 226 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,6 @@ sudo: false
language: java
jdk:
- oraclejdk8
- openjdk11
cache:

Datei anzeigen

@ -1,4 +1,4 @@
# ViaVersion 2.1.1 - Spigot, Sponge, BungeeCord, Velocity
# ViaVersion 2.1.3 - Spigot, Sponge, BungeeCord, Velocity
[![Build Status](https://travis-ci.com/ViaVersion/ViaVersion.svg?branch=master)](https://travis-ci.com/ViaVersion/ViaVersion)
[![Discord](https://img.shields.io/badge/chat-on%20discord-blue.svg)](https://viaversion.com/discord)

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -28,17 +28,17 @@ import java.util.UUID;
public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
private BukkitCommandHandler commandHandler;
private final BukkitCommandHandler commandHandler;
private boolean compatSpigotBuild = false;
private boolean spigot = true;
private boolean lateBind = false;
private boolean protocolSupport = false;
@Getter
private BukkitViaConfig conf;
private final BukkitViaConfig conf;
@Getter
private ViaAPI<Player> api = new BukkitViaAPI(this);
private List<Runnable> queuedTasks = new ArrayList<>();
private List<Runnable> asyncQueuedTasks = new ArrayList<>();
private final ViaAPI<Player> api = new BukkitViaAPI(this);
private final List<Runnable> queuedTasks = new ArrayList<>();
private final List<Runnable> asyncQueuedTasks = new ArrayList<>();
public ViaVersionPlugin() {
// Command handler
@ -238,7 +238,7 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
getLogger().severe("ViaVersion is already loaded, we're going to kick all the players... because otherwise we'll crash because of ProtocolLib.");
for (Player player : Bukkit.getOnlinePlayers()) {
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', getConf().getReloadDisconnectMsg()));
player.kickPlayer(ChatColor.translateAlternateColorCodes('&', conf.getReloadDisconnectMsg()));
}
} else {

Datei anzeigen

@ -9,7 +9,7 @@ import java.util.UUID;
@AllArgsConstructor
public class BukkitCommandSender implements ViaCommandSender {
private CommandSender sender;
private final CommandSender sender;
@Override
public boolean hasPermission(String permission) {

Datei anzeigen

@ -23,12 +23,13 @@ public class PlayerSneakListener extends ViaBukkitListener {
private static final float HEIGHT_1_9 = 1.6F;
private static final float DEFAULT_WIDTH = 0.6F;
private final boolean is1_9Fix;
private final boolean is1_14Fix;
private Map<Player, Boolean> sneaking; // true = 1.14+, else false
private Set<UUID> sneakingUuids;
private Method getHandle;
private Method setSize;
private boolean is1_9Fix;
private boolean is1_14Fix;
private boolean useCache;
public PlayerSneakListener(ViaVersionPlugin plugin, boolean is1_9Fix, boolean is1_14Fix) {

Datei anzeigen

@ -13,12 +13,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class HandItemCache extends BukkitRunnable {
public static boolean CACHE = false;
private static Map<UUID, Item> handCache = new ConcurrentHashMap<>();
public static Item getHandItem(UUID player) {
return handCache.get(player);
}
private final Map<UUID, Item> handCache = new ConcurrentHashMap<>();
@Override
public void run() {
@ -34,6 +29,10 @@ public class HandItemCache extends BukkitRunnable {
}
}
public Item getHandItem(UUID player) {
return handCache.get(player);
}
public static Item convert(ItemStack itemInHand) {
if (itemInHand == null) return new Item((short) 0, (byte) 0, (short) 0, null);
return new Item((short) itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null);

Datei anzeigen

@ -7,5 +7,5 @@ import us.myles.ViaVersion.api.platform.TaskId;
@Getter
@AllArgsConstructor
public class BukkitTaskId implements TaskId {
private Integer object;
private final Integer object;
}

Datei anzeigen

@ -26,7 +26,7 @@ import java.util.UUID;
@AllArgsConstructor
public class BukkitViaAPI implements ViaAPI<Player>, ViaVersionAPI {
private ViaVersionPlugin plugin;
private final ViaVersionPlugin plugin;
@Override
public int getPlayerVersion(@NonNull Player player) {

Datei anzeigen

@ -21,8 +21,8 @@ import java.lang.reflect.Method;
import java.util.List;
public class BukkitViaInjector implements ViaInjector {
private List<ChannelFuture> injectedFutures = new ConcurrentList<>();
private List<Pair<Field, Object>> injectedLists = new ConcurrentList<>();
private final List<ChannelFuture> injectedFutures = new ConcurrentList<>();
private final List<Pair<Field, Object>> injectedLists = new ConcurrentList<>();
@Override
public void inject() throws Exception {

Datei anzeigen

@ -37,10 +37,12 @@ import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
public class BukkitViaLoader implements ViaPlatformLoader {
private ViaVersionPlugin plugin;
private final ViaVersionPlugin plugin;
private Set<Listener> listeners = new HashSet<>();
private Set<BukkitTask> tasks = new HashSet<>();
private final Set<Listener> listeners = new HashSet<>();
private final Set<BukkitTask> tasks = new HashSet<>();
private HandItemCache handItemCache;
public BukkitViaLoader(ViaVersionPlugin plugin) {
this.plugin = plugin;
@ -94,8 +96,8 @@ public class BukkitViaLoader implements ViaPlatformLoader {
storeListener(new PaperPatch(plugin)).register();
}
if (plugin.getConf().isItemCache()) {
tasks.add(new HandItemCache().runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :)
HandItemCache.CACHE = true;
handItemCache = new HandItemCache();
tasks.add(handItemCache.runTaskTimerAsynchronously(plugin, 2L, 2L)); // Updates player's items :)
}
/* Providers */
@ -110,8 +112,8 @@ public class BukkitViaLoader implements ViaPlatformLoader {
Via.getManager().getProviders().use(HandItemProvider.class, new HandItemProvider() {
@Override
public Item getHandItem(final UserConnection info) {
if (HandItemCache.CACHE) {
return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
if (handItemCache != null) {
return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
} else {
try {
return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), new Callable<Item>() {

Datei anzeigen

@ -26,8 +26,8 @@ import java.util.logging.Level;
public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider {
private static Map<UUID, BukkitInventoryUpdateTask> updateTasks = new ConcurrentHashMap<UUID, BukkitInventoryUpdateTask>();
private boolean supported;
private final Map<UUID, BukkitInventoryUpdateTask> updateTasks = new ConcurrentHashMap<>();
private final boolean supported;
// packet class
private Class<?> windowClickPacketClass;
private Object clickTypeEnum;
@ -93,7 +93,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
if (tinvtype == InventoryType.BREWING) {
// 1.9 added the blaze powder slot to brewing stand fix for 1.8 servers
if (slotId >= 5 && slotId <= 40) {
slotId = (short) (slotId - 1);
slotId -= 1;
}
}
}

Datei anzeigen

@ -12,7 +12,7 @@ import java.util.UUID;
public class BukkitInventoryUpdateTask implements Runnable {
private BukkitInventoryQuickMoveProvider provider;
private final BukkitInventoryQuickMoveProvider provider;
private final UUID uuid;
private final List<ItemTransaction> items;

Datei anzeigen

@ -3,8 +3,8 @@ package us.myles.ViaVersion.bukkit.util;
import org.bukkit.Bukkit;
public class NMSUtil {
private static String BASE = Bukkit.getServer().getClass().getPackage().getName();
private static String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server");
private static final String BASE = Bukkit.getServer().getClass().getPackage().getName();
private static final String NMS = BASE.replace("org.bukkit.craftbukkit", "net.minecraft.server");
public static Class<?> nms(String className) throws ClassNotFoundException {
return Class.forName(NMS + "." + className);

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -7,6 +7,7 @@ import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.protocol.ProtocolConstants;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.command.ViaCommandSender;
@ -35,6 +36,17 @@ public class BungeePlugin extends Plugin implements ViaPlatform, Listener {
@Override
public void onLoad() {
try {
ProtocolConstants.class.getField("MINECRAFT_1_14_4");
} catch (NoSuchFieldException e) {
getLogger().warning(" / \\");
getLogger().warning(" / \\");
getLogger().warning(" / | \\");
getLogger().warning(" / | \\ BUNGEECORD IS OUTDATED");
getLogger().warning(" / \\ VIAVERSION MAY NOT WORK AS INTENDED");
getLogger().warning(" / o \\");
getLogger().warning("/_____________\\");
}
api = new BungeeViaAPI();
config = new BungeeViaConfig(getDataFolder());
commandHandler = new BungeeCommandHandler();

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -8,7 +8,7 @@ import java.util.List;
public abstract class AbstractViaConfig extends Config implements ViaVersionConfig {
public AbstractViaConfig(File configFile) {
protected AbstractViaConfig(File configFile) {
super(configFile);
}

Datei anzeigen

@ -21,14 +21,14 @@ import java.util.concurrent.ConcurrentHashMap;
@Getter
public class ViaManager {
private final Map<UUID, UserConnection> portedPlayers = new ConcurrentHashMap<>();
private ViaPlatform platform;
private ViaProviders providers = new ViaProviders();
private final ViaPlatform platform;
private final ViaProviders providers = new ViaProviders();
@Setter
private boolean debug = false;
// Internals
private ViaInjector injector;
private ViaCommandHandler commandHandler;
private ViaPlatformLoader loader;
private final ViaInjector injector;
private final ViaCommandHandler commandHandler;
private final ViaPlatformLoader loader;
@Builder
public ViaManager(ViaPlatform platform, ViaInjector injector, ViaCommandHandler commandHandler, ViaPlatformLoader loader) {
@ -52,19 +52,14 @@ public class ViaManager {
try {
injector.inject();
} catch (Exception e) {
getPlatform().getLogger().severe("ViaVersion failed to inject:");
platform.getLogger().severe("ViaVersion failed to inject:");
e.printStackTrace();
return;
}
// Mark as injected
System.setProperty("ViaVersion", getPlatform().getPluginVersion());
System.setProperty("ViaVersion", platform.getPluginVersion());
// If successful
platform.runSync(new Runnable() {
@Override
public void run() {
onServerLoaded();
}
});
platform.runSync(this::onServerLoaded);
}
@ -73,14 +68,14 @@ public class ViaManager {
try {
ProtocolRegistry.SERVER_PROTOCOL = injector.getServerProtocolVersion();
} catch (Exception e) {
getPlatform().getLogger().severe("ViaVersion failed to get the server protocol!");
platform.getLogger().severe("ViaVersion failed to get the server protocol!");
e.printStackTrace();
}
// Check if there are any pipes to this version
if (ProtocolRegistry.SERVER_PROTOCOL != -1) {
getPlatform().getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL));
platform.getLogger().info("ViaVersion detected server version: " + ProtocolVersion.getProtocol(ProtocolRegistry.SERVER_PROTOCOL));
if (!ProtocolRegistry.isWorkingPipe()) {
getPlatform().getLogger().warning("ViaVersion does not have any compatible versions for this server version, please read our resource page carefully.");
platform.getLogger().warning("ViaVersion does not have any compatible versions for this server version, please read our resource page carefully.");
}
}
// Load Listeners / Tasks
@ -95,11 +90,11 @@ public class ViaManager {
public void destroy() {
// Uninject
getPlatform().getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting.");
platform.getLogger().info("ViaVersion is disabling, if this is a reload and you experience issues consider rebooting.");
try {
injector.uninject();
} catch (Exception e) {
getPlatform().getLogger().severe("ViaVersion failed to uninject:");
platform.getLogger().severe("ViaVersion failed to uninject:");
e.printStackTrace();
}

Datei anzeigen

@ -224,7 +224,7 @@ public class PacketWrapper {
if (id != -1) {
Type.VAR_INT.write(buffer, id);
}
if (readableObjects.size() > 0) {
if (!readableObjects.isEmpty()) {
packetValues.addAll(readableObjects);
readableObjects.clear();
}

Datei anzeigen

@ -1,6 +1,34 @@
package us.myles.ViaVersion.api.data;
public interface Mappings {
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
int getNewId(int old);
import java.util.Arrays;
public class Mappings {
protected final short[] oldToNew;
public Mappings(int size, JsonObject oldMapping, JsonObject newMapping) {
oldToNew = new short[size];
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
}
public Mappings(JsonObject oldMapping, JsonObject newMapping) {
this(oldMapping.entrySet().size(), oldMapping, newMapping);
}
public Mappings(int size, JsonArray oldMapping, JsonArray newMapping) {
oldToNew = new short[size];
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, oldMapping, newMapping);
}
public Mappings(JsonArray oldMapping, JsonArray newMapping) {
this(oldMapping.size(), oldMapping, newMapping);
}
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}

Datei anzeigen

@ -6,5 +6,5 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public class StoredObject {
private UserConnection user;
private final UserConnection user;
}

Datei anzeigen

@ -19,6 +19,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_14_1to1_14.Protocol1_14_1To1_14;
import us.myles.ViaVersion.protocols.protocol1_14_2to1_14_1.Protocol1_14_2To1_14_1;
import us.myles.ViaVersion.protocols.protocol1_14_3to1_14_2.Protocol1_14_3To1_14_2;
import us.myles.ViaVersion.protocols.protocol1_14_4to1_14_3.Protocol1_14_4To1_14_3;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9;
@ -42,32 +43,44 @@ public class ProtocolRegistry {
static {
// Base Protocol
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
registerBaseProtocol(new BaseProtocol1_7(), Range.<Integer>all());
registerBaseProtocol(new BaseProtocol1_7(), Range.all());
// Register built in protocols
registerProtocol(new Protocol1_9To1_8(), Collections.singletonList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_8.getId());
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_3To1_9_1_2(), Collections.singletonList(ProtocolVersion.v1_9_3.getId()), ProtocolVersion.v1_9_2.getId());
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(), Collections.singletonList(ProtocolVersion.v1_9.getId()), ProtocolVersion.v1_9_2.getId());
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_10To1_9_3_4(), Collections.singletonList(ProtocolVersion.v1_10.getId()), ProtocolVersion.v1_9_3.getId());
registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3);
registerProtocol(new Protocol1_11To1_10(), Collections.singletonList(ProtocolVersion.v1_11.getId()), ProtocolVersion.v1_10.getId());
registerProtocol(new Protocol1_11_1To1_11(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_11.getId());
registerProtocol(new Protocol1_11To1_10(), ProtocolVersion.v1_11, ProtocolVersion.v1_10);
registerProtocol(new Protocol1_11_1To1_11(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_11);
registerProtocol(new Protocol1_12To1_11_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_11_1.getId());
registerProtocol(new Protocol1_12_1To1_12(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12.getId());
registerProtocol(new Protocol1_12_2To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12_2.getId()), ProtocolVersion.v1_12_1.getId());
registerProtocol(new Protocol1_12To1_11_1(), ProtocolVersion.v1_12, ProtocolVersion.v1_11_1);
registerProtocol(new Protocol1_12_1To1_12(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12);
registerProtocol(new Protocol1_12_2To1_12_1(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_12_1);
registerProtocol(new Protocol1_13To1_12_2(), Collections.singletonList(ProtocolVersion.v1_13.getId()), ProtocolVersion.v1_12_2.getId());
registerProtocol(new Protocol1_13_1To1_13(), Arrays.asList(ProtocolVersion.v1_13_1.getId()), ProtocolVersion.v1_13.getId());
registerProtocol(new Protocol1_13_2To1_13_1(), Arrays.asList(ProtocolVersion.v1_13_2.getId()), ProtocolVersion.v1_13_1.getId());
registerProtocol(new Protocol1_13To1_12_2(), ProtocolVersion.v1_13, ProtocolVersion.v1_12_2);
registerProtocol(new Protocol1_13_1To1_13(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13);
registerProtocol(new Protocol1_13_2To1_13_1(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_13_1);
registerProtocol(new Protocol1_14To1_13_2(), Arrays.asList(ProtocolVersion.v1_14.getId()), ProtocolVersion.v1_13_2.getId());
registerProtocol(new Protocol1_14_1To1_14(), Arrays.asList(ProtocolVersion.v1_14_1.getId()), ProtocolVersion.v1_14.getId());
registerProtocol(new Protocol1_14_2To1_14_1(), Arrays.asList(ProtocolVersion.v1_14_2.getId()), ProtocolVersion.v1_14_1.getId());
registerProtocol(new Protocol1_14_3To1_14_2(), Arrays.asList(ProtocolVersion.v1_14_3.getId()), ProtocolVersion.v1_14_2.getId());
registerProtocol(new Protocol1_14To1_13_2(), ProtocolVersion.v1_14, ProtocolVersion.v1_13_2);
registerProtocol(new Protocol1_14_1To1_14(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14);
registerProtocol(new Protocol1_14_2To1_14_1(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_1);
registerProtocol(new Protocol1_14_3To1_14_2(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_2);
registerProtocol(new Protocol1_14_4To1_14_3(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_14_3);
}
/**
* Register a protocol
*
* @param protocol The protocol to register.
* @param supported Supported client versions.
* @param output The output server version it converts to.
*/
public static void registerProtocol(Protocol protocol, ProtocolVersion supported, ProtocolVersion output) {
registerProtocol(protocol, Collections.singletonList(supported.getId()), output.getId());
}
/**
@ -79,7 +92,7 @@ public class ProtocolRegistry {
*/
public static void registerProtocol(Protocol protocol, List<Integer> supported, Integer output) {
// Clear cache as this may make new routes.
if (pathCache.size() > 0)
if (!pathCache.isEmpty())
pathCache.clear();
for (Integer version : supported) {

Datei anzeigen

@ -39,6 +39,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_14_1;
public static final ProtocolVersion v1_14_2;
public static final ProtocolVersion v1_14_3;
public static final ProtocolVersion v1_14_4;
public static final ProtocolVersion unknown;
private final int id;
@ -74,6 +75,7 @@ public class ProtocolVersion {
register(v1_14_1 = new ProtocolVersion(480, "1.14.1"));
register(v1_14_2 = new ProtocolVersion(485, "1.14.2"));
register(v1_14_3 = new ProtocolVersion(490, "1.14.3"));
register(v1_14_4 = new ProtocolVersion(498, "1.14.4"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}

Datei anzeigen

@ -23,7 +23,6 @@ public abstract class MetadataRewriter<T extends EntityType> {
metadataMap = Collections.unmodifiableMap(metadataMap);
for (Metadata metadata : new ArrayList<>(metadatas)) {
int oldId = metadata.getId();
try {
handleMetadata(entityId, type, metadata, metadatas, metadataMap, connection);
} catch (Exception e) {

Datei anzeigen

@ -107,7 +107,7 @@ public abstract class ViaCommandHandler implements ViaVersionCommand {
*/
public void showHelp(ViaCommandSender sender) {
Set<ViaSubCommand> allowed = calculateAllowedCommands(sender);
if (allowed.size() == 0) {
if (allowed.isEmpty()) {
sender.sendMessage(color("&cYou are not allowed to use these commands!"));
return;
}

Datei anzeigen

@ -4,8 +4,8 @@ import java.util.HashMap;
import java.util.Map;
public class InformativeException extends Exception {
final Map<String, Object> info = new HashMap<>();
int sources = 0;
private final Map<String, Object> info = new HashMap<>();
private int sources = 0;
public InformativeException(Throwable cause) {
super(cause);
@ -34,7 +34,7 @@ public class InformativeException extends Exception {
builder.append("Please post this error to http://github.com/ViaVersion/ViaVersion/issues\n{");
int i = 0;
for (Map.Entry<String, Object> entry : info.entrySet()) {
builder.append((i == 0 ? "" : ", ") + entry.getKey() + ": " + entry.getValue().toString());
builder.append(i == 0 ? "" : ", ").append(entry.getKey()).append(": ").append(entry.getValue().toString());
i++;
}
builder.append("}\nActual Error: ");

Datei anzeigen

@ -10,8 +10,8 @@ import io.netty.util.concurrent.EventExecutor;
import java.net.SocketAddress;
public class ChannelHandlerContextWrapper implements ChannelHandlerContext {
private ChannelHandlerContext base;
private ViaHandler handler;
private final ChannelHandlerContext base;
private final ViaHandler handler;
public ChannelHandlerContextWrapper(ChannelHandlerContext base, ViaHandler handler) {
this.base = base;

Datei anzeigen

@ -150,10 +150,10 @@ public enum PacketType {
}
}
private State state;
private Direction direction;
private int packetID;
private int newPacketID = -1;
private final State state;
private final Direction direction;
private final int packetID;
private final int newPacketID;
PacketType(State state, Direction direction, int packetID) {
this.state = state;

Datei anzeigen

@ -16,7 +16,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@ -46,17 +45,14 @@ public class MappingData {
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 EnchantmentMappingByteArray(mapping1_12.getAsJsonObject("enchantments"), mapping1_13.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 SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
soundMappings = new Mappings(662, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
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>>() {
}).getType());
new InputStreamReader(MappingData.class.getClassLoader().getResourceAsStream("assets/viaversion/data/mapping-lang-1.12-1.13.json")),
new TypeToken<Map<String, String>>() {
}.getType());
try {
String[] lines;
try (Reader reader = new InputStreamReader(MappingData.class.getClassLoader()
@ -100,12 +96,11 @@ public class MappingData {
}
}
private static class BlockMappingsShortArray implements Mappings {
private short[] oldToNew = new short[4084];
private static class BlockMappingsShortArray extends Mappings {
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) {
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_12, mapping1_13);
super(4084, mapping1_12, mapping1_13);
// Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13
if (Via.getConfig().isSnowCollisionFix()) {
oldToNew[1248] = 3416;
@ -119,38 +114,5 @@ public class MappingData {
oldToNew[1556] = 3985; // cracked stone bricks
oldToNew[1557] = 3986; // chiseled stone bricks
}
@Override
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
private static class SoundMappingShortArray implements Mappings {
private short[] oldToNew = new short[662];
private SoundMappingShortArray(JsonArray mapping1_12, JsonArray mapping1_13) {
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_12, mapping1_13);
}
@Override
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
private static class EnchantmentMappingByteArray implements Mappings {
private byte[] oldToNew = new byte[72];
private EnchantmentMappingByteArray(JsonObject m1_12, JsonObject m1_13) {
Arrays.fill(oldToNew, (byte) -1);
MappingDataLoader.mapIdentifiers(oldToNew, m1_12, m1_13);
}
@Override
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
}

Datei anzeigen

@ -27,6 +27,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.SpawnEggRewriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class InventoryPackets {
private static String NBT_TAG_NAME;
@ -404,13 +405,13 @@ public class InventoryPackets {
if (numberConverted != null) {
oldId = numberConverted;
}
String[] newValues = BlockIdData.blockIdMapping.get(oldId);
String[] newValues = BlockIdData.blockIdMapping.get(oldId.toLowerCase(Locale.ROOT));
if (newValues != null) {
for (String newValue : newValues) {
newCanPlaceOn.add(new StringTag("", newValue));
}
} else {
newCanPlaceOn.add(new StringTag("", oldId));
newCanPlaceOn.add(new StringTag("", oldId.toLowerCase(Locale.ROOT)));
}
}
tag.put(newCanPlaceOn);
@ -426,13 +427,13 @@ public class InventoryPackets {
if (numberConverted != null) {
oldId = numberConverted;
}
String[] newValues = BlockIdData.blockIdMapping.get(oldId);
String[] newValues = BlockIdData.blockIdMapping.get(oldId.toLowerCase(Locale.ROOT));
if (newValues != null) {
for (String newValue : newValues) {
newCanDestroy.add(new StringTag("", newValue));
}
} else {
newCanDestroy.add(new StringTag("", oldId));
newCanDestroy.add(new StringTag("", oldId.toLowerCase(Locale.ROOT)));
}
}
tag.put(newCanDestroy);

Datei anzeigen

@ -0,0 +1,47 @@
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;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class Protocol1_14_4To1_14_3 extends Protocol {
@Override
protected void registerPackets() {
// trade list
registerOutgoing(State.PLAY, 0x27, 0x27, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.VAR_INT);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.FLOAT);
wrapper.write(Type.INT, 0); // demand value added in pre5
}
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
}
}

Datei anzeigen

@ -40,7 +40,6 @@ public class Protocol1_14To1_13_2 extends Protocol {
registerOutgoing(State.PLAY, 0x1B, 0x1A);
registerOutgoing(State.PLAY, 0x1C, 0x1B);
registerOutgoing(State.PLAY, 0x1D, 0x54);
registerOutgoing(State.PLAY, 0x1E, 0x1C);
registerOutgoing(State.PLAY, 0x1F, 0x1D);
registerOutgoing(State.PLAY, 0x20, 0x1E);
registerOutgoing(State.PLAY, 0x21, 0x20);

Datei anzeigen

@ -9,10 +9,13 @@ import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class MappingData {
public final static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
public static final BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
public static Mappings blockStateMappings;
public static Mappings blockMappings;
public static Mappings soundMappings;
@ -23,13 +26,13 @@ public class MappingData {
JsonObject mapping1_14 = MappingDataLoader.loadData("mapping-1.14.json");
Via.getPlatform().getLogger().info("Loading 1.13.2 -> 1.14 blockstate mapping...");
blockStateMappings = new BlockMappingsShortArray(mapping1_13_2.getAsJsonObject("blockstates"), mapping1_14.getAsJsonObject("blockstates"));
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 BlockMappingsShortArray(mapping1_13_2.getAsJsonObject("blocks"), mapping1_14.getAsJsonObject("blocks"));
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 SoundMappingShortArray(mapping1_13_2.getAsJsonArray("sounds"), mapping1_14.getAsJsonArray("sounds"));
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");
@ -52,34 +55,4 @@ public class MappingData {
}
}
}
private static class SoundMappingShortArray implements Mappings {
private short[] oldToNew;
private SoundMappingShortArray(JsonArray mapping1_13_2, JsonArray mapping1_14) {
oldToNew = new short[mapping1_13_2.size()];
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_13_2, mapping1_14);
}
@Override
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
private static class BlockMappingsShortArray implements Mappings {
private short[] oldToNew;
private BlockMappingsShortArray(JsonObject mapping1_13_2, JsonObject mapping1_14) {
oldToNew = new short[mapping1_13_2.entrySet().size()];
Arrays.fill(oldToNew, (short) -1);
MappingDataLoader.mapIdentifiers(oldToNew, mapping1_13_2, mapping1_14);
}
@Override
public int getNewId(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
}

Datei anzeigen

@ -22,11 +22,18 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker1
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
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];
static {
Arrays.fill(FULL_LIGHT, (byte) 0xff);
}
public static void register(final Protocol protocol) {
@ -116,6 +123,30 @@ public class WorldPackets {
}
});
// Explosion
protocol.registerOutgoing(State.PLAY, 0x1E, 0x1C, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.FLOAT); // X
map(Type.FLOAT); // Y
map(Type.FLOAT); // Z
map(Type.FLOAT); // Radius
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
for (int i = 0; i < 3; i++) {
float coord = wrapper.get(Type.FLOAT, i);
if (coord < 0f) {
coord = (int) coord;
wrapper.set(Type.FLOAT, i, coord);
}
}
}
});
}
});
// Chunk
protocol.registerOutgoing(State.PLAY, 0x22, 0x21, new PacketRemapper() {
@Override
@ -172,24 +203,39 @@ public class WorldPackets {
PacketWrapper lightPacket = wrapper.create(0x24);
lightPacket.write(Type.VAR_INT, chunk.getX());
lightPacket.write(Type.VAR_INT, chunk.getZ());
int skyLightMask = 0;
int skyLightMask = chunk.isGroundUp() ? 0x3ffff : 0; // all 18 bits set if ground up
int blockLightMask = 0;
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection sec = chunk.getSections()[i];
if (sec == null) continue;
if (sec.hasSkyLight()) {
if (!chunk.isGroundUp() && sec.hasSkyLight()) {
skyLightMask |= (1 << (i + 1));
}
blockLightMask |= (1 << (i + 1));
}
lightPacket.write(Type.VAR_INT, skyLightMask);
lightPacket.write(Type.VAR_INT, blockLightMask);
lightPacket.write(Type.VAR_INT, 0); // empty sky light mask
lightPacket.write(Type.VAR_INT, 0); // empty block light mask
// not sending skylight/setting empty skylight causes client lag due to some weird calculations
// only do this on the initial chunk send (not when chunk.isGroundUp() is false)
if (chunk.isGroundUp())
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(FULL_LIGHT).toArray(new Byte[0])); // chunk below 0
for (ChunkSection section : chunk.getSections()) {
if (section == null || !section.hasSkyLight()) continue;
if (section == null || !section.hasSkyLight()) {
if (chunk.isGroundUp()) {
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(FULL_LIGHT).toArray(new Byte[0]));
}
continue;
}
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getSkyLight()).toArray(new Byte[0]));
}
if (chunk.isGroundUp())
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(FULL_LIGHT).toArray(new Byte[0])); // chunk above 255
for (ChunkSection section : chunk.getSections()) {
if (section == null) continue;
lightPacket.write(Type.BYTE_ARRAY, Bytes.asList(section.getBlockLight()).toArray(new Byte[0]));

Datei anzeigen

@ -17,45 +17,25 @@ import java.util.UUID;
public class UpdateUtil {
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
private final static String URL = "https://api.spiget.org/v2/resources/";
private final static int PLUGIN = 19254;
private final static String LATEST_VERSION = "/versions/latest";
public static final String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
private static final String URL = "https://api.spiget.org/v2/resources/";
private static final int PLUGIN = 19254;
private static final String LATEST_VERSION = "/versions/latest";
public static void sendUpdateMessage(final UUID uuid) {
Via.getPlatform().runAsync(new Runnable() {
@Override
public void run() {
final String message = getUpdateMessage(false);
if (message != null) {
Via.getPlatform().runSync(
new Runnable() {
@Override
public void run() {
Via.getPlatform().sendMessage(uuid, PREFIX + message);
}
}
);
}
Via.getPlatform().runAsync(() -> {
final String message = getUpdateMessage(false);
if (message != null) {
Via.getPlatform().runSync(() -> Via.getPlatform().sendMessage(uuid, PREFIX + message));
}
});
}
public static void sendUpdateMessage() {
Via.getPlatform().runAsync(new Runnable() {
@Override
public void run() {
final String message = getUpdateMessage(true);
if (message != null) {
Via.getPlatform().runSync(
new Runnable() {
@Override
public void run() {
Via.getPlatform().getLogger().warning(message);
}
}
);
}
Via.getPlatform().runAsync(() -> {
final String message = getUpdateMessage(true);
if (message != null) {
Via.getPlatform().runSync(() -> Via.getPlatform().getLogger().warning(message));
}
});
}

Datei anzeigen

@ -14,18 +14,15 @@ import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
public abstract class Config implements ConfigurationProvider {
private static final ThreadLocal<Yaml> YAML = new ThreadLocal<Yaml>() {
@Override
protected Yaml initialValue() {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(false);
options.setIndent(2);
return new Yaml(new YamlConstructor(), new Representer(), options);
}
};
private static final ThreadLocal<Yaml> YAML = ThreadLocal.withInitial(() -> {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
options.setPrettyFlow(false);
options.setIndent(2);
return new Yaml(new YamlConstructor(), new Representer(), options);
});
private CommentStore commentStore = new CommentStore('.', 2);
private final CommentStore commentStore = new CommentStore('.', 2);
private final File configFile;
private ConcurrentSkipListMap<String, Object> config;

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>2.1.3-SNAPSHOT</version>
<version>2.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>