Updated TelekinesisUtils and UpdateChecker
This commit is contained in:
@@ -5,6 +5,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
/**
|
||||
@@ -24,6 +26,15 @@ public final class TelekinesisUtils {
|
||||
return tests.testPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new test to check against.
|
||||
*
|
||||
* @param test The test to register, where the boolean output is if the player is telekinetic.
|
||||
*/
|
||||
public void registerTest(@NotNull final Function<Player, Boolean> test) {
|
||||
tests.registerTest(test);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the test to use.
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.willfp.eco.util.updater;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.util.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -11,20 +10,14 @@ import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class UpdateChecker {
|
||||
/**
|
||||
* The instance of the plugin to check updates for.
|
||||
*/
|
||||
@Getter(AccessLevel.PRIVATE)
|
||||
private final AbstractEcoPlugin plugin;
|
||||
|
||||
public class UpdateChecker extends PluginDependent {
|
||||
/**
|
||||
* Create an update checker for the specified spigot resource id.
|
||||
*
|
||||
* @param plugin The plugin to check.
|
||||
*/
|
||||
public UpdateChecker(@NotNull final AbstractEcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,15 +27,15 @@ public class UpdateChecker {
|
||||
*/
|
||||
public void getVersion(@NotNull final Consumer<? super String> consumer) {
|
||||
this.getPlugin().getScheduler().runAsync(() -> {
|
||||
try (
|
||||
InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.getPlugin().getResourceId()).openStream();
|
||||
Scanner scanner = new Scanner(inputStream)
|
||||
) {
|
||||
try {
|
||||
InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.getPlugin().getResourceId()).openStream();
|
||||
Scanner scanner = new Scanner(inputStream);
|
||||
|
||||
if (scanner.hasNext()) {
|
||||
consumer.accept(scanner.next());
|
||||
}
|
||||
} catch (IOException exception) {
|
||||
this.getPlugin().getLogger().warning("Failed to check for updates: " + exception.getMessage());
|
||||
} catch (IOException e) {
|
||||
this.getPlugin().getLogger().warning("Failed to check for updates: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user