Skip to content

Commit

Permalink
Merge remote-tracking branch 'HaHaWTH/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/maven.yml
#	pom.xml
#	src/main/resources/plugin.yml
  • Loading branch information
TheFloodDragon committed Jul 10, 2024
2 parents 280e441 + 18ce05d commit d9182dc
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/main/java/fr/xephi/authme/AuthMe.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ public class AuthMe extends JavaPlugin {
private static final int CLEANUP_INTERVAL = 5 * TICKS_PER_MINUTE;

// 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 String pluginBuildNumber = "50";
private static String pluginBuildNumber = "51";
// Private instances
private EmailService emailService;
private CommandHandler commandHandler;
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/fr/xephi/authme/api/v3/AuthMeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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;
Expand All @@ -24,6 +26,8 @@
import java.util.Locale;
import java.util.Optional;

import static fr.xephi.authme.listener.PlayerListener.PENDING_INVENTORIES;

/**
* The current API of AuthMe.
*
Expand All @@ -32,6 +36,7 @@
* AuthMeApi authmeApi = AuthMeApi.getInstance();
* </code>
*/
@SuppressWarnings("unused")
public class AuthMeApi {

private static AuthMeApi singleton;
Expand Down Expand Up @@ -256,6 +261,18 @@ 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.
*
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/fr/xephi/authme/listener/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
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.RestrictionSettings;
import fr.xephi.authme.util.TeleportUtils;
import fr.xephi.authme.util.message.I18NUtils;
import fr.xephi.authme.util.message.MiniMessageUtils;
import org.bukkit.ChatColor;
import org.bukkit.Location;
Expand Down Expand Up @@ -50,9 +52,12 @@
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;

Expand Down Expand Up @@ -93,6 +98,7 @@ public class PlayerListener implements Listener {
@Inject
private QuickCommandsProtectionManager quickCommandsProtectionManager;

public static List<Inventory> PENDING_INVENTORIES = new ArrayList<>();

// Lowest priority to apply fast protection checks
@EventHandler(priority = EventPriority.LOWEST)
Expand Down Expand Up @@ -248,6 +254,11 @@ public void onPlayerQuit(PlayerQuitEvent event) {
}
}

// Remove data from locale map when player quit
if (settings.getProperty(PluginSettings.I18N_MESSAGES)) {
I18NUtils.removeLocale(player.getUniqueId());
}

if (antiBotService.wasPlayerKicked(player.getName())) {
return;
}
Expand Down Expand Up @@ -489,6 +500,17 @@ 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) {
Expand All @@ -515,7 +537,8 @@ private boolean isInventoryWhitelisted(InventoryView inventory) {
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
final HumanEntity player = event.getPlayer();
if (listenerService.shouldCancelEvent(player)
&& !isInventoryWhitelisted(event.getView())) {
&& !isInventoryWhitelisted(event.getView())
&& !isInventoryOpenedByApi(event.getInventory())) {
event.setCancelled(true);

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;
import java.util.Locale;
Expand Down Expand Up @@ -208,7 +206,7 @@ private void processJoinSync(Player player, boolean isAuthAvailable) {
int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout;

// 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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;

Expand Down Expand Up @@ -75,7 +73,7 @@ private void applyLogoutEffect(Player player) {
// Apply Blindness effect
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;

Expand Down Expand Up @@ -150,7 +148,7 @@ private void performPostUnregisterActions(String name, Player player) {
private void applyBlindEffect(Player player) {
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
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)));
}
}

Expand Down
18 changes: 17 additions & 1 deletion src/main/java/fr/xephi/authme/service/BukkitService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import javax.inject.Inject;
import java.util.Collection;
Expand Down Expand Up @@ -327,6 +329,16 @@ public <E extends Event> E createAndCallEvent(Function<Boolean, E> eventSupplier
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.
*
Expand Down Expand Up @@ -380,7 +392,11 @@ public void sendBungeeMessage(Player player, byte[] bytes) {
* @param bytes the message
*/
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);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ private <T extends Command> void executeCommands(Player player, List<T> commands
if (predicate.test(cmd)) {
long delay = cmd.getDelay();
if (delay > 0) {
bukkitService.scheduleSyncDelayedTask(() -> dispatchCommand(player, cmd), delay);
bukkitService.runTaskLater(player, () -> dispatchCommand(player, cmd), delay);
} else {
dispatchCommand(player, cmd);
bukkitService.runTaskIfFolia(player, () -> dispatchCommand(player, cmd));
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/fr/xephi/authme/util/message/I18NUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public static void addLocale(UUID uuid, String 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.
* Dreeam - Hard mapping, based on mc1.20.6, 5/29/2024
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/fr/xephi/authme/util/message/MiniMessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import net.kyori.adventure.text.Component;
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.md_5.bungee.api.chat.BaseComponent;

public class MiniMessageUtils {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
Expand All @@ -19,18 +17,6 @@ public static String parseMiniMessageToLegacy(String message) {
Component component = miniMessage.deserialize(message);
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() {
}
}

0 comments on commit d9182dc

Please sign in to comment.