Skip to content

Commit

Permalink
Remove some utils that no longer need to exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed May 21, 2024
1 parent 398da14 commit 4353c39
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/main/java/io/github/gaming32/worldhost/WorldHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
import net.minecraft.network.protocol.status.ServerStatus;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -415,7 +416,7 @@ public static void commandRegistrationHandler(CommandDispatcher<CommandSourceSta
}
ctx.getSource().sendFailure(Components.translatable(
"world-host.worldhost.tempip.failure",
Components.wrapInSquareBrackets(Components.literal("/worldhost ip")).withStyle(style -> style
ComponentUtils.wrapInSquareBrackets(Components.literal("/worldhost ip")).withStyle(style -> style
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/worldhost ip"))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.github.gaming32.worldhost.WorldHost;
import io.github.gaming32.worldhost.protocol.proxy.ProxyPassthrough;
import io.github.gaming32.worldhost.toast.WHToast;
import io.github.gaming32.worldhost.versions.Components;
import net.minecraft.network.chat.Component;
import org.apache.commons.io.input.BoundedInputStream;
import org.apache.commons.io.input.CountingInputStream;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -64,7 +64,7 @@ public ProtocolClient(String host, boolean successToast, boolean failureToast) {
WorldHost.LOGGER.error("Failed to connect to {}.", target, e);
if (failureToast) {
WHToast.builder("world-host.wh_connect.connect_failed")
.description(Components.nullToEmpty(e.getLocalizedMessage()))
.description(Component.nullToEmpty(e.getLocalizedMessage()))
.show();
}
if (socket != null) {
Expand All @@ -74,7 +74,7 @@ public ProtocolClient(String host, boolean successToast, boolean failureToast) {
WorldHost.LOGGER.error("Failed to close WH socket", e1);
if (failureToast) {
WHToast.builder("world-host.wh_connect.close_failed")
.description(Components.nullToEmpty(e1.getLocalizedMessage()))
.description(Component.nullToEmpty(e1.getLocalizedMessage()))
.show();
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public ProtocolClient(String host, boolean successToast, boolean failureToast) {
WorldHost.LOGGER.error("Failed to close WH socket.", e);
if (WorldHost.CONFIG.isEnableReconnectionToasts()) {
WHToast.builder("world-host.wh_connect.close_failed")
.description(Components.nullToEmpty(e.getLocalizedMessage()))
.description(Component.nullToEmpty(e.getLocalizedMessage()))
.show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.network.chat.ClickEvent;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentUtils;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;

Expand Down Expand Up @@ -37,30 +38,22 @@ public static MutableComponent translatable(@Translatable(foldMethod = true) Str
}

public static MutableComponent translatable(@Translatable(foldMethod = true) String key, Object... args) {
//#if MC >= 1.20.3
return Component.translatableEscape(key, args);
//#elseif MC >= 1.19.1
//$$ return Component.translatable(key, args);
//#if MC >= 1.19.1
return Component.translatable(key, args);
//#else
//$$ return new TranslatableComponent(key, args);
//#endif
}

public static Component nullToEmpty(String text) {
return Component.nullToEmpty(text);
}

// TODO: Remove when 1.19.2 becomes the minimum
public static MutableComponent empty() {
return EMPTY.copy();
}

public static MutableComponent wrapInSquareBrackets(Component toWrap) {
return translatable("chat.square_brackets", toWrap);
}

// TODO: Remove when 1.19.4 becomes the minimum
public static MutableComponent copyOnClickText(Object obj) {
final String text = obj.toString();
return wrapInSquareBrackets(
return ComponentUtils.wrapInSquareBrackets(
literal(text).withStyle(style -> style
.withColor(ChatFormatting.GREEN)
.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, text))
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/assets/world-host/lang/be_by.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@
"world-host.play_world": "Гуляць у свет",
"world-host.share_world": "Падзяліцца светам",
"world-host.share_world.failed": "Не атрымалася падзяліцца светам",
"world-host.create_world": "Стварыць свет",
"chat.square_brackets": "[%s]"
"world-host.create_world": "Стварыць свет"
}
2 changes: 0 additions & 2 deletions src/main/resources/assets/world-host/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"world-host.config.onlineStatusLocation.off": "Aus",
"world-host.config.enableFriends": "Aktiviere Freunde",
"world-host.config.enableFriends.tooltip": "Aktiviert alle auf Freunde bezogenen GUIs und das gesamte Freundesystem.\nWenn du es deaktivierst und wieder aktivierst, sind alle deine Freunde noch da.",
"world-host.config.enableReconnectionToasts": "Enable Reconnection Toasts",
"world-host.config.noUPnP": "UPnP nicht ausprobieren",
"world-host.config.noUPnP.tooltip": "UPnP ist ein Mechanismus, der für eine direkte Verbindung verwendet werden kann. Allerdings treten dabei manchmal seltsame Probleme auf.\nAktiviere diese Einstellung, wenn Leute Probleme haben, sich über die Freundesliste oder Tempip mit dir zu verbinden.",
"world-host.config.useShortIp": "Kurze IP verwenden",
Expand Down Expand Up @@ -56,7 +55,6 @@
"world-host.joining_world_host": "Verbinde zu World Host world...",
"world-host.connection_not_found": "Welt konnte nicht gefunden werden",
"world-host.connection_not_found.desc": "World Host Welt %s konnte nicht gefunden werden.",
"chat.square_brackets": "[%s]",
"world-host.config.enableReconnectionToasts": "Reconnection Toasts aktivieren",
"world-host.config.shareButton": "Teilen-Button",
"world-host.config.shareButton.tooltip": "Zeigt einen \"Welt teilen\" Button neben dem \"Welt spielen\" Button im Einzelspieler-Menü an.\nDies aktiviert auch Shift+Doppelklick, um eine Welt zu teilen.",
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/assets/world-host/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@
"world-host.play_world": "Play World",
"world-host.share_world": "Share World",
"world-host.share_world.failed": "Failed to share world",
"world-host.create_world": "Create World",
"chat.square_brackets": "[%s]"
"world-host.create_world": "Create World"
}
2 changes: 1 addition & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ dependencies {
}
}

compileOnly("com.demonwav.mcdev:annotations:2.0.0")
compileOnly("com.demonwav.mcdev:annotations:2.1.0")
}

preprocess {
Expand Down

0 comments on commit 4353c39

Please sign in to comment.