From b9e2514556604fa3aae3cc51a9bf65fa7ab7fe96 Mon Sep 17 00:00:00 2001 From: HaHaWTH <102713261+HaHaWTH@users.noreply.github.com> Date: Mon, 4 Nov 2024 19:24:24 +0800 Subject: [PATCH] Cleanup --- README.md | 17 ++++++------ .../fr/xephi/authme/api/v3/AuthMeApi.java | 16 ----------- .../xephi/authme/listener/PlayerListener.java | 27 +------------------ .../java/fr/xephi/authme/task/Updater.java | 23 +++++++++------- 4 files changed, 23 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index 79ce794c3..0e1dba549 100644 --- a/README.md +++ b/README.md @@ -27,15 +27,14 @@ 10. Player login logic improvement to reduce lag 11. Automatically purge bot data 12. **Folia support (in active testing)** - 13. Offhand Menu compatibility(Thats amazing) - 14. **Velocity support (See [Velocity Support](./vc-support.md))** - 15. Support Virtual Threads caching - 16. Automatically fix portal stuck issue - 17. Automatically login for Bedrock players(configurable) - 18. Fix shulker box crash bug on legacy versions(MC 1.13-) - 19. **H2 database support** - 20. **100% compatibility with original authme and extensions** - 21. More...... + 13. **Velocity support (See [Velocity Support](./vc-support.md))** + 14. Support Virtual Threads caching + 15. Automatically fix portal stuck issue + 16. Automatically login for Bedrock players(configurable) + 17. Fix shulker box crash bug on legacy versions(MC 1.13-) + 18. **H2 database support** + 19. **100% compatibility with original authme and extensions** + 20. More...... **Download links:** [Releases](https://github.com/HaHaWTH/AuthMeReReloaded/releases/latest) diff --git a/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java b/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java index 27743d5d5..81f55863f 100644 --- a/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java +++ b/src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java @@ -15,8 +15,6 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; import javax.inject.Inject; import java.time.Instant; @@ -26,8 +24,6 @@ import java.util.Locale; import java.util.Optional; -import static fr.xephi.authme.listener.PlayerListener.PENDING_INVENTORIES; - /** * The current API of AuthMe. * @@ -261,18 +257,6 @@ public boolean registerPlayer(String playerName, String password) { return dataSource.saveAuth(auth); } - /** - * Open an inventory for the given player at any time. - * - * @param player The player to open the inventory for - * @param inventory The inventory to open - * @return The inventory view - */ - public InventoryView openInventory(Player player, Inventory inventory) { - PENDING_INVENTORIES.add(inventory); - return player.openInventory(inventory); - } - /** * Force a player to login, i.e. the player is logged in without needing his password. * diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index b24da9da2..60aa74015 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -52,12 +52,9 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerShearEntityEvent; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; import java.util.Locale; import java.util.Set; @@ -98,8 +95,6 @@ public class PlayerListener implements Listener { @Inject private QuickCommandsProtectionManager quickCommandsProtectionManager; - public static List PENDING_INVENTORIES = new ArrayList<>(); - // Lowest priority to apply fast protection checks @EventHandler(priority = EventPriority.LOWEST) public void onAsyncPlayerPreLoginEventLowest(AsyncPlayerPreLoginEvent event) { @@ -500,17 +495,6 @@ public void onPlayerConsumeItem(PlayerItemConsumeEvent event) { } } - private boolean isInventoryOpenedByApi(Inventory inventory) { - if (inventory == null) { - return false; - } - if (PENDING_INVENTORIES.contains(inventory)) { - PENDING_INVENTORIES.remove(inventory); - return true; - } else { - return false; - } - } @SuppressWarnings("all") private boolean isInventoryWhitelisted(InventoryView inventory) { if (inventory == null) { @@ -537,8 +521,7 @@ private boolean isInventoryWhitelisted(InventoryView inventory) { public void onPlayerInventoryOpen(InventoryOpenEvent event) { final HumanEntity player = event.getPlayer(); if (listenerService.shouldCancelEvent(player) - && !isInventoryWhitelisted(event.getView()) - && !isInventoryOpenedByApi(event.getInventory())) { + && !isInventoryWhitelisted(event.getView())) { event.setCancelled(true); /* @@ -556,12 +539,4 @@ public void onPlayerInventoryClick(InventoryClickEvent event) { event.setCancelled(true); } } -// @EventHandler(priority = EventPriority.LOWEST) -// public void onSwitchHand(PlayerSwapHandItemsEvent event) { -// Player player = event.getPlayer(); -// if (!player.isSneaking() || !player.hasPermission("keybindings.use")) -// return; -// event.setCancelled(true); -// Bukkit.dispatchCommand(event.getPlayer(), "help"); -// } } diff --git a/src/main/java/fr/xephi/authme/task/Updater.java b/src/main/java/fr/xephi/authme/task/Updater.java index 5616d88a8..52750873c 100644 --- a/src/main/java/fr/xephi/authme/task/Updater.java +++ b/src/main/java/fr/xephi/authme/task/Updater.java @@ -1,10 +1,13 @@ package fr.xephi.authme.task; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; + import java.io.IOException; +import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URI; import java.net.URL; -import java.util.Scanner; public class Updater { private final String currentVersion; @@ -32,14 +35,16 @@ public boolean isUpdateAvailable() { HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(10000); - Scanner scanner = new Scanner(conn.getInputStream()); - String response = scanner.useDelimiter("\\Z").next(); - scanner.close(); - String latestVersion = response.substring(response.indexOf("tag_name") + 11); - latestVersion = latestVersion.substring(0, latestVersion.indexOf("\"")); - this.latestVersion = latestVersion; - isUpdateAvailable = !currentVersion.equals(latestVersion); - return isUpdateAvailable; + conn.setRequestMethod("GET"); + conn.setRequestProperty("Accept", "application/vnd.github+json"); + try (InputStreamReader reader = new InputStreamReader(conn.getInputStream())) { + JsonObject jsonObject = new JsonParser().parse(reader).getAsJsonObject(); + String latest = jsonObject.get("tag_name").getAsString(); + latestVersion = latest; + isUpdateAvailable = !currentVersion.equals(latest); + reader.close(); + return isUpdateAvailable; + } } catch (IOException ignored) { this.latestVersion = null; isUpdateAvailable = false;