Skip to content

Commit

Permalink
add auto publish + installer
Browse files Browse the repository at this point in the history
  • Loading branch information
l3nnartt committed Feb 8, 2022
1 parent 0c51d6d commit e5b6003
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,17 @@ jobs:
with:
name: Artifacts
path: build/libs/

- name: Create Tag
uses: mathieudutour/github-tag-action@v6.0
id: tag_version
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Create Release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: Release ${{ steps.tag_version.outputs.new_tag }}
artifacts: "build/libs/LouderVoiceChat.jar"
token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.text.SimpleDateFormat

buildscript {
repositories {
jcenter()
Expand Down Expand Up @@ -76,6 +78,18 @@ processResources {
}
}

jar {
manifest {
attributes(
'Manifest-Version': '1.0',
'Main-Class' : 'com.github.l3nnartt.loudervoicechat.Main',
'Build-Timestamp' : new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
'Created-By' : "Gradle ${gradle.gradleVersion}",
'Build-Jdk' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})"
)
}
}

reobf {
jar {
useNotchSrg()
Expand Down
125 changes: 125 additions & 0 deletions src/main/java/com/github/l3nnartt/loudervoicechat/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.github.l3nnartt.loudervoicechat;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.Locale;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class Main {

private static HashMap<String, String> lang = new HashMap<>();
private static Icon icon;

public static void main(String[] args) {
initLookAndFeel();
initLanguage();
try {
String dir = initDirectory();
if (!new File(dir).exists()) {
throw new IOException("No .minecraft/LabyMod directory found!");
}
if (showConfirmDialog(String.format(lang.get("installation"), "1.0"))) {
File run = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if (run.exists() && run.isFile()) {
for (String version : new String[] { "1.8" }) {
File addonsDir = new File(dir + "addons-" + version);
addonsDir.mkdirs();
File mod = new File(addonsDir, "LouderVoiceChat.jar");
if (!mod.exists()) {
for (File addons : addonsDir.listFiles()) {
if (addons.getName().toLowerCase().contains("LouderVoiceChat")) {
addons.delete();
}
}
}
Files.copy(run.toPath(), mod.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
showMessageDialog(lang.get("success"), 1);
} else {
throw new IOException("Invalid path: " + run.getAbsolutePath());
}
}
} catch (FileSystemException e) {
e.printStackTrace();
if (e.getReason() != null && !e.getReason().isEmpty()) {
showMessageDialog(lang.get("closed") + "\n" + e.getReason(), 0);
} else {
showMessageDialog(lang.get("error"), 0);
}
} catch (Exception e) {
e.printStackTrace();
showMessageDialog(lang.get("error"), 0);
}
}

private static void initLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
URL url = Main.class.getResource("/assets/minecraft/loudervoicechat/Logo.png");
icon = new ImageIcon(new ImageIcon(url).getImage().getScaledInstance(64, 64, 4));
} catch (Exception e) {
e.printStackTrace();
}
}

private static String initDirectory() {
String dir = System.getenv("APPDATA") + "/.minecraft/LabyMod/";
if (!new File(dir).exists()) {
dir = System.getProperty("user.home") + "/Library/Application Support/minecraft/LabyMod/";
}
if (!new File(dir).exists()) {
dir = System.getProperty("user.home") + "/.minecraft/LabyMod/";
}
return dir;
}

private static void initLanguage() {
if (Locale.getDefault().toString().toLowerCase().contains("de")) {
lang.put("installation",
"LouderVoiceChat v%s kann nun installiert werden!\nMinecraft muss bei der Installation geschlossen sein!");
lang.put("success", "LouderVoiceChat Installation abgeschlossen!");
lang.put("closed", "Ist Minecraft geschlossen?");
lang.put("error",
"Installation fehlgeschlagen!\nKopiere die Mod in das Verzeichnis .minecraft/LabyMod/addons und starte Minecraft!");
} else if (Locale.getDefault().toString().toLowerCase().contains("es")) {
lang.put("installation",
"¡Se puede instalar el LouderVoiceChat v%s ahora!\n¡Minecraft tiene que estar cerrador para instalarlo!");
lang.put("success", "La instalación del LouderVoiceChat a terminado");
lang.put("closed", "¿Minecraft está cerrado?");
lang.put("error",
"¡La instalación falló!\n¡Copiá la Mod en la carpeta .minecraft/LabyMod/addons y empezá a jugar!");
} else if (Locale.getDefault().toString().toLowerCase().contains("pt")) {
lang.put("installation",
"O LouderVoiceChat v%s está pronto para instalação!\nFeche o Minecraft antes de continuar!");
lang.put("success", "Instalação do LouderVoiceChat concluída!");
lang.put("closed", "O Minecraft está fechado?");
lang.put("error",
"Instalação falhou!\nCopie os arquivos para a pasta .minecraft/LabyMod/addons e abra o Minecraft!");
} else {
lang.put("installation",
"LouderVoiceChat v%s is now ready for installation!\nClose Minecraft before continuing!");
lang.put("success", "LouderVoiceChat installation finished!");
lang.put("closed", "Minecraft closed?");
lang.put("error",
"Installation failed!\nCopy the file into .minecraft/LabyMod/addons and start Minecraft!");
}
}

private static boolean showConfirmDialog(String msg) {
return JOptionPane.showConfirmDialog(null, msg, "LouderVoiceChat \u00a9 L3nnart_", 2, 1, icon) == 0;
}

private static void showMessageDialog(String msg, int mode) {
JOptionPane.showMessageDialog(null, msg, "LouderVoiceChat \u00a9 L3nnart_", mode);
}
}

// Provided by CosmeticsMod
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e5b6003

Please sign in to comment.