mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-22 16:28:12 +01:00
cleanup code, avoid some deprecated methods, fix dedicated server packet sending and class not found
This commit is contained in:
parent
407d66b313
commit
e25b39e3f3
@ -42,11 +42,13 @@ dependencies {
|
||||
shade("de.gerrygames:viarewind-core:1.4.0") { transitive = false }
|
||||
shade("nl.matsv:viabackwards-core:3.0.0-19w11b") { transitive = false }
|
||||
|
||||
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
|
||||
minecraft "com.mojang:minecraft:19w11b"
|
||||
mappings "net.fabricmc:yarn:19w11b.2"
|
||||
mappings "net.fabricmc:yarn:19w11b.4"
|
||||
modCompile "net.fabricmc:fabric-loader:0.3.7.109"
|
||||
|
||||
modCompile "net.fabricmc:fabric:0.2.3.110"
|
||||
modCompile "net.fabricmc:fabric:0.2.3.111"
|
||||
}
|
||||
|
||||
jar {
|
||||
|
@ -39,7 +39,7 @@ import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.registry.CommandRegistry;
|
||||
import net.fabricmc.loader.FabricLoader;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import us.myles.ViaVersion.ViaManager;
|
||||
@ -66,10 +66,21 @@ public class ViaFabric implements ModInitializer {
|
||||
}
|
||||
|
||||
public static String getVersion() {
|
||||
return FabricLoader.INSTANCE.getModContainer("viafabric")
|
||||
return FabricLoader.getInstance().getModContainer("viafabric")
|
||||
.get().getMetadata().getVersion().getFriendlyString();
|
||||
}
|
||||
|
||||
private static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
|
||||
return LiteralArgumentBuilder.<S>literal(commandName)
|
||||
.then(
|
||||
RequiredArgumentBuilder
|
||||
.<S, String>argument("args", StringArgumentType.greedyString())
|
||||
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
|
||||
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
|
||||
)
|
||||
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
Via.init(ViaManager.builder()
|
||||
@ -83,7 +94,7 @@ public class ViaFabric implements ModInitializer {
|
||||
new VRRewindPlatform().init();
|
||||
new VRBackwardsPlatform().init();
|
||||
|
||||
if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT) {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
try {
|
||||
Class.forName("io.github.cottonmc.clientcommands.ClientCommands")
|
||||
.getMethod("registerCommand", Consumer.class)
|
||||
@ -105,15 +116,4 @@ public class ViaFabric implements ModInitializer {
|
||||
Via.getPlatform().getLogger().warning("Fabric API isn't installed");
|
||||
}
|
||||
}
|
||||
|
||||
private static <S extends CommandSource> LiteralArgumentBuilder<S> command(String commandName) {
|
||||
return LiteralArgumentBuilder.<S>literal(commandName)
|
||||
.then(
|
||||
RequiredArgumentBuilder
|
||||
.<S, String>argument("args", StringArgumentType.greedyString())
|
||||
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute)
|
||||
.suggests(((VRCommandHandler) Via.getManager().getCommandHandler())::suggestion)
|
||||
)
|
||||
.executes(((VRCommandHandler) Via.getManager().getCommandHandler())::execute);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,8 @@
|
||||
package com.github.creeper123123321.viafabric.commands;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.FabricLoader;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientCommandSource;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
@ -53,8 +54,8 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s)), false);
|
||||
} else if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
FabricLoader.INSTANCE.getEnvironmentHandler().getClientPlayer()
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
MinecraftClient.getInstance().player
|
||||
.appendCommandFeedback(TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s)));
|
||||
}
|
||||
}
|
||||
@ -64,8 +65,8 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
Entity entity = ((ServerCommandSource) source).getEntity();
|
||||
if (entity != null) return entity.getUuid();
|
||||
} else if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
return FabricLoader.INSTANCE.getEnvironmentHandler().getClientPlayer().getUuid();
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
return MinecraftClient.getInstance().player.getUuid();
|
||||
}
|
||||
return UUID.fromString(getName());
|
||||
}
|
||||
@ -74,8 +75,8 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
public String getName() {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
return ((ServerCommandSource) source).getName();
|
||||
} else if (FabricLoader.INSTANCE.getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
return FabricLoader.INSTANCE.getEnvironmentHandler().getClientPlayer().getEntityName();
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
return MinecraftClient.getInstance().player.getEntityName();
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.server.command.CommandSource;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.commands.ViaCommandHandler;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -50,12 +49,10 @@ public class VRCommandHandler extends ViaCommandHandler {
|
||||
args = StringArgumentType.getString(ctx, "args").split(" ");
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
Via.getManager()
|
||||
.getCommandHandler()
|
||||
.onCommand(
|
||||
new NMSCommandSender(ctx.getSource()),
|
||||
args
|
||||
);
|
||||
onCommand(
|
||||
new NMSCommandSender(ctx.getSource()),
|
||||
args
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class LeakDetectSubCommand extends ViaSubCommand {
|
||||
ResourceLeakDetector.setLevel(level);
|
||||
viaCommandSender.sendMessage("Set leak detector level to " + level);
|
||||
} catch (IllegalArgumentException e) {
|
||||
viaCommandSender.sendMessage("Invalid level (" + Arrays.toString(ResourceLeakDetector.Level.values()) +")");
|
||||
viaCommandSender.sendMessage("Invalid level (" + Arrays.toString(ResourceLeakDetector.Level.values()) + ")");
|
||||
}
|
||||
} else {
|
||||
viaCommandSender.sendMessage("Current leak detection level is " + ResourceLeakDetector.getLevel());
|
||||
|
@ -37,7 +37,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VRDecodeHandler extends ByteToMessageDecoder {
|
||||
@ -100,13 +99,11 @@ public class VRDecodeHandler extends ByteToMessageDecoder {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
//try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
|
||||
super.channelRead(ctx, msg);
|
||||
//}
|
||||
super.channelRead(ctx, msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
ProtocolInfo info = user.get(ProtocolInfo.class);
|
||||
if (info.getUuid() != null) {
|
||||
Via.getManager().removePortedClient(info.getUuid());
|
||||
|
@ -37,7 +37,6 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo;
|
||||
import us.myles.ViaVersion.util.PipelineUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class VREncodeHandler extends MessageToByteEncoder {
|
||||
private UserConnection user;
|
||||
@ -110,8 +109,6 @@ public class VREncodeHandler extends MessageToByteEncoder {
|
||||
|
||||
@Override
|
||||
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||
//try (AutoCloseable ignored = user.createTaskListAndRunOnClose()) {
|
||||
super.write(ctx, msg, promise);
|
||||
//}
|
||||
super.write(ctx, msg, promise);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ public class FabricDecodeHandler extends ByteToMessageDecoder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
public void channelInactive(ChannelHandlerContext ctx) {
|
||||
ProtocolInfo pi = info.get(ProtocolInfo.class);
|
||||
if (pi.getUuid() != null) {
|
||||
Via.getManager().removePortedClient(pi.getUuid());
|
||||
|
@ -28,7 +28,6 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToByteEncoder;
|
||||
import us.myles.ViaVersion.api.PacketWrapper;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
import us.myles.ViaVersion.api.data.UserConnection;
|
||||
import us.myles.ViaVersion.api.type.Type;
|
||||
import us.myles.ViaVersion.exception.CancelException;
|
||||
|
@ -29,7 +29,6 @@ import com.github.creeper123123321.viafabric.util.VersionFormatFilter;
|
||||
import net.minecraft.client.gui.Screen;
|
||||
import net.minecraft.client.gui.menu.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@ -45,11 +45,11 @@ public class VRInjector implements ViaInjector {
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
throw new UnsupportedOperationException();
|
||||
return "encoder";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
throw new UnsupportedOperationException();
|
||||
return "decoder";
|
||||
}
|
||||
}
|
||||
|
@ -29,8 +29,11 @@ import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
|
||||
import com.github.creeper123123321.viafabric.commands.UserCommandSender;
|
||||
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
|
||||
import com.github.creeper123123321.viafabric.util.FutureTaskId;
|
||||
import net.fabricmc.loader.FabricLoader;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.ModContainer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
@ -53,6 +56,7 @@ import us.myles.ViaVersion.sponge.VersionInfo;
|
||||
import us.myles.ViaVersion.util.GsonUtil;
|
||||
import us.myles.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@ -63,7 +67,21 @@ import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VRPlatform implements ViaPlatform {
|
||||
private VRViaConfig config = new VRViaConfig(FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.yml").toFile());
|
||||
private VRViaConfig config = new VRViaConfig(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.yml").toFile());
|
||||
|
||||
@Nullable
|
||||
public static MinecraftServer getServer() {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
return getIntegratedServer();
|
||||
}
|
||||
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
@Nullable
|
||||
private static MinecraftServer getIntegratedServer() {
|
||||
return MinecraftClient.getInstance().getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger getLogger() {
|
||||
@ -106,7 +124,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
// Kick task needs to be on main thread
|
||||
Executor executor = ViaFabric.EVENT_LOOP;
|
||||
boolean alreadyLogged;
|
||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||
MinecraftServer server = getServer();
|
||||
if (server != null) {
|
||||
alreadyLogged = true;
|
||||
executor = server;
|
||||
@ -161,7 +179,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
|
||||
@Override
|
||||
public ViaCommandSender[] getOnlinePlayers() {
|
||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||
MinecraftServer server = getServer();
|
||||
if (server != null && server.method_18854()) {
|
||||
// Not thread safe
|
||||
return server.getPlayerManager().getPlayerList().stream()
|
||||
@ -190,7 +208,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
}
|
||||
} else {
|
||||
runSync(() -> {
|
||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||
MinecraftServer server = getServer();
|
||||
if (server == null) return;
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return;
|
||||
@ -212,7 +230,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
MinecraftServer server = FabricLoader.INSTANCE.getEnvironmentHandler().getServerInstance();
|
||||
MinecraftServer server = getServer();
|
||||
if (server != null && server.method_18854()) {
|
||||
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
|
||||
if (player == null) return false;
|
||||
@ -251,7 +269,7 @@ public class VRPlatform implements ViaPlatform {
|
||||
public JsonObject getDump() {
|
||||
JsonObject platformSpecific = new JsonObject();
|
||||
List<PluginInfo> mods = new ArrayList<>();
|
||||
for (ModContainer mod : FabricLoader.INSTANCE.getModContainers()) {
|
||||
for (ModContainer mod : net.fabricmc.loader.FabricLoader.INSTANCE.getModContainers()) {
|
||||
mods.add(new PluginInfo(true,
|
||||
mod.getMetadata().getName(),
|
||||
mod.getMetadata().getVersion().getFriendlyString(),
|
||||
@ -270,5 +288,4 @@ public class VRPlatform implements ViaPlatform {
|
||||
public boolean isOldClientsAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,12 +28,12 @@ import com.github.creeper123123321.viafabric.ViaFabric;
|
||||
import de.gerrygames.viarewind.api.ViaRewindConfig;
|
||||
import de.gerrygames.viarewind.api.ViaRewindConfigImpl;
|
||||
import de.gerrygames.viarewind.api.ViaRewindPlatform;
|
||||
import net.fabricmc.loader.FabricLoader;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class VRRewindPlatform implements ViaRewindPlatform {
|
||||
private static ViaRewindConfig config = new ViaRewindConfigImpl(FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viarewind.yml").toFile());
|
||||
private static ViaRewindConfig config = new ViaRewindConfigImpl(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaFabric").resolve("viarewind.yml").toFile());
|
||||
|
||||
public void init() {
|
||||
init(config);
|
||||
|
@ -46,14 +46,15 @@ public class VRViaAPI implements ViaAPI<Void> {
|
||||
|
||||
@Override
|
||||
public int getPlayerVersion(UUID uuid) {
|
||||
if (!isPorted(uuid)) {
|
||||
try {
|
||||
return Via.getManager().getInjector().getServerProtocolVersion();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
UserConnection con = Via.getManager().getPortedPlayers().get(uuid);
|
||||
if (con != null) {
|
||||
return con.get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
try {
|
||||
return Via.getManager().getInjector().getServerProtocolVersion();
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
return Via.getManager().getPortedPlayers().get(uuid).get(ProtocolInfo.class).getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,46 +35,46 @@ import us.myles.ViaVersion.packets.State;
|
||||
|
||||
// Based on https://github.com/Gerrygames/ClientViaVersion
|
||||
public class Protocol1_7_6_10to1_7_1_5 extends Protocol {
|
||||
public static final ValueTransformer<String, String> INSERT_DASHES = new ValueTransformer<String, String>(Type.STRING) {
|
||||
@Override
|
||||
public String transform(PacketWrapper packetWrapper, String s) {
|
||||
StringBuilder builder = new StringBuilder(s);
|
||||
builder.insert(20, "-");
|
||||
builder.insert(16, "-");
|
||||
builder.insert(12, "-");
|
||||
builder.insert(8, "-");
|
||||
return builder.toString();
|
||||
}
|
||||
};
|
||||
public static final ValueTransformer<String, String> INSERT_DASHES = new ValueTransformer<String, String>(Type.STRING) {
|
||||
@Override
|
||||
public String transform(PacketWrapper packetWrapper, String s) {
|
||||
StringBuilder builder = new StringBuilder(s);
|
||||
builder.insert(20, "-");
|
||||
builder.insert(16, "-");
|
||||
builder.insert(12, "-");
|
||||
builder.insert(8, "-");
|
||||
return builder.toString();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
//Login Success
|
||||
this.registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING, INSERT_DASHES);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
//Login Success
|
||||
this.registerOutgoing(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING, INSERT_DASHES);
|
||||
}
|
||||
});
|
||||
|
||||
//Spawn Player
|
||||
this.registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.STRING, INSERT_DASHES);
|
||||
map(Type.STRING);
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
packetWrapper.write(Type.VAR_INT, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
//Spawn Player
|
||||
this.registerOutgoing(State.PLAY, 0x0C, 0x0C, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.VAR_INT);
|
||||
map(Type.STRING, INSERT_DASHES);
|
||||
map(Type.STRING);
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.VAR_INT, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
}
|
||||
@Override
|
||||
public void init(UserConnection userConnection) {
|
||||
}
|
||||
}
|
@ -57,12 +57,48 @@ import java.util.UUID;
|
||||
|
||||
// Based on https://github.com/Gerrygames/ClientViaVersion
|
||||
public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
private static ValueReader xyzToPosition = (ValueReader<Position>) packetWrapper -> {
|
||||
private static ValueReader<Position> xyzToPosition = packetWrapper -> {
|
||||
long x = packetWrapper.read(Type.INT);
|
||||
long y = packetWrapper.read(Type.INT);
|
||||
long z = packetWrapper.read(Type.INT);
|
||||
return new Position(x, y, z);
|
||||
};
|
||||
private static ArrayList<Integer> placeable = new ArrayList<>();
|
||||
|
||||
static {
|
||||
placeable.add(6);
|
||||
placeable.add(27);
|
||||
placeable.add(28);
|
||||
placeable.add(30);
|
||||
placeable.add(31);
|
||||
placeable.add(32);
|
||||
placeable.add(37);
|
||||
placeable.add(38);
|
||||
placeable.add(39);
|
||||
placeable.add(40);
|
||||
placeable.add(50);
|
||||
placeable.add(65);
|
||||
placeable.add(66);
|
||||
placeable.add(69);
|
||||
placeable.add(70);
|
||||
placeable.add(72);
|
||||
placeable.add(76);
|
||||
placeable.add(77);
|
||||
placeable.add(96);
|
||||
placeable.add(106);
|
||||
placeable.add(111);
|
||||
placeable.add(131);
|
||||
placeable.add(143);
|
||||
placeable.add(147);
|
||||
placeable.add(148);
|
||||
placeable.add(157);
|
||||
placeable.add(167);
|
||||
placeable.add(175);
|
||||
for (int i = 256; i <= 378; i++) placeable.add(i);
|
||||
for (int i = 381; i <= 396; i++) placeable.add(i);
|
||||
for (int i = 398; i <= 452; i++) placeable.add(i);
|
||||
for (int i = 2256; i <= 2267; i++) placeable.add(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerPackets() {
|
||||
@ -86,7 +122,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.STRING); //Level Type
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BOOLEAN, false); //Reduced Debug Info
|
||||
}
|
||||
});
|
||||
@ -100,7 +136,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.STRING); //Chat Message
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BYTE, (byte) 0); //Position (chat box)
|
||||
}
|
||||
});
|
||||
@ -519,7 +555,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.BYTE); //z
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BOOLEAN, true); //OnGround
|
||||
}
|
||||
});
|
||||
@ -535,7 +571,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.BYTE); //pitch
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BOOLEAN, true); //OnGround
|
||||
}
|
||||
});
|
||||
@ -554,7 +590,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.BYTE); //pitch
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BOOLEAN, true); //OnGround
|
||||
}
|
||||
});
|
||||
@ -573,7 +609,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.BYTE); //pitch
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BOOLEAN, true); //OnGround
|
||||
}
|
||||
});
|
||||
@ -622,7 +658,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.SHORT, Type.VAR_INT); //Duration
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BOOLEAN, false);
|
||||
}
|
||||
}); //Hide Particles
|
||||
@ -911,7 +947,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
items = new Item[old.length + 1];
|
||||
items[0] = old[0];
|
||||
System.arraycopy(old, 1, items, 2, old.length - 1);
|
||||
items[1] = new Item((short) 351, (byte) 3, (short) 4, null);
|
||||
items[1] = new Item(351, (byte) 3, (short) 4, null);
|
||||
}
|
||||
packetWrapper.write(Type.ITEM_ARRAY, items); //Items
|
||||
}
|
||||
@ -1309,7 +1345,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
Item item = packetWrapper.read(Type.ITEM);
|
||||
packetWrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item);
|
||||
|
||||
if (isPlayerInsideBlock(x, y, z, direction) && !isPlaceable(item.getId()))
|
||||
if (isPlayerInsideBlock(x, y, z, direction) && !isPlaceable(item.getIdentifier()))
|
||||
packetWrapper.cancel();
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@ -1331,7 +1367,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
public void registerMap() {
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.INT, 0); //Entity Id, hopefully 0 is ok
|
||||
packetWrapper.write(Type.BYTE, (byte) 1); //Animation
|
||||
}
|
||||
@ -1452,7 +1488,7 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
map(Type.BOOLEAN);
|
||||
create(new ValueCreator() {
|
||||
@Override
|
||||
public void write(PacketWrapper packetWrapper) throws Exception {
|
||||
public void write(PacketWrapper packetWrapper) {
|
||||
packetWrapper.write(Type.BYTE, (byte) 0);
|
||||
}
|
||||
});
|
||||
@ -1564,43 +1600,6 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ArrayList<Integer> placeable = new ArrayList<>();
|
||||
|
||||
static {
|
||||
placeable.add(6);
|
||||
placeable.add(27);
|
||||
placeable.add(28);
|
||||
placeable.add(30);
|
||||
placeable.add(31);
|
||||
placeable.add(32);
|
||||
placeable.add(37);
|
||||
placeable.add(38);
|
||||
placeable.add(39);
|
||||
placeable.add(40);
|
||||
placeable.add(50);
|
||||
placeable.add(65);
|
||||
placeable.add(66);
|
||||
placeable.add(69);
|
||||
placeable.add(70);
|
||||
placeable.add(72);
|
||||
placeable.add(76);
|
||||
placeable.add(77);
|
||||
placeable.add(96);
|
||||
placeable.add(106);
|
||||
placeable.add(111);
|
||||
placeable.add(131);
|
||||
placeable.add(143);
|
||||
placeable.add(147);
|
||||
placeable.add(148);
|
||||
placeable.add(157);
|
||||
placeable.add(167);
|
||||
placeable.add(175);
|
||||
for (int i = 256; i <= 378; i++) placeable.add(i);
|
||||
for (int i = 381; i <= 396; i++) placeable.add(i);
|
||||
for (int i = 398; i <= 452; i++) placeable.add(i);
|
||||
for (int i = 2256; i <= 2267; i++) placeable.add(i);
|
||||
}
|
||||
|
||||
private boolean isPlaceable(int id) {
|
||||
return placeable.contains(id);
|
||||
}
|
||||
@ -1680,9 +1679,20 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
ITEM_TAKE("take"),
|
||||
MOB_APPEARANCE("mobappearance");
|
||||
|
||||
private static final HashMap<String, Particle> particleMap = new HashMap<>();
|
||||
|
||||
static {
|
||||
Particle[] particles = values();
|
||||
int var1 = particles.length;
|
||||
|
||||
for (Particle particle : particles) {
|
||||
particleMap.put(particle.name, particle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final String name;
|
||||
public final int extra;
|
||||
private static final HashMap<String, Particle> particleMap = new HashMap<>();
|
||||
|
||||
Particle(String name) {
|
||||
this(name, 0);
|
||||
@ -1696,15 +1706,5 @@ public class Protocol1_8TO1_7_6_10 extends Protocol {
|
||||
public static Particle find(String part) {
|
||||
return particleMap.get(part);
|
||||
}
|
||||
|
||||
static {
|
||||
Particle[] particles = values();
|
||||
int var1 = particles.length;
|
||||
|
||||
for (Particle particle : particles) {
|
||||
particleMap.put(particle.name, particle);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -37,156 +37,156 @@ import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
public class ChunkPacketTransformer {
|
||||
public static void transformChunk(PacketWrapper packetWrapper) throws Exception {
|
||||
int chunkX = packetWrapper.read(Type.INT);
|
||||
int chunkZ = packetWrapper.read(Type.INT);
|
||||
boolean groundUp = packetWrapper.read(Type.BOOLEAN);
|
||||
int primaryBitMask = packetWrapper.read(Type.SHORT);
|
||||
int addBitMask = packetWrapper.read(Type.SHORT);
|
||||
int compressedSize = packetWrapper.read(Type.INT);
|
||||
CustomByteType customByteType = new CustomByteType(compressedSize);
|
||||
byte[] data = packetWrapper.read(customByteType);
|
||||
public static void transformChunk(PacketWrapper packetWrapper) throws Exception {
|
||||
int chunkX = packetWrapper.read(Type.INT);
|
||||
int chunkZ = packetWrapper.read(Type.INT);
|
||||
boolean groundUp = packetWrapper.read(Type.BOOLEAN);
|
||||
int primaryBitMask = packetWrapper.read(Type.SHORT);
|
||||
int addBitMask = packetWrapper.read(Type.SHORT);
|
||||
int compressedSize = packetWrapper.read(Type.INT);
|
||||
CustomByteType customByteType = new CustomByteType(compressedSize);
|
||||
byte[] data = packetWrapper.read(customByteType);
|
||||
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
|
||||
for(int j = 0; j < 16; ++j) {
|
||||
k += primaryBitMask >> j & 1;
|
||||
l += addBitMask >> j & 1;
|
||||
}
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
k += primaryBitMask >> j & 1;
|
||||
l += addBitMask >> j & 1;
|
||||
}
|
||||
|
||||
int uncompressedSize = 12288 * k;
|
||||
uncompressedSize += 2048 * l;
|
||||
if (groundUp) {
|
||||
uncompressedSize += 256;
|
||||
}
|
||||
int uncompressedSize = 12288 * k;
|
||||
uncompressedSize += 2048 * l;
|
||||
if (groundUp) {
|
||||
uncompressedSize += 256;
|
||||
}
|
||||
|
||||
byte[] uncompressedData = new byte[uncompressedSize];
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(data, 0, compressedSize);
|
||||
try {
|
||||
inflater.inflate(uncompressedData);
|
||||
} catch (DataFormatException ex) {
|
||||
throw new IOException("Bad compressed data format");
|
||||
} finally {
|
||||
inflater.end();
|
||||
}
|
||||
byte[] uncompressedData = new byte[uncompressedSize];
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(data, 0, compressedSize);
|
||||
try {
|
||||
inflater.inflate(uncompressedData);
|
||||
} catch (DataFormatException ex) {
|
||||
throw new IOException("Bad compressed data format");
|
||||
} finally {
|
||||
inflater.end();
|
||||
}
|
||||
|
||||
Chunk1_8to1_7_6_10 chunk = new Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp);
|
||||
Chunk1_8to1_7_6_10 chunk = new Chunk1_8to1_7_6_10(uncompressedData, primaryBitMask, addBitMask, true, groundUp);
|
||||
|
||||
Field field = PacketWrapper.class.getDeclaredField("packetValues");
|
||||
field.setAccessible(true);
|
||||
((List)field.get(packetWrapper)).clear();
|
||||
field = PacketWrapper.class.getDeclaredField("readableObjects");
|
||||
field.setAccessible(true);
|
||||
((LinkedList)field.get(packetWrapper)).clear();
|
||||
field = PacketWrapper.class.getDeclaredField("inputBuffer");
|
||||
field.setAccessible(true);
|
||||
ByteBuf buffer = (ByteBuf) field.get(packetWrapper);
|
||||
buffer.clear();
|
||||
Field field = PacketWrapper.class.getDeclaredField("packetValues");
|
||||
field.setAccessible(true);
|
||||
((List) field.get(packetWrapper)).clear();
|
||||
field = PacketWrapper.class.getDeclaredField("readableObjects");
|
||||
field.setAccessible(true);
|
||||
((LinkedList) field.get(packetWrapper)).clear();
|
||||
field = PacketWrapper.class.getDeclaredField("inputBuffer");
|
||||
field.setAccessible(true);
|
||||
ByteBuf buffer = (ByteBuf) field.get(packetWrapper);
|
||||
buffer.clear();
|
||||
|
||||
buffer.writeInt(chunkX);
|
||||
buffer.writeInt(chunkZ);
|
||||
buffer.writeBoolean(groundUp);
|
||||
buffer.writeShort(primaryBitMask);
|
||||
byte[] finaldata = chunk.get1_8Data();
|
||||
Type.VAR_INT.write(buffer, finaldata.length);
|
||||
buffer.writeBytes(finaldata);
|
||||
}
|
||||
buffer.writeInt(chunkX);
|
||||
buffer.writeInt(chunkZ);
|
||||
buffer.writeBoolean(groundUp);
|
||||
buffer.writeShort(primaryBitMask);
|
||||
byte[] finaldata = chunk.get1_8Data();
|
||||
Type.VAR_INT.write(buffer, finaldata.length);
|
||||
buffer.writeBytes(finaldata);
|
||||
}
|
||||
|
||||
public static void transformChunkBulk(PacketWrapper packetWrapper) throws Exception {
|
||||
short columnCount = packetWrapper.read(Type.SHORT); //short1
|
||||
int size = packetWrapper.read(Type.INT); //size
|
||||
boolean skyLightSent = packetWrapper.read(Type.BOOLEAN); //h
|
||||
int[] chunkX = new int[columnCount]; //a
|
||||
int[] chunkZ = new int[columnCount]; //b
|
||||
int[] primaryBitMask = new int[columnCount]; //c
|
||||
int[] addBitMask = new int[columnCount]; //d
|
||||
byte[][] inflatedBuffers = new byte[columnCount][]; //inflatedBuffers
|
||||
CustomByteType customByteType = new CustomByteType(size);
|
||||
byte[] buildBuffer = packetWrapper.read(customByteType); //buildBuffer
|
||||
public static void transformChunkBulk(PacketWrapper packetWrapper) throws Exception {
|
||||
short columnCount = packetWrapper.read(Type.SHORT); //short1
|
||||
int size = packetWrapper.read(Type.INT); //size
|
||||
boolean skyLightSent = packetWrapper.read(Type.BOOLEAN); //h
|
||||
int[] chunkX = new int[columnCount]; //a
|
||||
int[] chunkZ = new int[columnCount]; //b
|
||||
int[] primaryBitMask = new int[columnCount]; //c
|
||||
int[] addBitMask = new int[columnCount]; //d
|
||||
byte[][] inflatedBuffers = new byte[columnCount][]; //inflatedBuffers
|
||||
CustomByteType customByteType = new CustomByteType(size);
|
||||
byte[] buildBuffer = packetWrapper.read(customByteType); //buildBuffer
|
||||
|
||||
byte[] data = new byte[196864 * columnCount]; //abyte
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(buildBuffer, 0, size);
|
||||
byte[] data = new byte[196864 * columnCount]; //abyte
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(buildBuffer, 0, size);
|
||||
|
||||
try {
|
||||
inflater.inflate(data);
|
||||
} catch (DataFormatException ex) {
|
||||
throw new IOException("Bad compressed data format");
|
||||
} finally {
|
||||
inflater.end();
|
||||
}
|
||||
try {
|
||||
inflater.inflate(data);
|
||||
} catch (DataFormatException ex) {
|
||||
throw new IOException("Bad compressed data format");
|
||||
} finally {
|
||||
inflater.end();
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int i = 0;
|
||||
|
||||
for(int j = 0; j < columnCount; ++j) {
|
||||
chunkX[j] = packetWrapper.read(Type.INT);
|
||||
chunkZ[j] = packetWrapper.read(Type.INT);
|
||||
primaryBitMask[j] = packetWrapper.read(Type.SHORT);
|
||||
addBitMask[j] = packetWrapper.read(Type.SHORT);
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
for (int j = 0; j < columnCount; ++j) {
|
||||
chunkX[j] = packetWrapper.read(Type.INT);
|
||||
chunkZ[j] = packetWrapper.read(Type.INT);
|
||||
primaryBitMask[j] = packetWrapper.read(Type.SHORT);
|
||||
addBitMask[j] = packetWrapper.read(Type.SHORT);
|
||||
int k = 0;
|
||||
int l = 0;
|
||||
|
||||
int i1;
|
||||
for(i1 = 0; i1 < 16; ++i1) {
|
||||
k += primaryBitMask[j] >> i1 & 1;
|
||||
l += addBitMask[j] >> i1 & 1;
|
||||
}
|
||||
int i1;
|
||||
for (i1 = 0; i1 < 16; ++i1) {
|
||||
k += primaryBitMask[j] >> i1 & 1;
|
||||
l += addBitMask[j] >> i1 & 1;
|
||||
}
|
||||
|
||||
i1 = 8192 * k + 256;
|
||||
i1 += 2048 * l;
|
||||
if (skyLightSent) {
|
||||
i1 += 2048 * k;
|
||||
}
|
||||
i1 = 8192 * k + 256;
|
||||
i1 += 2048 * l;
|
||||
if (skyLightSent) {
|
||||
i1 += 2048 * k;
|
||||
}
|
||||
|
||||
inflatedBuffers[j] = new byte[i1];
|
||||
System.arraycopy(data, i, inflatedBuffers[j], 0, i1);
|
||||
i += i1;
|
||||
}
|
||||
inflatedBuffers[j] = new byte[i1];
|
||||
System.arraycopy(data, i, inflatedBuffers[j], 0, i1);
|
||||
i += i1;
|
||||
}
|
||||
|
||||
Chunk1_8to1_7_6_10[] chunks = new Chunk1_8to1_7_6_10[columnCount];
|
||||
for (i = 0; i<columnCount; i++) {
|
||||
chunks[i] = new Chunk1_8to1_7_6_10(inflatedBuffers[i], primaryBitMask[i], addBitMask[i], skyLightSent, true);
|
||||
}
|
||||
Chunk1_8to1_7_6_10[] chunks = new Chunk1_8to1_7_6_10[columnCount];
|
||||
for (i = 0; i < columnCount; i++) {
|
||||
chunks[i] = new Chunk1_8to1_7_6_10(inflatedBuffers[i], primaryBitMask[i], addBitMask[i], skyLightSent, true);
|
||||
}
|
||||
|
||||
|
||||
packetWrapper.write(Type.BOOLEAN, skyLightSent);
|
||||
packetWrapper.write(Type.VAR_INT, (int)columnCount);
|
||||
packetWrapper.write(Type.BOOLEAN, skyLightSent);
|
||||
packetWrapper.write(Type.VAR_INT, (int) columnCount);
|
||||
|
||||
for(i = 0; i < columnCount; ++i) {
|
||||
packetWrapper.write(Type.INT, chunkX[i]);
|
||||
packetWrapper.write(Type.INT, chunkZ[i]);
|
||||
packetWrapper.write(Type.UNSIGNED_SHORT, primaryBitMask[i]);
|
||||
}
|
||||
for (i = 0; i < columnCount; ++i) {
|
||||
packetWrapper.write(Type.INT, chunkX[i]);
|
||||
packetWrapper.write(Type.INT, chunkZ[i]);
|
||||
packetWrapper.write(Type.UNSIGNED_SHORT, primaryBitMask[i]);
|
||||
}
|
||||
|
||||
for(i = 0; i < columnCount; ++i) {
|
||||
data = chunks[i].get1_8Data();
|
||||
customByteType = new CustomByteType(data.length);
|
||||
packetWrapper.write(customByteType, data);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < columnCount; ++i) {
|
||||
data = chunks[i].get1_8Data();
|
||||
customByteType = new CustomByteType(data.length);
|
||||
packetWrapper.write(customByteType, data);
|
||||
}
|
||||
}
|
||||
|
||||
public static void transformMultiBlockChange(PacketWrapper packetWrapper) throws Exception {
|
||||
int chunkX = packetWrapper.read(Type.INT);
|
||||
int chunkZ = packetWrapper.read(Type.INT);
|
||||
int size = packetWrapper.read(Type.SHORT);
|
||||
packetWrapper.read(Type.INT);
|
||||
short[] blocks = new short[size];
|
||||
short[] positions = new short[size];
|
||||
public static void transformMultiBlockChange(PacketWrapper packetWrapper) throws Exception {
|
||||
int chunkX = packetWrapper.read(Type.INT);
|
||||
int chunkZ = packetWrapper.read(Type.INT);
|
||||
int size = packetWrapper.read(Type.SHORT);
|
||||
packetWrapper.read(Type.INT);
|
||||
short[] blocks = new short[size];
|
||||
short[] positions = new short[size];
|
||||
|
||||
for (int i = 0; i<size; i++) {
|
||||
positions[i] = packetWrapper.read(Type.SHORT);
|
||||
blocks[i] = packetWrapper.read(Type.SHORT);
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
positions[i] = packetWrapper.read(Type.SHORT);
|
||||
blocks[i] = packetWrapper.read(Type.SHORT);
|
||||
}
|
||||
|
||||
packetWrapper.write(Type.INT, chunkX);
|
||||
packetWrapper.write(Type.INT, chunkZ);
|
||||
packetWrapper.write(Type.VAR_INT, size);
|
||||
packetWrapper.write(Type.INT, chunkX);
|
||||
packetWrapper.write(Type.INT, chunkZ);
|
||||
packetWrapper.write(Type.VAR_INT, size);
|
||||
|
||||
for (int i = 0; i<size; i++) {
|
||||
packetWrapper.write(Type.SHORT, positions[i]);
|
||||
packetWrapper.write(Type.VAR_INT, (int)blocks[i]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < size; i++) {
|
||||
packetWrapper.write(Type.SHORT, positions[i]);
|
||||
packetWrapper.write(Type.VAR_INT, (int) blocks[i]);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,101 +27,101 @@ package com.github.creeper123123321.viafabric.protocol.protocol1_8to1_7_6_10.chu
|
||||
import us.myles.ViaVersion.api.minecraft.chunks.NibbleArray;
|
||||
|
||||
public class ExtendedBlockStorage {
|
||||
private int yBase;
|
||||
private byte[] blockLSBArray;
|
||||
private NibbleArray blockMSBArray;
|
||||
private NibbleArray blockMetadataArray;
|
||||
private NibbleArray blocklightArray;
|
||||
private NibbleArray skylightArray;
|
||||
private int yBase;
|
||||
private byte[] blockLSBArray;
|
||||
private NibbleArray blockMSBArray;
|
||||
private NibbleArray blockMetadataArray;
|
||||
private NibbleArray blocklightArray;
|
||||
private NibbleArray skylightArray;
|
||||
|
||||
public ExtendedBlockStorage(int paramInt, boolean paramBoolean) {
|
||||
this.yBase = paramInt;
|
||||
this.blockLSBArray = new byte[4096];
|
||||
this.blockMetadataArray = new NibbleArray(this.blockLSBArray.length);
|
||||
this.blocklightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
if (paramBoolean) {
|
||||
this.skylightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
}
|
||||
}
|
||||
public ExtendedBlockStorage(int paramInt, boolean paramBoolean) {
|
||||
this.yBase = paramInt;
|
||||
this.blockLSBArray = new byte[4096];
|
||||
this.blockMetadataArray = new NibbleArray(this.blockLSBArray.length);
|
||||
this.blocklightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
if (paramBoolean) {
|
||||
this.skylightArray = new NibbleArray(this.blockLSBArray.length);
|
||||
}
|
||||
}
|
||||
|
||||
public int getExtBlockMetadata(int paramInt1, int paramInt2, int paramInt3) {
|
||||
return this.blockMetadataArray.get(paramInt1, paramInt2, paramInt3);
|
||||
}
|
||||
public int getExtBlockMetadata(int paramInt1, int paramInt2, int paramInt3) {
|
||||
return this.blockMetadataArray.get(paramInt1, paramInt2, paramInt3);
|
||||
}
|
||||
|
||||
public void setExtBlockMetadata(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
this.blockMetadataArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
|
||||
}
|
||||
public void setExtBlockMetadata(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
this.blockMetadataArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
|
||||
}
|
||||
|
||||
public int getYLocation() {
|
||||
return this.yBase;
|
||||
}
|
||||
public int getYLocation() {
|
||||
return this.yBase;
|
||||
}
|
||||
|
||||
public void setExtSkylightValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
this.skylightArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
|
||||
}
|
||||
public void setExtSkylightValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
this.skylightArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
|
||||
}
|
||||
|
||||
public int getExtSkylightValue(int paramInt1, int paramInt2, int paramInt3) {
|
||||
return this.skylightArray.get(paramInt1, paramInt2, paramInt3);
|
||||
}
|
||||
public int getExtSkylightValue(int paramInt1, int paramInt2, int paramInt3) {
|
||||
return this.skylightArray.get(paramInt1, paramInt2, paramInt3);
|
||||
}
|
||||
|
||||
public void setExtBlocklightValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
this.blocklightArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
|
||||
}
|
||||
public void setExtBlocklightValue(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
|
||||
this.blocklightArray.set(paramInt1, paramInt2, paramInt3, paramInt4);
|
||||
}
|
||||
|
||||
public int getExtBlocklightValue(int paramInt1, int paramInt2, int paramInt3) {
|
||||
return this.blocklightArray.get(paramInt1, paramInt2, paramInt3);
|
||||
}
|
||||
public int getExtBlocklightValue(int paramInt1, int paramInt2, int paramInt3) {
|
||||
return this.blocklightArray.get(paramInt1, paramInt2, paramInt3);
|
||||
}
|
||||
|
||||
public byte[] getBlockLSBArray() {
|
||||
return this.blockLSBArray;
|
||||
}
|
||||
public byte[] getBlockLSBArray() {
|
||||
return this.blockLSBArray;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return this.blockMSBArray==null;
|
||||
}
|
||||
public void setBlockLSBArray(byte[] paramArrayOfByte) {
|
||||
this.blockLSBArray = paramArrayOfByte;
|
||||
}
|
||||
|
||||
public void clearMSBArray() {
|
||||
this.blockMSBArray = null;
|
||||
}
|
||||
public boolean isEmpty() {
|
||||
return this.blockMSBArray == null;
|
||||
}
|
||||
|
||||
public NibbleArray getBlockMSBArray() {
|
||||
return this.blockMSBArray;
|
||||
}
|
||||
public void clearMSBArray() {
|
||||
this.blockMSBArray = null;
|
||||
}
|
||||
|
||||
public NibbleArray getMetadataArray() {
|
||||
return this.blockMetadataArray;
|
||||
}
|
||||
public NibbleArray getBlockMSBArray() {
|
||||
return this.blockMSBArray;
|
||||
}
|
||||
|
||||
public NibbleArray getBlocklightArray() {
|
||||
return this.blocklightArray;
|
||||
}
|
||||
public void setBlockMSBArray(NibbleArray paramNibbleArray) {
|
||||
this.blockMSBArray = paramNibbleArray;
|
||||
}
|
||||
|
||||
public NibbleArray getSkylightArray() {
|
||||
return this.skylightArray;
|
||||
}
|
||||
public NibbleArray getMetadataArray() {
|
||||
return this.blockMetadataArray;
|
||||
}
|
||||
|
||||
public void setBlockLSBArray(byte[] paramArrayOfByte) {
|
||||
this.blockLSBArray = paramArrayOfByte;
|
||||
}
|
||||
public NibbleArray getBlocklightArray() {
|
||||
return this.blocklightArray;
|
||||
}
|
||||
|
||||
public void setBlockMSBArray(NibbleArray paramNibbleArray) {
|
||||
this.blockMSBArray = paramNibbleArray;
|
||||
}
|
||||
public void setBlocklightArray(NibbleArray paramNibbleArray) {
|
||||
this.blocklightArray = paramNibbleArray;
|
||||
}
|
||||
|
||||
public void setBlockMetadataArray(NibbleArray paramNibbleArray) {
|
||||
this.blockMetadataArray = paramNibbleArray;
|
||||
}
|
||||
public NibbleArray getSkylightArray() {
|
||||
return this.skylightArray;
|
||||
}
|
||||
|
||||
public void setBlocklightArray(NibbleArray paramNibbleArray) {
|
||||
this.blocklightArray = paramNibbleArray;
|
||||
}
|
||||
public void setSkylightArray(NibbleArray paramNibbleArray) {
|
||||
this.skylightArray = paramNibbleArray;
|
||||
}
|
||||
|
||||
public void setSkylightArray(NibbleArray paramNibbleArray) {
|
||||
this.skylightArray = paramNibbleArray;
|
||||
}
|
||||
public void setBlockMetadataArray(NibbleArray paramNibbleArray) {
|
||||
this.blockMetadataArray = paramNibbleArray;
|
||||
}
|
||||
|
||||
public NibbleArray createBlockMSBArray() {
|
||||
this.blockMSBArray = new NibbleArray(this.blockLSBArray.length);
|
||||
return this.blockMSBArray;
|
||||
}
|
||||
public NibbleArray createBlockMSBArray() {
|
||||
this.blockMSBArray = new NibbleArray(this.blockLSBArray.length);
|
||||
return this.blockMSBArray;
|
||||
}
|
||||
}
|
||||
|
@ -36,74 +36,74 @@ import java.util.List;
|
||||
|
||||
public class MetadataRewriter {
|
||||
|
||||
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
|
||||
for (Metadata entry : new ArrayList<>(list)) {
|
||||
MetaIndex1_8to1_7_6_10 metaIndex = MetaIndex1_8to1_7_6_10.searchIndex(type, entry.getId());
|
||||
try {
|
||||
if (metaIndex == null) throw new Exception("Could not find valid metadata");
|
||||
if (metaIndex.getNewType() == MetaType1_8.NonExistent) {
|
||||
list.remove(entry);
|
||||
return;
|
||||
}
|
||||
Object value = entry.getValue();
|
||||
if (!value.getClass().isAssignableFrom(metaIndex.getOldType().getType().getOutputClass())) {
|
||||
list.remove(entry);
|
||||
return;
|
||||
}
|
||||
entry.setMetaType(metaIndex.getNewType());
|
||||
entry.setId(metaIndex.getNewIndex());
|
||||
switch (metaIndex.getNewType()) {
|
||||
case Int:
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Byte) {
|
||||
entry.setValue(((Byte) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Short) {
|
||||
entry.setValue(((Short) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Int) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
break;
|
||||
case Byte:
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Int) {
|
||||
entry.setValue(((Integer) value).byteValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Byte) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
if (metaIndex==MetaIndex1_8to1_7_6_10.HUMAN_SKIN_FLAGS) {
|
||||
byte flags = (byte) value;
|
||||
boolean cape = flags==2;
|
||||
flags = (byte) (cape ? 127 : 125);
|
||||
entry.setValue(flags);
|
||||
}
|
||||
break;
|
||||
case Slot:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Float:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Short:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case String:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Position:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Rotation:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
default:
|
||||
Via.getPlatform().getLogger().warning("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||
list.remove(entry);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
list.remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void transform(Entity1_10Types.EntityType type, List<Metadata> list) {
|
||||
for (Metadata entry : new ArrayList<>(list)) {
|
||||
MetaIndex1_8to1_7_6_10 metaIndex = MetaIndex1_8to1_7_6_10.searchIndex(type, entry.getId());
|
||||
try {
|
||||
if (metaIndex == null) throw new Exception("Could not find valid metadata");
|
||||
if (metaIndex.getNewType() == MetaType1_8.NonExistent) {
|
||||
list.remove(entry);
|
||||
return;
|
||||
}
|
||||
Object value = entry.getValue();
|
||||
if (!value.getClass().isAssignableFrom(metaIndex.getOldType().getType().getOutputClass())) {
|
||||
list.remove(entry);
|
||||
return;
|
||||
}
|
||||
entry.setMetaType(metaIndex.getNewType());
|
||||
entry.setId(metaIndex.getNewIndex());
|
||||
switch (metaIndex.getNewType()) {
|
||||
case Int:
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Byte) {
|
||||
entry.setValue(((Byte) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Short) {
|
||||
entry.setValue(((Short) value).intValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Int) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
break;
|
||||
case Byte:
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Int) {
|
||||
entry.setValue(((Integer) value).byteValue());
|
||||
}
|
||||
if (metaIndex.getOldType() == MetaType1_7_6_10.Byte) {
|
||||
entry.setValue(value);
|
||||
}
|
||||
if (metaIndex == MetaIndex1_8to1_7_6_10.HUMAN_SKIN_FLAGS) {
|
||||
byte flags = (byte) value;
|
||||
boolean cape = flags == 2;
|
||||
flags = (byte) (cape ? 127 : 125);
|
||||
entry.setValue(flags);
|
||||
}
|
||||
break;
|
||||
case Slot:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Float:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Short:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case String:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Position:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
case Rotation:
|
||||
entry.setValue(value);
|
||||
break;
|
||||
default:
|
||||
Via.getPlatform().getLogger().warning("[Out] Unhandled MetaDataType: " + metaIndex.getNewType());
|
||||
list.remove(entry);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
list.remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,48 +39,48 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class EntityTracker extends StoredObject {
|
||||
private final Map<Integer, Entity1_10Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, Entity1_10Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||
private final Map<Integer, List<Metadata>> metadataBuffer = new ConcurrentHashMap<>();
|
||||
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public EntityTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
}
|
||||
public void removeEntity(int entityId) {
|
||||
clientEntityTypes.remove(entityId);
|
||||
}
|
||||
|
||||
public Map<Integer, Entity1_10Types.EntityType> getClientEntityTypes() {
|
||||
return this.clientEntityTypes;
|
||||
}
|
||||
public Map<Integer, Entity1_10Types.EntityType> getClientEntityTypes() {
|
||||
return this.clientEntityTypes;
|
||||
}
|
||||
|
||||
public void addMetadataToBuffer(int entityID, List<Metadata> metadataList) {
|
||||
if (this.metadataBuffer.containsKey(entityID)) {
|
||||
this.metadataBuffer.get(entityID).addAll(metadataList);
|
||||
} else if (!metadataList.isEmpty()) {
|
||||
this.metadataBuffer.put(entityID, metadataList);
|
||||
}
|
||||
}
|
||||
public void addMetadataToBuffer(int entityID, List<Metadata> metadataList) {
|
||||
if (this.metadataBuffer.containsKey(entityID)) {
|
||||
this.metadataBuffer.get(entityID).addAll(metadataList);
|
||||
} else if (!metadataList.isEmpty()) {
|
||||
this.metadataBuffer.put(entityID, metadataList);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Metadata> getBufferedMetadata(int entityId) {
|
||||
return metadataBuffer.get(entityId);
|
||||
}
|
||||
public List<Metadata> getBufferedMetadata(int entityId) {
|
||||
return metadataBuffer.get(entityId);
|
||||
}
|
||||
|
||||
public void sendMetadataBuffer(int entityId) {
|
||||
if (!this.metadataBuffer.containsKey(entityId)) return;
|
||||
PacketWrapper wrapper = new PacketWrapper(0x1C, null, this.getUser());
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Types1_8.METADATA_LIST, this.metadataBuffer.get(entityId));
|
||||
MetadataRewriter.transform(this.getClientEntityTypes().get(entityId), this.metadataBuffer.get(entityId));
|
||||
if (!this.metadataBuffer.get(entityId).isEmpty()) {
|
||||
try {
|
||||
wrapper.send(Protocol1_8TO1_7_6_10.class);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void sendMetadataBuffer(int entityId) {
|
||||
if (!this.metadataBuffer.containsKey(entityId)) return;
|
||||
PacketWrapper wrapper = new PacketWrapper(0x1C, null, this.getUser());
|
||||
wrapper.write(Type.VAR_INT, entityId);
|
||||
wrapper.write(Types1_8.METADATA_LIST, this.metadataBuffer.get(entityId));
|
||||
MetadataRewriter.transform(this.getClientEntityTypes().get(entityId), this.metadataBuffer.get(entityId));
|
||||
if (!this.metadataBuffer.get(entityId).isEmpty()) {
|
||||
try {
|
||||
wrapper.send(Protocol1_8TO1_7_6_10.class);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
this.metadataBuffer.remove(entityId);
|
||||
}
|
||||
this.metadataBuffer.remove(entityId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,36 +31,36 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapStorage extends StoredObject {
|
||||
private Map<Integer, MapData> maps = new HashMap<>();
|
||||
private Map<Integer, MapData> maps = new HashMap<>();
|
||||
|
||||
public MapStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public MapStorage(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public MapData getMapData(int id) {
|
||||
return maps.get(id);
|
||||
}
|
||||
public MapData getMapData(int id) {
|
||||
return maps.get(id);
|
||||
}
|
||||
|
||||
public void putMapData(int id, MapData mapData) {
|
||||
maps.put(id, mapData);
|
||||
}
|
||||
public void putMapData(int id, MapData mapData) {
|
||||
maps.put(id, mapData);
|
||||
}
|
||||
|
||||
public static class MapData {
|
||||
public byte scale = 0;
|
||||
public MapIcon[] mapIcons = {};
|
||||
}
|
||||
public static class MapData {
|
||||
public byte scale = 0;
|
||||
public MapIcon[] mapIcons = {};
|
||||
}
|
||||
|
||||
public static class MapIcon {
|
||||
public byte direction;
|
||||
public byte type;
|
||||
public byte x;
|
||||
public byte z;
|
||||
public static class MapIcon {
|
||||
public byte direction;
|
||||
public byte type;
|
||||
public byte x;
|
||||
public byte z;
|
||||
|
||||
public MapIcon(byte direction, byte type, byte x, byte z) {
|
||||
this.direction = direction;
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
public MapIcon(byte direction, byte type, byte x, byte z) {
|
||||
this.direction = direction;
|
||||
this.type = type;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,17 +31,17 @@ import java.util.HashMap;
|
||||
|
||||
public class Scoreboard extends StoredObject {
|
||||
|
||||
private HashMap<String, String> objectives = new HashMap<>();
|
||||
private HashMap<String, String> objectives = new HashMap<>();
|
||||
|
||||
public Scoreboard(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public Scoreboard(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void put(String name, String objective) {
|
||||
objectives.put(name, objective);
|
||||
}
|
||||
public void put(String name, String objective) {
|
||||
objectives.put(name, objective);
|
||||
}
|
||||
|
||||
public String get(String name) {
|
||||
return objectives.getOrDefault(name, "null");
|
||||
}
|
||||
public String get(String name) {
|
||||
return objectives.getOrDefault(name, "null");
|
||||
}
|
||||
}
|
||||
|
@ -33,56 +33,56 @@ import java.util.UUID;
|
||||
|
||||
public class Tablist extends StoredObject {
|
||||
|
||||
private ArrayList<TabListEntry> tablist = new ArrayList<>();
|
||||
private ArrayList<TabListEntry> tablist = new ArrayList<>();
|
||||
|
||||
public Tablist(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public Tablist(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public TabListEntry getTabListEntry(String name) {
|
||||
for (TabListEntry entry : tablist) if (name.equals(entry.name)) return entry;
|
||||
return null;
|
||||
}
|
||||
public static boolean shouldUpdateDisplayName(String oldName, String newName) {
|
||||
return oldName == null && newName != null || oldName != null && newName == null || oldName != null && !oldName.equals(newName);
|
||||
}
|
||||
|
||||
public TabListEntry getTabListEntry(UUID uuid) {
|
||||
for (TabListEntry entry : tablist) if (uuid.equals(entry.uuid)) return entry;
|
||||
return null;
|
||||
}
|
||||
public TabListEntry getTabListEntry(String name) {
|
||||
for (TabListEntry entry : tablist) if (name.equals(entry.name)) return entry;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void remove(TabListEntry entry) {
|
||||
tablist.remove(entry);
|
||||
}
|
||||
public TabListEntry getTabListEntry(UUID uuid) {
|
||||
for (TabListEntry entry : tablist) if (uuid.equals(entry.uuid)) return entry;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(TabListEntry entry) {
|
||||
tablist.add(entry);
|
||||
}
|
||||
public void remove(TabListEntry entry) {
|
||||
tablist.remove(entry);
|
||||
}
|
||||
|
||||
public static boolean shouldUpdateDisplayName(String oldName, String newName) {
|
||||
return oldName == null && newName != null || oldName != null && newName == null || oldName != null && !oldName.equals(newName);
|
||||
}
|
||||
public void add(TabListEntry entry) {
|
||||
tablist.add(entry);
|
||||
}
|
||||
|
||||
public static class TabListEntry {
|
||||
public String name;
|
||||
public String displayName;
|
||||
public UUID uuid;
|
||||
public int ping;
|
||||
public List<Property> properties = new ArrayList<>();
|
||||
public static class TabListEntry {
|
||||
public String name;
|
||||
public String displayName;
|
||||
public UUID uuid;
|
||||
public int ping;
|
||||
public List<Property> properties = new ArrayList<>();
|
||||
|
||||
public TabListEntry(String name, UUID uuid) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
public TabListEntry(String name, UUID uuid) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Property {
|
||||
public String name;
|
||||
public String value;
|
||||
public String signature;
|
||||
public static class Property {
|
||||
public String name;
|
||||
public String value;
|
||||
public String signature;
|
||||
|
||||
public Property(String name, String value, String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
public Property(String name, String value, String signature) {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ import java.util.HashMap;
|
||||
|
||||
public class Windows extends StoredObject {
|
||||
|
||||
public HashMap<Short, Short> types = new HashMap<>();
|
||||
public HashMap<Short, Short> types = new HashMap<>();
|
||||
|
||||
public Windows(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
public Windows(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public short get(short windowId) {
|
||||
return types.getOrDefault(windowId, (short)-1);
|
||||
}
|
||||
public short get(short windowId) {
|
||||
return types.getOrDefault(windowId, (short) -1);
|
||||
}
|
||||
}
|
||||
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2018 creeper123123321 and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package com.github.creeper123123321.viafabric.util;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// Based on ViaVersion's Version
|
||||
public class Version implements Comparable<Version> {
|
||||
private static final Pattern semVer = Pattern.compile("(?<a>0|[1-9]\\d*)\\.(?<b>0|[1-9]\\d*)(?:\\.(?<c>0|[1-9]\\d*))?(?:-(?<tag>[A-z0-9.-]*))?");
|
||||
private final int[] parts = new int[3];
|
||||
private String tag;
|
||||
|
||||
public Version(String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("Version can not be null");
|
||||
} else {
|
||||
Matcher matcher = semVer.matcher(value);
|
||||
if (!matcher.matches()) {
|
||||
throw new IllegalArgumentException("Invalid version format");
|
||||
} else {
|
||||
this.parts[0] = Integer.parseInt(matcher.group("a"));
|
||||
this.parts[1] = Integer.parseInt(matcher.group("b"));
|
||||
this.parts[2] = matcher.group("c") == null ? 0 : Integer.parseInt(matcher.group("c"));
|
||||
this.tag = matcher.group("tag") == null ? "" : matcher.group("tag");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int compare(Version verA, Version verB) {
|
||||
if (verA == verB) {
|
||||
return 0;
|
||||
} else if (verA == null) {
|
||||
return -1;
|
||||
} else if (verB == null) {
|
||||
return 1;
|
||||
} else {
|
||||
int max = Math.max(verA.parts.length, verB.parts.length);
|
||||
|
||||
for(int i = 0; i < max; ++i) {
|
||||
int partA = i < verA.parts.length ? verA.parts[i] : 0;
|
||||
int partB = i < verB.parts.length ? verB.parts[i] : 0;
|
||||
if (partA < partB) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (partA > partB) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
// ViaFabric
|
||||
if (verA.tag.isEmpty() && verB.tag.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
if (verA.tag.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
if (verB.tag.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
return verA.tag.compareTo(verB.tag);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean equals(Version verA, Version verB) {
|
||||
return verA == verB || verA != null && verB != null && compare(verA, verB) == 0;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String[] split = new String[this.parts.length];
|
||||
|
||||
for(int i = 0; i < this.parts.length; ++i) {
|
||||
split[i] = String.valueOf(this.parts[i]);
|
||||
}
|
||||
|
||||
return Joiner.on(".").join(split) + (this.tag.length() != 0 ? "-" + this.tag : "");
|
||||
}
|
||||
|
||||
public int compareTo(Version that) {
|
||||
return compare(this, that);
|
||||
}
|
||||
|
||||
public boolean equals(Object that) {
|
||||
return that instanceof Version && equals(this, (Version)that);
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return this.tag;
|
||||
}
|
||||
}
|
@ -46,7 +46,7 @@ public class VersionFormatFilter implements Predicate<String> {
|
||||
.flatMap(str -> Stream.concat(
|
||||
Arrays.stream(str.split("-")),
|
||||
Arrays.stream(new String[]{str})
|
||||
))
|
||||
))
|
||||
.anyMatch(ver -> ver.startsWith(s));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user