Throw away ClientSideReference and add entrypoint - not tested

This commit is contained in:
creeper123123321 2019-05-29 17:35:25 -03:00
parent 6aaa206bb9
commit b954b04800
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
4 changed files with 36 additions and 77 deletions

View File

@ -91,6 +91,8 @@ public class ViaFabric implements ModInitializer {
new VRRewindPlatform().init(); new VRRewindPlatform().init();
new VRBackwardsPlatform().init(); new VRBackwardsPlatform().init();
FabricLoader.getInstance().getEntrypoints("viafabric:via_api_initialized", Runnable.class).forEach(Runnable::run);
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion"))); CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaversion")));
CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver"))); CommandRegistry.INSTANCE.register(false, c -> c.register(command("viaver")));
CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric"))); CommandRegistry.INSTANCE.register(false, c -> c.register(command("vvfabric")));

View File

@ -27,7 +27,6 @@ package com.github.creeper123123321.viafabric.mixin.client;
import com.github.creeper123123321.viafabric.handler.clientside.VRDecodeHandler; import com.github.creeper123123321.viafabric.handler.clientside.VRDecodeHandler;
import com.github.creeper123123321.viafabric.handler.clientside.VREncodeHandler; import com.github.creeper123123321.viafabric.handler.clientside.VREncodeHandler;
import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection; import com.github.creeper123123321.viafabric.platform.VRClientSideUserConnection;
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
@ -37,7 +36,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolPipeline;
@Mixin(targets = "net.minecraft.network.ClientConnection$1") @Mixin(targets = "net.minecraft.network.ClientConnection$1")
public class MixinClientConnectionChInit { public class MixinClientConnectionChInit {
@ -45,7 +43,6 @@ public class MixinClientConnectionChInit {
private void onInitChannel(Channel channel, CallbackInfo ci) { private void onInitChannel(Channel channel, CallbackInfo ci) {
if (channel instanceof SocketChannel) { if (channel instanceof SocketChannel) {
UserConnection user = new VRClientSideUserConnection(channel); UserConnection user = new VRClientSideUserConnection(channel);
new ProtocolPipeline(user).add(new ClientSideReference());
MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder"); MessageToByteEncoder oldEncoder = (MessageToByteEncoder) channel.pipeline().get("encoder");
ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder"); ByteToMessageDecoder oldDecoder = (ByteToMessageDecoder) channel.pipeline().get("decoder");

View File

@ -27,7 +27,6 @@ package com.github.creeper123123321.viafabric.platform;
import com.github.creeper123123321.viafabric.ViaFabric; import com.github.creeper123123321.viafabric.ViaFabric;
import com.github.creeper123123321.viafabric.commands.NMSCommandSender; import com.github.creeper123123321.viafabric.commands.NMSCommandSender;
import com.github.creeper123123321.viafabric.commands.UserCommandSender; import com.github.creeper123123321.viafabric.commands.UserCommandSender;
import com.github.creeper123123321.viafabric.protocol.ClientSideReference;
import com.github.creeper123123321.viafabric.providers.VRVersionProvider; import com.github.creeper123123321.viafabric.providers.VRVersionProvider;
import com.github.creeper123123321.viafabric.util.FutureTaskId; import com.github.creeper123123321.viafabric.util.FutureTaskId;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@ -35,12 +34,15 @@ import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.packet.ChatMessageS2CPacket;
import net.minecraft.client.network.packet.DisconnectS2CPacket;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.network.OffThreadException;
import net.minecraft.network.chat.ChatMessageType; import net.minecraft.network.chat.ChatMessageType;
import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TextComponent;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaAPI; import us.myles.ViaVersion.api.ViaAPI;
import us.myles.ViaVersion.api.ViaVersionConfig; import us.myles.ViaVersion.api.ViaVersionConfig;
@ -49,9 +51,7 @@ import us.myles.ViaVersion.api.configuration.ConfigurationProvider;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.platform.TaskId; import us.myles.ViaVersion.api.platform.TaskId;
import us.myles.ViaVersion.api.platform.ViaPlatform; import us.myles.ViaVersion.api.platform.ViaPlatform;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.dump.PluginInfo;
import us.myles.ViaVersion.exception.CancelException;
import us.myles.ViaVersion.protocols.base.VersionProvider; import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
import us.myles.ViaVersion.sponge.VersionInfo; import us.myles.ViaVersion.sponge.VersionInfo;
@ -198,16 +198,7 @@ public class VRPlatform implements ViaPlatform {
public void sendMessage(UUID uuid, String s) { public void sendMessage(UUID uuid, String s) {
UserConnection user = Via.getManager().getPortedPlayers().get(uuid); UserConnection user = Via.getManager().getPortedPlayers().get(uuid);
if (user instanceof VRClientSideUserConnection) { if (user instanceof VRClientSideUserConnection) {
PacketWrapper chat = new PacketWrapper(0x0E, null, user); sendMessageClient(s);
chat.write(Type.STRING, ChatRewriter.legacyTextToJson(s));
chat.write(Type.BYTE, (byte) 0); // Position chat box
try {
chat.send(ClientSideReference.class);
} catch (CancelException e) {
// Ignore
} catch (Exception e) {
e.printStackTrace();
}
} else { } else {
runSync(() -> { runSync(() -> {
MinecraftServer server = getServer(); MinecraftServer server = getServer();
@ -219,18 +210,24 @@ public class VRPlatform implements ViaPlatform {
} }
} }
@Environment(EnvType.CLIENT)
private void sendMessageClient(String s) {
ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
if (handler != null) {
try {
handler.onChatMessage(new ChatMessageS2CPacket(
TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(s))
));
} catch (OffThreadException ignored) {
}
}
}
@Override @Override
public boolean kickPlayer(UUID uuid, String s) { public boolean kickPlayer(UUID uuid, String s) {
UserConnection user = Via.getManager().getPortedPlayers().get(uuid); UserConnection user = Via.getManager().getPortedPlayers().get(uuid);
if (user instanceof VRClientSideUserConnection) { if (user instanceof VRClientSideUserConnection) {
PacketWrapper chat = new PacketWrapper(0x1B, null, user); return kickClient(s);
chat.write(Type.STRING, ChatRewriter.legacyTextToJson(s));
try {
chat.sendFuture(ClientSideReference.class).addListener(future -> user.getChannel().close());
return true;
} catch (Exception e) {
e.printStackTrace();
}
} else { } else {
MinecraftServer server = getServer(); MinecraftServer server = getServer();
if (server != null && server.isOnThread()) { if (server != null && server.isOnThread()) {
@ -242,6 +239,21 @@ public class VRPlatform implements ViaPlatform {
return false; return false;
} }
@Environment(EnvType.CLIENT)
private boolean kickClient(String msg) {
ClientPlayNetworkHandler handler = MinecraftClient.getInstance().getNetworkHandler();
if (handler != null) {
try {
handler.onDisconnect(new DisconnectS2CPacket(
TextComponent.Serializer.fromJsonString(ChatRewriter.legacyTextToJson(msg))
));
} catch (OffThreadException ignored) {
}
return true;
}
return false;
}
@Override @Override
public boolean isPluginEnabled() { public boolean isPluginEnabled() {
return true; return true;

View File

@ -1,52 +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.protocol;
import com.google.common.base.Joiner;
import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import java.nio.charset.StandardCharsets;
import java.util.LinkedList;
import java.util.List;
public class ClientSideReference extends Protocol {
@Override
protected void registerPackets() {
}
@Override
public void init(UserConnection userConnection) {
}
}