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

Commit

Permalink
added metrics + update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperdefined committed Apr 17, 2022
1 parent 71a54a2 commit e1641c4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>lol.hyper.lecterncrashfix.bstats</shadedPattern>
</relocation>
</relocations>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -76,5 +98,17 @@
<version>4.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>lol.hyper</groupId>
<artifactId>github-release-api</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
31 changes: 31 additions & 0 deletions src/main/java/lol/hyper/lecterncrashfix/LecternCrashFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import lol.hyper.githubreleaseapi.GitHubRelease;
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
import lol.hyper.lecterncrashfix.wrapper.WrapperPlayClientWindowClick;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -15,6 +18,7 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

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

Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);

new Metrics(this, 14959);

ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(this, ListenerPriority.HIGHEST, PacketType.Play.Client.WINDOW_CLICK) {
@Override
public void onPacketReceiving(PacketEvent event) {
Expand Down Expand Up @@ -74,4 +82,27 @@ private void runCommand(Player player) {
String finalCommand = command;
Bukkit.getScheduler().runTaskLater(this, ()-> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand), 20);
}

public void checkForUpdates() {
GitHubReleaseAPI api;
try {
api = new GitHubReleaseAPI("LecternCrashFix", "hyperdefined");
} catch (IOException e) {
logger.warning("Unable to check updates!");
e.printStackTrace();
return;
}
GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
GitHubRelease latest = api.getLatestVersion();
if (current == null) {
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!");
return;
}
int buildsBehind = api.getBuildsBehind(current);
if (buildsBehind == 0) {
logger.info("You are running the latest version.");
} else {
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ name: LecternCrashFix
version: '${project.version}'
main: lol.hyper.lecterncrashfix.LecternCrashFix
api-version: 1.14
depend: [ProtocolLib]
depend: [ProtocolLib]
libraries:
- lol.hyper:github-release-api:1.0.1

0 comments on commit e1641c4

Please sign in to comment.