mirror of
				https://github.com/PlaceholderAPI/PlaceholderAPI
				synced 2025-10-30 18:03:43 +01:00 
			
		
		
		
	Merge pull request #832 from PlaceholderAPI/feature/log-missing-plugin
This commit is contained in:
		| @@ -332,10 +332,9 @@ public final class PlaceholderAPI { | |||||||
|   @Deprecated |   @Deprecated | ||||||
|   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") |   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") | ||||||
|   public static boolean registerPlaceholderHook(Plugin plugin, PlaceholderHook placeholderHook) { |   public static boolean registerPlaceholderHook(Plugin plugin, PlaceholderHook placeholderHook) { | ||||||
|     PlaceholderAPIPlugin.getInstance().getLogger().warning(plugin.getName() |     Msg.warn("Nag author(s) %s of plugin %s about their usage of the deprecated PlaceholderHook"  | ||||||
|         + " is attempting to register placeholders via a PlaceholderHook class which is no longer supported!" |         + " class! This class will be removed in v2.13.0!", plugin.getDescription().getAuthors(), | ||||||
|         + " Please reach out to " + plugin.getDescription().getAuthors().toString() |         plugin.getName()); | ||||||
|         + " and let them know that they need to update ASAP!"); |  | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -351,8 +350,8 @@ public final class PlaceholderAPI { | |||||||
|   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") |   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") | ||||||
|   public static boolean registerPlaceholderHook(String identifier, |   public static boolean registerPlaceholderHook(String identifier, | ||||||
|       PlaceholderHook placeholderHook) { |       PlaceholderHook placeholderHook) { | ||||||
|     PlaceholderAPIPlugin.getInstance().getLogger().warning(identifier |     Msg.warn("%s is attempting to register placeholders via deprecated PlaceholderHook class."  | ||||||
|         + " is attempting to register placeholders via a PlaceholderHook class which is no longer supported!"); |         + " This class is no longer supported and will be removed in v2.13.0!", identifier); | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -366,10 +365,9 @@ public final class PlaceholderAPI { | |||||||
|   @Deprecated |   @Deprecated | ||||||
|   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") |   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") | ||||||
|   public static boolean unregisterPlaceholderHook(Plugin plugin) { |   public static boolean unregisterPlaceholderHook(Plugin plugin) { | ||||||
|     PlaceholderAPIPlugin.getInstance().getLogger().warning(plugin.getName() |     Msg.warn("Nag author(s) %s of plugin %s about their usage of the PlaceholderAPI class." | ||||||
|         + " is attempting to unregister placeholders via the PlaceholderAPI class which is no longer supported!" |             + " This way of unregistering placeholders is no longer supported and will be removed"  | ||||||
|         + " Please reach out to " + plugin.getDescription().getAuthors().toString() |             + " in v2.13.0!", plugin.getDescription().getAuthors(), plugin.getName()); | ||||||
|         + " and let them know that they need to update ASAP!"); |  | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -383,8 +381,9 @@ public final class PlaceholderAPI { | |||||||
|   @Deprecated |   @Deprecated | ||||||
|   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") |   @ApiStatus.ScheduledForRemoval(inVersion = "2.13.0") | ||||||
|   public static boolean unregisterPlaceholderHook(String identifier) { |   public static boolean unregisterPlaceholderHook(String identifier) { | ||||||
|     PlaceholderAPIPlugin.getInstance().getLogger().warning(identifier |     Msg.warn("%s is attempting to unregister placeholders via PlaceholderAPI class." | ||||||
|         + " is attempting to unregister placeholders through the PlaceholderAPI class which is no longer supported!"); |         + " This way of unregistering placeholders is no longer supported and will be removed" | ||||||
|  |         + " in v2.13.0!", identifier); | ||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,7 +23,6 @@ package me.clip.placeholderapi; | |||||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.logging.Level; |  | ||||||
| import me.clip.placeholderapi.commands.PlaceholderCommandRouter; | import me.clip.placeholderapi.commands.PlaceholderCommandRouter; | ||||||
| import me.clip.placeholderapi.configuration.PlaceholderAPIConfig; | import me.clip.placeholderapi.configuration.PlaceholderAPIConfig; | ||||||
| import me.clip.placeholderapi.expansion.PlaceholderExpansion; | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
| @@ -32,6 +31,7 @@ import me.clip.placeholderapi.expansion.manager.CloudExpansionManager; | |||||||
| import me.clip.placeholderapi.expansion.manager.LocalExpansionManager; | import me.clip.placeholderapi.expansion.manager.LocalExpansionManager; | ||||||
| import me.clip.placeholderapi.listeners.ServerLoadEventListener; | import me.clip.placeholderapi.listeners.ServerLoadEventListener; | ||||||
| import me.clip.placeholderapi.updatechecker.UpdateChecker; | import me.clip.placeholderapi.updatechecker.UpdateChecker; | ||||||
|  | import me.clip.placeholderapi.util.Msg; | ||||||
| import net.kyori.adventure.platform.bukkit.BukkitAudiences; | import net.kyori.adventure.platform.bukkit.BukkitAudiences; | ||||||
| import org.bstats.bukkit.Metrics; | import org.bstats.bukkit.Metrics; | ||||||
| import org.bstats.charts.AdvancedPie; | import org.bstats.charts.AdvancedPie; | ||||||
| @@ -121,7 +121,8 @@ public final class PlaceholderAPIPlugin extends JavaPlugin { | |||||||
|     try { |     try { | ||||||
|       return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat()); |       return new SimpleDateFormat(getInstance().getPlaceholderAPIConfig().dateFormat()); | ||||||
|     } catch (final IllegalArgumentException ex) { |     } catch (final IllegalArgumentException ex) { | ||||||
|       getInstance().getLogger().log(Level.WARNING, "configured date format is invalid", ex); |       Msg.warn("Configured Date format ('%s') is invalid! Defaulting to 'MM/dd/yy HH:mm:ss'", | ||||||
|  |           ex, getInstance().getPlaceholderAPIConfig().dateFormat()); | ||||||
|       return new SimpleDateFormat("MM/dd/yy HH:mm:ss"); |       return new SimpleDateFormat("MM/dd/yy HH:mm:ss"); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -22,11 +22,32 @@ package me.clip.placeholderapi.expansion.manager; | |||||||
|  |  | ||||||
| import com.google.common.collect.ImmutableSet; | import com.google.common.collect.ImmutableSet; | ||||||
| import com.google.common.collect.Sets; | import com.google.common.collect.Sets; | ||||||
|  | import java.io.File; | ||||||
|  | import java.lang.reflect.Modifier; | ||||||
|  | import java.util.Arrays; | ||||||
|  | import java.util.Collection; | ||||||
|  | import java.util.Collections; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Locale; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Objects; | ||||||
|  | import java.util.Optional; | ||||||
|  | import java.util.Set; | ||||||
|  | import java.util.concurrent.CompletableFuture; | ||||||
|  | import java.util.concurrent.CompletionException; | ||||||
|  | import java.util.concurrent.ConcurrentHashMap; | ||||||
|  | import java.util.concurrent.locks.ReentrantLock; | ||||||
|  | import java.util.stream.Collectors; | ||||||
| import me.clip.placeholderapi.PlaceholderAPIPlugin; | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import me.clip.placeholderapi.events.ExpansionRegisterEvent; | import me.clip.placeholderapi.events.ExpansionRegisterEvent; | ||||||
| import me.clip.placeholderapi.events.ExpansionUnregisterEvent; | import me.clip.placeholderapi.events.ExpansionUnregisterEvent; | ||||||
| import me.clip.placeholderapi.events.ExpansionsLoadedEvent; | import me.clip.placeholderapi.events.ExpansionsLoadedEvent; | ||||||
| import me.clip.placeholderapi.expansion.*; | import me.clip.placeholderapi.expansion.Cacheable; | ||||||
|  | import me.clip.placeholderapi.expansion.Cleanable; | ||||||
|  | import me.clip.placeholderapi.expansion.Configurable; | ||||||
|  | import me.clip.placeholderapi.expansion.PlaceholderExpansion; | ||||||
|  | import me.clip.placeholderapi.expansion.Taskable; | ||||||
|  | import me.clip.placeholderapi.expansion.VersionSpecific; | ||||||
| import me.clip.placeholderapi.expansion.cloud.CloudExpansion; | import me.clip.placeholderapi.expansion.cloud.CloudExpansion; | ||||||
| import me.clip.placeholderapi.util.FileUtil; | import me.clip.placeholderapi.util.FileUtil; | ||||||
| import me.clip.placeholderapi.util.Futures; | import me.clip.placeholderapi.util.Futures; | ||||||
| @@ -45,16 +66,6 @@ import org.jetbrains.annotations.NotNull; | |||||||
| import org.jetbrains.annotations.Nullable; | import org.jetbrains.annotations.Nullable; | ||||||
| import org.jetbrains.annotations.Unmodifiable; | import org.jetbrains.annotations.Unmodifiable; | ||||||
|  |  | ||||||
| import java.io.File; |  | ||||||
| import java.lang.reflect.Modifier; |  | ||||||
| import java.util.*; |  | ||||||
| import java.util.concurrent.CompletableFuture; |  | ||||||
| import java.util.concurrent.CompletionException; |  | ||||||
| import java.util.concurrent.ConcurrentHashMap; |  | ||||||
| import java.util.concurrent.locks.ReentrantLock; |  | ||||||
| import java.util.logging.Level; |  | ||||||
| import java.util.stream.Collectors; |  | ||||||
|  |  | ||||||
| public final class LocalExpansionManager implements Listener { | public final class LocalExpansionManager implements Listener { | ||||||
|  |  | ||||||
|   @NotNull |   @NotNull | ||||||
| @@ -81,7 +92,7 @@ public final class LocalExpansionManager implements Listener { | |||||||
|     this.folder = new File(plugin.getDataFolder(), EXPANSIONS_FOLDER_NAME); |     this.folder = new File(plugin.getDataFolder(), EXPANSIONS_FOLDER_NAME); | ||||||
|  |  | ||||||
|     if (!this.folder.exists() && !folder.mkdirs()) { |     if (!this.folder.exists() && !folder.mkdirs()) { | ||||||
|       plugin.getLogger().log(Level.WARNING, "failed to create expansions folder!"); |       Msg.warn("Failed to create expansions folder!"); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -169,7 +180,16 @@ public final class LocalExpansionManager implements Listener { | |||||||
|       Objects.requireNonNull(expansion.getIdentifier(), "The expansion identifier is null!"); |       Objects.requireNonNull(expansion.getIdentifier(), "The expansion identifier is null!"); | ||||||
|       Objects.requireNonNull(expansion.getVersion(), "The expansion version is null!"); |       Objects.requireNonNull(expansion.getVersion(), "The expansion version is null!"); | ||||||
|        |        | ||||||
|  |       if (expansion.getRequiredPlugin() != null && !expansion.getRequiredPlugin().isEmpty()) { | ||||||
|  |         if (!Bukkit.getPluginManager().isPluginEnabled(expansion.getRequiredPlugin())) { | ||||||
|  |           Msg.warn("Cannot load expansion %s due to a missing Plugin: %s", expansion.getIdentifier(), | ||||||
|  |               expansion.getRequiredPlugin()); | ||||||
|  |           return Optional.empty(); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |        | ||||||
|       if (!expansion.register()) { |       if (!expansion.register()) { | ||||||
|  |         Msg.warn("Cannot load expansion %s due to an unknown issue.", expansion.getIdentifier()); | ||||||
|         return Optional.empty(); |         return Optional.empty(); | ||||||
|       } |       } | ||||||
|  |  | ||||||
| @@ -183,9 +203,7 @@ public final class LocalExpansionManager implements Listener { | |||||||
|         reason = " - One of its properties is null which is not allowed!"; |         reason = " - One of its properties is null which is not allowed!"; | ||||||
|       } |       } | ||||||
|        |        | ||||||
|       plugin.getLogger().severe("Failed to load expansion class " + clazz.getSimpleName() + |       Msg.severe("Failed to load expansion class %s%s", ex, clazz.getSimpleName(), reason); | ||||||
|               reason); |  | ||||||
|       plugin.getLogger().log(Level.SEVERE, "", ex); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return Optional.empty(); |     return Optional.empty(); | ||||||
| @@ -234,8 +252,8 @@ public final class LocalExpansionManager implements Listener { | |||||||
|     if (expansion instanceof VersionSpecific) { |     if (expansion instanceof VersionSpecific) { | ||||||
|       VersionSpecific nms = (VersionSpecific) expansion; |       VersionSpecific nms = (VersionSpecific) expansion; | ||||||
|       if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) { |       if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) { | ||||||
|         plugin.getLogger().warning("Your server version is not compatible with expansion " + |         Msg.warn("Your server version is incompatible with expansion %s %s", | ||||||
|             expansion.getIdentifier() + " " + expansion.getVersion()); |             expansion.getIdentifier(), expansion.getVersion()); | ||||||
|         return false; |         return false; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
| @@ -263,8 +281,8 @@ public final class LocalExpansionManager implements Listener { | |||||||
|       Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin); |       Bukkit.getPluginManager().registerEvents(((Listener) expansion), plugin); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier() +  |     Msg.info("Successfully registered expansion: %s [%s]", expansion.getIdentifier(), | ||||||
|         " [" + expansion.getVersion() + "]"); |         expansion.getVersion()); | ||||||
|  |  | ||||||
|     if (expansion instanceof Taskable) { |     if (expansion instanceof Taskable) { | ||||||
|       ((Taskable) expansion).start(); |       ((Taskable) expansion).start(); | ||||||
| @@ -315,13 +333,12 @@ public final class LocalExpansionManager implements Listener { | |||||||
|     return true; |     return true; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |  | ||||||
|   private void registerAll(@NotNull final CommandSender sender) { |   private void registerAll(@NotNull final CommandSender sender) { | ||||||
|     plugin.getLogger().info("Placeholder expansion registration initializing..."); |     Msg.info("Placeholder expansion registratuib initializing..."); | ||||||
|  |  | ||||||
|     Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> { |     Futures.onMainThread(plugin, findExpansionsOnDisk(), (classes, exception) -> { | ||||||
|       if (exception != null) { |       if (exception != null) { | ||||||
|         plugin.getLogger().log(Level.SEVERE, "failed to load class files of expansions", exception); |         Msg.severe("Failed to load class files of expansion.", exception); | ||||||
|         return; |         return; | ||||||
|       } |       } | ||||||
|        |        | ||||||
| @@ -388,8 +405,8 @@ public final class LocalExpansionManager implements Listener { | |||||||
|         final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class); |         final Class<? extends PlaceholderExpansion> expansionClass = FileUtil.findClass(file, PlaceholderExpansion.class); | ||||||
|  |  | ||||||
|         if (expansionClass == null) { |         if (expansionClass == null) { | ||||||
|           plugin.getLogger().severe("Failed to load Expansion: " + file.getName() + ", as it does not have" + |           Msg.severe("Failed to load Expansion %s, as it does not have a class which"  | ||||||
|                   " a class which extends PlaceholderExpansion."); |               + " extends PlaceholderExpansion", file.getName()); | ||||||
|           return null; |           return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -397,16 +414,15 @@ public final class LocalExpansionManager implements Listener { | |||||||
|                 .map(method -> new MethodSignature(method.getName(), method.getParameterTypes())) |                 .map(method -> new MethodSignature(method.getName(), method.getParameterTypes())) | ||||||
|                 .collect(Collectors.toSet()); |                 .collect(Collectors.toSet()); | ||||||
|         if (!expansionMethods.containsAll(ABSTRACT_EXPANSION_METHODS)) { |         if (!expansionMethods.containsAll(ABSTRACT_EXPANSION_METHODS)) { | ||||||
|           plugin.getLogger().severe("Failed to load Expansion: " + file.getName() + ", as it does not have the" + |           Msg.severe("Failed to load Expansion %s, as it does not have the required"  | ||||||
|                   " required methods declared for a PlaceholderExpansion."); |               + " methods declared for a PlaceholderExpansion.", file.getName()); | ||||||
|           return null; |           return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return expansionClass; |         return expansionClass; | ||||||
|       } catch (final VerifyError ex) { |       } catch (final VerifyError ex) { | ||||||
|         plugin.getLogger().severe("Failed to load Expansion class " + file.getName() + |         Msg.severe("Failed to load Expansion class %s (Is a dependency missing?", file.getName()); | ||||||
|             " (Is a dependency missing?)"); |         Msg.severe("Cause: %s %s", ex.getClass().getSimpleName(), ex.getMessage()); | ||||||
|         plugin.getLogger().severe("Cause: " + ex.getClass().getSimpleName() + " " + ex.getMessage()); |  | ||||||
|         return null; |         return null; | ||||||
|       } catch (final Exception ex) { |       } catch (final Exception ex) { | ||||||
|         throw new CompletionException(ex); |         throw new CompletionException(ex); | ||||||
| @@ -425,8 +441,7 @@ public final class LocalExpansionManager implements Listener { | |||||||
|         throw ((LinkageError) ex.getCause()); |         throw ((LinkageError) ex.getCause()); | ||||||
|       } |       } | ||||||
|        |        | ||||||
|       plugin.getLogger().warning("There was an issue with loading an expansion."); |       Msg.warn("There was an issue with loading an Expansion."); | ||||||
|        |  | ||||||
|       return null; |       return null; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @@ -456,7 +471,8 @@ public final class LocalExpansionManager implements Listener { | |||||||
|       } |       } | ||||||
|  |  | ||||||
|       expansion.unregister(); |       expansion.unregister(); | ||||||
|       plugin.getLogger().info("Unregistered placeholder expansion: " + expansion.getName()); |       Msg.info("Unregistered placeholder Expansion %s", expansion.getIdentifier()); | ||||||
|  |       Msg.info("Reason: Required plugin %s was disabled.", name); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,7 +21,9 @@ | |||||||
| package me.clip.placeholderapi.util; | package me.clip.placeholderapi.util; | ||||||
|  |  | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
|  | import java.util.logging.Level; | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
|  | import me.clip.placeholderapi.PlaceholderAPIPlugin; | ||||||
| import org.bukkit.Bukkit; | import org.bukkit.Bukkit; | ||||||
| import org.bukkit.ChatColor; | import org.bukkit.ChatColor; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| @@ -29,6 +31,30 @@ import org.jetbrains.annotations.NotNull; | |||||||
|  |  | ||||||
| public final class Msg { | public final class Msg { | ||||||
|    |    | ||||||
|  |   public static void log(Level level, String msg, Object... args) { | ||||||
|  |     PlaceholderAPIPlugin.getInstance().getLogger().log(level, String.format(msg, args)); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   public static void info(String msg, Object... args) { | ||||||
|  |     log(Level.INFO, msg, args); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   public static void warn(String msg, Object... args) { | ||||||
|  |     log(Level.WARNING, msg, args); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   public static void warn(String msg, Throwable throwable, Object... args){ | ||||||
|  |     PlaceholderAPIPlugin.getInstance().getLogger().log(Level.WARNING, String.format(msg, args), throwable); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   public static void severe(String msg, Object... args) { | ||||||
|  |     log(Level.SEVERE, msg, args); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   public static void severe(String msg, Throwable throwable, Object... args) { | ||||||
|  |     PlaceholderAPIPlugin.getInstance().getLogger().log(Level.SEVERE, String.format(msg, args), throwable); | ||||||
|  |   } | ||||||
|  |    | ||||||
|   public static void msg(@NotNull final CommandSender sender, @NotNull final String... messages) { |   public static void msg(@NotNull final CommandSender sender, @NotNull final String... messages) { | ||||||
|     if (messages.length == 0) { |     if (messages.length == 0) { | ||||||
|       return; |       return; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user