Skip to content

Commit

Permalink
Fixed typo in README.
Browse files Browse the repository at this point in the history
Added an update checker.

Signed-off-by: hypil <klxzz.dev@gmail.com>
  • Loading branch information
fleroviums committed Aug 30, 2022
1 parent fe408dc commit d2471ea
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 3 deletions.
Binary file modified .gradle/7.4/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.4/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# depixa-lifesteal
A simple lifesteal plugin.

## Permissiosn
## Permissions
- dls.main **(/lifesteal)**
- Main command
- dls.bypass
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'gq.depixa.lifesteal'
version '1.0.1'
version '1.0.2'

compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/gq/depixa/lifesteal/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public void onEnable() {
this.getCommand("revive").setExecutor(new CommandRevive());
this.getCommand("transfer").setExecutor(new CommandTransfer());
new HeartRecipe().heartRecipe();

new UpdateChecker(this, 104937).getVersion(version -> {
if (this.getDescription().getVersion().equals(version)) {
getLogger().info("You are running the latest version. (" + version + ")");
} else {
getLogger().warning("There is a new version available: " + version + ". You are on: " + this.getDescription().getVersion() + ". Get the latest version at https://www.spigotmc.org/resources/depixa-lifesteal.104937/");
}
});
}

@Override
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/gq/depixa/lifesteal/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package gq.depixa.lifesteal;

import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;

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

public class UpdateChecker {

private final JavaPlugin plugin;
private final int resourceId;

public UpdateChecker(JavaPlugin plugin, int resourceId) {
this.plugin = plugin;
this.resourceId = resourceId;
}

public void getVersion(final Consumer<String> consumer) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
if (scanner.hasNext()) {
consumer.accept(scanner.next());
}
} catch (IOException exception) {
plugin.getLogger().info("Unable to check for updates: " + exception.getMessage());
}
});
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Depixa-Lifesteal
version: 1.0.1
version: 1.0.2
author: Klxzz
main: gq.depixa.lifesteal.Main
api-version: 1.17
Expand Down

0 comments on commit d2471ea

Please sign in to comment.