diff --git a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java index 6b1215c3bd0..01f7fa3caf0 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java +++ b/Essentials/src/main/java/com/earth2me/essentials/AlternativeCommandsHandler.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import java.util.stream.Collectors; +import net.ess3.provider.KnownCommandsProvider; import org.bukkit.command.Command; import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.plugin.Plugin; @@ -67,7 +68,7 @@ public final void addPlugin(final Plugin plugin) { private List> getPluginCommands(Plugin plugin) { final Map commands = new HashMap<>(); - for (final Map.Entry entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) { + for (final Map.Entry entry : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) { if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) { commands.put(entry.getKey(), entry.getValue()); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java index 9e360f53841..2ae888decd9 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Essentials.java @@ -59,27 +59,11 @@ import net.ess3.nms.refl.providers.ReflSpawnEggProvider; import net.ess3.nms.refl.providers.ReflSpawnerBlockProvider; import net.ess3.nms.refl.providers.ReflSyncCommandsProvider; -import net.ess3.provider.BannerDataProvider; -import net.ess3.provider.BiomeKeyProvider; -import net.ess3.provider.ContainerProvider; -import net.ess3.provider.DamageEventProvider; -import net.ess3.provider.FormattedCommandAliasProvider; import net.ess3.provider.InventoryViewProvider; -import net.ess3.provider.ItemUnbreakableProvider; import net.ess3.provider.KnownCommandsProvider; -import net.ess3.provider.MaterialTagProvider; -import net.ess3.provider.PersistentDataProvider; import net.ess3.provider.PlayerLocaleProvider; -import net.ess3.provider.PotionMetaProvider; import net.ess3.provider.ProviderListener; -import net.ess3.provider.SerializationProvider; import net.ess3.provider.ServerStateProvider; -import net.ess3.provider.SignDataProvider; -import net.ess3.provider.SpawnEggProvider; -import net.ess3.provider.SpawnerBlockProvider; -import net.ess3.provider.SpawnerItemProvider; -import net.ess3.provider.SyncCommandsProvider; -import net.ess3.provider.WorldInfoProvider; import net.ess3.provider.providers.BaseBannerDataProvider; import net.ess3.provider.providers.BaseInventoryViewProvider; import net.ess3.provider.providers.BaseLoggerProvider; @@ -171,6 +155,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { private final transient TNTExplodeListener tntListener = new TNTExplodeListener(); private final transient Set vanishedPlayers = new LinkedHashSet<>(); private final transient Map commandMap = new HashMap<>(); + private final transient ProviderFactory providerFactory = new ProviderFactory(this); private transient ISettings settings; private transient Jails jails; private transient Warps warps; @@ -190,28 +175,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { private transient I18n i18n; private transient MetricsWrapper metrics; private transient EssentialsTimer timer; - private transient SpawnerItemProvider spawnerItemProvider; - private transient SpawnerBlockProvider spawnerBlockProvider; - private transient SpawnEggProvider spawnEggProvider; - private transient PotionMetaProvider potionMetaProvider; - private transient BannerDataProvider bannerDataProvider; - private transient ServerStateProvider serverStateProvider; - private transient ContainerProvider containerProvider; - private transient SerializationProvider serializationProvider; - private transient KnownCommandsProvider knownCommandsProvider; - private transient FormattedCommandAliasProvider formattedCommandAliasProvider; private transient ProviderListener recipeBookEventProvider; - private transient MaterialTagProvider materialTagProvider; - private transient SyncCommandsProvider syncCommandsProvider; - private transient PersistentDataProvider persistentDataProvider; - private transient ReflOnlineModeProvider onlineModeProvider; - private transient ItemUnbreakableProvider unbreakableProvider; - private transient WorldInfoProvider worldInfoProvider; - private transient PlayerLocaleProvider playerLocaleProvider; - private transient SignDataProvider signDataProvider; - private transient DamageEventProvider damageEventProvider; - private transient BiomeKeyProvider biomeKeyProvider; - private transient InventoryViewProvider inventoryViewProvider; private transient Kits kits; private transient RandomTeleport randomTeleport; private transient UpdateChecker updateChecker; @@ -392,129 +356,87 @@ public void onEnable() { execTimer.mark("Init(Jails)"); EconomyLayers.onEnable(this); + execTimer.mark("Init(EconomyLayers)"); - //Spawner item provider only uses one but it's here for legacy... - spawnerItemProvider = new BlockMetaSpawnerItemProvider(); + // Spawner item provider only uses one, but it's here for legacy... + providerFactory.registerProvider(BlockMetaSpawnerItemProvider.class); - //Spawner block providers - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_12_0_R01)) { - spawnerBlockProvider = new ReflSpawnerBlockProvider(); - } else { - spawnerBlockProvider = new BukkitSpawnerBlockProvider(); - } + // Spawner block providers + providerFactory.registerProvider(ReflSpawnerBlockProvider.class, BukkitSpawnerBlockProvider.class); - //Spawn Egg Providers - if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) { - spawnEggProvider = new LegacySpawnEggProvider(); - } else if (VersionUtil.getServerBukkitVersion().isLowerThanOrEqualTo(VersionUtil.v1_12_2_R01)) { - spawnEggProvider = new ReflSpawnEggProvider(); - } else { - spawnEggProvider = new FlatSpawnEggProvider(); - } + // Spawn Egg Providers + providerFactory.registerProvider(LegacySpawnEggProvider.class, ReflSpawnEggProvider.class, FlatSpawnEggProvider.class); //Potion Meta Provider - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) { - potionMetaProvider = new ModernPotionMetaProvider(); - } else if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_9_R01)) { - potionMetaProvider = new PrehistoricPotionMetaProvider(); - } else { - potionMetaProvider = new LegacyPotionMetaProvider(); - } + providerFactory.registerProvider(PrehistoricPotionMetaProvider.class, LegacyPotionMetaProvider.class, ModernPotionMetaProvider.class); //Banner Meta Provider - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_6_R01)) { - bannerDataProvider = new BaseBannerDataProvider(); - } else { - bannerDataProvider = new LegacyBannerDataProvider(); - } + providerFactory.registerProvider(LegacyBannerDataProvider.class, BaseBannerDataProvider.class); - //Server State Provider - //Container Provider - if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_15_2_R01)) { - serverStateProvider = new PaperServerStateProvider(); - containerProvider = new PaperContainerProvider(); - serializationProvider = new PaperSerializationProvider(); - } else { - serverStateProvider = new ReflServerStateProvider(); - } + // Server State Provider + providerFactory.registerProvider(ReflServerStateProvider.class, PaperServerStateProvider.class); - //Event Providers - if (PaperLib.isPaper()) { - try { - Class.forName("com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent"); - recipeBookEventProvider = new PaperRecipeBookListener(event -> { - if (this.getUser(((PlayerEvent) event).getPlayer()).isRecipeSee()) { - ((Cancellable) event).setCancelled(true); - } - }); - } catch (final ClassNotFoundException ignored) { - } - } + // Container Provider + providerFactory.registerProvider(PaperContainerProvider.class); - //Known Commands Provider - if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01)) { - knownCommandsProvider = new PaperKnownCommandsProvider(); - } else { - knownCommandsProvider = new ReflKnownCommandsProvider(); - } + // Serialization Provider + providerFactory.registerProvider(PaperSerializationProvider.class); - // Command aliases provider - formattedCommandAliasProvider = new ReflFormattedCommandAliasProvider(PaperLib.isPaper()); + // Known Commands Provider + providerFactory.registerProvider(ReflKnownCommandsProvider.class, PaperKnownCommandsProvider.class); + + // Command Aliases Provider + providerFactory.registerProvider(ReflFormattedCommandAliasProvider.class); // Material Tag Providers - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_13_0_R01)) { - materialTagProvider = PaperLib.isPaper() ? new PaperMaterialTagProvider() : new BukkitMaterialTagProvider(); - } + providerFactory.registerProvider(BukkitMaterialTagProvider.class, PaperMaterialTagProvider.class); // Sync Commands Provider - syncCommandsProvider = new ReflSyncCommandsProvider(); + providerFactory.registerProvider(ReflSyncCommandsProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) { - persistentDataProvider = new ModernPersistentDataProvider(this); - } else { - persistentDataProvider = new ReflPersistentDataProvider(this); - } + // Persistent Data Provider + providerFactory.registerProvider(ReflPersistentDataProvider.class, ModernPersistentDataProvider.class); - onlineModeProvider = new ReflOnlineModeProvider(); + // Online Mode Provider + providerFactory.registerProvider(ReflOnlineModeProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_11_2_R01)) { - unbreakableProvider = new ModernItemUnbreakableProvider(); - } else { - unbreakableProvider = new LegacyItemUnbreakableProvider(); - } + // Unbreakable Provider + providerFactory.registerProvider(LegacyItemUnbreakableProvider.class, ModernItemUnbreakableProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_17_1_R01)) { - worldInfoProvider = new ModernDataWorldInfoProvider(); - } else if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_16_5_R01)) { - worldInfoProvider = new ReflDataWorldInfoProvider(); - } else { - worldInfoProvider = new FixedHeightWorldInfoProvider(); - } + // World Info Provider + providerFactory.registerProvider(FixedHeightWorldInfoProvider.class, ReflDataWorldInfoProvider.class, ModernDataWorldInfoProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_14_4_R01)) { - signDataProvider = new ModernSignDataProvider(this); - } + // Sign Data Provider + providerFactory.registerProvider(ModernSignDataProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_12_2_R01)) { - playerLocaleProvider = new ModernPlayerLocaleProvider(); - } else { - playerLocaleProvider = new LegacyPlayerLocaleProvider(); - } + // Player Locale Provider + providerFactory.registerProvider(ModernPlayerLocaleProvider.class, LegacyPlayerLocaleProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_20_4_R01)) { - damageEventProvider = new ModernDamageEventProvider(); - } else { - damageEventProvider = new LegacyDamageEventProvider(); - } + // Damage Event Provider + providerFactory.registerProvider(ModernDamageEventProvider.class, LegacyDamageEventProvider.class); - if (VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_21_R01)) { - inventoryViewProvider = new BaseInventoryViewProvider(); - } else { - inventoryViewProvider = new LegacyInventoryViewProvider(); - } + // Inventory View Provider + providerFactory.registerProvider(LegacyInventoryViewProvider.class, BaseInventoryViewProvider.class); - if (PaperLib.isPaper() && VersionUtil.getServerBukkitVersion().isHigherThanOrEqualTo(VersionUtil.v1_19_4_R01)) { - biomeKeyProvider = new PaperBiomeKeyProvider(); + // Biome Key Provider + providerFactory.registerProvider(PaperBiomeKeyProvider.class); + + providerFactory.finalizeRegistration(); + + // Event Providers + if (PaperLib.isPaper()) { + try { + Class.forName("com.destroystokyo.paper.event.player.PlayerRecipeBookClickEvent"); + recipeBookEventProvider = new PaperRecipeBookListener(event -> { + if (this.getUser(((PlayerEvent) event).getPlayer()).isRecipeSee()) { + ((Cancellable) event).setCancelled(true); + } + }); + if (getSettings().isDebug()) { + LOGGER.log(Level.INFO, "Registered Paper Recipe Book Event Listener"); + } + } catch (final ClassNotFoundException ignored) { + } } execTimer.mark("Init(Providers)"); @@ -620,9 +542,14 @@ private void registerListeners(final PluginManager pm) { jails.resetListener(); } + @Override + public ProviderFactory getProviders() { + return providerFactory; + } + @Override public void onDisable() { - final boolean stopping = getServerStateProvider().isStopping(); + final boolean stopping = provider(ServerStateProvider.class).isStopping(); if (!stopping) { LOGGER.log(Level.SEVERE, AdventureUtil.miniToLegacy(tlLiteral("serverReloading"))); } @@ -743,11 +670,9 @@ public List onTabCompleteEssentials(final CommandSender cSender, final C // Check for disabled commands if (getSettings().isCommandDisabled(commandLabel)) { - if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) { - final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel); - if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) { - return newCmd.tabComplete(cSender, commandLabel, args); - } + final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel); + if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this)) { + return newCmd.tabComplete(cSender, commandLabel, args); } return Collections.emptyList(); } @@ -810,7 +735,8 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co } catch (final Exception ex) { LOGGER.log(Level.SEVERE, ex.getMessage(), ex); if (cSender instanceof Player) { - getBukkitAudience().sender(cSender).sendMessage(AdventureUtil.miniMessage().deserialize(tlLocale(I18n.getLocale(getPlayerLocaleProvider().getLocale((Player) cSender)), "internalError"))); + final PlayerLocaleProvider localeProvider = provider(PlayerLocaleProvider.class); + getBukkitAudience().sender(cSender).sendMessage(AdventureUtil.miniMessage().deserialize(tlLocale(I18n.getLocale(localeProvider.getLocale((Player) cSender)), "internalError"))); } else { cSender.sendMessage(tlLiteral("internalError")); } @@ -853,11 +779,9 @@ public boolean onCommandEssentials(final CommandSender cSender, final Command co // Check for disabled commands if (getSettings().isCommandDisabled(commandLabel)) { - if (getKnownCommandsProvider().getKnownCommands().containsKey(commandLabel)) { - final Command newCmd = getKnownCommandsProvider().getKnownCommands().get(commandLabel); - if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) { - return newCmd.execute(cSender, commandLabel, args); - } + final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel); + if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin()))) { + return newCmd.execute(cSender, commandLabel, args); } sender.sendTl("commandDisabled", commandLabel); return true; @@ -939,16 +863,17 @@ private boolean isEssentialsPlugin(Plugin plugin) { } public void cleanupOpenInventories() { + final InventoryViewProvider provider = provider(InventoryViewProvider.class); for (final User user : getOnlineUsers()) { if (user.isRecipeSee()) { final InventoryView view = user.getBase().getOpenInventory(); - inventoryViewProvider.getTopInventory(view).clear(); - inventoryViewProvider.close(view); + provider.getTopInventory(view).clear(); + provider.close(view); user.setRecipeSee(false); } if (user.isInvSee() || user.isEnderSee()) { - inventoryViewProvider.close(user.getBase().getOpenInventory()); + provider.close(user.getBase().getOpenInventory()); user.setInvSee(false); user.setEnderSee(false); } @@ -1375,115 +1300,11 @@ public Iterable getOnlineUsers() { return onlineUsers; } - @Override - public SpawnerItemProvider getSpawnerItemProvider() { - return spawnerItemProvider; - } - - @Override - public SpawnerBlockProvider getSpawnerBlockProvider() { - return spawnerBlockProvider; - } - - @Override - public SpawnEggProvider getSpawnEggProvider() { - return spawnEggProvider; - } - - @Override - public PotionMetaProvider getPotionMetaProvider() { - return potionMetaProvider; - } - - @Override - public BannerDataProvider getBannerDataProvider() { - return bannerDataProvider; - } - - @Override - public InventoryViewProvider getInventoryViewProvider() { - return inventoryViewProvider; - } - @Override public CustomItemResolver getCustomItemResolver() { return customItemResolver; } - @Override - public ServerStateProvider getServerStateProvider() { - return serverStateProvider; - } - - public MaterialTagProvider getMaterialTagProvider() { - return materialTagProvider; - } - - @Override - public ContainerProvider getContainerProvider() { - return containerProvider; - } - - @Override - public KnownCommandsProvider getKnownCommandsProvider() { - return knownCommandsProvider; - } - - @Override - public SerializationProvider getSerializationProvider() { - return serializationProvider; - } - - @Override - public FormattedCommandAliasProvider getFormattedCommandAliasProvider() { - return formattedCommandAliasProvider; - } - - @Override - public SyncCommandsProvider getSyncCommandsProvider() { - return syncCommandsProvider; - } - - @Override - public PersistentDataProvider getPersistentDataProvider() { - return persistentDataProvider; - } - - @Override - public ReflOnlineModeProvider getOnlineModeProvider() { - return onlineModeProvider; - } - - @Override - public ItemUnbreakableProvider getItemUnbreakableProvider() { - return unbreakableProvider; - } - - @Override - public WorldInfoProvider getWorldInfoProvider() { - return worldInfoProvider; - } - - @Override - public PlayerLocaleProvider getPlayerLocaleProvider() { - return playerLocaleProvider; - } - - @Override - public DamageEventProvider getDamageEventProvider() { - return damageEventProvider; - } - - @Override - public BiomeKeyProvider getBiomeKeyProvider() { - return biomeKeyProvider; - } - - @Override - public SignDataProvider getSignDataProvider() { - return signDataProvider; - } - @Override public PluginCommand getPluginCommand(final String cmd) { return this.getCommand(cmd); diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsBlockListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsBlockListener.java index c0a861ce737..2890bc2a79e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsBlockListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsBlockListener.java @@ -3,6 +3,8 @@ import com.earth2me.essentials.craftbukkit.Inventories; import com.earth2me.essentials.utils.MaterialUtil; import net.ess3.api.IEssentials; +import net.ess3.provider.PersistentDataProvider; +import net.ess3.provider.SpawnerItemProvider; import org.bukkit.GameMode; import org.bukkit.block.BlockState; import org.bukkit.block.CreatureSpawner; @@ -26,11 +28,11 @@ public EssentialsBlockListener(final IEssentials ess) { public void onBlockPlace(final BlockPlaceEvent event) { final ItemStack is = event.getItemInHand(); - if (is.getType() == MaterialUtil.SPAWNER && ess.getPersistentDataProvider().getString(is, "convert") != null) { + if (is.getType() == MaterialUtil.SPAWNER && ess.provider(PersistentDataProvider.class).getString(is, "convert") != null) { final BlockState blockState = event.getBlockPlaced().getState(); if (blockState instanceof CreatureSpawner) { final CreatureSpawner spawner = (CreatureSpawner) blockState; - final EntityType type = ess.getSpawnerItemProvider().getEntityType(event.getItemInHand()); + final EntityType type = ess.provider(SpawnerItemProvider.class).getEntityType(event.getItemInHand()); if (type != null && Mob.fromBukkitType(type) != null) { if (ess.getUser(event.getPlayer()).isAuthorized("essentials.spawnerconvert." + Mob.fromBukkitType(type).name().toLowerCase(Locale.ENGLISH))) { spawner.setSpawnedType(type); diff --git a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java index e6b5043e079..65d495c9955 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/main/java/com/earth2me/essentials/EssentialsPlayerListener.java @@ -17,6 +17,9 @@ import net.ess3.api.IEssentials; import net.ess3.api.events.AfkStatusChangeEvent; import net.ess3.provider.CommandSendListenerProvider; +import net.ess3.provider.FormattedCommandAliasProvider; +import net.ess3.provider.InventoryViewProvider; +import net.ess3.provider.KnownCommandsProvider; import net.ess3.provider.providers.BukkitCommandSendListenerProvider; import net.ess3.provider.providers.PaperCommandSendListenerProvider; import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent; @@ -298,7 +301,7 @@ public void onPlayerQuit(final PlayerQuitEvent event) { } user.setLogoutLocation(); if (user.isRecipeSee()) { - ess.getInventoryViewProvider().getTopInventory(user.getBase().getOpenInventory()).clear(); + ess.provider(InventoryViewProvider.class).getTopInventory(user.getBase().getOpenInventory()).clear(); } final ArrayList viewers = new ArrayList<>(user.getBase().getInventory().getViewers()); @@ -615,10 +618,10 @@ public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) // If the plugin command does not exist, check if it is an alias from commands.yml if (ess.getServer().getPluginCommand(cmd) == null) { - final Command knownCommand = ess.getKnownCommandsProvider().getKnownCommands().get(cmd); + final Command knownCommand = ess.provider(KnownCommandsProvider.class).getKnownCommands().get(cmd); if (knownCommand instanceof FormattedCommandAlias) { final FormattedCommandAlias command = (FormattedCommandAlias) knownCommand; - for (String fullCommand : ess.getFormattedCommandAliasProvider().createCommands(command, event.getPlayer(), args.split(" "))) { + for (String fullCommand : ess.provider(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) { handlePlayerCommandPreprocess(event, fullCommand); } return; @@ -892,14 +895,15 @@ public void run() { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onInventoryClickEvent(final InventoryClickEvent event) { Player refreshPlayer = null; - final Inventory top = ess.getInventoryViewProvider().getTopInventory(event.getView()); + final InventoryViewProvider provider = ess.provider(InventoryViewProvider.class); + final Inventory top = provider.getTopInventory(event.getView()); final InventoryType type = top.getType(); final Inventory clickedInventory; if (event.getRawSlot() < 0) { clickedInventory = null; } else { - clickedInventory = event.getRawSlot() < top.getSize() ? top : ess.getInventoryViewProvider().getBottomInventory(event.getView()); + clickedInventory = event.getRawSlot() < top.getSize() ? top : provider.getBottomInventory(event.getView()); } final User user = ess.getUser((Player) event.getWhoClicked()); @@ -958,7 +962,8 @@ private boolean isPreventBindingHat(User user, PlayerInventory inventory) { @EventHandler(priority = EventPriority.MONITOR) public void onInventoryCloseEvent(final InventoryCloseEvent event) { Player refreshPlayer = null; - final Inventory top = ess.getInventoryViewProvider().getTopInventory(event.getView()); + final InventoryViewProvider provider = ess.provider(InventoryViewProvider.class); + final Inventory top = provider.getTopInventory(event.getView()); final InventoryType type = top.getType(); if (type == InventoryType.PLAYER) { final User user = ess.getUser((Player) event.getPlayer()); @@ -972,7 +977,7 @@ public void onInventoryCloseEvent(final InventoryCloseEvent event) { final User user = ess.getUser((Player) event.getPlayer()); if (user.isRecipeSee()) { user.setRecipeSee(false); - ess.getInventoryViewProvider().getTopInventory(event.getView()).clear(); + provider.getTopInventory(event.getView()).clear(); refreshPlayer = user.getBase(); } } else if (type == InventoryType.CHEST && top.getSize() == 9) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java b/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java index 598b1abe51e..bdcaa1dcae1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/IEssentials.java @@ -8,25 +8,7 @@ import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.updatecheck.UpdateChecker; import com.earth2me.essentials.userstorage.IUserMap; -import net.ess3.nms.refl.providers.ReflOnlineModeProvider; -import net.ess3.provider.BannerDataProvider; -import net.ess3.provider.BiomeKeyProvider; -import net.ess3.provider.ContainerProvider; -import net.ess3.provider.DamageEventProvider; -import net.ess3.provider.FormattedCommandAliasProvider; -import net.ess3.provider.InventoryViewProvider; -import net.ess3.provider.ItemUnbreakableProvider; -import net.ess3.provider.KnownCommandsProvider; -import net.ess3.provider.MaterialTagProvider; -import net.ess3.provider.PersistentDataProvider; -import net.ess3.provider.PlayerLocaleProvider; -import net.ess3.provider.SerializationProvider; -import net.ess3.provider.ServerStateProvider; -import net.ess3.provider.SignDataProvider; -import net.ess3.provider.SpawnerBlockProvider; -import net.ess3.provider.SpawnerItemProvider; -import net.ess3.provider.SyncCommandsProvider; -import net.ess3.provider.WorldInfoProvider; +import net.ess3.provider.Provider; import net.essentialsx.api.v2.services.BalanceTop; import net.essentialsx.api.v2.services.mail.MailService; import org.bukkit.Server; @@ -157,43 +139,11 @@ public interface IEssentials extends Plugin { Iterable getOnlineUsers(); - SpawnerItemProvider getSpawnerItemProvider(); - - SpawnerBlockProvider getSpawnerBlockProvider(); - - ServerStateProvider getServerStateProvider(); - - MaterialTagProvider getMaterialTagProvider(); - - ContainerProvider getContainerProvider(); - - KnownCommandsProvider getKnownCommandsProvider(); - - SerializationProvider getSerializationProvider(); - - FormattedCommandAliasProvider getFormattedCommandAliasProvider(); - - SyncCommandsProvider getSyncCommandsProvider(); - - PersistentDataProvider getPersistentDataProvider(); - - ReflOnlineModeProvider getOnlineModeProvider(); - - ItemUnbreakableProvider getItemUnbreakableProvider(); - - WorldInfoProvider getWorldInfoProvider(); - - SignDataProvider getSignDataProvider(); - - PlayerLocaleProvider getPlayerLocaleProvider(); - - DamageEventProvider getDamageEventProvider(); - - BiomeKeyProvider getBiomeKeyProvider(); - - BannerDataProvider getBannerDataProvider(); + PluginCommand getPluginCommand(String cmd); - InventoryViewProvider getInventoryViewProvider(); + ProviderFactory getProviders(); - PluginCommand getPluginCommand(String cmd); + default

P provider(final Class

providerClass) { + return getProviders().get(providerClass); + } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/Kit.java b/Essentials/src/main/java/com/earth2me/essentials/Kit.java index 322fad65fc1..2c9753e0428 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Kit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Kit.java @@ -12,6 +12,7 @@ import net.ess3.api.IEssentials; import net.ess3.api.TranslatableException; import net.ess3.api.events.KitClaimEvent; +import net.ess3.provider.SerializationProvider; import net.essentialsx.api.v2.events.KitPreExpandItemsEvent; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -191,13 +192,14 @@ public boolean expandItems(final User user, final List items) throws Exc } final ItemStack stack; + final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class); if (kitItem.startsWith("@")) { - if (ess.getSerializationProvider() == null) { + if (serializationProvider == null) { ess.getLogger().log(Level.WARNING, AdventureUtil.miniToLegacy(tlLiteral("kitError3", kitName, user.getName()))); continue; } - stack = ess.getSerializationProvider().deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))); + stack = serializationProvider.deserializeItem(Base64Coder.decodeLines(kitItem.substring(1))); } else { final String[] parts = kitItem.split(" +"); final ItemStack parseStack = ess.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); diff --git a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java index a317b2ff27a..68d9cf68ed7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java +++ b/Essentials/src/main/java/com/earth2me/essentials/MetaItemStack.java @@ -11,6 +11,9 @@ import com.google.common.base.Joiner; import net.ess3.api.IEssentials; import net.ess3.api.TranslatableException; +import net.ess3.provider.BannerDataProvider; +import net.ess3.provider.ItemUnbreakableProvider; +import net.ess3.provider.PotionMetaProvider; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; @@ -565,7 +568,7 @@ public void addPotionMeta(final CommandSource sender, final boolean allowShortNa } pmeta.addCustomEffect(pEffect, true); stack.setItemMeta(pmeta); - ess.getPotionMetaProvider().setSplashPotion(stack, isSplashPotion); + ess.provider(PotionMetaProvider.class).setSplashPotion(stack, isSplashPotion); resetPotionMeta(); } } @@ -655,7 +658,7 @@ public void addBannerMeta(final CommandSource sender, final boolean allowShortNa final BannerMeta meta = (BannerMeta) stack.getItemMeta(); if (split[0].equalsIgnoreCase("basecolor")) { final Color color = Color.fromRGB(Integer.parseInt(split[1])); - ess.getBannerDataProvider().setBaseColor(stack, DyeColor.getByColor(color)); + ess.provider(BannerDataProvider.class).setBaseColor(stack, DyeColor.getByColor(color)); } else if (patternType != null) { //noinspection removal final PatternType type = PatternType.getByIdentifier(split[0]); @@ -718,7 +721,7 @@ private boolean hasMetaPermission(final User user, final String metaPerm, final private void setUnbreakable(final IEssentials ess, final ItemStack is, final boolean unbreakable) { final ItemMeta meta = is.getItemMeta(); - ess.getItemUnbreakableProvider().setUnbreakable(meta, unbreakable); + ess.provider(ItemUnbreakableProvider.class).setUnbreakable(meta, unbreakable); is.setItemMeta(meta); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java b/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java new file mode 100644 index 00000000000..e9b23dc13e4 --- /dev/null +++ b/Essentials/src/main/java/com/earth2me/essentials/ProviderFactory.java @@ -0,0 +1,137 @@ +package com.earth2me.essentials; + +import io.papermc.lib.PaperLib; +import net.ess3.provider.Provider; +import net.essentialsx.providers.NullableProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; +import org.bukkit.plugin.Plugin; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; + +public class ProviderFactory { + private final Map, Provider> providers = new HashMap<>(); + private final Map, List>> registeredProviders = new HashMap<>(); + private final Essentials essentials; + + public ProviderFactory(final Essentials essentials) { + this.essentials = essentials; + } + + /** + * Gets the provider which has been selected for the given type. + * @param providerClass The provider type. + * @return the provider or null if no provider could be selected for that type. + */ + public

P get(final Class

providerClass) { + final Provider provider = providers.get(providerClass); + if (provider == null) { + return null; + } + //noinspection unchecked + return (P) provider; + } + + @SafeVarargs + public final void registerProvider(final Class... toRegister) { + for (final Class provider : toRegister) { + final Class superclass = provider.getInterfaces().length > 0 ? provider.getInterfaces()[0] : provider.getSuperclass(); + if (Provider.class.isAssignableFrom(superclass)) { + //noinspection unchecked + registeredProviders.computeIfAbsent((Class) superclass, k -> new ArrayList<>()).add(provider); + if (essentials.getSettings().isDebug()) { + essentials.getLogger().info("Registered provider " + provider.getSimpleName() + " for " + superclass.getSimpleName()); + } + } + } + } + + public void finalizeRegistration() { + for (final Map.Entry, List>> entry : registeredProviders.entrySet()) { + final Class providerClass = entry.getKey(); + final boolean nullable = providerClass.isAnnotationPresent(NullableProvider.class); + Class highestProvider = null; + ProviderData highestProviderData = null; + int highestWeight = -1; + for (final Class provider : entry.getValue()) { + try { + final ProviderData providerData = provider.getAnnotation(ProviderData.class); + if (providerData.weight() > highestWeight && testProvider(provider)) { + highestWeight = providerData.weight(); + highestProvider = provider; + highestProviderData = providerData; + } + } catch (final Exception e) { + essentials.getLogger().log(Level.SEVERE, "Failed to initialize provider " + provider.getName(), e); + } + } + + if (highestProvider != null) { + essentials.getLogger().info("Selected " + highestProviderData.description() + " as the provider for " + providerClass.getSimpleName()); + providers.put(providerClass, getProviderInstance(highestProvider)); + } else if (!nullable) { + throw new IllegalStateException("No provider found for " + providerClass.getName()); + } else { + essentials.getLogger().info("No provider found for " + providerClass.getSimpleName() + ", but it is nullable"); + } + } + registeredProviders.clear(); + } + + private boolean testProvider(final Class providerClass) throws InvocationTargetException, IllegalAccessException { + try { + for (final Method method : providerClass.getMethods()) { + if (method.isAnnotationPresent(ProviderTest.class)) { + return (Boolean) method.invoke(null); + } + } + return true; + } catch (final NoClassDefFoundError ignored) { + return false; + } + } + + private

P getProviderInstance(final Class

provider) { + try { + final Constructor constructor = provider.getConstructors()[0]; + if (constructor.getParameterTypes().length == 0) { + //noinspection unchecked + return (P) constructor.newInstance(); + } + final Object[] args = new Object[constructor.getParameterTypes().length]; + + /* + Providers can have constructors with any of the following types, and this code will automatically supply them; + - Plugin - The Essentials instance will be passed + - boolean - True will be passed if this server is running Paper, otherwise false. + */ + for (int i = 0; i < args.length; i++) { + final Class paramType = constructor.getParameterTypes()[i]; + if (paramType.isAssignableFrom(Plugin.class)) { + args[i] = essentials; + } else if (paramType.isAssignableFrom(boolean.class)) { + args[i] = PaperLib.isPaper(); + } else { + throw new IllegalArgumentException("Unsupported parameter type " + paramType.getName()); + } + } + + //noinspection unchecked + return (P) constructor.newInstance(args); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + try { + return provider.getConstructor().newInstance(); + } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex) { + e.printStackTrace(); + throw new RuntimeException(ex); + } + } + } +} diff --git a/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java b/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java index 1529fd74430..163e76dcaa0 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java +++ b/Essentials/src/main/java/com/earth2me/essentials/RandomTeleport.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.VersionUtil; import io.papermc.lib.PaperLib; import net.ess3.provider.BiomeKeyProvider; +import net.ess3.provider.WorldInfoProvider; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -29,12 +30,12 @@ public class RandomTeleport implements IConf { private final IEssentials ess; private final EssentialsConfiguration config; private final Map> cachedLocations = new HashMap<>(); + private WorldInfoProvider worldInfoProvider; public RandomTeleport(final IEssentials essentials) { this.ess = essentials; config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml", "Configuration for the random teleport command.\nUse the /settpr command in-game to set random teleport locations."); - reloadConfig(); } public EssentialsConfiguration getConfig() { @@ -43,6 +44,7 @@ public EssentialsConfiguration getConfig() { @Override public void reloadConfig() { + worldInfoProvider = ess.provider(WorldInfoProvider.class); config.load(); cachedLocations.clear(); } @@ -200,7 +202,7 @@ private CompletableFuture calculateRandomLocation(final Location cente final Location location = new Location( center.getWorld(), center.getX() + offsetX, - ess.getWorldInfoProvider().getMaxHeight(center.getWorld()), + worldInfoProvider.getMaxHeight(center.getWorld()), center.getZ() + offsetZ, 360 * RANDOM.nextFloat() - 180, 0 @@ -219,7 +221,7 @@ private CompletableFuture calculateRandomLocation(final Location cente // Returns an appropriate elevation for a given location in the nether, or MIN_VALUE if none is found private double getNetherYAt(final Location location) { final World world = location.getWorld(); - for (int y = 32; y < ess.getWorldInfoProvider().getMaxHeight(world); ++y) { + for (int y = 32; y < worldInfoProvider.getMaxHeight(world); ++y) { if (Material.BEDROCK.equals(world.getBlockAt(location.getBlockX(), y, location.getBlockZ()).getType())) { break; } @@ -231,7 +233,7 @@ private double getNetherYAt(final Location location) { } private boolean isValidRandomLocation(final Location location) { - return location.getBlockY() > ess.getWorldInfoProvider().getMinHeight(location.getWorld()) && !isExcludedBiome(location); + return location.getBlockY() > worldInfoProvider.getMinHeight(location.getWorld()) && !isExcludedBiome(location); } // Exclude biome if enum or namespaced key matches @@ -247,7 +249,7 @@ private boolean isExcludedBiome(final Location location) { return false; } final String biomeKey; - final BiomeKeyProvider biomeKeyProvider = ess.getBiomeKeyProvider(); + final BiomeKeyProvider biomeKeyProvider = ess.provider(BiomeKeyProvider.class); if (biomeKeyProvider != null) { // Works with custom biome keys biomeKey = biomeKeyProvider.getBiomeKey(location.getBlock()).toString(); diff --git a/Essentials/src/main/java/com/earth2me/essentials/Settings.java b/Essentials/src/main/java/com/earth2me/essentials/Settings.java index f817dca9273..4f490d5841a 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/Settings.java +++ b/Essentials/src/main/java/com/earth2me/essentials/Settings.java @@ -14,6 +14,8 @@ import com.earth2me.essentials.utils.LocationUtil; import com.earth2me.essentials.utils.NumberUtil; import net.ess3.api.IEssentials; +import net.ess3.provider.KnownCommandsProvider; +import net.ess3.provider.SyncCommandsProvider; import net.essentialsx.api.v2.ChatType; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextColor; @@ -338,9 +340,11 @@ public boolean isVerboseCommandUsages() { } private void _addAlternativeCommand(final String label, final Command current) { + final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class); + Command cmd = ess.getAlternativeCommandsHandler().getAlternative(label); if (cmd == null) { - for (final Map.Entry entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) { + for (final Map.Entry entry : knownCommandsProvider.getKnownCommands().entrySet()) { final String[] split = entry.getKey().split(":"); if (entry.getValue() != current && split[split.length - 1].equals(label)) { cmd = entry.getValue(); @@ -350,7 +354,7 @@ private void _addAlternativeCommand(final String label, final Command current) { } if (cmd != null) { - ess.getKnownCommandsProvider().getKnownCommands().put(label, cmd); + knownCommandsProvider.getKnownCommands().put(label, cmd); } } @@ -809,14 +813,16 @@ public void reloadConfig() { overriddenCommands = _getOverriddenCommands(); playerCommands = _getPlayerCommands(); + final KnownCommandsProvider knownCommandsProvider = ess.provider(KnownCommandsProvider.class); + // This will be late loaded - if (ess.getKnownCommandsProvider() != null) { + if (knownCommandsProvider != null) { boolean mapModified = false; if (!disabledBukkitCommands.isEmpty()) { if (isDebug()) { ess.getLogger().log(Level.INFO, "Re-adding " + disabledBukkitCommands.size() + " disabled commands!"); } - ess.getKnownCommandsProvider().getKnownCommands().putAll(disabledBukkitCommands); + knownCommandsProvider.getKnownCommands().putAll(disabledBukkitCommands); disabledBukkitCommands.clear(); mapModified = true; } @@ -840,7 +846,7 @@ public void reloadConfig() { if (isDebug()) { ess.getLogger().log(Level.INFO, "Attempting removal of " + effectiveAlias); } - final Command removed = ess.getKnownCommandsProvider().getKnownCommands().remove(effectiveAlias); + final Command removed = knownCommandsProvider.getKnownCommands().remove(effectiveAlias); if (removed != null) { if (isDebug()) { ess.getLogger().log(Level.INFO, "Adding command " + effectiveAlias + " to disabled map!"); @@ -858,14 +864,16 @@ public void reloadConfig() { } } + final SyncCommandsProvider syncCommandsProvider = ess.provider(SyncCommandsProvider.class); + if (mapModified) { if (isDebug()) { ess.getLogger().log(Level.INFO, "Syncing commands"); } if (reloadCount.get() < 2) { - ess.scheduleSyncDelayedTask(() -> ess.getSyncCommandsProvider().syncCommands()); + ess.scheduleSyncDelayedTask(syncCommandsProvider::syncCommands); } else { - ess.getSyncCommandsProvider().syncCommands(); + syncCommandsProvider.syncCommands(); } } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/User.java b/Essentials/src/main/java/com/earth2me/essentials/User.java index 595c659f63e..ec823e2062e 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/User.java +++ b/Essentials/src/main/java/com/earth2me/essentials/User.java @@ -21,6 +21,7 @@ import net.ess3.api.events.JailStatusChangeEvent; import net.ess3.api.events.MuteStatusChangeEvent; import net.ess3.api.events.UserBalanceUpdateEvent; +import net.ess3.provider.PlayerLocaleProvider; import net.essentialsx.api.v2.events.TransactionEvent; import net.essentialsx.api.v2.services.mail.MailSender; import net.kyori.adventure.text.Component; @@ -1088,7 +1089,8 @@ public void sendTl(String tlKey, Object... args) { @Override public String playerTl(String tlKey, Object... args) { if (ess.getSettings().isPerPlayerLocale()) { - return tlLocale(getPlayerLocale(ess.getPlayerLocaleProvider().getLocale(base)), tlKey, args); + final PlayerLocaleProvider provider = ess.provider(PlayerLocaleProvider.class); + return tlLocale(getPlayerLocale(provider.getLocale(base)), tlKey, args); } return tlLiteral(tlKey, args); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandanvil.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandanvil.java index 7497980f871..7619086dde4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandanvil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandanvil.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.ContainerProvider; import org.bukkit.Server; public class Commandanvil extends EssentialsCommand { @@ -11,11 +12,13 @@ public Commandanvil() { @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - if (ess.getContainerProvider() == null) { + final ContainerProvider containerProvider = ess.provider(ContainerProvider.class); + + if (containerProvider == null) { user.sendTl("unsupportedBrand"); return; } - ess.getContainerProvider().openAnvil(user.getBase()); + containerProvider.openAnvil(user.getBase()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java index 0e5b8223fed..d940c317d29 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandbottom.java @@ -3,6 +3,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.LocationUtil; +import net.ess3.provider.WorldInfoProvider; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent; @@ -21,7 +22,7 @@ public void run(final Server server, final User user, final String commandLabel, final int bottomZ = user.getLocation().getBlockZ(); final float pitch = user.getLocation().getPitch(); final float yaw = user.getLocation().getYaw(); - final Location unsafe = new Location(user.getWorld(), bottomX, ess.getWorldInfoProvider().getMinHeight(user.getWorld()), bottomZ, yaw, pitch); + final Location unsafe = new Location(user.getWorld(), bottomX, ess.provider(WorldInfoProvider.class).getMinHeight(user.getWorld()), bottomZ, yaw, pitch); final Location safe = LocationUtil.getSafeDestination(ess, unsafe); final CompletableFuture future = getNewExceptionFuture(user.getSource(), commandLabel); future.thenAccept(success -> { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcartographytable.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcartographytable.java index 36526a6e0bf..e6ab8da9278 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcartographytable.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcartographytable.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.ContainerProvider; import org.bukkit.Server; public class Commandcartographytable extends EssentialsCommand { @@ -11,11 +12,13 @@ public Commandcartographytable() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (ess.getContainerProvider() == null) { + final ContainerProvider containerProvider = ess.provider(ContainerProvider.class); + + if (containerProvider == null) { user.sendTl("unsupportedBrand"); return; } - ess.getContainerProvider().openCartographyTable(user.getBase()); + containerProvider.openCartographyTable(user.getBase()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java index eda36424cb8..7325a75b770 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandcreatekit.java @@ -6,6 +6,7 @@ import com.earth2me.essentials.utils.DateUtil; import com.earth2me.essentials.utils.PasteUtil; import net.ess3.api.TranslatableException; +import net.ess3.provider.SerializationProvider; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.inventory.ItemStack; @@ -42,9 +43,10 @@ public void run(final Server server, final User user, final String commandLabel, final ItemStack[] items = Inventories.getInventory(user.getBase(), true); final List list = new ArrayList<>(); + final SerializationProvider serializationProvider = ess.provider(SerializationProvider.class); boolean useSerializationProvider = ess.getSettings().isUseBetterKits(); - if (useSerializationProvider && ess.getSerializationProvider() == null) { + if (useSerializationProvider && serializationProvider == null) { ess.showError(user.getSource(), new TranslatableException("createKitUnsupported"), commandLabel); useSerializationProvider = false; } @@ -53,7 +55,7 @@ public void run(final Server server, final User user, final String commandLabel, if (is != null && is.getType() != null && is.getType() != Material.AIR) { final String serialized; if (useSerializationProvider) { - serialized = "@" + Base64Coder.encodeLines(ess.getSerializationProvider().serializeItem(is)); + serialized = "@" + Base64Coder.encodeLines(serializationProvider.serializeItem(is)); } else { serialized = ess.getItemDb().serialize(is); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java index 1d65353eff4..eabef57c9f1 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandessentials.java @@ -22,6 +22,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import net.ess3.api.TranslatableException; +import net.ess3.provider.KnownCommandsProvider; +import net.ess3.provider.OnlineModeProvider; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; @@ -263,7 +265,7 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S serverData.addProperty("bukkit-version", Bukkit.getBukkitVersion()); serverData.addProperty("server-version", Bukkit.getVersion()); serverData.addProperty("server-brand", Bukkit.getName()); - serverData.addProperty("online-mode", ess.getOnlineModeProvider().getOnlineModeString()); + serverData.addProperty("online-mode", ess.provider(OnlineModeProvider.class).getOnlineModeString()); final JsonObject supportStatus = new JsonObject(); final VersionUtil.SupportStatus status = VersionUtil.getServerSupportStatus(); supportStatus.addProperty("status", status.name()); @@ -334,7 +336,7 @@ private void runDump(Server server, CommandSource sender, String commandLabel, S final Plugin essDiscordLink = Bukkit.getPluginManager().getPlugin("EssentialsDiscordLink"); final Plugin essSpawn = Bukkit.getPluginManager().getPlugin("EssentialsSpawn"); - final Map knownCommandsCopy = new HashMap<>(ess.getKnownCommandsProvider().getKnownCommands()); + final Map knownCommandsCopy = new HashMap<>(ess.provider(KnownCommandsProvider.class).getKnownCommands()); final Map disabledCommandsCopy = new HashMap<>(ess.getAlternativeCommandsHandler().disabledCommands()); // Further operations will be heavy IO diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgrindstone.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgrindstone.java index 05b379aba0e..b625683c4a5 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgrindstone.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandgrindstone.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.ContainerProvider; import org.bukkit.Server; public class Commandgrindstone extends EssentialsCommand { @@ -11,11 +12,13 @@ public Commandgrindstone() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (ess.getContainerProvider() == null) { + final ContainerProvider containerProvider = ess.provider(ContainerProvider.class); + + if (containerProvider == null) { user.sendTl("unsupportedBrand"); return; } - ess.getContainerProvider().openGrindstone(user.getBase()); + containerProvider.openGrindstone(user.getBase()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java index 2df0eb13f38..d3cb65a827b 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandhelp.java @@ -9,6 +9,7 @@ import com.earth2me.essentials.textreader.TextPager; import com.earth2me.essentials.utils.AdventureUtil; import com.earth2me.essentials.utils.NumberUtil; +import net.ess3.provider.KnownCommandsProvider; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.PluginIdentifiableCommand; @@ -36,7 +37,7 @@ protected void run(final Server server, final User user, final String commandLab if (input.getLines().isEmpty()) { if (pageStr != null && pageStr.startsWith("/")) { final String cmd = pageStr.substring(1); - for (final Map.Entry knownCmd : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) { + for (final Map.Entry knownCmd : ess.provider(KnownCommandsProvider.class).getKnownCommands().entrySet()) { if (knownCmd.getKey().equalsIgnoreCase(cmd)) { final Command bukkit = knownCmd.getValue(); final boolean isEssCommand = bukkit instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) bukkit).getPlugin().equals(ess); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkill.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkill.java index d2a76cbfade..e5145852616 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkill.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandkill.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.CommandSource; import com.earth2me.essentials.User; +import net.ess3.provider.DamageEventProvider; import org.bukkit.Server; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; @@ -29,7 +30,9 @@ protected void updatePlayer(final Server server, final CommandSource sender, fin if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) { throw new PlayerExemptException("killExempt", matchPlayer.getDisplayName()); } - final EntityDamageEvent ede = ess.getDamageEventProvider().callDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE); + final DamageEventProvider provider = ess.provider(DamageEventProvider.class); + + final EntityDamageEvent ede = provider.callDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE); if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) { return; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandloom.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandloom.java index 94cf37ed2e4..d1440c01cf0 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandloom.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandloom.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.ContainerProvider; import org.bukkit.Server; public class Commandloom extends EssentialsCommand { @@ -11,11 +12,13 @@ public Commandloom() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (ess.getContainerProvider() == null) { + final ContainerProvider containerProvider = ess.provider(ContainerProvider.class); + + if (containerProvider == null) { user.sendTl("unsupportedBrand"); return; } - ess.getContainerProvider().openLoom(user.getBase()); + containerProvider.openLoom(user.getBase()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java index 264a3effcf7..3f7d353af6f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandpay.java @@ -10,6 +10,7 @@ import net.ess3.api.MaxMoneyException; import net.ess3.api.TranslatableException; import net.ess3.api.events.UserBalanceUpdateEvent; +import net.ess3.provider.PlayerLocaleProvider; import org.bukkit.Server; import java.math.BigDecimal; @@ -42,7 +43,8 @@ public void run(final Server server, final User user, final String commandLabel, final BigDecimal amount; if (ess.getSettings().isPerPlayerLocale()) { - amount = NumberUtil.parseStringToBDecimal(ogStr, user.getPlayerLocale(ess.getPlayerLocaleProvider().getLocale(user.getBase()))); + final String playerLocale = ess.provider(PlayerLocaleProvider.class).getLocale(user.getBase()); + amount = NumberUtil.parseStringToBDecimal(ogStr, user.getPlayerLocale(playerLocale)); } else { amount = NumberUtil.parseStringToBDecimal(ogStr); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java index 5d9a27beb00..1baea775e70 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrecipe.java @@ -8,6 +8,7 @@ import com.earth2me.essentials.utils.NumberUtil; import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.TranslatableException; +import net.ess3.provider.InventoryViewProvider; import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Material; import org.bukkit.Server; @@ -133,7 +134,7 @@ public void shapedRecipe(final CommandSource sender, final ShapedRecipe recipe, if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) { item.setDurability((short) 0); } - ess.getInventoryViewProvider().getTopInventory(view).setItem(j * 3 + k + 1, item); + ess.provider(InventoryViewProvider.class).getTopInventory(view).setItem(j * 3 + k + 1, item); } } } else { @@ -186,7 +187,7 @@ public void shapelessRecipe(final CommandSource sender, final ShapelessRecipe re if (VersionUtil.PRE_FLATTENING && item.getDurability() == Short.MAX_VALUE) { item.setDurability((short) 0); } - ess.getInventoryViewProvider().setItem(view, i + 1, item); + ess.provider(InventoryViewProvider.class).setItem(view, i + 1, item); } } else { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsmithingtable.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsmithingtable.java index 2a66e93836b..0e06d5a085f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsmithingtable.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsmithingtable.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.ContainerProvider; import org.bukkit.Server; public class Commandsmithingtable extends EssentialsCommand { @@ -11,11 +12,13 @@ public Commandsmithingtable() { @Override protected void run(Server server, User user, String commandLabel, String[] args) throws Exception { - if (ess.getContainerProvider() == null) { + final ContainerProvider containerProvider = ess.provider(ContainerProvider.class); + + if (containerProvider == null) { user.sendTl("unsupportedBrand"); return; } - ess.getContainerProvider().openSmithingTable(user.getBase()); + containerProvider.openSmithingTable(user.getBase()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandspawner.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandspawner.java index 3c763b2be74..bf5ef7d98c7 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandspawner.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandspawner.java @@ -60,7 +60,7 @@ protected void run(final Server server, final User user, final String commandLab final CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState(); spawner.setSpawnedType(mob.getType()); if (delay > 0) { - final SpawnerBlockProvider spawnerBlockProvider = ess.getSpawnerBlockProvider(); + final SpawnerBlockProvider spawnerBlockProvider = ess.provider(SpawnerBlockProvider.class); spawnerBlockProvider.setMinSpawnDelay(spawner, 1); spawnerBlockProvider.setMaxSpawnDelay(spawner, Integer.MAX_VALUE); spawnerBlockProvider.setMinSpawnDelay(spawner, delay); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandstonecutter.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandstonecutter.java index 1751ffeb438..db396ca5a89 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandstonecutter.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandstonecutter.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.ContainerProvider; import org.bukkit.Server; public class Commandstonecutter extends EssentialsCommand { @@ -11,11 +12,13 @@ public Commandstonecutter() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - if (ess.getContainerProvider() == null) { + final ContainerProvider containerProvider = ess.provider(ContainerProvider.class); + + if (containerProvider == null) { user.sendTl("unsupportedBrand"); return; } - ess.getContainerProvider().openStonecutter(user.getBase()); + containerProvider.openStonecutter(user.getBase()); } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsuicide.java index eb259bc539b..2d4984447f6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandsuicide.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import com.earth2me.essentials.User; +import net.ess3.provider.DamageEventProvider; import org.bukkit.Server; import org.bukkit.event.entity.EntityDamageEvent; @@ -14,7 +15,9 @@ public Commandsuicide() { @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - final EntityDamageEvent ede = ess.getDamageEventProvider().callDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE); + final DamageEventProvider provider = ess.provider(DamageEventProvider.class); + + final EntityDamageEvent ede = provider.callDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Float.MAX_VALUE); ede.getEntity().setLastDamageCause(ede); user.getBase().setHealth(0); user.sendTl("suicideMessage"); diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtop.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtop.java index 837adf6c5d6..ebffb5459cd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtop.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandtop.java @@ -3,6 +3,7 @@ import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.LocationUtil; +import net.ess3.provider.WorldInfoProvider; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @@ -20,7 +21,7 @@ public void run(final Server server, final User user, final String commandLabel, final int topZ = user.getLocation().getBlockZ(); final float pitch = user.getLocation().getPitch(); final float yaw = user.getLocation().getYaw(); - final Location unsafe = new Location(user.getWorld(), topX, ess.getWorldInfoProvider().getMaxHeight(user.getWorld()), topZ, yaw, pitch); + final Location unsafe = new Location(user.getWorld(), topX, ess.provider(WorldInfoProvider.class).getMaxHeight(user.getWorld()), topZ, yaw, pitch); final Location safe = LocationUtil.getSafeDestination(ess, unsafe); final CompletableFuture future = getNewExceptionFuture(user.getSource(), commandLabel); future.thenAccept(success -> { diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java index 18706729899..897c3d98101 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/EssentialsCommand.java @@ -11,6 +11,7 @@ import com.google.common.collect.Maps; import net.ess3.api.IEssentials; import net.ess3.api.TranslatableException; +import net.ess3.provider.KnownCommandsProvider; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -277,7 +278,7 @@ protected List getMatchingItems(final String arg) { * Lists all commands. */ protected final List getCommands(Server server) { - final Map commandMap = Maps.newHashMap(this.ess.getKnownCommandsProvider().getKnownCommands()); + final Map commandMap = Maps.newHashMap(this.ess.provider(KnownCommandsProvider.class).getKnownCommands()); final List commands = Lists.newArrayListWithCapacity(commandMap.size()); for (final Command command : commandMap.values()) { if (!(command instanceof PluginIdentifiableCommand)) { diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java index 79043276de7..a3bcd932fdc 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/AbstractItemDb.java @@ -9,6 +9,8 @@ import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; import net.ess3.api.PluginKey; +import net.ess3.provider.BannerDataProvider; +import net.ess3.provider.PotionMetaProvider; import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.FireworkEffect; @@ -284,8 +286,9 @@ public String serialize(final ItemStack is, final boolean useResolvers) { serializeEffectMeta(sb, fireworkEffectMeta.getEffect()); } } else if (MaterialUtil.isPotion(material)) { - final boolean splash = ess.getPotionMetaProvider().isSplashPotion(is); - final Collection effects = ess.getPotionMetaProvider().getCustomEffects(is); + final PotionMetaProvider provider = ess.provider(PotionMetaProvider.class); + final boolean splash = provider.isSplashPotion(is); + final Collection effects = provider.getCustomEffects(is); for (final PotionEffect e : effects) { // long but needs to be effect:speed power:2 duration:120 in that order. @@ -316,7 +319,7 @@ public String serialize(final ItemStack is, final boolean useResolvers) { } else { final BannerMeta bannerMeta = (BannerMeta) is.getItemMeta(); if (bannerMeta != null) { - DyeColor baseDyeColor = ess.getBannerDataProvider().getBaseColor(is); + DyeColor baseDyeColor = ess.provider(BannerDataProvider.class).getBaseColor(is); if (baseDyeColor == null) { baseDyeColor = MaterialUtil.getColorOf(material); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java index af2e2f9108e..eff20d361ea 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/FlatItemDb.java @@ -9,7 +9,9 @@ import com.google.gson.JsonParser; import net.ess3.api.IEssentials; import net.ess3.api.TranslatableException; +import net.ess3.provider.PersistentDataProvider; import net.ess3.provider.PotionMetaProvider; +import net.ess3.provider.SpawnerItemProvider; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; @@ -132,7 +134,7 @@ public ItemStack get(String id, final boolean useResolvers) throws Exception { final ItemData.EssentialPotionData potionData = data.getPotionData(); if (potionData != null && stack.getItemMeta() instanceof PotionMeta) { - ess.getPotionMetaProvider().setBasePotionType(stack, potionData.getType(), potionData.isExtended(), potionData.isUpgraded()); + ess.provider(PotionMetaProvider.class).setBasePotionType(stack, potionData.getType(), potionData.isExtended(), potionData.isUpgraded()); } final ItemMeta meta = stack.getItemMeta(); @@ -150,8 +152,8 @@ public ItemStack get(String id, final boolean useResolvers) throws Exception { // setItemMeta to prevent a race condition final EntityType entity = data.getEntity(); if (entity != null && material.toString().contains("SPAWNER")) { - ess.getSpawnerItemProvider().setEntityType(stack, entity); - ess.getPersistentDataProvider().set(stack, "convert", "true"); + ess.provider(SpawnerItemProvider.class).setEntityType(stack, entity); + ess.provider(PersistentDataProvider.class).set(stack, "convert", "true"); } return stack; @@ -206,10 +208,10 @@ private ItemData lookup(final ItemStack is) { final Material type = is.getType(); if (MaterialUtil.isPotion(type) && is.getItemMeta() instanceof PotionMeta) { - final PotionMetaProvider provider = ess.getPotionMetaProvider(); + final PotionMetaProvider provider = ess.provider(PotionMetaProvider.class); return new ItemData(type, new ItemData.EssentialPotionData(provider.getBasePotionType(is), provider.isUpgraded(is), provider.isExtended(is))); } else if (type.toString().contains("SPAWNER")) { - final EntityType entity = ess.getSpawnerItemProvider().getEntityType(is); + final EntityType entity = ess.provider(SpawnerItemProvider.class).getEntityType(is); return new ItemData(type, entity); } else { return new ItemData(type); diff --git a/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java b/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java index 7f13f1d1a7c..8427031c157 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java +++ b/Essentials/src/main/java/com/earth2me/essentials/items/LegacyItemDb.java @@ -7,6 +7,10 @@ import com.earth2me.essentials.utils.VersionUtil; import net.ess3.api.IEssentials; import net.ess3.api.TranslatableException; +import net.ess3.provider.PersistentDataProvider; +import net.ess3.provider.PotionMetaProvider; +import net.ess3.provider.SpawnEggProvider; +import net.ess3.provider.SpawnerItemProvider; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; @@ -187,8 +191,8 @@ public ItemStack get(final String id, final boolean useResolvers) throws Excepti if (mat == MOB_SPAWNER) { if (metaData == 0) metaData = EntityType.PIG.getTypeId(); try { - retval = ess.getSpawnerItemProvider().setEntityType(retval, EntityType.fromId(metaData)); - ess.getPersistentDataProvider().set(retval, "convert", "true"); + retval = ess.provider(SpawnerItemProvider.class).setEntityType(retval, EntityType.fromId(metaData)); + ess.provider(PersistentDataProvider.class).set(retval, "convert", "true"); } catch (final IllegalArgumentException e) { throw new Exception("Can't spawn entity ID " + metaData + " from mob spawners."); } @@ -199,10 +203,10 @@ public ItemStack get(final String id, final boolean useResolvers) throws Excepti } catch (final IllegalArgumentException e) { throw new Exception("Can't spawn entity ID " + metaData + " from spawn eggs."); } - retval = ess.getSpawnEggProvider().createEggItem(type); + retval = ess.provider(SpawnEggProvider.class).createEggItem(type); } else if (mat.name().endsWith("POTION") && VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_11_R01)) { // Only apply this to pre-1.11 as items.csv might only work in 1.11 - retval = ess.getPotionMetaProvider().createPotionItem(mat, metaData); + retval = ess.provider(PotionMetaProvider.class).createPotionItem(mat, metaData); } else { retval.setDurability(metaData); } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java index 97cac9e5b3d..f7bd95ba7c6 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/EssentialsSign.java @@ -15,6 +15,7 @@ import net.ess3.api.events.SignBreakEvent; import net.ess3.api.events.SignCreateEvent; import net.ess3.api.events.SignInteractEvent; +import net.ess3.provider.SignDataProvider; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Block; @@ -166,24 +167,26 @@ public void setOwner(final IEssentials ess, final User user, final ISign signPro } public void setOwnerData(final IEssentials ess, final User user, final ISign signProvider) { - if (ess.getSignDataProvider() == null) { + final SignDataProvider dataProvider = ess.provider(SignDataProvider.class); + if (dataProvider == null) { return; } final Sign sign = (Sign) signProvider.getBlock().getState(); - ess.getSignDataProvider().setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString()); + dataProvider.setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString()); } public boolean isOwner(final IEssentials ess, final User user, final ISign signProvider, final int nameIndex, final String namePrefix) { + final SignDataProvider dataProvider = ess.provider(SignDataProvider.class); final Sign sign = (Sign) signProvider.getBlock().getState(); - if (ess.getSignDataProvider() == null || ess.getSignDataProvider().getSignData(sign, SIGN_OWNER_KEY) == null) { + if (dataProvider == null || dataProvider.getSignData(sign, SIGN_OWNER_KEY) == null) { final boolean isLegacyOwner = FormatUtil.stripFormat(signProvider.getLine(nameIndex)).equalsIgnoreCase(getUsername(user)); - if (ess.getSignDataProvider() != null && isLegacyOwner) { - ess.getSignDataProvider().setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString()); + if (dataProvider != null && isLegacyOwner) { + dataProvider.setSignData(sign, SIGN_OWNER_KEY, user.getUUID().toString()); } return isLegacyOwner; } - if (user.getUUID().toString().equals(ess.getSignDataProvider().getSignData(sign, SIGN_OWNER_KEY))) { + if (user.getUUID().toString().equals(dataProvider.getSignData(sign, SIGN_OWNER_KEY))) { signProvider.setLine(nameIndex, namePrefix + getUsername(user)); return true; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignAnvil.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignAnvil.java index 13bb2ef1e72..59d1da322b4 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignAnvil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignAnvil.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.ContainerProvider; public class SignAnvil extends EssentialsSign { public SignAnvil() { @@ -10,7 +11,7 @@ public SignAnvil() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { - if (ess.getContainerProvider() == null) { + if (ess.provider(ContainerProvider.class) == null) { player.sendTl("unsupportedBrand"); return false; } @@ -19,7 +20,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { - ess.getContainerProvider().openAnvil(player.getBase()); + ess.provider(ContainerProvider.class).openAnvil(player.getBase()); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignCartography.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignCartography.java index e9a9e34fec7..26953aefe6f 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignCartography.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignCartography.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.ContainerProvider; public class SignCartography extends EssentialsSign { public SignCartography() { @@ -10,7 +11,7 @@ public SignCartography() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { - if (ess.getContainerProvider() == null) { + if (ess.provider(ContainerProvider.class) == null) { player.sendTl("unsupportedBrand"); return false; } @@ -19,7 +20,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { - ess.getContainerProvider().openCartographyTable(player.getBase()); + ess.provider(ContainerProvider.class).openCartographyTable(player.getBase()); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java index fe67342302c..1858180787c 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignEnchant.java @@ -21,7 +21,7 @@ public SignEnchant() { protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { final ItemStack stack; final String itemName = sign.getLine(1); - final MaterialTagProvider tagProvider = ess.getMaterialTagProvider(); + final MaterialTagProvider tagProvider = ess.provider(MaterialTagProvider.class); try { stack = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName)) ? null : getItemStack(sign.getLine(1), 1, ess); } catch (final SignException e) { @@ -66,7 +66,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException { final ItemStack playerHand = Inventories.getItemInHand(player.getBase()); - final MaterialTagProvider tagProvider = ess.getMaterialTagProvider(); + final MaterialTagProvider tagProvider = ess.provider(MaterialTagProvider.class); final String itemName = sign.getLine(1); final ItemStack search = itemName.equals("*") || itemName.equalsIgnoreCase("any") || (tagProvider != null && tagProvider.tagExists(itemName) && tagProvider.isTagged(itemName, playerHand.getType())) ? null : getItemStack(itemName, 1, ess); final Trade charge = getTrade(sign, 3, ess); diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignGrindstone.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignGrindstone.java index 3d2d1b410f7..ec73e24d802 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignGrindstone.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignGrindstone.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.ContainerProvider; public class SignGrindstone extends EssentialsSign { public SignGrindstone() { @@ -10,7 +11,7 @@ public SignGrindstone() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { - if (ess.getContainerProvider() == null) { + if (ess.provider(ContainerProvider.class) == null) { player.sendTl("unsupportedBrand"); return false; } @@ -19,7 +20,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { - ess.getContainerProvider().openGrindstone(player.getBase()); + ess.provider(ContainerProvider.class).openGrindstone(player.getBase()); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignLoom.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignLoom.java index eae93576b6c..e74a2077f24 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignLoom.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignLoom.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.ContainerProvider; public class SignLoom extends EssentialsSign { public SignLoom() { @@ -10,7 +11,7 @@ public SignLoom() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { - if (ess.getContainerProvider() == null) { + if (ess.provider(ContainerProvider.class) == null) { player.sendTl("unsupportedBrand"); return false; } @@ -19,7 +20,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { - ess.getContainerProvider().openLoom(player.getBase()); + ess.provider(ContainerProvider.class).openLoom(player.getBase()); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/signs/SignSmithing.java b/Essentials/src/main/java/com/earth2me/essentials/signs/SignSmithing.java index 2064fb1edfb..acc6a9b14af 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/signs/SignSmithing.java +++ b/Essentials/src/main/java/com/earth2me/essentials/signs/SignSmithing.java @@ -2,6 +2,7 @@ import com.earth2me.essentials.User; import net.ess3.api.IEssentials; +import net.ess3.provider.ContainerProvider; public class SignSmithing extends EssentialsSign { public SignSmithing() { @@ -10,7 +11,7 @@ public SignSmithing() { @Override protected boolean onSignCreate(final ISign sign, final User player, final String username, final IEssentials ess) { - if (ess.getContainerProvider() == null) { + if (ess.provider(ContainerProvider.class) == null) { player.sendTl("unsupportedBrand"); return false; } @@ -19,7 +20,7 @@ protected boolean onSignCreate(final ISign sign, final User player, final String @Override protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) { - ess.getContainerProvider().openSmithingTable(player.getBase()); + ess.provider(ContainerProvider.class).openSmithingTable(player.getBase()); return true; } } diff --git a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java index a4d37fb9813..d37a0a636fa 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java +++ b/Essentials/src/main/java/com/earth2me/essentials/textreader/HelpInput.java @@ -5,6 +5,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import net.ess3.api.IEssentials; +import net.ess3.provider.KnownCommandsProvider; import org.bukkit.command.Command; import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.plugin.Plugin; @@ -32,7 +33,7 @@ public HelpInput(final User user, final String match, final IEssentials ess) { } final Multimap pluginCommands = HashMultimap.create(); - for (final Command command : ess.getKnownCommandsProvider().getKnownCommands().values()) { + for (final Command command : ess.provider(KnownCommandsProvider.class).getKnownCommands().values()) { if (!(command instanceof PluginIdentifiableCommand)) { continue; } diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/CommandMapUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/CommandMapUtil.java index 287da28c4c6..336de90c438 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/CommandMapUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/CommandMapUtil.java @@ -6,6 +6,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import net.ess3.api.IEssentials; +import net.ess3.provider.FormattedCommandAliasProvider; import org.bukkit.command.Command; import org.bukkit.command.FormattedCommandAlias; import org.bukkit.command.PluginCommand; @@ -60,7 +61,7 @@ public static JsonObject toJson(IEssentials ess, Command value) { } else if (value instanceof FormattedCommandAlias) { json.addProperty("source", "commands.yml"); final JsonArray formatStrings = new JsonArray(); - for (final String entry : ess.getFormattedCommandAliasProvider().getFormatStrings((FormattedCommandAlias) value)) { + for (final String entry : ess.provider(FormattedCommandAliasProvider.class).getFormatStrings((FormattedCommandAlias) value)) { formatStrings.add(new JsonPrimitive(entry)); } json.add("bukkit_aliases", formatStrings); diff --git a/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java b/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java index ab3a8980f10..f9eb69c20cd 100644 --- a/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java +++ b/Essentials/src/main/java/com/earth2me/essentials/utils/LocationUtil.java @@ -4,6 +4,7 @@ import com.earth2me.essentials.IEssentials; import net.ess3.api.IUser; import net.ess3.api.TranslatableException; +import net.ess3.provider.WorldInfoProvider; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -113,7 +114,7 @@ public static Location getTarget(final LivingEntity entity, final int maxDistanc } public static boolean isBlockAboveAir(IEssentials ess, final World world, final int x, final int y, final int z) { - return y > ess.getWorldInfoProvider().getMaxHeight(world) || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType()); + return y > ess.provider(WorldInfoProvider.class).getMaxHeight(world) || HOLLOW_MATERIALS.contains(world.getBlockAt(x, y - 1, z).getType()); } public static boolean isBlockOutsideWorldBorder(final World world, final int x, final int z) { @@ -218,10 +219,12 @@ public static Location getSafeDestination(IEssentials ess, final Location loc) t if (loc == null || loc.getWorld() == null) { throw new TranslatableException("destinationNotSet"); } + final WorldInfoProvider worldInfoProvider = ess.provider(WorldInfoProvider.class); + final World world = loc.getWorld(); - final int worldMinY = ess.getWorldInfoProvider().getMinHeight(world); - final int worldLogicalY = ess.getWorldInfoProvider().getLogicalHeight(world); - final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : ess.getWorldInfoProvider().getMaxHeight(world); + final int worldMinY = worldInfoProvider.getMinHeight(world); + final int worldLogicalY = worldInfoProvider.getLogicalHeight(world); + final int worldMaxY = loc.getBlockY() < worldLogicalY ? worldLogicalY : worldInfoProvider.getMaxHeight(world); int x = loc.getBlockX(); int y = (int) Math.round(loc.getY()); int z = loc.getBlockZ(); @@ -278,13 +281,14 @@ public static Location getSafeDestination(IEssentials ess, final Location loc) t } public static boolean shouldFly(IEssentials ess, final Location loc) { + final WorldInfoProvider worldInfoProvider = ess.provider(WorldInfoProvider.class); final World world = loc.getWorld(); final int x = loc.getBlockX(); int y = (int) Math.round(loc.getY()); final int z = loc.getBlockZ(); int count = 0; // Check whether more than 2 unsafe block are below player. - while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= ess.getWorldInfoProvider().getMinHeight(world)) { + while (LocationUtil.isBlockUnsafe(ess, world, x, y, z) && y >= worldInfoProvider.getMinHeight(world)) { y--; count++; if (count > 2) { @@ -293,7 +297,7 @@ public static boolean shouldFly(IEssentials ess, final Location loc) { } // If not then check if player is in the void - return y < ess.getWorldInfoProvider().getMinHeight(world); + return y < worldInfoProvider.getMinHeight(world); } public static class Vector3D { diff --git a/Essentials/src/main/java/net/ess3/api/IEssentials.java b/Essentials/src/main/java/net/ess3/api/IEssentials.java index 92ebfe981d4..4344ea1cfde 100644 --- a/Essentials/src/main/java/net/ess3/api/IEssentials.java +++ b/Essentials/src/main/java/net/ess3/api/IEssentials.java @@ -1,8 +1,6 @@ package net.ess3.api; import com.earth2me.essentials.items.CustomItemResolver; -import net.ess3.provider.PotionMetaProvider; -import net.ess3.provider.SpawnEggProvider; import java.util.Collection; @@ -19,20 +17,6 @@ public interface IEssentials extends com.earth2me.essentials.IEssentials { */ Collection getVanishedPlayersNew(); - /** - * Get the spawn egg provider for the current platform. - * - * @return The current active spawn egg provider - */ - SpawnEggProvider getSpawnEggProvider(); - - /** - * Get the potion meta provider for the current platform. - * - * @return The current active potion meta provider - */ - PotionMetaProvider getPotionMetaProvider(); - /** * Get the {@link CustomItemResolver} that is currently in use. * diff --git a/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyBannerDataProvider.java b/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyBannerDataProvider.java index afd971ffd14..2a06ad753f8 100644 --- a/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyBannerDataProvider.java +++ b/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyBannerDataProvider.java @@ -1,10 +1,12 @@ package net.ess3.provider.providers; import net.ess3.provider.BannerDataProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.DyeColor; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BannerMeta; +@ProviderData(description = "Legacy Banner Meta Provider") public class LegacyBannerDataProvider implements BannerDataProvider { @Override public DyeColor getBaseColor(ItemStack stack) { @@ -18,9 +20,4 @@ public void setBaseColor(ItemStack stack, DyeColor color) { bannerMeta.setBaseColor(color); stack.setItemMeta(bannerMeta); } - - @Override - public String getDescription() { - return "Legacy Banner Meta Provider"; - } } diff --git a/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyInventoryViewProvider.java b/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyInventoryViewProvider.java index 1fd5ca68f35..7a7fbfbddce 100644 --- a/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyInventoryViewProvider.java +++ b/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyInventoryViewProvider.java @@ -1,10 +1,12 @@ package net.ess3.provider.providers; import net.ess3.provider.InventoryViewProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +@ProviderData(description = "Legacy InventoryView Abstract Class ABI Provider") public class LegacyInventoryViewProvider implements InventoryViewProvider { @Override public Inventory getTopInventory(InventoryView view) { @@ -25,9 +27,4 @@ public void setItem(InventoryView view, int slot, ItemStack item) { public void close(InventoryView view) { view.close(); } - - @Override - public String getDescription() { - return "Legacy InventoryView Abstract Class ABI Provider"; - } } diff --git a/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyPotionMetaProvider.java b/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyPotionMetaProvider.java index d28fe62135d..667959f5e33 100644 --- a/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyPotionMetaProvider.java +++ b/providers/1_12Provider/src/main/java/net/ess3/provider/providers/LegacyPotionMetaProvider.java @@ -2,6 +2,8 @@ import com.google.common.collect.ImmutableMap; import net.ess3.provider.PotionMetaProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; @@ -12,6 +14,7 @@ import java.util.Collection; import java.util.Map; +@ProviderData(description = "1.9-1.20.4 Potion Meta Provider", weight = 1) public class LegacyPotionMetaProvider implements PotionMetaProvider { private static final Map damageValueToType = ImmutableMap.builder() .put(1, PotionType.REGEN) @@ -127,8 +130,14 @@ public void setBasePotionType(final ItemStack stack, final PotionType type, fina stack.setItemMeta(meta); } - @Override - public String getDescription() { - return "1.9-1.20.4 Potion Meta Provider"; + @ProviderTest + public static boolean test() { + try { + // This provider was created to support the new PotionData API introduced in 1.9 + Class.forName("org.bukkit.potion.PotionData"); + return false; + } catch (final Throwable ignored) { + return true; + } } } diff --git a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyDamageEventProvider.java b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyDamageEventProvider.java index 74487c25dca..f70cb36db4e 100644 --- a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyDamageEventProvider.java +++ b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyDamageEventProvider.java @@ -1,9 +1,11 @@ package net.ess3.provider.providers; import net.ess3.provider.DamageEventProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +@ProviderData(description = "Legacy Damage Event Provider") public class LegacyDamageEventProvider implements DamageEventProvider { @Override public EntityDamageEvent callDamageEvent(Player player, EntityDamageEvent.DamageCause cause, double damage) { @@ -11,9 +13,4 @@ public EntityDamageEvent callDamageEvent(Player player, EntityDamageEvent.Damage player.getServer().getPluginManager().callEvent(ede); return ede; } - - @Override - public String getDescription() { - return "Legacy Damage Event Provider"; - } } diff --git a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyItemUnbreakableProvider.java b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyItemUnbreakableProvider.java index f4781514d77..ec1539ca0b2 100644 --- a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyItemUnbreakableProvider.java +++ b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyItemUnbreakableProvider.java @@ -1,16 +1,13 @@ package net.ess3.provider.providers; import net.ess3.provider.ItemUnbreakableProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.inventory.meta.ItemMeta; +@ProviderData(description = "Legacy Item Unbreakable Provider") public class LegacyItemUnbreakableProvider implements ItemUnbreakableProvider { @Override public void setUnbreakable(ItemMeta meta, boolean unbreakable) { meta.spigot().setUnbreakable(unbreakable); } - - @Override - public String getDescription() { - return "Legacy ItemMeta Unbreakable Provider"; - } } diff --git a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyPlayerLocaleProvider.java b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyPlayerLocaleProvider.java index faa73e39fa6..0fb601374ca 100644 --- a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyPlayerLocaleProvider.java +++ b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/LegacyPlayerLocaleProvider.java @@ -1,8 +1,10 @@ package net.ess3.provider.providers; import net.ess3.provider.PlayerLocaleProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.entity.Player; +@ProviderData(description = "Legacy Player Locale Provider") public class LegacyPlayerLocaleProvider implements PlayerLocaleProvider { @Override public String getLocale(Player player) { @@ -13,9 +15,4 @@ public String getLocale(Player player) { return null; } } - - @Override - public String getDescription() { - return "Legacy Player Locale Provider"; - } } diff --git a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/PrehistoricPotionMetaProvider.java b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/PrehistoricPotionMetaProvider.java index 05dc7ce608b..c5df091122f 100644 --- a/providers/1_8Provider/src/main/java/net/ess3/provider/providers/PrehistoricPotionMetaProvider.java +++ b/providers/1_8Provider/src/main/java/net/ess3/provider/providers/PrehistoricPotionMetaProvider.java @@ -1,6 +1,7 @@ package net.ess3.provider.providers; import net.ess3.provider.PotionMetaProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.Potion; @@ -9,6 +10,7 @@ import java.util.Collection; +@ProviderData(description = "Legacy 1.8 Potion Meta Provider") public class PrehistoricPotionMetaProvider implements PotionMetaProvider { @Override public ItemStack createPotionItem(final Material initial, final int effectId) { @@ -77,9 +79,4 @@ public void setBasePotionType(final ItemStack stack, final PotionType type, fina potion.apply(stack); } - - @Override - public String getDescription() { - return "Legacy 1.8 Potion Meta Provider"; - } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/BiomeKeyProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/BiomeKeyProvider.java index 94ee756fc03..fff7290b08a 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/BiomeKeyProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/BiomeKeyProvider.java @@ -1,8 +1,10 @@ package net.ess3.provider; +import net.essentialsx.providers.NullableProvider; import org.bukkit.NamespacedKey; import org.bukkit.block.Block; +@NullableProvider public interface BiomeKeyProvider extends Provider { NamespacedKey getBiomeKey(Block block); } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/ContainerProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/ContainerProvider.java index f1d886335a6..cb8654a99b5 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/ContainerProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/ContainerProvider.java @@ -1,8 +1,10 @@ package net.ess3.provider; +import net.essentialsx.providers.NullableProvider; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryView; +@NullableProvider public interface ContainerProvider extends Provider { InventoryView openAnvil(Player player); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/MaterialTagProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/MaterialTagProvider.java index aaf6a05effa..63f87c731d1 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/MaterialTagProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/MaterialTagProvider.java @@ -1,8 +1,10 @@ package net.ess3.provider; +import net.essentialsx.providers.NullableProvider; import org.bukkit.Material; -public interface MaterialTagProvider { +@NullableProvider +public interface MaterialTagProvider extends Provider { boolean tagExists(String tagName); boolean isTagged(String tagName, Material material); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/OnlineModeProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/OnlineModeProvider.java new file mode 100644 index 00000000000..664a26dbbb1 --- /dev/null +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/OnlineModeProvider.java @@ -0,0 +1,5 @@ +package net.ess3.provider; + +public interface OnlineModeProvider extends Provider { + String getOnlineModeString(); +} diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/Provider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/Provider.java index 5e3916ca8d1..e4100bdbe56 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/Provider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/Provider.java @@ -1,5 +1,4 @@ package net.ess3.provider; public interface Provider { - String getDescription(); } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/SerializationProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/SerializationProvider.java index 252af46be6b..6ccaf94862f 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/SerializationProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/SerializationProvider.java @@ -1,7 +1,9 @@ package net.ess3.provider; +import net.essentialsx.providers.NullableProvider; import org.bukkit.inventory.ItemStack; +@NullableProvider public interface SerializationProvider extends Provider { byte[] serializeItem(ItemStack stack); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/SignDataProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/SignDataProvider.java index f84c851444d..d4215d6b705 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/SignDataProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/SignDataProvider.java @@ -1,7 +1,9 @@ package net.ess3.provider; +import net.essentialsx.providers.NullableProvider; import org.bukkit.block.Sign; +@NullableProvider public interface SignDataProvider extends Provider { void setSignData(Sign sign, String key, String value); diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseBannerDataProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseBannerDataProvider.java index 4fbfb24a799..f7871349865 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseBannerDataProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseBannerDataProvider.java @@ -3,10 +3,13 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import net.ess3.provider.BannerDataProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +@ProviderData(description = "1.20.5+ Banner Data Provider", weight = 1) public class BaseBannerDataProvider implements BannerDataProvider { private final BiMap materialToDyeMap = HashBiMap.create(); @@ -42,8 +45,14 @@ public void setBaseColor(ItemStack stack, DyeColor color) { } } - @Override - public String getDescription() { - return "1.20.5+ Banner Data Provider."; + @ProviderTest + public static boolean test() { + try { + //noinspection unused + final Material needAVariable = Material.LIGHT_BLUE_BANNER; + return true; + } catch (final Throwable t) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseInventoryViewProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseInventoryViewProvider.java index d6b8194e218..47cd709df81 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseInventoryViewProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BaseInventoryViewProvider.java @@ -1,10 +1,13 @@ package net.ess3.provider.providers; import net.ess3.provider.InventoryViewProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; +@ProviderData(description = "1.21+ InventoryView Interface ABI Provider", weight = 1) public class BaseInventoryViewProvider implements InventoryViewProvider { @Override public Inventory getTopInventory(InventoryView view) { @@ -26,8 +29,8 @@ public void close(InventoryView view) { view.close(); } - @Override - public String getDescription() { - return "1.21+ InventoryView Interface ABI Provider"; + @ProviderTest + public static boolean test() { + return InventoryView.class.isInterface(); } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BlockMetaSpawnerItemProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BlockMetaSpawnerItemProvider.java index 79023106023..fc8acbc20bc 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BlockMetaSpawnerItemProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BlockMetaSpawnerItemProvider.java @@ -1,12 +1,14 @@ package net.ess3.provider.providers; import net.ess3.provider.SpawnerItemProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.block.BlockState; import org.bukkit.block.CreatureSpawner; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; +@ProviderData(description = "1.8.3+ Spawner Item Provider") public class BlockMetaSpawnerItemProvider implements SpawnerItemProvider { @Override public ItemStack setEntityType(final ItemStack is, final EntityType type) throws IllegalArgumentException { @@ -24,9 +26,4 @@ public EntityType getEntityType(final ItemStack is) throws IllegalArgumentExcept final CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState(); return bs.getSpawnedType(); } - - @Override - public String getDescription() { - return "1.8.3+ Spawner Provider"; - } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitCommandSendListenerProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitCommandSendListenerProvider.java index d3feffc687c..6cf3f2ee67e 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitCommandSendListenerProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitCommandSendListenerProvider.java @@ -17,9 +17,4 @@ public void onCommandSend(PlayerCommandSendEvent event) { final Predicate filter = filter(event.getPlayer()); event.getCommands().removeIf(filter); } - - @Override - public String getDescription() { - return "Bukkit synchronous command send listener"; - } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitMaterialTagProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitMaterialTagProvider.java index a6f28f96894..567b837317c 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitMaterialTagProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitMaterialTagProvider.java @@ -1,6 +1,8 @@ package net.ess3.provider.providers; import net.ess3.provider.MaterialTagProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Material; import org.bukkit.Tag; @@ -8,6 +10,7 @@ import java.util.HashMap; import java.util.Map; +@ProviderData(description = "Bukkit Material Tag Provider") public class BukkitMaterialTagProvider implements MaterialTagProvider { private final Map> stringToTagMap = new HashMap<>(); @@ -46,4 +49,14 @@ private Tag getTag(String tagName) { } return stringToTagMap.get(tagName); } + + @ProviderTest + public static boolean test() { + try { + Class.forName("org.bukkit.Tag"); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } + } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSpawnerBlockProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSpawnerBlockProvider.java index fd6e8c30e54..43494b2d132 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSpawnerBlockProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/BukkitSpawnerBlockProvider.java @@ -1,8 +1,11 @@ package net.ess3.provider.providers; import net.ess3.provider.SpawnerBlockProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.block.CreatureSpawner; +@ProviderData(description = "1.12+ Spawner Block Provider", weight = 1) public class BukkitSpawnerBlockProvider implements SpawnerBlockProvider { @Override public void setMaxSpawnDelay(final CreatureSpawner spawner, final int delay) { @@ -14,8 +17,13 @@ public void setMinSpawnDelay(final CreatureSpawner spawner, final int delay) { spawner.setMinSpawnDelay(delay); } - @Override - public String getDescription() { - return "Bukkit 1.12+ provider"; + @ProviderTest + public static boolean test() { + try { + CreatureSpawner.class.getDeclaredMethod("setMaxSpawnDelay", int.class); + return true; + } catch (final NoSuchMethodException ignored) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FixedHeightWorldInfoProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FixedHeightWorldInfoProvider.java index b4d4ffda6b6..59c81c4ecb0 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FixedHeightWorldInfoProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FixedHeightWorldInfoProvider.java @@ -1,14 +1,11 @@ package net.ess3.provider.providers; import net.ess3.provider.WorldInfoProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.World; +@ProviderData(description = "Fixed Height World Info Provider") public class FixedHeightWorldInfoProvider implements WorldInfoProvider { - @Override - public String getDescription() { - return "Fixed world info provider for pre-1.16"; - } - @Override public int getMaxHeight(World world) { // Method has existed since Beta 1.7 (yes, *beta*) diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java index 794a4770701..2240cce8a9c 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/FlatSpawnEggProvider.java @@ -1,10 +1,13 @@ package net.ess3.provider.providers; import net.ess3.provider.SpawnEggProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +@ProviderData(description = "1.13+ Spawn Egg Provider", weight = 2) public class FlatSpawnEggProvider implements SpawnEggProvider { @Override public ItemStack createEggItem(final EntityType type) throws IllegalArgumentException { @@ -21,8 +24,14 @@ public EntityType getSpawnedType(final ItemStack eggItem) throws IllegalArgument throw new IllegalArgumentException("Not a spawn egg"); } - @Override - public String getDescription() { - return "1.13+ Flattening Spawn Egg Provider"; + @ProviderTest + public static boolean test() { + try { + //noinspection unused + final Material itMakesMeDeclareAVariable = Material.COW_SPAWN_EGG; + return true; + } catch (final Throwable ignored) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/LegacySpawnEggProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/LegacySpawnEggProvider.java index c16bee48fa2..3be3e6fb267 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/LegacySpawnEggProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/LegacySpawnEggProvider.java @@ -1,12 +1,14 @@ package net.ess3.provider.providers; import net.ess3.provider.SpawnEggProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.material.SpawnEgg; @SuppressWarnings("deprecation") +@ProviderData(description = "1.8 Spawn Egg Provider") public class LegacySpawnEggProvider implements SpawnEggProvider { @Override public ItemStack createEggItem(final EntityType type) throws IllegalArgumentException { @@ -21,9 +23,4 @@ public EntityType getSpawnedType(final ItemStack eggItem) throws IllegalArgument } throw new IllegalArgumentException("Item is missing data"); } - - @Override - public String getDescription() { - return "Legacy 1.8 Spawn Egg Provider"; - } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDamageEventProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDamageEventProvider.java index 77ba5cb9bd3..990f042fc9b 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDamageEventProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDamageEventProvider.java @@ -1,12 +1,15 @@ package net.ess3.provider.providers; import net.ess3.provider.DamageEventProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.damage.DamageSource; import org.bukkit.damage.DamageType; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; @SuppressWarnings("UnstableApiUsage") +@ProviderData(description = "1.20.4+ Damage Event Provider", weight = 1) public class ModernDamageEventProvider implements DamageEventProvider { private final DamageSource MAGIC_SOURCE = DamageSource.builder(DamageType.MAGIC).build(); @@ -17,8 +20,13 @@ public EntityDamageEvent callDamageEvent(Player player, EntityDamageEvent.Damage return ede; } - @Override - public String getDescription() { - return "1.20.4+ Damage Event Provider"; + @ProviderTest + public static boolean test() { + try { + Class.forName("org.bukkit.damage.DamageSource"); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDataWorldInfoProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDataWorldInfoProvider.java index 55e10f253aa..6d840c081db 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDataWorldInfoProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernDataWorldInfoProvider.java @@ -1,14 +1,12 @@ package net.ess3.provider.providers; import net.ess3.provider.WorldInfoProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.World; +@ProviderData(description = "1.17.1+ World Info Provider", weight = 2) public class ModernDataWorldInfoProvider implements WorldInfoProvider { - @Override - public String getDescription() { - return "API world info provider for data-driven worldgen for 1.17.1+"; - } - @Override public int getMaxHeight(World world) { return world.getMaxHeight(); @@ -23,4 +21,14 @@ public int getLogicalHeight(World world) { public int getMinHeight(World world) { return world.getMinHeight(); } + + @ProviderTest + public static boolean test() { + try { + Class.forName("org.bukkit.generator.WorldInfo"); + return true; + } catch (final ClassNotFoundException ignored) { + return false; + } + } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernItemUnbreakableProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernItemUnbreakableProvider.java index 74775dd9cda..de65a32a15c 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernItemUnbreakableProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernItemUnbreakableProvider.java @@ -1,16 +1,24 @@ package net.ess3.provider.providers; import net.ess3.provider.ItemUnbreakableProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.inventory.meta.ItemMeta; +@ProviderData(description = "1.11+ Item Unbreakable Provider", weight = 1) public class ModernItemUnbreakableProvider implements ItemUnbreakableProvider { @Override public void setUnbreakable(ItemMeta meta, boolean unbreakable) { meta.setUnbreakable(unbreakable); } - @Override - public String getDescription() { - return "1.11+ ItemMeta Unbreakable Provider"; + @ProviderTest + public static boolean test() { + try { + ItemMeta.class.getDeclaredMethod("setUnbreakable", boolean.class); + return true; + } catch (final NoSuchMethodException ignored) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPersistentDataProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPersistentDataProvider.java index 7c3ebbedecb..d51d2204db2 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPersistentDataProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPersistentDataProvider.java @@ -1,6 +1,8 @@ package net.ess3.provider.providers; import net.ess3.provider.PersistentDataProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -8,6 +10,7 @@ import org.bukkit.plugin.Plugin; @SuppressWarnings("ConstantConditions") +@ProviderData(description = "1.14.4+ Persistent Data Container Provider", weight = 1) public class ModernPersistentDataProvider implements PersistentDataProvider { private final Plugin plugin; @@ -44,8 +47,13 @@ public void remove(ItemStack itemStack, String key) { itemStack.getItemMeta().getPersistentDataContainer().remove(new NamespacedKey(plugin, key)); } - @Override - public String getDescription() { - return "1.14+ Persistent Data Container Provider"; + @ProviderTest + public static boolean test() { + try { + Class.forName("org.bukkit.persistence.PersistentDataHolder"); + return true; + } catch (final ClassNotFoundException ignored) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPlayerLocaleProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPlayerLocaleProvider.java index 0075650eac8..828309a0a6e 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPlayerLocaleProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPlayerLocaleProvider.java @@ -1,16 +1,24 @@ package net.ess3.provider.providers; import net.ess3.provider.PlayerLocaleProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.entity.Player; +@ProviderData(description = "1.12.2+ Player Locale Provider", weight = 1) public class ModernPlayerLocaleProvider implements PlayerLocaleProvider { @Override public String getLocale(Player player) { return player.getLocale(); } - @Override - public String getDescription() { - return "1.12.2+ Player Locale Provider"; + @ProviderTest + public static boolean test() { + try { + Player.class.getDeclaredMethod("getLocale"); + return true; + } catch (final NoSuchMethodException ignored) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPotionMetaProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPotionMetaProvider.java index 02ad54cdb2b..d46039336d8 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPotionMetaProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernPotionMetaProvider.java @@ -1,6 +1,8 @@ package net.ess3.provider.providers; import net.ess3.provider.PotionMetaProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.PotionMeta; @@ -9,6 +11,7 @@ import java.util.Collection; +@ProviderData(description = "1.20.6+ Potion Meta Provider", weight = 2) public class ModernPotionMetaProvider implements PotionMetaProvider { @Override public ItemStack createPotionItem(Material initial, int effectId) { @@ -100,8 +103,14 @@ public void setSplashPotion(ItemStack stack, boolean isSplash) { } } - @Override - public String getDescription() { - return "1.20.5+ Potion Meta Provider"; + @ProviderTest + public static boolean test() { + try { + // This provider was created due to Potion being removed in 1.20.6 + Class.forName("org.bukkit.potion.Potion"); + return false; + } catch (final Throwable ignored) { + return true; + } } } diff --git a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernSignDataProvider.java b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernSignDataProvider.java index 84687c0ed43..99afe040a16 100644 --- a/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernSignDataProvider.java +++ b/providers/BaseProviders/src/main/java/net/ess3/provider/providers/ModernSignDataProvider.java @@ -1,11 +1,14 @@ package net.ess3.provider.providers; import net.ess3.provider.SignDataProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.NamespacedKey; import org.bukkit.block.Sign; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.Plugin; +@ProviderData(description = "1.14+ Sign Data Provider") public class ModernSignDataProvider implements SignDataProvider { private final Plugin plugin; @@ -36,8 +39,13 @@ public String getSignData(Sign sign, String key) { } } - @Override - public String getDescription() { - return "1.14+ Persistent Data Sign Provider"; + @ProviderTest + public static boolean test() { + try { + Class.forName("org.bukkit.block.TileState"); + return true; + } catch (ClassNotFoundException e) { + return false; + } } } diff --git a/providers/BaseProviders/src/main/java/net/essentialsx/providers/NullableProvider.java b/providers/BaseProviders/src/main/java/net/essentialsx/providers/NullableProvider.java new file mode 100644 index 00000000000..32d8606945f --- /dev/null +++ b/providers/BaseProviders/src/main/java/net/essentialsx/providers/NullableProvider.java @@ -0,0 +1,14 @@ +package net.essentialsx.providers; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marks a provider as nullable, meaning that an error will not be thrown if no provider is found for the given type. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface NullableProvider { +} diff --git a/providers/BaseProviders/src/main/java/net/essentialsx/providers/ProviderData.java b/providers/BaseProviders/src/main/java/net/essentialsx/providers/ProviderData.java new file mode 100644 index 00000000000..3f050847268 --- /dev/null +++ b/providers/BaseProviders/src/main/java/net/essentialsx/providers/ProviderData.java @@ -0,0 +1,21 @@ +package net.essentialsx.providers; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ProviderData { + /** + * A brief description of when this specific provider is used (MC Version, Server Software) and its name. + */ + String description(); + + /** + * If there is multiple providers for a given type that pass their {@link ProviderTest}, the one with the highest weight will be used. + * @return the weight of the provider. + */ + int weight() default 0; +} diff --git a/providers/BaseProviders/src/main/java/net/essentialsx/providers/ProviderTest.java b/providers/BaseProviders/src/main/java/net/essentialsx/providers/ProviderTest.java new file mode 100644 index 00000000000..099b88f6d9a --- /dev/null +++ b/providers/BaseProviders/src/main/java/net/essentialsx/providers/ProviderTest.java @@ -0,0 +1,11 @@ +package net.essentialsx.providers; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ProviderTest { +} diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java index f9ac85c8cc9..145a8983c17 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflDataWorldInfoProvider.java @@ -1,14 +1,12 @@ package net.ess3.nms.refl.providers; import net.ess3.provider.WorldInfoProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.World; +@ProviderData(description = "Reflection World Info Provider", weight = 1) public class ReflDataWorldInfoProvider implements WorldInfoProvider { - @Override - public String getDescription() { - return "NMS world info provider for data-driven worldgen for 1.16.x"; - } - @Override public int getMaxHeight(World world) { // Method has existed since Beta 1.7 (yes, *beta*) @@ -28,4 +26,10 @@ public int getMinHeight(World world) { // Worlds could not go below 0 until Minecraft 1.16 return 0; } + + @ProviderTest + public static boolean test() { + // TODO: THIS IS INCORRECT + return false; + } } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflFormattedCommandAliasProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflFormattedCommandAliasProvider.java index e7563ca274a..ff20f66b32d 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflFormattedCommandAliasProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflFormattedCommandAliasProvider.java @@ -2,6 +2,7 @@ import net.ess3.nms.refl.ReflUtil; import net.ess3.provider.FormattedCommandAliasProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.command.CommandSender; import org.bukkit.command.FormattedCommandAlias; @@ -12,15 +13,14 @@ import java.util.ArrayList; import java.util.List; +@ProviderData(description = "Reflection Formatted Command Alias Provider") public class ReflFormattedCommandAliasProvider implements FormattedCommandAliasProvider { - - private final boolean paper; + private final boolean senderArg; private final Field formatStringsField; private final MethodHandle buildCommandMethodHandle; - public ReflFormattedCommandAliasProvider(boolean paper) { - this.paper = paper; - + public ReflFormattedCommandAliasProvider() { + boolean senderArg = true; final Class formattedCommandAliasClass; Field formatStringsField = null; MethodHandle buildCommandMethodHandle = null; @@ -28,14 +28,16 @@ public ReflFormattedCommandAliasProvider(boolean paper) { formattedCommandAliasClass = FormattedCommandAlias.class; formatStringsField = ReflUtil.getFieldCached(formattedCommandAliasClass, "formatStrings"); - final Class[] parameterTypes; - if (paper) { - parameterTypes = new Class[] {CommandSender.class, String.class, String[].class}; - } else { - parameterTypes = new Class[] {String.class, String[].class}; + Method buildCommandMethod = ReflUtil.getMethodCached(formattedCommandAliasClass, "buildCommand", CommandSender.class, String.class, String[].class); + if (buildCommandMethod == null) { + senderArg = false; + buildCommandMethod = ReflUtil.getMethodCached(formattedCommandAliasClass, "buildCommand", String.class, String[].class); + } + + if (buildCommandMethod == null) { + throw new NoSuchMethodException("Could not find buildCommand method in FormattedCommandAlias"); } - final Method buildCommandMethod = ReflUtil.getMethodCached(formattedCommandAliasClass, "buildCommand", parameterTypes); buildCommandMethod.setAccessible(true); buildCommandMethodHandle = MethodHandles.lookup().unreflect(buildCommandMethod); } catch (final Exception ex) { @@ -43,6 +45,7 @@ public ReflFormattedCommandAliasProvider(boolean paper) { } finally { this.formatStringsField = formatStringsField; this.buildCommandMethodHandle = buildCommandMethodHandle; + this.senderArg = senderArg; } } @@ -75,7 +78,7 @@ public String[] getFormatStrings(FormattedCommandAlias command) { @Override public String buildCommand(FormattedCommandAlias command, CommandSender sender, String formatString, String[] args) { try { - if (paper) { + if (senderArg) { return (String) buildCommandMethodHandle.invoke(command, sender, formatString, args); } else { return (String) buildCommandMethodHandle.invoke(command, formatString, args); @@ -85,8 +88,4 @@ public String buildCommand(FormattedCommandAlias command, CommandSender sender, } } - @Override - public String getDescription() { - return "NMS Reflection Provider for FormattedCommandAlias methods"; - } } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflKnownCommandsProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflKnownCommandsProvider.java index 19c558d5669..7cd5167200d 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflKnownCommandsProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflKnownCommandsProvider.java @@ -2,6 +2,7 @@ import net.ess3.nms.refl.ReflUtil; import net.ess3.provider.KnownCommandsProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.Command; @@ -11,6 +12,7 @@ import java.util.HashMap; import java.util.Map; +@ProviderData(description = "Reflection Known Commands Provider") public class ReflKnownCommandsProvider implements KnownCommandsProvider { private final Map knownCommands; @@ -25,6 +27,7 @@ public ReflKnownCommandsProvider() { final SimpleCommandMap simpleCommandMap = (SimpleCommandMap) commandMapField.get(Bukkit.getServer()); final Field knownCommandsField = ReflUtil.getFieldCached(SimpleCommandMap.class, "knownCommands"); if (knownCommandsField != null) { + //noinspection unchecked knownCommands = (Map) knownCommandsField.get(simpleCommandMap); } } @@ -40,9 +43,4 @@ public ReflKnownCommandsProvider() { public Map getKnownCommands() { return this.knownCommands; } - - @Override - public String getDescription() { - return "NMS Reflection Known Commands Provider"; - } } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflOnlineModeProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflOnlineModeProvider.java index ff61a7c9de1..2205fcc8650 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflOnlineModeProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflOnlineModeProvider.java @@ -1,13 +1,16 @@ package net.ess3.nms.refl.providers; import net.ess3.nms.refl.ReflUtil; +import net.ess3.provider.OnlineModeProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.Bukkit; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -public class ReflOnlineModeProvider { +@ProviderData(description = "Reflection Online Mode Provider") +public class ReflOnlineModeProvider implements OnlineModeProvider { private final MethodHandle spigotBungeeGetter; private final MethodHandle paperBungeeGetter; private final Object paperProxiesInstance; @@ -42,6 +45,7 @@ public ReflOnlineModeProvider() { this.fancyPaperCheck = fancyCheck; } + @Override public String getOnlineModeString() { if (spigotBungeeGetter == null) { return Bukkit.getOnlineMode() ? "Online Mode" : "Offline Mode"; @@ -53,7 +57,7 @@ public String getOnlineModeString() { } if (fancyPaperCheck) { - if ((boolean) paperBungeeGetter.invoke()) { + if ((boolean) (paperProxiesInstance != null ? paperBungeeGetter.invoke(paperProxiesInstance) : paperBungeeGetter.invoke())) { // Could be Velocity or Bungee, so do not specify. return "Proxy Mode"; } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflPersistentDataProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflPersistentDataProvider.java index 41fa62a008d..8ddd34e320f 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflPersistentDataProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflPersistentDataProvider.java @@ -2,6 +2,7 @@ import net.ess3.nms.refl.ReflUtil; import net.ess3.provider.PersistentDataProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; @@ -15,6 +16,7 @@ * Stores persistent data on 1.8-1.13 in a manner that's consistent with PDC on 1.14+ to enable * seamless upgrades. */ +@ProviderData(description = "Reflection Persistent Data Container Provider") public class ReflPersistentDataProvider implements PersistentDataProvider { private static final String PDC_ROOT_TAG = "PublicBukkitValues"; private static final String ROOT_TAG = "tag"; @@ -123,9 +125,4 @@ public void remove(ItemStack itemStack, String key) { } catch (Throwable ignored) { } } - - @Override - public String getDescription() { - return "1.13 >= Persistent Data Container Provider"; - } } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflServerStateProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflServerStateProvider.java index 86711facb66..81e445f1d91 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflServerStateProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflServerStateProvider.java @@ -2,11 +2,13 @@ import net.ess3.nms.refl.ReflUtil; import net.ess3.provider.ServerStateProvider; +import net.essentialsx.providers.ProviderData; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +@ProviderData(description = "Reflection Server State Provider") public class ReflServerStateProvider implements ServerStateProvider { private final Object nmsServer; private final MethodHandle nmsIsRunning; @@ -52,9 +54,4 @@ public boolean isStopping() { } return false; } - - @Override - public String getDescription() { - return "NMS Reflection Server State Provider"; - } } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnEggProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnEggProvider.java index 34b68f870c6..a1bd623a92f 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnEggProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnEggProvider.java @@ -2,9 +2,12 @@ import net.ess3.nms.refl.SpawnEggRefl; import net.ess3.provider.SpawnEggProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +@ProviderData(description = "1.9-1.12.2 Spawn Egg Provider", weight = 1) public class ReflSpawnEggProvider implements SpawnEggProvider { @Override @@ -25,8 +28,14 @@ public EntityType getSpawnedType(final ItemStack eggItem) throws IllegalArgument } } - @Override - public String getDescription() { - return "NMS Reflection Provider"; + @ProviderTest + public static boolean test() { + try { + // There isn't a real good way to test this, but we can check if the Shulker class exists. + Class.forName("org.bukkit.entity.Shulker"); + return true; + } catch (final Throwable ignored) { + return false; + } } } diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnerBlockProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnerBlockProvider.java index 96266474c57..cdfb73286d1 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnerBlockProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSpawnerBlockProvider.java @@ -2,12 +2,14 @@ import net.ess3.nms.refl.ReflUtil; import net.ess3.provider.SpawnerBlockProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.block.CreatureSpawner; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +@ProviderData(description = "Reflection Spawner Block Provider") public class ReflSpawnerBlockProvider implements SpawnerBlockProvider { @Override public void setMaxSpawnDelay(final CreatureSpawner spawner, final int delay) { @@ -33,11 +35,6 @@ public void setMinSpawnDelay(final CreatureSpawner spawner, final int delay) { } } - @Override - public String getDescription() { - return "Reflection based provider"; - } - private Object getNMSSpawner(final CreatureSpawner spawner) { try { final Class craftWorld = ReflUtil.getOBCClass("CraftWorld"); diff --git a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSyncCommandsProvider.java b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSyncCommandsProvider.java index 6fc754df2bf..1ba7ef3bc7f 100644 --- a/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSyncCommandsProvider.java +++ b/providers/NMSReflectionProvider/src/main/java/net/ess3/nms/refl/providers/ReflSyncCommandsProvider.java @@ -2,12 +2,14 @@ import net.ess3.nms.refl.ReflUtil; import net.ess3.provider.SyncCommandsProvider; +import net.essentialsx.providers.ProviderData; import org.bukkit.Bukkit; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +@ProviderData(description = "Reflection Sync Commands Provider") public class ReflSyncCommandsProvider implements SyncCommandsProvider { private final MethodHandle nmsSyncCommands; @@ -22,11 +24,6 @@ public ReflSyncCommandsProvider() { nmsSyncCommands = syncCommands; } - @Override - public String getDescription() { - return "NMS Reflection Sync Commands Provider"; - } - @Override public void syncCommands() { if (nmsSyncCommands != null) { diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperBiomeKeyProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperBiomeKeyProvider.java index 34c26ea4844..1b72d82b6f3 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperBiomeKeyProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperBiomeKeyProvider.java @@ -1,19 +1,30 @@ package net.ess3.provider.providers; import net.ess3.provider.BiomeKeyProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; +import org.bukkit.RegionAccessor; +import org.bukkit.UnsafeValues; import org.bukkit.block.Block; -@SuppressWarnings("deprecation") +@ProviderData(description = "Paper Biome Key Provider") public class PaperBiomeKeyProvider implements BiomeKeyProvider { @Override public NamespacedKey getBiomeKey(final Block block) { + //noinspection deprecation return Bukkit.getUnsafe().getBiomeKey(block.getWorld(), block.getX(), block.getY(), block.getZ()); } - @Override - public String getDescription() { - return "Paper Biome Key Provider"; + @ProviderTest + public static boolean test() { + try { + //noinspection deprecation + UnsafeValues.class.getDeclaredMethod("getBiomeKey", RegionAccessor.class, int.class, int.class, int.class); + return true; + } catch (final Throwable ignored) { + return false; + } } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperCommandSendListenerProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperCommandSendListenerProvider.java index 1bc1a56e440..2eb391e16a0 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperCommandSendListenerProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperCommandSendListenerProvider.java @@ -27,9 +27,4 @@ public void onAsyncCommandSend(@SuppressWarnings("deprecation") AsyncPlayerSendC children.removeIf(node -> filter.test(node.getName())); } - - @Override - public String getDescription() { - return "Paper async Brigadier command send listener"; - } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperContainerProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperContainerProvider.java index 9210de53c41..f7cd1490c49 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperContainerProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperContainerProvider.java @@ -1,9 +1,14 @@ package net.ess3.provider.providers; import net.ess3.provider.ContainerProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; +import org.bukkit.Location; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.InventoryView; +@ProviderData(description = "Paper Container Provider") public class PaperContainerProvider implements ContainerProvider { @Override @@ -36,9 +41,13 @@ public InventoryView openStonecutter(Player player) { return player.openStonecutter(null, true); } - @Override - public String getDescription() { - return "Paper Container Opening Provider"; + @ProviderTest + public static boolean test() { + try { + HumanEntity.class.getDeclaredMethod("openCartographyTable", Location.class, boolean.class); + return true; + } catch (final NoSuchMethodException ignored) { + return false; + } } - } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperKnownCommandsProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperKnownCommandsProvider.java index b1666962b7a..1ed3de90a58 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperKnownCommandsProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperKnownCommandsProvider.java @@ -1,19 +1,29 @@ package net.ess3.provider.providers; import net.ess3.provider.KnownCommandsProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Bukkit; import org.bukkit.command.Command; +import org.bukkit.command.CommandMap; import java.util.Map; +@ProviderData(description = "Paper Known Commands Provider", weight = 1) public class PaperKnownCommandsProvider implements KnownCommandsProvider { @Override public Map getKnownCommands() { return Bukkit.getCommandMap().getKnownCommands(); } - @Override - public String getDescription() { - return "Paper Known Commands Provider"; + @ProviderTest + public static boolean test() { + try { + Bukkit.class.getDeclaredMethod("getCommandMap"); + CommandMap.class.getDeclaredMethod("getKnownCommands"); + return true; + } catch (NoSuchMethodException e) { + return false; + } } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperMaterialTagProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperMaterialTagProvider.java index aded175f928..67406df73f9 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperMaterialTagProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperMaterialTagProvider.java @@ -3,6 +3,8 @@ import com.destroystokyo.paper.MaterialSetTag; import com.destroystokyo.paper.MaterialTags; import net.ess3.provider.MaterialTagProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Material; import org.bukkit.Tag; @@ -10,6 +12,7 @@ import java.util.HashMap; import java.util.Map; +@ProviderData(description = "Paper Material Tag Provider", weight = 1) public class PaperMaterialTagProvider implements MaterialTagProvider { private final Map> bukkitTagMap = new HashMap<>(); private final Map paperTagMap = new HashMap<>(); @@ -73,4 +76,15 @@ private Tag getBukkitTag(String tagName) { } return bukkitTagMap.get(tagName); } + + @ProviderTest + public static boolean test() { + try { + Class.forName("org.bukkit.Tag"); + Class.forName("com.destroystokyo.paper.MaterialTags"); + return true; + } catch (ClassNotFoundException ignored) { + return false; + } + } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperRecipeBookListener.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperRecipeBookListener.java index 2db752d5141..6db9428e9fd 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperRecipeBookListener.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperRecipeBookListener.java @@ -16,9 +16,4 @@ public PaperRecipeBookListener(final Consumer function) { public void onPlayerRecipeBookClick(final PlayerRecipeBookClickEvent event) { function.accept(event); } - - @Override - public String getDescription() { - return "Paper Player Recipe Book Click Event Provider"; - } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperSerializationProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperSerializationProvider.java index 9665cdf18a1..6b053f7dabb 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperSerializationProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperSerializationProvider.java @@ -1,8 +1,11 @@ package net.ess3.provider.providers; import net.ess3.provider.SerializationProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.inventory.ItemStack; +@ProviderData(description = "Paper Serialization Provider") public class PaperSerializationProvider implements SerializationProvider { @Override @@ -15,8 +18,13 @@ public ItemStack deserializeItem(byte[] bytes) { return ItemStack.deserializeBytes(bytes); } - @Override - public String getDescription() { - return "Paper Serialization Provider"; + @ProviderTest + public static boolean test() { + try { + ItemStack.class.getDeclaredMethod("serializeAsBytes"); + return true; + } catch (final NoSuchMethodException ignored) { + return false; + } } } diff --git a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperServerStateProvider.java b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperServerStateProvider.java index ab201ed0b57..b91b3d8c6f6 100644 --- a/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperServerStateProvider.java +++ b/providers/PaperProvider/src/main/java/net/ess3/provider/providers/PaperServerStateProvider.java @@ -1,16 +1,24 @@ package net.ess3.provider.providers; import net.ess3.provider.ServerStateProvider; +import net.essentialsx.providers.ProviderData; +import net.essentialsx.providers.ProviderTest; import org.bukkit.Bukkit; +@ProviderData(description = "Paper Server State Provider", weight = 1) public class PaperServerStateProvider implements ServerStateProvider { @Override public boolean isStopping() { return Bukkit.isStopping(); } - @Override - public String getDescription() { - return "Paper Server State Provider"; + @ProviderTest + public static boolean test() { + try { + Bukkit.class.getDeclaredMethod("isStopping"); + return true; + } catch (final NoSuchMethodException ignored) { + return false; + } } }