Skip to content

Commit

Permalink
New update checker and fixed whitelist/blacklist bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
byteful authored and byteful committed Oct 18, 2022
1 parent ffeb7a5 commit d15c2da
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
Binary file modified LevelTools.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
}

group = 'me.byteful.plugin'
version = '1.3.0'
version = '1.3.1'
description = 'LevelTools'
java.sourceCompatibility = JavaVersion.VERSION_1_8

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.inventory.ItemStack;
import redempt.redlib.blockdata.DataBlock;

import java.util.Objects;
import java.util.stream.Stream;

public class BlockEventListener extends XPListener {
Expand All @@ -37,7 +38,7 @@ public void onBlockBreak(BlockBreakEvent e) {

final String type = LevelToolsPlugin.getInstance().getConfig().getString("block_list_type", "blacklist");
final Stream<Material> stream = LevelToolsPlugin.getInstance().getConfig().getStringList("block_list").stream()
.map(Material::getMaterial);
.map(Material::getMaterial).filter(Objects::nonNull);

if (type.equalsIgnoreCase("whitelist") && stream.noneMatch(material -> block.getType() == material)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;

import java.util.Objects;
import java.util.stream.Stream;

public class EntityEventListener extends XPListener {
Expand All @@ -24,7 +25,13 @@ public void onEntityKillEntity(EntityDeathEvent e) {

final String ltype = LevelToolsPlugin.getInstance().getConfig().getString("entity_list_type", "blacklist");
final Stream<EntityType> stream = LevelToolsPlugin.getInstance().getConfig().getStringList("entity_list").stream()
.map(EntityType::valueOf);
.map(str -> {
try {
return EntityType.valueOf(str);
} catch (Exception ignored) {
return null;
}
}).filter(Objects::nonNull);

if (ltype.equalsIgnoreCase("whitelist") && stream.noneMatch(type -> e.getEntityType() == type)) {
return;
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/me/byteful/plugin/leveltools/util/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.byteful.plugin.leveltools.util;

import org.bukkit.plugin.java.JavaPlugin;
import me.byteful.plugin.leveltools.LevelToolsPlugin;
import org.jetbrains.annotations.NotNull;
import redempt.redlib.misc.Task;

Expand All @@ -9,39 +9,36 @@
import java.net.URL;
import java.util.Scanner;

// From: https://www.spigotmc.org/wiki/creating-an-update-checker-that-checks-for-updates
// Further modified by byteful to accompany LevelTools
public class UpdateChecker {
public static final int SPIGOT_RESOURCE_ID = 97516;

@NotNull
private final JavaPlugin plugin;
private final LevelToolsPlugin plugin;

public UpdateChecker(@NotNull JavaPlugin plugin) {
public UpdateChecker(@NotNull LevelToolsPlugin plugin) {
this.plugin = plugin;
}

public void check() {
plugin.getLogger().info("Checking for updates...");
final String currentVersion = plugin.getDescription().getVersion();
if (currentVersion.contains("BETA")) {
plugin.getLogger().info("Update check was cancelled because you are running a beta build!");

return;
}

Task.asyncDelayed(plugin, () -> {
try (final InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + SPIGOT_RESOURCE_ID).openStream(); final Scanner scanner = new Scanner(inputStream)) {
try (final InputStream inputStream = new URL("https://api.byteful.me/leveltools").openStream(); final Scanner scanner = new Scanner(inputStream)) {
if (!scanner.hasNext()) {
return;
}

final String currentVersion = plugin.getDescription().getVersion();
if (currentVersion.contains("BETA")) {
plugin.getLogger().info("Update check was cancelled because you are running a beta build!");

return;
}
final String latestVersion = scanner.next();

if (currentVersion.equals(latestVersion)) {
plugin.getLogger().info("No new updates found.");
} else {
plugin.getLogger().info("A new update was found. You are on " + currentVersion + " while the latest version is " + latestVersion + ".");
plugin.getLogger().info("Please install this update from: https://www.spigotmc.org/resources/" + SPIGOT_RESOURCE_ID);
plugin.getLogger().info("Please install this update from: https://github.com/byteful/LevelTools/releases/download/v" + latestVersion + "/LevelTools-" + latestVersion + ".jar");
}
} catch (IOException e) {
plugin.getLogger().info("Unable to check for updates: " + e.getMessage());
Expand Down

0 comments on commit d15c2da

Please sign in to comment.