Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.

Commit e1641c4

Browse files
committed
added metrics + update checker
1 parent 71a54a2 commit e1641c4

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@
4343
</execution>
4444
</executions>
4545
</plugin>
46+
<plugin>
47+
<groupId>org.apache.maven.plugins</groupId>
48+
<artifactId>maven-shade-plugin</artifactId>
49+
<version>3.3.0</version>
50+
<executions>
51+
<execution>
52+
<phase>package</phase>
53+
<goals>
54+
<goal>shade</goal>
55+
</goals>
56+
<configuration>
57+
<relocations>
58+
<relocation>
59+
<pattern>org.bstats</pattern>
60+
<shadedPattern>lol.hyper.lecterncrashfix.bstats</shadedPattern>
61+
</relocation>
62+
</relocations>
63+
<createDependencyReducedPom>false</createDependencyReducedPom>
64+
</configuration>
65+
</execution>
66+
</executions>
67+
</plugin>
4668
</plugins>
4769
<resources>
4870
<resource>
@@ -76,5 +98,17 @@
7698
<version>4.7.0</version>
7799
<scope>provided</scope>
78100
</dependency>
101+
<dependency>
102+
<groupId>org.bstats</groupId>
103+
<artifactId>bstats-bukkit</artifactId>
104+
<version>3.0.0</version>
105+
<scope>compile</scope>
106+
</dependency>
107+
<dependency>
108+
<groupId>lol.hyper</groupId>
109+
<artifactId>github-release-api</artifactId>
110+
<version>1.0.1</version>
111+
<scope>provided</scope>
112+
</dependency>
79113
</dependencies>
80114
</project>

src/main/java/lol/hyper/lecterncrashfix/LecternCrashFix.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import com.comphenix.protocol.events.ListenerPriority;
66
import com.comphenix.protocol.events.PacketAdapter;
77
import com.comphenix.protocol.events.PacketEvent;
8+
import lol.hyper.githubreleaseapi.GitHubRelease;
9+
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
810
import lol.hyper.lecterncrashfix.wrapper.WrapperPlayClientWindowClick;
11+
import org.bstats.bukkit.Metrics;
912
import org.bukkit.Bukkit;
1013
import org.bukkit.configuration.file.FileConfiguration;
1114
import org.bukkit.configuration.file.YamlConfiguration;
@@ -15,6 +18,7 @@
1518
import org.bukkit.plugin.java.JavaPlugin;
1619

1720
import java.io.File;
21+
import java.io.IOException;
1822
import java.util.logging.Logger;
1923

2024
public final class LecternCrashFix extends JavaPlugin {
@@ -34,6 +38,10 @@ public void onEnable() {
3438
logger.warning("Your config file is outdated! Please regenerate the config.");
3539
}
3640

41+
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
42+
43+
new Metrics(this, 14959);
44+
3745
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Client.WINDOW_CLICK) {
3846
@Override
3947
public void onPacketReceiving(PacketEvent event) {
@@ -74,4 +82,27 @@ private void runCommand(Player player) {
7482
String finalCommand = command;
7583
Bukkit.getScheduler().runTaskLater(this, ()-> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand), 20);
7684
}
85+
86+
public void checkForUpdates() {
87+
GitHubReleaseAPI api;
88+
try {
89+
api = new GitHubReleaseAPI("LecternCrashFix", "hyperdefined");
90+
} catch (IOException e) {
91+
logger.warning("Unable to check updates!");
92+
e.printStackTrace();
93+
return;
94+
}
95+
GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
96+
GitHubRelease latest = api.getLatestVersion();
97+
if (current == null) {
98+
logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
99+
return;
100+
}
101+
int buildsBehind = api.getBuildsBehind(current);
102+
if (buildsBehind == 0) {
103+
logger.info("You are running the latest version.");
104+
} else {
105+
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
106+
}
107+
}
77108
}

src/main/resources/plugin.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ name: LecternCrashFix
22
version: '${project.version}'
33
main: lol.hyper.lecterncrashfix.LecternCrashFix
44
api-version: 1.14
5-
depend: [ProtocolLib]
5+
depend: [ProtocolLib]
6+
libraries:
7+
- lol.hyper:github-release-api:1.0.1

0 commit comments

Comments
 (0)