Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from RealMuffinTime/master
Browse files Browse the repository at this point in the history
Quality of life improvents :)
  • Loading branch information
Northernside authored Jan 25, 2024
2 parents 917c2ff + f8b439c commit 4d7886d
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 135 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: LabyAddon Build
name: Build LabyAddon UUIDCollector

on:
push:
Expand Down
1 change: 0 additions & 1 deletion addon-template
Submodule addon-template deleted from 719e7f
11 changes: 7 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ labyMod {
addonInfo {
namespace = "uuidcollector"
displayName = "UUIDCollector"
author = "Northernside, Bisou"
author = "Northernside, Bisou, RealMuffinTime"
description = "Collects UUIDs on servers and sends them to an external endpoint."
minecraftVersion = "*"
version = "1.1.0"
version = getVersion().toString()
}

minecraft {
Expand All @@ -29,7 +29,10 @@ labyMod {
"1.18.2",
"1.19.2",
"1.19.3",
"1.19.4"
"1.19.4",
"1.20.1",
"1.20.2",
"1.20.4"
) { version, provider ->
configureRun(provider, version)
}
Expand All @@ -42,7 +45,7 @@ labyMod {
}

addonDev {
snapshotRelease()
productionRelease()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
// Shit Code, idc. Open up a PR if you want to clean up my code <3
// Here it is. :)

// TODO unify endpoints with UUIDCollectorBackend
// TODO check url/key for validity after modified

package de.northernside.uuidcollector;

import de.northernside.uuidcollector.hud.InCollectionHUD;
import de.northernside.uuidcollector.hud.OnServerHUD;
import de.northernside.uuidcollector.listener.PlayerInfoAddListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import de.northernside.uuidcollector.listener.ServerDisconnectListener;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.labymod.api.Laby;
import net.labymod.api.addon.LabyAddon;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.models.addon.annotation.AddonMain;
import net.labymod.api.notification.Notification;

@AddonMain
public class UUIDCollector extends LabyAddon<UUIDCollectorConfiguration> {
Expand All @@ -33,52 +26,12 @@ public class UUIDCollector extends LabyAddon<UUIDCollectorConfiguration> {
protected void enable() {
this.registerSettingCategory();
this.registerListener(new PlayerInfoAddListener(this));
this.registerListener(new ServerDisconnectListener(this));
this.labyAPI().hudWidgetRegistry().register(new InCollectionHUD());
this.labyAPI().hudWidgetRegistry().register(new OnServerHUD());
this.logger().info("Enabled UUIDCollector Addon");

Thread updateStatsThread = new Thread(() -> {
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
Runnable toRun = () -> {
try {
URL url = new URL(configuration().collectionServer().get() + "key/"
+ configuration().authenticationKey().get() + "/length");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream inputStream = connection.getInputStream();

if (connection.getResponseCode() != 200) {
Notification errorNotification = Notification.builder()
.icon(Component.icon(
Icon.url("https://cdn.ebio.gg/logos/logo.png").aspectRatio(10, 10))
.getIcon())
.title(Component.text("Error " + connection.getResponseCode()))
.text(Component.text("The collection server responded with an error."))
.duration(4500)
.build();

Laby.labyAPI().minecraft().executeOnRenderThread(
() -> Laby.labyAPI().notificationController().push(errorNotification));
} else {
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
String inputLine;
StringBuilder response = new StringBuilder();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}

in.close();
OnServerHUD.updateOnServer(Integer.parseInt(response.toString()));
}
} catch (IOException exception) {
exception.printStackTrace();
}
};

scheduler.scheduleAtFixedRate(toRun, 1, 10, TimeUnit.SECONDS);
});
this.logger().info("Enabled UUIDCollector Addon.");

updateStatsThread.start();
this.configuration().getOnServer();
}

@Override
Expand Down
Loading

0 comments on commit 4d7886d

Please sign in to comment.