Skip to content

Commit

Permalink
Merge pull request #6 from 3093FengMing/patch-1
Browse files Browse the repository at this point in the history
Update VMTranslationUpdate.java
  • Loading branch information
Wulian233 authored Nov 19, 2023
2 parents 8e841f6 + d0feba2 commit 34683ca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.slf4j.LoggerFactory;
import top.vmctcn.vmtranslationupdate.util.*;

import java.io.File;
import java.nio.file.Files;
import java.util.Locale;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
Expand All @@ -35,46 +35,48 @@ public static void init() {
random = new Random();
PackDownloadUtil.downloadResPack();
ClientTickEvent.CLIENT_POST.register((client) -> {
if (client.player == null) return;
tickCounter++;
int tickInterval = 20 * 60 * TipsUtil.getMinutes();
if (tickCounter >= tickInterval) {
tickCounter = 0;
CompletableFuture.supplyAsync(() -> TipsUtil.getRandomMessageFromURLAsync(ModConfigUtil.getConfig().tipsUrl))
.thenAccept(message -> {
String randomMessage = TipsUtil.getRandomMessageFromURL(ModConfigUtil.getConfig().tipsUrl);
if (message != null) {
if (client.player != null) {
client.player.sendSystemMessage(new TranslatableText(randomMessage), Util.NIL_UUID);
}
}
});
.thenAccept(message -> {
if (message == null) return;
String randomMessage = TipsUtil.getRandomMessageFromURL(ModConfigUtil.getConfig().tipsUrl);
client.player.sendSystemMessage(new TranslatableText(randomMessage), Util.NIL_UUID);
});
}

});

NameUtil.init();
if (ModConfigUtil.getConfig().updateUrl.length() > 0) {
PlayerEvent.PLAYER_JOIN.register((player) -> {
String localVersion = ModConfigUtil.getConfig().translationVersion;
String onlineVersion = VersionCheckUtil.getOnlineVersion(player);
if (ModConfigUtil.getConfig().updateUrl.isEmpty()) return;
PlayerEvent.PLAYER_JOIN.register((player) -> {
String localVersion = ModConfigUtil.getConfig().translationVersion;
String onlineVersion = VersionCheckUtil.getOnlineVersion(player);

if (!localVersion.equals(onlineVersion)) {
Text message = new TranslatableText("vmtranslationupdate.message.update2")
.append(new TranslatableText(ModConfigUtil.getConfig().downloadUrl).setStyle(
Style.EMPTY
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, ModConfigUtil.getConfig().downloadUrl))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("vmtranslationupdate.message.hover")))
.withColor(Formatting.AQUA)
))
.append(new TranslatableText("vmtranslationupdate.message.update3"));

player.sendSystemMessage(message, Util.NIL_UUID);
}

if (new File(PackDownloadUtil.resourcePackDir.toFile(), PackDownloadUtil.resourcePackName).exists()
&& !client.options.resourcePacks.contains(PackDownloadUtil.resourcePackName) && !client.options.resourcePacks.contains("file/" + PackDownloadUtil.resourcePackName)) {
Text message = new TranslatableText("vmtranslationupdate.message.pack", ModConfigUtil.getConfig().packName).setStyle(Style.EMPTY.withColor(Formatting.GOLD));
player.sendSystemMessage(message, Util.NIL_UUID);
}
});
}
if (localVersion.equals(onlineVersion)
&& Files.exists(PackDownloadUtil.resourcePackDir)
&& !client.options.resourcePacks.contains(PackDownloadUtil.resourcePackName)
&& !client.options.resourcePacks.contains("file/" + PackDownloadUtil.resourcePackName)) {
Text message = new TranslatableText("vmtranslationupdate.message.pack", ModConfigUtil.getConfig().packName)
.setStyle(Style.EMPTY.withColor(Formatting.GOLD));
player.sendSystemMessage(message, Util.NIL_UUID);

} else if (!localVersion.equals(onlineVersion)) {
Text message = new TranslatableText("vmtranslationupdate.message.update2")
.append(new TranslatableText(ModConfigUtil.getConfig().downloadUrl)
.setStyle(Style.EMPTY
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, ModConfigUtil.getConfig().downloadUrl))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("vmtranslationupdate.message.hover")))
.withColor(Formatting.AQUA)
))
.append(new TranslatableText("vmtranslationupdate.message.update3"));
player.sendSystemMessage(message, Util.NIL_UUID);
}

});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public static void init() {
String onlineVersion = VersionCheckUtil.getOnlineVersion(player);
name = "岷叔";
player.sendSystemMessage(new TranslatableText("vmtranslationupdate.message.zimin"), Util.NIL_UUID);
if (!localVersion.equals(onlineVersion) && ModConfigUtil.getConfig().updateUrl.length() > 0) {
if (!localVersion.equals(onlineVersion) && !ModConfigUtil.getConfig().updateUrl.isEmpty()) {
player.sendSystemMessage(new TranslatableText("vmtranslationupdate.message.update", name, localVersion, VersionCheckUtil.getOnlineVersion(player)), Util.NIL_UUID);
}
}else {
if (ModConfigUtil.getConfig().updateUrl.length() > 0) {
} else {
if (!ModConfigUtil.getConfig().updateUrl.isEmpty()) {
try {
String onlineVersion = VersionCheckUtil.getOnlineVersion(player);
URL url = new URL(ModConfigUtil.getConfig().nameUrl);
Expand Down Expand Up @@ -56,4 +56,4 @@ public static void init() {
}
});
}
}
}

0 comments on commit 34683ca

Please sign in to comment.