Merge remote-tracking branch 'HaHaWTH/master'

# Conflicts:
#	.github/workflows/maven.yml
#	pom.xml
#	src/main/resources/plugin.yml
This commit is contained in:
MC~蛟龙 2024-07-10 18:13:21 +08:00
commit d9182dca62
10 changed files with 69 additions and 29 deletions

View File

@ -74,9 +74,9 @@ public class AuthMe extends JavaPlugin {
private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE; private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE;
// Version and build number values // Version and build number values
private static String pluginVersion = "5.6.0-Fork"; private static String pluginVersion = "5.7.0-Fork";
private static final String pluginBuild = "b"; private static final String pluginBuild = "b";
private static String pluginBuildNumber = "50"; private static String pluginBuildNumber = "51";
// Private instances // Private instances
private EmailService emailService; private EmailService emailService;
private CommandHandler commandHandler; private CommandHandler commandHandler;

View File

@ -15,6 +15,8 @@ import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import javax.inject.Inject; import javax.inject.Inject;
import java.time.Instant; import java.time.Instant;
@ -24,6 +26,8 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import static fr.xephi.authme.listener.PlayerListener.PENDING_INVENTORIES;
/** /**
* The current API of AuthMe. * The current API of AuthMe.
* *
@ -32,6 +36,7 @@ import java.util.Optional;
* AuthMeApi authmeApi = AuthMeApi.getInstance(); * AuthMeApi authmeApi = AuthMeApi.getInstance();
* </code> * </code>
*/ */
@SuppressWarnings("unused")
public class AuthMeApi { public class AuthMeApi {
private static AuthMeApi singleton; private static AuthMeApi singleton;
@ -256,6 +261,18 @@ public class AuthMeApi {
return dataSource.saveAuth(auth); 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. * Force a player to login, i.e. the player is logged in without needing his password.
* *

View File

@ -16,9 +16,11 @@ import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.TeleportUtils; import fr.xephi.authme.util.TeleportUtils;
import fr.xephi.authme.util.message.I18NUtils;
import fr.xephi.authme.util.message.MiniMessageUtils; import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -50,9 +52,12 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerShearEntityEvent; import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
@ -93,6 +98,7 @@ public class PlayerListener implements Listener {
@Inject @Inject
private QuickCommandsProtectionManager quickCommandsProtectionManager; private QuickCommandsProtectionManager quickCommandsProtectionManager;
public static List<Inventory> PENDING_INVENTORIES = new ArrayList<>();
// Lowest priority to apply fast protection checks // Lowest priority to apply fast protection checks
@EventHandler(priority = EventPriority.LOWEST) @EventHandler(priority = EventPriority.LOWEST)
@ -248,6 +254,11 @@ public class PlayerListener implements Listener {
} }
} }
// Remove data from locale map when player quit
if (settings.getProperty(PluginSettings.I18N_MESSAGES)) {
I18NUtils.removeLocale(player.getUniqueId());
}
if (antiBotService.wasPlayerKicked(player.getName())) { if (antiBotService.wasPlayerKicked(player.getName())) {
return; return;
} }
@ -489,6 +500,17 @@ public class PlayerListener implements Listener {
} }
} }
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") @SuppressWarnings("all")
private boolean isInventoryWhitelisted(InventoryView inventory) { private boolean isInventoryWhitelisted(InventoryView inventory) {
if (inventory == null) { if (inventory == null) {
@ -515,7 +537,8 @@ public class PlayerListener implements Listener {
public void onPlayerInventoryOpen(InventoryOpenEvent event) { public void onPlayerInventoryOpen(InventoryOpenEvent event) {
final HumanEntity player = event.getPlayer(); final HumanEntity player = event.getPlayer();
if (listenerService.shouldCancelEvent(player) if (listenerService.shouldCancelEvent(player)
&& !isInventoryWhitelisted(event.getView())) { && !isInventoryWhitelisted(event.getView())
&& !isInventoryOpenedByApi(event.getInventory())) {
event.setCancelled(true); event.setCancelled(true);
/* /*

View File

@ -29,8 +29,6 @@ import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Locale; import java.util.Locale;
@ -208,7 +206,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout; int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout;
// AuthMeReReloaded - Fix potion apply on Folia // AuthMeReReloaded - Fix potion apply on Folia
bukkitService.runTaskIfFolia(player,() -> player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2))); bukkitService.runTaskIfFolia(player, () -> player.addPotionEffect(bukkitService.createBlindnessEffect(blindTimeOut)));
} }
commandManager.runCommandsOnJoin(player); commandManager.runCommandsOnJoin(player);
}); });

View File

@ -14,8 +14,6 @@ import fr.xephi.authme.settings.commandconfig.CommandManager;
import fr.xephi.authme.settings.properties.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import javax.inject.Inject; import javax.inject.Inject;
@ -75,7 +73,7 @@ public class ProcessSyncPlayerLogout implements SynchronousProcess {
// Apply Blindness effect // Apply Blindness effect
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); player.addPotionEffect(bukkitService.createBlindnessEffect(timeout));
} }
// Set player's data to unauthenticated // Set player's data to unauthenticated

View File

@ -23,8 +23,6 @@ import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import javax.inject.Inject; import javax.inject.Inject;
@ -150,7 +148,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
private void applyBlindEffect(Player player) { private void applyBlindEffect(Player player) {
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2)); bukkitService.runTaskIfFolia(player, () -> player.addPotionEffect(bukkitService.createBlindnessEffect(timeout)));
} }
} }

View File

@ -18,6 +18,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Collection; import java.util.Collection;
@ -327,6 +329,16 @@ public class BukkitService implements SettingsDependent {
return event; return event;
} }
/**
* Creates a PotionEffect with blindness for the given duration in ticks.
*
* @param timeoutInTicks duration of the effect in ticks
* @return blindness potion effect
*/
public PotionEffect createBlindnessEffect(int timeoutInTicks) {
return new PotionEffect(PotionEffectType.BLINDNESS, timeoutInTicks, 2);
}
/** /**
* Gets the world with the given name. * Gets the world with the given name.
* *
@ -380,7 +392,11 @@ public class BukkitService implements SettingsDependent {
* @param bytes the message * @param bytes the message
*/ */
public void sendVelocityMessage(Player player, byte[] bytes) { public void sendVelocityMessage(Player player, byte[] bytes) {
player.sendPluginMessage(authMe, "authmevelocity:main", bytes); if (player != null) {
player.sendPluginMessage(authMe, "authmevelocity:main", bytes);
} else {
Bukkit.getServer().sendPluginMessage(authMe, "authmevelocity:main", bytes);
}
} }

View File

@ -129,9 +129,9 @@ public class CommandManager implements Reloadable {
if (predicate.test(cmd)) { if (predicate.test(cmd)) {
long delay = cmd.getDelay(); long delay = cmd.getDelay();
if (delay > 0) { if (delay > 0) {
bukkitService.scheduleSyncDelayedTask(() -> dispatchCommand(player, cmd), delay); bukkitService.runTaskLater(player, () -> dispatchCommand(player, cmd), delay);
} else { } else {
dispatchCommand(player, cmd); bukkitService.runTaskIfFolia(player, () -> dispatchCommand(player, cmd));
} }
} }
} }

View File

@ -60,6 +60,10 @@ public class I18NUtils {
PLAYER_LOCALE.put(uuid, locale); PLAYER_LOCALE.put(uuid, locale);
} }
public static void removeLocale(UUID uuid) {
PLAYER_LOCALE.remove(uuid);
}
/** /**
* Returns the AuthMe messages file language code, by given locale and settings. * Returns the AuthMe messages file language code, by given locale and settings.
* Dreeam - Hard mapping, based on mc1.20.6, 5/29/2024 * Dreeam - Hard mapping, based on mc1.20.6, 5/29/2024

View File

@ -2,9 +2,7 @@ package fr.xephi.authme.util.message;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
public class MiniMessageUtils { public class MiniMessageUtils {
private static final MiniMessage miniMessage = MiniMessage.miniMessage(); private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@ -19,18 +17,6 @@ public class MiniMessageUtils {
Component component = miniMessage.deserialize(message); Component component = miniMessage.deserialize(message);
return LegacyComponentSerializer.legacyAmpersand().serialize(component); return LegacyComponentSerializer.legacyAmpersand().serialize(component);
} }
/**
* Parse a MiniMessage string into a BaseComponent.
*
* @param message The message to parse.
* @return The parsed message.
*/
public static BaseComponent[] parseMiniMessageToBaseComponent(String message) {
Component component = miniMessage.deserialize(message);
return BungeeComponentSerializer.legacy().serialize(component);
}
private MiniMessageUtils() { private MiniMessageUtils() {
} }
} }