Skip to content

Commit

Permalink
Added Metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
LucFr1746 committed Dec 11, 2024
1 parent ed87c3a commit 215a3e3
Show file tree
Hide file tree
Showing 4 changed files with 791 additions and 13 deletions.
13 changes: 0 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/github/lucfr1746/LWardrobe/LWardrobe.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import io.github.lucfr1746.LWardrobe.Commands.CommandsRegister;
import io.github.lucfr1746.LWardrobe.DataManager.DataManager;
import io.github.lucfr1746.LWardrobe.Metrics.UpdateChecker;
import io.github.lucfr1746.LWardrobe.Metrics.bStatsMetrics;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public final class LWardrobe extends JavaPlugin {

private static LWardrobe plugin;

@Override
public void onEnable() {
plugin = this;
// Metrics
new UpdateChecker(this);
new bStatsMetrics(this, 24103);
// Data Manager
new DataManager(this);
// Commands
Expand All @@ -18,4 +27,8 @@ public void onEnable() {
public void onDisable() {
// Plugin shutdown logic
}

public static Plugin getInstance() {
return plugin;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.lucfr1746.LWardrobe.Metrics;

import io.github.lucfr1746.LWardrobe.LWardrobe;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginDescriptionFile;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Scanner;
import java.util.function.Consumer;

public class UpdateChecker {

private final LWardrobe plugin;

public UpdateChecker(LWardrobe plugin) {
this.plugin = plugin;
check(-1);
}

public void getLatestVersion(Consumer<String> consumer, int resourceId) {
try (InputStream inputStream = new URI("https://api.spigotmc.org/legacy/update.php?resource=" + resourceId).toURL().openStream();
Scanner scanner = new Scanner(inputStream)) {

if (scanner.hasNext()) {
consumer.accept(scanner.next());
}
} catch (IOException | URISyntaxException exception) {
plugin.getLogger().info("Update checker is broken, can't find an update! " + exception.getMessage());
}
}

public void check(int resourceId) {
// getLatestVersion(version -> {
// PluginDescriptionFile pdf = plugin.getDescription();
// // Check if the current version matches the latest version.
// if (pdf.getVersion().equalsIgnoreCase(version)) {
// this.plugin.getLogger().info("Version: " + ChatColor.GREEN + pdf.getVersion());
// this.plugin.getLogger().info("Plugin is up to date!");
// } else {
// this.plugin.getLogger().info("Version: " + ChatColor.RED + pdf.getVersion());
// this.plugin.getLogger().info("Plugin has an update! Download at: https://www.spigotmc.org/resources/" + resourceId);
// }
// }, resourceId);
}
}
Loading

0 comments on commit 215a3e3

Please sign in to comment.