308 lines
14 KiB
Java
308 lines
14 KiB
Java
/* */ package com.minehut.cosmetics;
|
|
/* */
|
|
/* */ import com.google.gson.Gson;
|
|
/* */ import com.google.gson.GsonBuilder;
|
|
/* */ import com.google.gson.JsonDeserializationContext;
|
|
/* */ import com.google.gson.JsonElement;
|
|
/* */ import com.google.gson.JsonObject;
|
|
/* */ import com.google.gson.JsonParseException;
|
|
/* */ import com.google.gson.JsonSerializationContext;
|
|
/* */ import com.minehut.cosmetics.api.CosmeticUIBridge;
|
|
/* */ import com.minehut.cosmetics.api.InteractableBehaviorBridge;
|
|
/* */ import com.minehut.cosmetics.api.PluginApi;
|
|
/* */ import com.minehut.cosmetics.commands.EquipCommand;
|
|
/* */ import com.minehut.cosmetics.commands.MenuCommand;
|
|
/* */ import com.minehut.cosmetics.commands.SkinCommand;
|
|
/* */ import com.minehut.cosmetics.commands.UnSkinCommand;
|
|
/* */ import com.minehut.cosmetics.commands.debug.Debug;
|
|
/* */ import com.minehut.cosmetics.commands.debug.GiveCosmetic;
|
|
/* */ import com.minehut.cosmetics.commands.smp.SmpCrateKeyCommand;
|
|
/* */ import com.minehut.cosmetics.config.Config;
|
|
/* */ import com.minehut.cosmetics.config.Mode;
|
|
/* */ import com.minehut.cosmetics.cosmetics.Cosmetic;
|
|
/* */ import com.minehut.cosmetics.cosmetics.CosmeticSupplier;
|
|
/* */ import com.minehut.cosmetics.cosmetics.CosmeticsManager;
|
|
/* */ import com.minehut.cosmetics.cosmetics.crates.CratesModule;
|
|
/* */ import com.minehut.cosmetics.cosmetics.entities.EntityHandler;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.CosmeticEntityListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.CosmeticItemListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.CosmeticsListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.CosmeticsTeleportListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.DeathListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.EmojiListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.LeashListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.PlayerVisibilityListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.ResourcePackListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.skins.SkinDurabilityListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.skins.SkinEquipListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.skins.SkinModifyListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.skins.SkinTriggerListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.trinkets.IceStaffListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.trinkets.InteractableListener;
|
|
/* */ import com.minehut.cosmetics.cosmetics.listeners.visibility.VisibilityHandler;
|
|
/* */ import com.minehut.cosmetics.cosmetics.properties.CosmeticSlot;
|
|
/* */ import com.minehut.cosmetics.cosmetics.types.trinket.listener.TrinketListener;
|
|
/* */ import com.minehut.cosmetics.model.request.CosmeticState;
|
|
/* */ import com.minehut.cosmetics.modules.LocalStorageManager;
|
|
/* */ import com.minehut.cosmetics.modules.polling.RankPollingModule;
|
|
/* */ import com.minehut.cosmetics.modules.polling.ResourcePackPollingModule;
|
|
/* */ import com.minehut.cosmetics.network.ExternalAPI;
|
|
/* */ import com.minehut.cosmetics.network.InternalAPI;
|
|
/* */ import com.minehut.cosmetics.network.NetworkApi;
|
|
/* */ import com.minehut.cosmetics.pack.ResourcePackManager;
|
|
/* */ import com.minehut.cosmetics.util.EntityUtil;
|
|
/* */ import com.minehut.cosmetics.util.Version;
|
|
/* */ import com.minehut.cosmetics.util.data.Key;
|
|
/* */ import java.lang.reflect.Type;
|
|
/* */ import java.util.Locale;
|
|
/* */ import java.util.function.Consumer;
|
|
/* */ import net.kyori.adventure.text.format.NamedTextColor;
|
|
/* */ import net.kyori.adventure.text.format.TextColor;
|
|
/* */ import org.bukkit.Bukkit;
|
|
/* */ import org.bukkit.World;
|
|
/* */ import org.bukkit.entity.Entity;
|
|
/* */ import org.bukkit.entity.Player;
|
|
/* */ import org.bukkit.event.Listener;
|
|
/* */ import org.bukkit.plugin.Plugin;
|
|
/* */ import org.bukkit.plugin.java.JavaPlugin;
|
|
/* */ import org.jetbrains.annotations.Nullable;
|
|
/* */
|
|
/* */ public final class Cosmetics extends JavaPlugin {
|
|
/* */ private Config config;
|
|
/* */ private CosmeticsManager manager;
|
|
/* */
|
|
/* 74 */ private InteractableBehaviorBridge behaviorBridge = new InteractableBehaviorBridge() {
|
|
/* */ @Nullable
|
|
/* */ public Consumer<Player> cosmeticBehavior(CosmeticSupplier<?> identifier) {
|
|
/* 77 */ return null;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public float mutateCooldown(Player player, float originalCooldown) {
|
|
/* 82 */ return originalCooldown;
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */ public boolean hasPermissionOverride(Player player, Cosmetic cosmetic) {
|
|
/* 87 */ return false;
|
|
/* */ }
|
|
/* */ };
|
|
/* */
|
|
/* */
|
|
/* */ @Nullable
|
|
/* */ private CosmeticUIBridge uiBridge;
|
|
/* */
|
|
/* */ @Nullable
|
|
/* */ private LocalStorageManager localStorage;
|
|
/* */ @Nullable
|
|
/* */ private CratesModule crates;
|
|
/* */ private ResourcePackPollingModule packModule;
|
|
/* */ private EntityHandler entityHandler;
|
|
/* */ private VisibilityHandler visibilityHandler;
|
|
/* */ private ResourcePackManager resourcePackManager;
|
|
/* */ private PluginApi pluginApi;
|
|
/* */ private NetworkApi api;
|
|
/* */
|
|
/* */ public void onEnable() {
|
|
/* 107 */ Key.init((Plugin)this);
|
|
/* */
|
|
/* 109 */ Gson gson = buildGson();
|
|
/* 110 */ this.config = new Config((Plugin)this);
|
|
/* 111 */ this.manager = new CosmeticsManager();
|
|
/* 112 */ this.entityHandler = new EntityHandler();
|
|
/* 113 */ this.visibilityHandler = new VisibilityHandler(this);
|
|
/* 114 */ this.resourcePackManager = new ResourcePackManager();
|
|
/* 115 */ this.pluginApi = new PluginApi(this);
|
|
/* */
|
|
/* */
|
|
/* 118 */ switch (config().mode()) { case LOBBY:
|
|
/* */ case SMP:
|
|
/* 120 */ this.api = (NetworkApi)new InternalAPI(this.config, gson);
|
|
/* 121 */ this.crates = new CratesModule(this);
|
|
/* 122 */ (new GiveCosmetic()).register((Plugin)this);
|
|
/* 123 */ (new SmpCrateKeyCommand(this)).register((Plugin)this);
|
|
/* */ break;
|
|
/* */ case PLAYER_SERVER:
|
|
/* 126 */ this.localStorage = new LocalStorageManager((Plugin)this);
|
|
/* 127 */ this.api = (NetworkApi)new ExternalAPI(this.config, gson);
|
|
/* */
|
|
/* 129 */ registerEvents((Listener)new SkinTriggerListener(this, this.manager));
|
|
/* 130 */ registerEvents((Listener)new SkinEquipListener());
|
|
/* 131 */ registerEvents((Listener)new SkinDurabilityListener());
|
|
/* 132 */ registerEvents((Listener)new SkinModifyListener());
|
|
/* */
|
|
/* */
|
|
/* 135 */ (new SkinCommand(this)).register((Plugin)this);
|
|
/* 136 */ (new UnSkinCommand()).register((Plugin)this);
|
|
/* */ break; }
|
|
/* */
|
|
/* 139 */ if (Version.V_1_19.isSupported()) {
|
|
/* 140 */ registerEvents((Listener)new PlayerVisibilityListener());
|
|
/* */ }
|
|
/* 142 */ removeCosmeticEntities();
|
|
/* */
|
|
/* */
|
|
/* 145 */ this.packModule = new ResourcePackPollingModule(this);
|
|
/* 146 */ this.packModule.init();
|
|
/* 147 */ RankPollingModule rankPollingModule = new RankPollingModule(this);
|
|
/* 148 */ rankPollingModule.init();
|
|
/* */
|
|
/* 150 */ getLogger().info("Using operation mode '%s'!".formatted(new Object[] { this.config.mode() }));
|
|
/* */
|
|
/* 152 */ registerEvents((Listener)new CosmeticsListener(this));
|
|
/* 153 */ registerEvents((Listener)new ResourcePackListener(this.packModule));
|
|
/* 154 */ registerEvents((Listener)new DeathListener(this));
|
|
/* 155 */ registerEvents((Listener)new LeashListener());
|
|
/* 156 */ registerEvents((Listener)new CosmeticsTeleportListener(this));
|
|
/* 157 */ registerEvents((Listener)new CosmeticEntityListener());
|
|
/* 158 */ registerEvents((Listener)new CosmeticItemListener());
|
|
/* 159 */ registerEvents((Listener)new TrinketListener());
|
|
/* 160 */ registerEvents((Listener)new EmojiListener(this));
|
|
/* 161 */ registerEvents((Listener)this.resourcePackManager);
|
|
/* 162 */ registerEvents((Listener)this.entityHandler);
|
|
/* */
|
|
/* */
|
|
/* 165 */ registerEvents((Listener)this.visibilityHandler);
|
|
/* */
|
|
/* */
|
|
/* 168 */ registerEvents((Listener)new IceStaffListener());
|
|
/* 169 */ registerEvents((Listener)new InteractableListener());
|
|
/* */
|
|
/* */
|
|
/* 172 */ (new MenuCommand()).register((Plugin)this);
|
|
/* 173 */ (new EquipCommand((Plugin)this, this.manager)).register((Plugin)this);
|
|
/* 174 */ (new Debug()).register((Plugin)this);
|
|
/* */ }
|
|
/* */
|
|
/* */ private void registerEvents(Listener listener) {
|
|
/* 178 */ getServer().getPluginManager().registerEvents(listener, (Plugin)this);
|
|
/* */ }
|
|
/* */
|
|
/* */ private Gson buildGson() {
|
|
/* 182 */ GsonBuilder builder = new GsonBuilder();
|
|
/* 183 */ builder.registerTypeAdapter(TextColor.class, (element, type, context) -> {
|
|
/* */ try {
|
|
/* */ return (TextColor)NamedTextColor.NAMES.value(element.getAsJsonPrimitive().getAsString().toLowerCase(Locale.ROOT));
|
|
/* 186 */ } catch (IllegalArgumentException ex) {
|
|
/* */ return (TextColor)NamedTextColor.WHITE;
|
|
/* */ }
|
|
/* */ });
|
|
/* */
|
|
/* 191 */ builder.registerTypeAdapter(CosmeticState.class, (element, type, context) -> {
|
|
/* */ CosmeticState state = new CosmeticState();
|
|
/* */
|
|
/* */ try {
|
|
/* */ JsonObject obj = element.getAsJsonObject();
|
|
/* */
|
|
/* */ for (CosmeticSlot slot : CosmeticSlot.values()) {
|
|
/* */ JsonElement idElement = obj.get(slot.name());
|
|
/* */ if (idElement != null) {
|
|
/* */ Cosmetic cosmetic = Cosmetic.fromQualifiedId(idElement.getAsString()).orElse(null);
|
|
/* */ state.set(slot, cosmetic);
|
|
/* */ }
|
|
/* */ }
|
|
/* 204 */ } catch (IllegalArgumentException illegalArgumentException) {}
|
|
/* */
|
|
/* */
|
|
/* */ return state;
|
|
/* */ });
|
|
/* */
|
|
/* */
|
|
/* 211 */ builder.registerTypeAdapter(CosmeticState.class, (element, type, context) -> {
|
|
/* */ JsonObject obj = new JsonObject();
|
|
/* */
|
|
/* */ for (CosmeticSlot slot : CosmeticSlot.values()) {
|
|
/* */ Cosmetic cosmetic = element.get(slot);
|
|
/* */
|
|
/* */ obj.addProperty(slot.name(), (cosmetic == null) ? "EMPTY" : cosmetic.getQualifiedId());
|
|
/* */ }
|
|
/* */ return (JsonElement)obj;
|
|
/* */ });
|
|
/* 221 */ return builder.create();
|
|
/* */ }
|
|
/* */
|
|
/* */ public LocalStorageManager localStorage() {
|
|
/* 225 */ if (Mode.PLAYER_SERVER != config().mode()) {
|
|
/* 226 */ throw new IllegalStateException("Must be in player server mode to access local storage");
|
|
/* */ }
|
|
/* 228 */ return this.localStorage;
|
|
/* */ }
|
|
/* */
|
|
/* */ public CosmeticsManager manager() {
|
|
/* 232 */ return this.manager;
|
|
/* */ }
|
|
/* */
|
|
/* */ public Config config() {
|
|
/* 236 */ return this.config;
|
|
/* */ }
|
|
/* */
|
|
/* */ public NetworkApi networkApi() {
|
|
/* 240 */ return this.api;
|
|
/* */ }
|
|
/* */
|
|
/* */ public PluginApi getPluginApi() {
|
|
/* 244 */ return this.pluginApi;
|
|
/* */ }
|
|
/* */
|
|
/* */ public CratesModule crates() {
|
|
/* 248 */ return this.crates;
|
|
/* */ }
|
|
/* */
|
|
/* */ public EntityHandler entityHandler() {
|
|
/* 252 */ return this.entityHandler;
|
|
/* */ }
|
|
/* */
|
|
/* */ public ResourcePackPollingModule packModule() {
|
|
/* 256 */ return this.packModule;
|
|
/* */ }
|
|
/* */
|
|
/* */ public VisibilityHandler visibilityHandler() {
|
|
/* 260 */ return this.visibilityHandler;
|
|
/* */ }
|
|
/* */
|
|
/* */ public static Mode mode() {
|
|
/* 264 */ return get().config().mode();
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ private void removeCosmeticEntities() {
|
|
/* 271 */ Bukkit.getWorlds().forEach(world -> world.getEntities().forEach(()));
|
|
/* */ }
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */
|
|
/* */ public ResourcePackManager resourcePackManager() {
|
|
/* 280 */ return this.resourcePackManager;
|
|
/* */ }
|
|
/* */
|
|
/* */ public static Cosmetics get() {
|
|
/* 284 */ return (Cosmetics)JavaPlugin.getPlugin(Cosmetics.class);
|
|
/* */ }
|
|
/* */
|
|
/* */ public InteractableBehaviorBridge getInteractableBridge() {
|
|
/* 288 */ return this.behaviorBridge;
|
|
/* */ }
|
|
/* */
|
|
/* */ public void setInteractableBridge(InteractableBehaviorBridge behaviorBridge) {
|
|
/* 292 */ this.behaviorBridge = behaviorBridge;
|
|
/* */ }
|
|
/* */ @Nullable
|
|
/* */ public CosmeticUIBridge getUiBridge() {
|
|
/* 296 */ return this.uiBridge;
|
|
/* */ }
|
|
/* */
|
|
/* */ public void setUiBridge(@Nullable CosmeticUIBridge uiBridge) {
|
|
/* 300 */ this.uiBridge = uiBridge;
|
|
/* */ }
|
|
/* */ }
|
|
|
|
|
|
/* Location: C:\Users\Xiao\Downloads\MinehutCosmetics.jar!\com\minehut\cosmetics\Cosmetics.class
|
|
* Java compiler version: 17 (61.0)
|
|
* JD-Core Version: 1.1.3
|
|
*/ |