Skip to content

Commit

Permalink
Compat with BMFloodgate + bStats & UpdateChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
TechnicJelle committed May 3, 2023
1 parent e7d2c1d commit ef3f21c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.technicjelle</groupId>
<artifactId>BlueMapCustomSkinProvider</artifactId>
<version>1.0</version>
<version>1.1</version>
<packaging>jar</packaging>

<name>BlueMapCustomSkinProvider</name>
Expand All @@ -33,6 +33,14 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>com.technicjelle.bluemapfloodgate</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
Expand Down Expand Up @@ -88,5 +96,11 @@
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.bluecolored.bluemap.api.BlueMapAPI;
import de.bluecolored.bluemap.api.plugin.SkinProvider;
import org.bstats.bukkit.Metrics;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

Expand All @@ -24,12 +25,17 @@ public final class BlueMapCustomSkinProvider extends JavaPlugin {

@Override
public void onEnable() {
new Metrics(this, 18368);

UpdateChecker.check("TechnicJelle", "BlueMapCustomSkinProvider", getDescription().getVersion());

BlueMapAPI.onEnable(blueMapOnEnableListener);

getLogger().info("BlueMapCustomSkinProvider plugin enabled!");
}

private final Consumer<BlueMapAPI> blueMapOnEnableListener = blueMapAPI -> {
UpdateChecker.logUpdateMessage(getLogger());

// Setup config
if(getDataFolder().mkdirs()) getLogger().info("Created plugin config directory");
Expand All @@ -49,15 +55,15 @@ public void onEnable() {
//Load config values into variables
String url = getConfig().getString("url");

SkinProvider floodgateSkinProvider = playerUUID -> {
SkinProvider customSkinProvider = playerUUID -> {
String username = getServer().getOfflinePlayer(playerUUID).getName();
String localUrl = url.replace("{UUID}", playerUUID.toString()).replace("{USERNAME}", username);
getLogger().info("Downloading skin for " + username + " from " + localUrl);
BufferedImage img = imageFromURL(localUrl);
return Optional.ofNullable(img);
};

blueMapAPI.getPlugin().setSkinProvider(floodgateSkinProvider);
blueMapAPI.getPlugin().setSkinProvider(customSkinProvider);
};


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//TechnicJelle's GitHub Update Checker v1
package com.technicjelle.bluemapcustomskinprovider;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;

@SuppressWarnings("SameParameterValue")
public class UpdateChecker {
private static boolean updateAvailable = false;
private static URL url = null;
private static String latestVersion = null;
private static String curVer = null;


static void check(String author, String name, String currentVersion) {
curVer = currentVersion;
new Thread(() -> {
try {
url = new URL("https://github.com/"+author+"/"+name+"/releases/latest");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}

HttpURLConnection con;
try {
con = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
throw new RuntimeException(e);
}
con.setInstanceFollowRedirects(false);

String newUrl = con.getHeaderField("Location");

if(newUrl == null) {
throw new RuntimeException("Did not get a redirect");
}

String[] split = newUrl.split("/");
latestVersion = split[split.length - 1].replace("v", "");

if (!latestVersion.equals(curVer)) updateAvailable = true;
}, name + "-Update-Checker").start();
}

static void logUpdateMessage(Logger logger) {
if (updateAvailable) {
logger.warning("New version available: v" + latestVersion + " (current: v" + curVer + ")");
logger.warning("Download it at " + url);
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ depend:
authors: [ TechnicJelle ]
description: ${project.description}
website: ${project.url}
loadbefore:
- BlueMapFloodgate

0 comments on commit ef3f21c

Please sign in to comment.