Skip to content

Commit

Permalink
Updated Via API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Dec 29, 2023
1 parent 9bc6fb9 commit d6386bf
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 29 deletions.
11 changes: 0 additions & 11 deletions src/main/java/com/viaversion/fabric/common/util/RemappingUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.viaversion.fabric.common.util;

import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;

public class RemappingUtil {
public static int swordId(String id) {
// https://github.com/ViaVersion/ViaVersion/blob/8de26a0ad33f5b739f5394ed80f69d14197fddc7/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java#L86
Expand All @@ -21,12 +18,4 @@ public static int swordId(String id) {
return 0;
}

private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.builder()
.character('§')
.extractUrls()
.build();

public static String legacyToJson(String legacy) {
return GsonComponentSerializer.gson().serialize(LEGACY_SERIALIZER.deserialize(legacy));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.viaversion.fabric.mc114.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
Expand All @@ -28,7 +28,7 @@ public boolean hasPermission(String s) {
}

public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serializer.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.viaversion.fabric.mc115.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
Expand All @@ -28,7 +28,7 @@ public boolean hasPermission(String s) {
}

public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serializer.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.viaversion.fabric.mc116.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
Expand All @@ -25,7 +25,7 @@ public boolean hasPermission(String s) {
}

public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serializer.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.viaversion.fabric.mc117.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
Expand All @@ -26,7 +26,7 @@ public boolean hasPermission(String s) {
}

public static MutableText fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serializer.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.viaversion.fabric.mc118.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
Expand All @@ -25,7 +25,7 @@ public boolean hasPermission(String s) {
}

public static Text fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serializer.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.viaversion.fabric.mc119.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
Expand All @@ -26,7 +26,7 @@ public boolean hasPermission(String s) {
}

public static MutableText fromLegacy(String legacy) {
return Text.Serializer.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serializer.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.viaversion.fabric.mc120.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
Expand All @@ -26,7 +26,7 @@ public boolean hasPermission(String s) {
}

public static MutableText fromLegacy(String legacy) {
return Text.Serialization.fromJson(RemappingUtil.legacyToJson(legacy));
return Text.Serialization.fromJson(ComponentUtil.legacyToJsonString(legacy));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.viaversion.fabric.mc18.commands;

import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.util.ComponentUtil;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
Expand All @@ -24,7 +24,7 @@ public boolean hasPermission(String s) {

@Override
public void sendMessage(String s) {
source.sendMessage(Text.Serializer.deserialize(RemappingUtil.legacyToJson(s)));
source.sendMessage(Text.Serializer.deserialize(ComponentUtil.legacyToJsonString(s)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.viaversion.fabric.common.platform.NativeVersionProvider;
import com.viaversion.fabric.common.provider.AbstractFabricPlatform;
import com.viaversion.fabric.common.util.FutureTaskId;
import com.viaversion.fabric.common.util.RemappingUtil;
import com.viaversion.fabric.mc18.ViaFabric;
import com.viaversion.fabric.mc18.commands.NMSCommandSender;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.command.ViaCommandSender;
import com.viaversion.viaversion.util.ComponentUtil;
import io.netty.channel.EventLoop;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
Expand Down Expand Up @@ -106,7 +106,7 @@ private void sendMessageServer(UUID uuid, String s) {
runServerSync(() -> {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
if (player == null) return;
player.sendMessage(Text.Serializer.deserialize(RemappingUtil.legacyToJson(s)));
player.sendMessage(Text.Serializer.deserialize(ComponentUtil.legacyToJsonString(s)));
});
}

Expand Down

0 comments on commit d6386bf

Please sign in to comment.