Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework the provider system #5087

Merged
merged 35 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9771d16
Rework the provider system
JRoy Aug 23, 2022
a6441d7
pop review
JRoy Aug 24, 2022
0f045fb
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Oct 13, 2022
5edbc5e
Merge branch '2.x' into rework/providers
JRoy Oct 13, 2022
faab19b
kennytv.dmg
JRoy Nov 8, 2022
02b6b1b
Merge branch '2.x' into rework/providers
JRoy Nov 8, 2022
b5b3de9
Merge branch '2.x' into rework/providers
JRoy Dec 26, 2022
ebca72c
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy May 23, 2023
8eac04a
Update provider calls in /bottom
JRoy May 23, 2023
d45af88
Merge branch '2.x' into rework/providers
JRoy May 23, 2023
ea622f8
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Jul 29, 2023
0008e1c
Merge branch '2.x' into rework/providers
JRoy Aug 22, 2023
4d6558a
Merge branch '2.x' into rework/providers
mdcfe Dec 18, 2023
7f417ef
Add some javadocs
JRoy Dec 21, 2023
0360db3
inline some usages
JRoy Dec 26, 2023
99357fc
Merge branch '2.x' into rework/providers
JRoy Feb 12, 2024
f36c2dc
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Feb 19, 2024
0dcdb8b
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Jul 23, 2024
4e5c194
Fix missing test from 1.9-1.12 Spawn Egg Provider
JRoy Jul 23, 2024
f05a9dd
Fix compile/merge errors
JRoy Jul 24, 2024
dda1325
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Aug 11, 2024
a32ad6f
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Sep 14, 2024
06c5a86
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Oct 13, 2024
1018210
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Nov 9, 2024
8f41b5a
Merge branch '2.x' into rework/providers
JRoy Nov 17, 2024
92c71f2
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Nov 24, 2024
149110e
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Nov 24, 2024
2c4576e
fix compile
JRoy Nov 25, 2024
b1c51db
Merge remote-tracking branch 'upstream/2.x' into rework/providers
JRoy Nov 30, 2024
cd007e8
fix compile
JRoy Nov 30, 2024
c8d6f64
Merge branch '2.x' into rework/providers
JRoy Dec 14, 2024
5b146f8
fix issue w/FormattedCommandAliasProvider on 1.8 forks
JRoy Dec 19, 2024
73426f4
fix old provider method call
JRoy Dec 30, 2024
aad0ee5
review concerns
JRoy Dec 30, 2024
a869f09
fix 1.8 spigot compat
JRoy Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.earth2me.essentials;

import net.ess3.provider.KnownCommandsProvider;
import org.bukkit.command.Command;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -66,7 +67,7 @@ public final void addPlugin(final Plugin plugin) {

private Map<String, Command> getPluginCommands(Plugin plugin) {
final Map<String, Command> commands = new HashMap<>();
for (final Map.Entry<String, Command> entry : ess.getKnownCommandsProvider().getKnownCommands().entrySet()) {
for (final Map.Entry<String, Command> entry : ess.getProviders().get(KnownCommandsProvider.class).getKnownCommands().entrySet()) {
if (entry.getValue() instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) entry.getValue()).getPlugin().equals(plugin)) {
commands.put(entry.getKey(), entry.getValue());
}
Expand Down
245 changes: 57 additions & 188 deletions Essentials/src/main/java/com/earth2me/essentials/Essentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,9 @@
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.ContainerProvider;
import net.ess3.provider.FormattedCommandAliasProvider;
import net.ess3.provider.ItemUnbreakableProvider;
import net.ess3.provider.KnownCommandsProvider;
import net.ess3.provider.MaterialTagProvider;
import net.ess3.provider.PersistentDataProvider;
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.BaseLoggerProvider;
import net.ess3.provider.providers.BasePotionDataProvider;
import net.ess3.provider.providers.BlockMetaSpawnerItemProvider;
Expand Down Expand Up @@ -146,6 +133,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
private static Logger LOGGER = null;
private final transient TNTExplodeListener tntListener = new TNTExplodeListener();
private final transient Set<String> vanishedPlayers = new LinkedHashSet<>();
private final transient ProviderFactory providerFactory = new ProviderFactory(this);
private transient ISettings settings;
private transient Jails jails;
private transient Warps warps;
Expand All @@ -165,23 +153,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 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 SignDataProvider signDataProvider;
private transient Kits kits;
private transient RandomTeleport randomTeleport;
private transient UpdateChecker updateChecker;
Expand Down Expand Up @@ -359,98 +331,69 @@ 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().isLowerThan(VersionUtil.v1_9_R01)) {
potionMetaProvider = new LegacyPotionMetaProvider();
} else {
potionMetaProvider = new BasePotionDataProvider();
}
// Potion Meta Provider
providerFactory.registerProvider(LegacyPotionMetaProvider.class, BasePotionDataProvider.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);

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);
}
});
} catch (final ClassNotFoundException ignored) {
}
}

execTimer.mark("Init(Providers)");
Expand Down Expand Up @@ -556,9 +499,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 = getProviders().get(ServerStateProvider.class).isStopping();
if (!stopping) {
LOGGER.log(Level.SEVERE, tl("serverReloading"));
}
Expand Down Expand Up @@ -671,8 +619,8 @@ public List<String> 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 (getProviders().get(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
final Command newCmd = getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) {
return newCmd.tabComplete(cSender, commandLabel, args);
}
Expand Down Expand Up @@ -777,8 +725,8 @@ 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 (getProviders().get(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
final Command newCmd = getProviders().get(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) {
return newCmd.execute(cSender, commandLabel, args);
}
Expand Down Expand Up @@ -1243,90 +1191,11 @@ public Iterable<User> 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 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 SignDataProvider getSignDataProvider() {
return signDataProvider;
}

@Override
public PluginCommand getPluginCommand(final String cmd) {
return this.getCommand(cmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.getProviders().get(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.getProviders().get(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
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.KnownCommandsProvider;
import net.ess3.provider.providers.BukkitCommandSendListenerProvider;
import net.ess3.provider.providers.PaperCommandSendListenerProvider;
import net.essentialsx.api.v2.events.AsyncUserDataLoadEvent;
Expand Down Expand Up @@ -605,10 +607,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.getProviders().get(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.getProviders().get(FormattedCommandAliasProvider.class).createCommands(command, event.getPlayer(), args.split(" "))) {
handlePlayerCommandPreprocess(event, fullCommand);
}
return;
Expand Down
Loading