review concerns

This commit is contained in:
JRoy 2024-12-30 09:09:35 -05:00
parent 73426f42d3
commit aad0ee5778
No known key found for this signature in database
GPG Key ID: FAD510B503869E7D
8 changed files with 40 additions and 16 deletions

View File

@ -432,6 +432,9 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
((Cancellable) event).setCancelled(true); ((Cancellable) event).setCancelled(true);
} }
}); });
if (getSettings().isDebug()) {
LOGGER.log(Level.INFO, "Registered Paper Recipe Book Event Listener");
}
} catch (final ClassNotFoundException ignored) { } catch (final ClassNotFoundException ignored) {
} }
} }
@ -439,7 +442,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
execTimer.mark("Init(Providers)"); execTimer.mark("Init(Providers)");
reload(); reload();
// The item spawn blacklist is loaded with all other settings, before the item\ // The item spawn blacklist is loaded with all other settings, before the item
// DB, but it depends on the item DB, so we need to reload it again here: // DB, but it depends on the item DB, so we need to reload it again here:
((Settings) settings)._lateLoadItemSpawnBlacklist(); ((Settings) settings)._lateLoadItemSpawnBlacklist();
backup = new Backup(this); backup = new Backup(this);
@ -667,12 +670,10 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
// Check for disabled commands // Check for disabled commands
if (getSettings().isCommandDisabled(commandLabel)) { if (getSettings().isCommandDisabled(commandLabel)) {
if (provider(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel); final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
if (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this) { if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || ((PluginIdentifiableCommand) newCmd).getPlugin() != this)) {
return newCmd.tabComplete(cSender, commandLabel, args); return newCmd.tabComplete(cSender, commandLabel, args);
} }
}
return Collections.emptyList(); return Collections.emptyList();
} }
@ -778,12 +779,10 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials {
// Check for disabled commands // Check for disabled commands
if (getSettings().isCommandDisabled(commandLabel)) { if (getSettings().isCommandDisabled(commandLabel)) {
if (provider(KnownCommandsProvider.class).getKnownCommands().containsKey(commandLabel)) {
final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel); final Command newCmd = provider(KnownCommandsProvider.class).getKnownCommands().get(commandLabel);
if (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin())) { if (newCmd != null && (!(newCmd instanceof PluginIdentifiableCommand) || !isEssentialsPlugin(((PluginIdentifiableCommand) newCmd).getPlugin()))) {
return newCmd.execute(cSender, commandLabel, args); return newCmd.execute(cSender, commandLabel, args);
} }
}
sender.sendTl("commandDisabled", commandLabel); sender.sendTl("commandDisabled", commandLabel);
return true; return true;
} }

View File

@ -2,6 +2,7 @@ package com.earth2me.essentials;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.ess3.provider.Provider; import net.ess3.provider.Provider;
import net.essentialsx.providers.NullableProvider;
import net.essentialsx.providers.ProviderData; import net.essentialsx.providers.ProviderData;
import net.essentialsx.providers.ProviderTest; import net.essentialsx.providers.ProviderTest;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -55,6 +56,7 @@ public class ProviderFactory {
public void finalizeRegistration() { public void finalizeRegistration() {
for (final Map.Entry<Class<? extends Provider>, List<Class<? extends Provider>>> entry : registeredProviders.entrySet()) { for (final Map.Entry<Class<? extends Provider>, List<Class<? extends Provider>>> entry : registeredProviders.entrySet()) {
final Class<? extends Provider> providerClass = entry.getKey(); final Class<? extends Provider> providerClass = entry.getKey();
final boolean nullable = providerClass.isAnnotationPresent(NullableProvider.class);
Class<? extends Provider> highestProvider = null; Class<? extends Provider> highestProvider = null;
ProviderData highestProviderData = null; ProviderData highestProviderData = null;
int highestWeight = -1; int highestWeight = -1;
@ -70,12 +72,13 @@ public class ProviderFactory {
essentials.getLogger().log(Level.SEVERE, "Failed to initialize provider " + provider.getName(), e); essentials.getLogger().log(Level.SEVERE, "Failed to initialize provider " + provider.getName(), e);
} }
} }
if (highestProvider == null) {
throw new IllegalStateException("No provider found for " + providerClass.getName());
}
if (highestProvider != null) {
essentials.getLogger().info("Selected " + highestProviderData.description() + " as the provider for " + providerClass.getSimpleName()); essentials.getLogger().info("Selected " + highestProviderData.description() + " as the provider for " + providerClass.getSimpleName());
providers.put(providerClass, getProviderInstance(highestProvider)); providers.put(providerClass, getProviderInstance(highestProvider));
} else if (!nullable) {
throw new IllegalStateException("No provider found for " + providerClass.getName());
}
} }
registeredProviders.clear(); registeredProviders.clear();
} }

View File

@ -35,7 +35,7 @@ public class RandomTeleport implements IConf {
public RandomTeleport(final IEssentials essentials) { public RandomTeleport(final IEssentials essentials) {
this.ess = essentials; this.ess = essentials;
config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml", config = new EssentialsConfiguration(new File(essentials.getDataFolder(), "tpr.yml"), "/tpr.yml",
"Configuration for the random teleport command.\nSome settings may be defaulted, and can be changed via the /settpr command in-game."); "Configuration for the random teleport command.\nUse the /settpr command in-game to set random teleport locations.");
} }
public EssentialsConfiguration getConfig() { public EssentialsConfiguration getConfig() {

View File

@ -1,8 +1,10 @@
package net.ess3.provider; package net.ess3.provider;
import net.essentialsx.providers.NullableProvider;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@NullableProvider
public interface BiomeKeyProvider extends Provider { public interface BiomeKeyProvider extends Provider {
NamespacedKey getBiomeKey(Block block); NamespacedKey getBiomeKey(Block block);
} }

View File

@ -1,8 +1,10 @@
package net.ess3.provider; package net.ess3.provider;
import net.essentialsx.providers.NullableProvider;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
@NullableProvider
public interface ContainerProvider extends Provider { public interface ContainerProvider extends Provider {
InventoryView openAnvil(Player player); InventoryView openAnvil(Player player);

View File

@ -1,7 +1,9 @@
package net.ess3.provider; package net.ess3.provider;
import net.essentialsx.providers.NullableProvider;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@NullableProvider
public interface SerializationProvider extends Provider { public interface SerializationProvider extends Provider {
byte[] serializeItem(ItemStack stack); byte[] serializeItem(ItemStack stack);

View File

@ -1,7 +1,9 @@
package net.ess3.provider; package net.ess3.provider;
import net.essentialsx.providers.NullableProvider;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
@NullableProvider
public interface SignDataProvider extends Provider { public interface SignDataProvider extends Provider {
void setSignData(Sign sign, String key, String value); void setSignData(Sign sign, String key, String value);

View File

@ -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 {
}