9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

Merge pull request #181 from DebitCardz/fix-add-user

add user to pre unload
This commit is contained in:
Logan
2025-05-16 14:50:22 -05:00
committed by GitHub
2 changed files with 11 additions and 10 deletions

View File

@@ -1,11 +1,10 @@
package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
/**
* Called before a player's data is un-loaded from the plugin.
*
@@ -14,13 +13,13 @@ import java.util.UUID;
* and will be kept in memory.
* </p>
*/
public class PlayerPreUnloadEvent extends PlayerEvent implements Cancellable {
public class PlayerPreUnloadEvent extends PlayerCosmeticEvent implements Cancellable {
private static final HandlerList HANDLER_LIST = new HandlerList();
private boolean cancelled = false;
public PlayerPreUnloadEvent(@NotNull UUID id) {
super(id);
public PlayerPreUnloadEvent(@NotNull CosmeticUser who) {
super(who);
}
@Override

View File

@@ -72,19 +72,21 @@ public class PlayerConnectionListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(@NotNull PlayerQuitEvent event) {
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(event.getPlayer().getUniqueId());
Bukkit.getPluginManager().callEvent(preUnloadEvent);
if (preUnloadEvent.isCancelled()) return;
CosmeticUser user = CosmeticUsers.getUser(event.getPlayer());
if (user == null) return; // Player never initialized, don't do anything
PlayerPreUnloadEvent preUnloadEvent = new PlayerPreUnloadEvent(user);
Bukkit.getPluginManager().callEvent(preUnloadEvent);
if (preUnloadEvent.isCancelled()) return;
PlayerUnloadEvent playerUnloadEvent = new PlayerUnloadEvent(user);
Bukkit.getPluginManager().callEvent(playerUnloadEvent);
if (user.isInWardrobe()) {
user.leaveWardrobe(true);
user.getPlayer().setInvisible(false);
final Player player = user.getPlayer();
if(player != null) player.setInvisible(false);
}
Menus.removeCooldown(event.getPlayer().getUniqueId()); // Removes any menu cooldowns a player might have
Database.save(user);