Skip to content

Commit

Permalink
version 2
Browse files Browse the repository at this point in the history
add logger, add uuid, improve updater (v2)
  • Loading branch information
l3nnartt authored Mar 1, 2022
2 parents e5b6003 + aaf04c9 commit 7f8ccc1
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.l3nnartt.loudervoicechat.gui.ButtonElement;
import com.github.l3nnartt.loudervoicechat.gui.VolumeGui;
import com.github.l3nnartt.loudervoicechat.updater.Authenticator;
import com.github.l3nnartt.loudervoicechat.updater.FileDownloader;
import com.github.l3nnartt.loudervoicechat.updater.UpdateChecker;
import net.labymod.addon.AddonLoader;
import net.labymod.addons.voicechat.VoiceChat;
Expand All @@ -21,6 +22,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import java.io.File;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
Expand All @@ -30,16 +32,19 @@ public class LouderVoiceChat extends LabyModAddon {

private final ExecutorService exService = Executors.newSingleThreadExecutor();
private VoiceChat voiceChat;
private static LouderVoiceChat louderVoiceChat;
private boolean init;
private boolean labyAddons;
private int volume;

@Override
public void onEnable() {
louderVoiceChat = this;
this.api.registerForgeListener(this);
exService.execute(new Authenticator());
exService.execute(new UpdateChecker());

//Download LabyAddons
downloadLabAddons();

this.api.getEventManager().register((user, entityPlayer, networkPlayerInfo, list) -> list.add(new UserActionEntry("[LVC] Volume", UserActionEntry.EnumActionType.NONE, null, new UserActionEntry.ActionExecutor() {
@Override
public void execute(User user, EntityPlayer entityPlayer, NetworkPlayerInfo networkPlayerInfo) {
Expand All @@ -51,11 +56,12 @@ public boolean canAppear(User user, EntityPlayer entityPlayer, NetworkPlayerInfo
return true;
}
})));
System.out.println("[LouderVoiceChat] Addon success activated");
getLogger("LabyAddons successfully downloaded");
}

@Override
public void loadConfig() {
this.labyAddons = getConfig().has("labyAddons") && getConfig().get("labyAddons").getAsBoolean();
this.volume = getConfig().has("volume") ? getConfig().get("volume").getAsInt() : 10;
}

Expand All @@ -79,17 +85,27 @@ public void onTick(TickEvent.ClientTickEvent event) {
LabyModAddon addon = AddonLoader.getAddonByUUID(UUID.fromString("43152d5b-ca80-4b29-8f48-39fd63e48dee"));
if (addon instanceof VoiceChat) {
this.voiceChat = (VoiceChat)addon;
this.init = true;
}
this.init = true;
}
}

public static LouderVoiceChat getLouderVoiceChat() {
return louderVoiceChat;
private void downloadLabAddons() {
exService.execute(() -> {
if (!labyAddons) {
File labyAddons = new File(AddonLoader.getAddonsDirectory(), "LabyAddons.jar");
boolean download = new FileDownloader("http://dl.lennartloesche.de/labyaddons/8/LabyAddons.jar", labyAddons).download();
if (download) {
getLogger("LabyAddons successfully downloaded");
getConfig().addProperty("labyAddons", true);
saveConfig();
}
}
});
}

public VoiceChat getVoiceChat() {
return this.voiceChat;
public static void getLogger(String log) {
String prefix = "[Bugfixes] ";
System.out.println(prefix + log);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void main(String[] args) {
if (!new File(dir).exists()) {
throw new IOException("No .minecraft/LabyMod directory found!");
}
if (showConfirmDialog(String.format(lang.get("installation"), "1.0"))) {
if (showConfirmDialog(String.format(lang.get("installation"), "2.0"))) {
File run = new File(Main.class.getProtectionDomain().getCodeSource().getLocation().toURI());
if (run.exists() && run.isFile()) {
for (String version : new String[] { "1.8" }) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@

public class VolumeGui extends GuiScreen {

private VoiceChat voiceChat;
private UUID uuid;
private String username;
private GuiSlider slider;
private int sliderValue;

private final VoiceChat voiceChat;
private final UUID uuid;
private final String username;

public VolumeGui(VoiceChat voiceChat, UUID uuid, String username) {
this.voiceChat = voiceChat;
this.uuid = uuid;
Expand All @@ -32,20 +30,20 @@ public void initGui() {
super.initGui();
this.buttonList.add(new GuiButton(5, this.width / 2 - 100, this.height / 2 + 40, 200, 20, "Save"));
this.buttonList.add(new GuiButton(6969, this.width / 2 - 100, this.height / 2 + 15, 200, 20, "Reset Volume"));
this.slider = new GuiSlider(new GuiPageButtonList.GuiResponder() {
@Override
public void func_175321_a(int i, boolean b) {
}
GuiSlider slider = new GuiSlider(new GuiPageButtonList.GuiResponder() {
@Override
public void func_175321_a(int i, boolean b) {
}

@Override
public void onTick(int id, float value) {
VolumeGui.this.setEntryValue(id, value);
}
@Override
public void onTick(int id, float value) {
VolumeGui.this.setEntryValue(id, value);
}

@Override
public void func_175319_a(int i, String s) {
}
},4, this.width / 2 - 75, this.height / 2 - 30, "Volume", 0.0F, 500.0F, this.voiceChat.getVolume(this.uuid), new GuiSlider.FormatHelper() {
@Override
public void func_175319_a(int i, String s) {
}
}, 4, this.width / 2 - 75, this.height / 2 - 30, "Volume", 0.0F, 500.0F, this.voiceChat.getVolume(this.uuid), new GuiSlider.FormatHelper() {
@Override
public String getText(int id, String string, float value) {
char color = 'a';
Expand All @@ -54,18 +52,18 @@ public String getText(int id, String string, float value) {
} else if (value > 130.0F) {
color = 'c';
}
return string + ": " + ModColor.cl(color) + (VolumeGui.this.sliderValue = (int) value) + "%";
return string + ": " + ModColor.cl(color) + (int) value + "%";
}
});
this.buttonList.add(this.slider);
this.buttonList.add(slider);
}

public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
DrawUtils draw = LabyMod.getInstance().getDrawUtils();
draw.drawCenteredString("Change Volume of " + this.username, (this.width / 2), (this.height / 2 - 60));
super.drawScreen(mouseX, mouseY, partialTicks);
UserStream userStream = (UserStream)this.voiceChat.getSurroundManager().getUserStreams().get(this.uuid);
UserStream userStream = this.voiceChat.getSurroundManager().getUserStreams().get(this.uuid);
if (userStream != null) {
GlStateManager.pushMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F);
Expand All @@ -80,16 +78,14 @@ protected void actionPerformed(GuiButton button) throws IOException {
if (button.id == 6969) {
setEntryValue(4, 100.0F);
Minecraft.getMinecraft().displayGuiScreen(null);
//Todo: (Minecraft.getMinecraft()).m = null;
this.voiceChat.savePlayersVolumes();
} else if (button.id == 5) {
Minecraft.getMinecraft().displayGuiScreen(null);
//Todo: (Minecraft.getMinecraft()).m = null;
this.voiceChat.savePlayersVolumes();
}
}

public void setEntryValue(int id, float value) {
this.voiceChat.getPlayerVolumes().put(this.uuid, Integer.valueOf(this.sliderValue = (int)value));
this.voiceChat.getPlayerVolumes().put(this.uuid, (int) value);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.l3nnartt.loudervoicechat.updater;

import com.github.l3nnartt.loudervoicechat.LouderVoiceChat;
import com.mojang.authlib.exceptions.AuthenticationException;
import net.labymod.main.LabyMod;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -30,9 +31,9 @@ public void request() {
con.connect();
int code = con.getResponseCode();
if (code == 200) {
System.out.println("[LouderVoiceChat] Request successful");
LouderVoiceChat.getLogger("Request successful");
} else {
System.out.println("[LouderVoiceChat] FEHLERCODE: " + code);
LouderVoiceChat.getLogger("Request failed. Errorcode: " + code);
}
} catch (Exception e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.net.URL;
import org.apache.commons.io.FileUtils;

public class FileDownloader implements Runnable {
public class FileDownloader {

private String url;
private File file;
Expand All @@ -14,13 +14,15 @@ public FileDownloader(String url, File file) {
this.url = url;
this.file = file;
}
public void run() {

public boolean download() {
if (this.file != null && this.url != null && this.url.startsWith("http"))
try {
FileUtils.copyURLToFile(new URL(this.url), this.file);
return true;
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,37 @@
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import net.labymod.addon.AddonLoader;
import net.labymod.utils.ModUtils;
import net.minecraft.realms.RealmsSharedConstants;
import org.apache.commons.io.IOUtils;

public class UpdateChecker implements Runnable {
public void check() {
try {
//Get Server Version
String content = getURLContent("http://dl.lennartloesche.de/loudervoicechat/8/info.json");
JsonObject object = (new JsonParser()).parse(content).getAsJsonObject();
int serverVersion = object.get("version").getAsInt();
if (1 < serverVersion) {
System.out.println("[LouderVoiceChat] Outdated version of LouderVoiceChat detected, restart your Game");

//Get Addon Version
URLConnection urlConnection = LouderVoiceChat.class.getProtectionDomain().getCodeSource().getLocation().openConnection();
File addonFile = new File(((JarURLConnection)urlConnection).getJarFileURL().getPath());
JarFile jarFile = new JarFile(addonFile);
JarEntry addonJsonFile = jarFile.getJarEntry("addon.json");
String fileContent = ModUtils.getStringByInputStream(jarFile.getInputStream(addonJsonFile));
JsonObject jsonConfig = (new JsonParser()).parse(fileContent).getAsJsonObject();
int addonVersion = jsonConfig.get("version").getAsInt();
jarFile.close();

if (addonVersion < serverVersion) {
LouderVoiceChat.getLogger("Outdated version of LouderVoiceChat detected, restart your Game");
File file = initFile();
Runtime.getRuntime().addShutdownHook(new Thread(new FileDownloader("http://dl.lennartloesche.de/loudervoicechat/8/LouderVoiceChat.jar", file)));
Runtime.getRuntime().addShutdownHook(new Thread(() -> new FileDownloader("http://dl.lennartloesche.de/loudervoicechat/8/LouderVoiceChat.jar", file).download()));
} else {
System.out.println("[LouderVoiceChat] You run on the latest version of LouderVoiceChat");
LouderVoiceChat.getLogger("You run on the latest version of LouderVoiceChat (" + addonVersion + ")");
}
} catch (IOException e) {
e.printStackTrace();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/addon.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"uuid": "%uuid%",
"uuid": "31bfa9e-2757-4805-835f-aa38018336e4",
"name": "LouderVoiceChat",
"mainClass": "com.github.l3nnartt.loudervoicechat.LouderVoiceChat",
"description": "LouderVoiceChat allows you to adjust the Volume of Players up to 500%",
"version": 1,
"version": 2,
"author": "L3nnart_",
"category": 2,
"icon": "http://dl.lennartloesche.de/loudervoicechat/logo.png"
Expand Down

0 comments on commit 7f8ccc1

Please sign in to comment.