This repository has been archived by the owner on Jan 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eadf417
commit 5c72d99
Showing
5 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/org/cfpa/i18nupdatemod/notice/NoticeButton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.cfpa.i18nupdatemod.notice; | ||
|
||
import net.minecraft.client.gui.GuiButton; | ||
|
||
import java.awt.*; | ||
import java.net.URI; | ||
|
||
public class NoticeButton extends GuiButton { | ||
public NoticeButton(int buttonId, int x, int y, String buttonText) { | ||
super(buttonId, x, y, 200, 20, buttonText); | ||
} | ||
|
||
public void mouseReleased(int mouseX, int mouseY) { | ||
String url = "https://github.com/CFPAOrg/Minecraft-Mod-Language-Package#%E4%BB%93%E5%BA%93%E8%AF%B4%E6%98%8E"; | ||
try { | ||
Desktop.getDesktop().browse(new URI(url)); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/main/java/org/cfpa/i18nupdatemod/notice/ShowNoticeFirst.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package org.cfpa.i18nupdatemod.notice; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.util.text.TextComponentTranslation; | ||
import net.minecraftforge.client.event.RenderGameOverlayEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
import org.apache.commons.io.IOUtils; | ||
import org.cfpa.i18nupdatemod.I18nUpdateMod; | ||
|
||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
@Mod.EventBusSubscriber(modid = I18nUpdateMod.MODID) | ||
public class ShowNoticeFirst { | ||
@SubscribeEvent | ||
@SideOnly(Side.CLIENT) | ||
public static void onPlayerFirstJoin(RenderGameOverlayEvent.Post event) throws InterruptedException { | ||
if (event.getType() != RenderGameOverlayEvent.ElementType.HOTBAR || fileIsExist()) { | ||
return; | ||
} | ||
showNotice(); | ||
} | ||
|
||
private static List<String> strings; | ||
|
||
public static void showNotice() { | ||
new Thread(() -> { | ||
try { | ||
createFile(); // 创建证明文件 | ||
Thread.sleep(1000); // 手榴弹,都给我延时 1 秒丢出去 | ||
URL url = new URL("http://p985car2i.bkt.clouddn.com/Notice.txt"); | ||
strings = IOUtils.readLines(url.openStream(), StandardCharsets.UTF_8); | ||
onDone(); | ||
} catch (Throwable e) { | ||
catching(e); | ||
} | ||
}, "I18n_NOTICE_PENDING_THREAD").start(); | ||
} | ||
|
||
private static void onDone() { | ||
Minecraft.getMinecraft().displayGuiScreen(new NoticeGui(strings)); | ||
} | ||
|
||
private static void catching(Throwable e) { | ||
Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("获取公告失败。")); | ||
I18nUpdateMod.logger.error("获取公告失败:", e); | ||
} | ||
|
||
private static void createFile() { | ||
Minecraft mc = Minecraft.getMinecraft(); | ||
File file = new File(mc.mcDataDir.getPath() + File.separator + "config" + File.separator + I18nUpdateMod.MODID + ".txt"); | ||
try { | ||
FileOutputStream fos = new FileOutputStream(file); | ||
IOUtils.write("你看到这个文件时候,说明你已经不是第一次使用该模组了", fos, "UTF-8"); | ||
fos.close(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private static boolean fileIsExist() { | ||
Minecraft mc = Minecraft.getMinecraft(); | ||
File file = new File(mc.mcDataDir.getPath() + File.separator + "config" + File.separator + I18nUpdateMod.MODID + ".txt"); | ||
if (file.exists()) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 英文?英文是不存在的 | ||
key.category.i18nmod=汉化更新模组键位设定 | ||
key.report_key.desc=报告键 |