mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
Merge remote-tracking branch 'origin/remapped' into remapped
This commit is contained in:
@@ -9,11 +9,9 @@ import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
import org.bukkit.Color;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -151,21 +149,21 @@ public final class HMCCosmeticsAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new cosmetic user provider to use to construct {@link CosmeticUser}s.
|
||||
* Registers a new cosmetic user provider to use for constructing {@link CosmeticUser} instances.
|
||||
*
|
||||
* @param provider the provider to register
|
||||
* @throws IllegalArgumentException if another plugin has already registered a provider
|
||||
*/
|
||||
public static void registerCosmeticUserProvider(final CosmeticUserProvider provider) {
|
||||
public static void registerCosmeticUserProvider(@NotNull CosmeticUserProvider provider) {
|
||||
CosmeticUsers.registerProvider(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the current {@link CosmeticUserProvider} that is in use.
|
||||
* Retrieves the current {@link CosmeticUserProvider} that is in use.
|
||||
*
|
||||
* @return the {@link CosmeticUserProvider}
|
||||
* @return the current {@link CosmeticUserProvider}
|
||||
*/
|
||||
public static CosmeticUserProvider getCosmeticUserProvider() {
|
||||
public static @NotNull CosmeticUserProvider getCosmeticUserProvider() {
|
||||
return CosmeticUsers.getProvider();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.api.events;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menu;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -10,9 +11,19 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
|
||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
private final InventoryCloseEvent.Reason reason;
|
||||
|
||||
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
|
||||
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu, @NotNull InventoryCloseEvent.Reason reason) {
|
||||
super(who, menu);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link InventoryCloseEvent.Reason} why the menu was closed.
|
||||
* @return The reason why the menu was closed.
|
||||
*/
|
||||
public InventoryCloseEvent.Reason getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hibiscusmc.hmccosmetics.gui;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
@@ -169,6 +170,9 @@ public class Menu {
|
||||
});
|
||||
|
||||
gui.setCloseGuiAction(event -> {
|
||||
PlayerMenuCloseEvent closeEvent = new PlayerMenuCloseEvent(user, this, event.getReason());
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(closeEvent));
|
||||
|
||||
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
|
||||
});
|
||||
|
||||
|
||||
@@ -3,12 +3,15 @@ package com.hibiscusmc.hmccosmetics.gui;
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.lojosho.shaded.configurate.CommentedConfigurationNode;
|
||||
import me.lojosho.shaded.configurate.ConfigurateException;
|
||||
import me.lojosho.shaded.configurate.yaml.YamlConfigurationLoader;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
@@ -22,10 +25,11 @@ public class Menus {
|
||||
private static final HashMap<String, Menu> MENUS = new HashMap<>();
|
||||
private static final HashMap<UUID, Long> COOLDOWNS = new HashMap<>();
|
||||
|
||||
public static void addMenu(Menu menu) {
|
||||
public static void addMenu(@NotNull Menu menu) {
|
||||
MENUS.put(menu.getId().toUpperCase(), menu);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Menu getMenu(@NotNull String id) {
|
||||
return MENUS.get(id.toUpperCase());
|
||||
}
|
||||
@@ -40,11 +44,18 @@ public class Menus {
|
||||
return MENUS.containsKey(id.toUpperCase());
|
||||
}
|
||||
|
||||
public static boolean hasMenu(Menu menu) {
|
||||
public static boolean hasMenu(@NotNull Menu menu) {
|
||||
return MENUS.containsValue(menu);
|
||||
}
|
||||
|
||||
public static Menu getDefaultMenu() { return Menus.getMenu(Settings.getDefaultMenu()); }
|
||||
public static boolean hasDefaultMenu() {
|
||||
return MENUS.containsKey(Settings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Menu getDefaultMenu() {
|
||||
return Menus.getMenu(Settings.getDefaultMenu());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<String> getMenuNames() {
|
||||
|
||||
@@ -1,21 +1,16 @@
|
||||
package com.hibiscusmc.hmccosmetics.listener;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.api.HMCCosmeticsAPI;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerLoadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerPreLoadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.api.events.PlayerUnloadEvent;
|
||||
import com.hibiscusmc.hmccosmetics.config.DatabaseSettings;
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.database.Database;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import com.hibiscusmc.hmccosmetics.gui.Menus;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUserProvider;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEmoteManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -26,7 +21,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class PlayerConnectionListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@@ -69,7 +63,7 @@ public class PlayerConnectionListener implements Listener {
|
||||
}, 4);
|
||||
});
|
||||
}).exceptionally(ex -> {
|
||||
log.error("Unable to load Cosmetic User {}", uuid, ex);
|
||||
MessagesUtil.sendDebugMessages("Unable to load Cosmetic User " + uuid + ". Exception: " + ex.getMessage());
|
||||
return null;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
|
||||
import com.hibiscusmc.hmccosmetics.database.UserData;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -20,7 +21,7 @@ public interface CosmeticUserProvider {
|
||||
* @return the {@link CosmeticUser}
|
||||
* @apiNote This method is called during the {@link PlayerJoinEvent}.
|
||||
*/
|
||||
CosmeticUser createCosmeticUser(UUID playerId, UserData userData);
|
||||
@NotNull CosmeticUser createCosmeticUser(@NotNull UUID playerId, @NotNull UserData userData);
|
||||
|
||||
/**
|
||||
* Construct the custom {@link CosmeticUser}.
|
||||
@@ -28,7 +29,7 @@ public interface CosmeticUserProvider {
|
||||
* @return the {@link CosmeticUser}
|
||||
* @apiNote This method is called during the {@link PlayerJoinEvent}.
|
||||
*/
|
||||
CosmeticUser createCosmeticUserWithoutData(UUID playerId);
|
||||
@NotNull CosmeticUser createCosmeticUserWithoutData(@NotNull UUID playerId);
|
||||
|
||||
/**
|
||||
* Represents the plugin that is providing this {@link CosmeticUserProvider}
|
||||
@@ -41,12 +42,12 @@ public interface CosmeticUserProvider {
|
||||
*/
|
||||
class Default implements CosmeticUserProvider {
|
||||
@Override
|
||||
public CosmeticUser createCosmeticUser(UUID playerId, UserData userData) {
|
||||
public @NotNull CosmeticUser createCosmeticUser(@NotNull UUID playerId, @NotNull UserData userData) {
|
||||
return new CosmeticUser(playerId, userData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CosmeticUser createCosmeticUserWithoutData(UUID playerId) {
|
||||
public @NotNull CosmeticUser createCosmeticUserWithoutData(@NotNull UUID playerId) {
|
||||
return new CosmeticUser(playerId);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.hibiscusmc.hmccosmetics.user;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCServerUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -54,7 +53,7 @@ public class CosmeticUsers {
|
||||
/**
|
||||
* This method allows you to get a CosmeticUser from just using the player class. This just allows you to have a bit less boilerplate.
|
||||
* @param player The player to lookup (will take their UUID from the class)
|
||||
* @return Returns the user if there is a vlaid user, returns null if not.
|
||||
* @return Returns the user if there is a valid user, returns null if not.
|
||||
*/
|
||||
@Nullable
|
||||
public static CosmeticUser getUser(@NotNull Player player) {
|
||||
|
||||
Reference in New Issue
Block a user