mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-11-22 11:45:47 +01:00
fix #124, some cleanup
This commit is contained in:
parent
042e6b1ed6
commit
b3735fc9c6
@ -0,0 +1,32 @@
|
||||
package com.viaversion.fabric.common.platform;
|
||||
|
||||
import com.viaversion.fabric.common.handler.CommonTransformer;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
public abstract class AbstractFabricInjector implements ViaInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
// *looks at Mixins*
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject() {
|
||||
// not possible *plays sad violin*
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getDump() {
|
||||
return new JsonObject();
|
||||
}
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
package com.viaversion.fabric.mc114.commands;
|
||||
|
||||
import io.github.cottonmc.clientcommands.CottonClientCommandSource;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
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;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -29,8 +31,9 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
} else if (source instanceof CottonClientCommandSource) {
|
||||
((CottonClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
|
||||
&& source instanceof ClientCommandSource) {
|
||||
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +46,8 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
Entity entity = ((ServerCommandSource) source).getEntity();
|
||||
if (entity != null) return entity.getUuid();
|
||||
} else if (source instanceof CottonClientCommandSource) {
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
|
||||
&& source instanceof ClientCommandSource) {
|
||||
return MinecraftClient.getInstance().player.getUuid();
|
||||
}
|
||||
return UUID.fromString(getName());
|
||||
@ -53,7 +57,8 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
public String getName() {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
return ((ServerCommandSource) source).getName();
|
||||
} else if (source instanceof CottonClientCommandSource) {
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT
|
||||
&& source instanceof ClientCommandSource) {
|
||||
return MinecraftClient.getInstance().player.getEntityName();
|
||||
}
|
||||
return "?";
|
||||
|
@ -1,61 +1,11 @@
|
||||
package com.viaversion.fabric.mc114.platform;
|
||||
|
||||
import com.viaversion.fabric.common.handler.CommonTransformer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import com.viaversion.fabric.common.platform.AbstractFabricInjector;
|
||||
import net.minecraft.SharedConstants;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricInjector implements ViaInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
// *looks at Mixins*
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject() {
|
||||
// not possible *plays sad violin*
|
||||
}
|
||||
|
||||
public class FabricInjector extends AbstractFabricInjector {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getDump() {
|
||||
JsonObject obj = new JsonObject();
|
||||
try {
|
||||
obj.add("serverNetworkIOChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_3242$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
try {
|
||||
obj.add("clientConnectionChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_2535$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
package com.viaversion.fabric.mc115.commands;
|
||||
|
||||
import io.github.cottonmc.clientcommands.CottonClientCommandSource;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
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;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -29,8 +31,8 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
public void sendMessage(String s) {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
((ServerCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
} else if (source instanceof CottonClientCommandSource) {
|
||||
((CottonClientCommandSource) source).sendFeedback(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
MinecraftClient.getInstance().player.addChatMessage(Text.Serializer.fromJson(legacyToJson(s)), false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +45,7 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
Entity entity = ((ServerCommandSource) source).getEntity();
|
||||
if (entity != null) return entity.getUuid();
|
||||
} else if (source instanceof CottonClientCommandSource) {
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
return MinecraftClient.getInstance().player.getUuid();
|
||||
}
|
||||
return UUID.fromString(getName());
|
||||
@ -53,7 +55,7 @@ public class NMSCommandSender implements ViaCommandSender {
|
||||
public String getName() {
|
||||
if (source instanceof ServerCommandSource) {
|
||||
return ((ServerCommandSource) source).getName();
|
||||
} else if (source instanceof CottonClientCommandSource) {
|
||||
} else if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT && source instanceof ClientCommandSource) {
|
||||
return MinecraftClient.getInstance().player.getEntityName();
|
||||
}
|
||||
return "?";
|
||||
|
@ -1,61 +1,11 @@
|
||||
package com.viaversion.fabric.mc115.platform;
|
||||
|
||||
import com.viaversion.fabric.common.handler.CommonTransformer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import com.viaversion.fabric.common.platform.AbstractFabricInjector;
|
||||
import net.minecraft.SharedConstants;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricInjector implements ViaInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
// *looks at Mixins*
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject() {
|
||||
// not possible *plays sad violin*
|
||||
}
|
||||
|
||||
public class FabricInjector extends AbstractFabricInjector {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getDump() {
|
||||
JsonObject obj = new JsonObject();
|
||||
try {
|
||||
obj.add("serverNetworkIOChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_3242$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
try {
|
||||
obj.add("clientConnectionChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_2535$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +1,11 @@
|
||||
package com.viaversion.fabric.mc116.platform;
|
||||
|
||||
import com.viaversion.fabric.common.handler.CommonTransformer;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import com.viaversion.fabric.common.platform.AbstractFabricInjector;
|
||||
import net.minecraft.SharedConstants;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricInjector implements ViaInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
// *looks at Mixins*
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject() {
|
||||
// not possible *plays sad violin*
|
||||
}
|
||||
|
||||
public class FabricInjector extends AbstractFabricInjector {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getDump() {
|
||||
JsonObject obj = new JsonObject();
|
||||
try {
|
||||
obj.add("serverNetworkIOChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_3242$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
try {
|
||||
obj.add("clientConnectionChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_2535$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,22 @@
|
||||
package com.viaversion.fabric.mc117.platform;
|
||||
|
||||
import com.viaversion.fabric.common.handler.CommonTransformer;
|
||||
import com.viaversion.fabric.common.platform.AbstractFabricInjector;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.SharedConstants;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricInjector implements ViaInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
// *looks at Mixins*
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject() {
|
||||
// not possible *plays sad violin*
|
||||
}
|
||||
|
||||
public class FabricInjector extends AbstractFabricInjector {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
@ -1,29 +1,13 @@
|
||||
package com.viaversion.fabric.mc18.platform;
|
||||
|
||||
import com.viaversion.fabric.common.handler.CommonTransformer;
|
||||
import com.viaversion.fabric.common.platform.AbstractFabricInjector;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.realms.RealmsSharedConstants;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class FabricInjector implements ViaInjector {
|
||||
@Override
|
||||
public void inject() {
|
||||
// *looks at Mixins*
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uninject() {
|
||||
// not possible *plays sad violin*
|
||||
}
|
||||
|
||||
public class FabricInjector extends AbstractFabricInjector {
|
||||
@Override
|
||||
public int getServerProtocolVersion() throws NoSuchFieldException, IllegalAccessException {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
@ -36,36 +20,4 @@ public class FabricInjector implements ViaInjector {
|
||||
private int getClientProtocol() throws NoSuchFieldException, IllegalAccessException {
|
||||
return RealmsSharedConstants.class.getField("NETWORK_PROTOCOL_VERSION").getInt(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoderName() {
|
||||
return CommonTransformer.HANDLER_ENCODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDecoderName() {
|
||||
return CommonTransformer.HANDLER_DECODER_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getDump() {
|
||||
JsonObject obj = new JsonObject();
|
||||
try {
|
||||
obj.add("serverNetworkIOChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_3242$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
try {
|
||||
obj.add("clientConnectionChInit", GsonUtil.getGson().toJsonTree(
|
||||
Arrays.stream(Class.forName("net.minecraft.class_2535$1").getDeclaredMethods())
|
||||
.map(Method::toString)
|
||||
.toArray(String[]::new)));
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user