Fix Inconsistencies with Paper Plugin Names (#9098)

This commit is contained in:
Luke Chambers 2023-04-16 12:49:13 -04:00
parent 77aec31991
commit d8b12ddb4c
4 changed files with 55 additions and 19 deletions

View file

@ -56,4 +56,5 @@ Kieran Wallbanks <kieran.wallbanks@gmail.com>
Denery <dorofeevij@gmail.com>
Jakubk15 <jakubk15@protonmail.com>
Redned <redned235@gmail.com>
Luke Chambers <consolelogluke@gmail.com>
```

View file

@ -88,8 +88,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ Bukkit.getLogger().warning(
+ String.format("Nag author(s): '%s' of '%s' about their usage of System.out/err.print. "
+ + "Please use your plugin's logger instead (JavaPlugin#getLogger).",
+ plugin.getDescription().getAuthors(),
+ plugin.getName())
+ plugin.getPluginMeta().getAuthors(),
+ plugin.getPluginMeta().getDisplayName())
+ );
+ } catch (final IllegalArgumentException | IllegalStateException e) {
+ // If anything happens, the calling class doesn't exist, there is no JavaPlugin that "owns" the calling class, etc

View file

@ -612,13 +612,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ ComponentLogger logger, Path pluginSource) implements PluginProviderContext {
+
+ public static PluginProviderContextImpl of(PluginMeta config, ComponentLogger logger, Path pluginSource) {
+ Path dataFolder = PluginInitializerManager.instance().pluginDirectoryPath().resolve(config.getDisplayName());
+ Path dataFolder = PluginInitializerManager.instance().pluginDirectoryPath().resolve(config.getName());
+
+ return new PluginProviderContextImpl(config, dataFolder, logger, pluginSource);
+ }
+
+ public static PluginProviderContextImpl of(PluginProvider<?> provider, Path pluginFolder) {
+ Path dataFolder = pluginFolder.resolve(provider.getMeta().getDisplayName());
+ Path dataFolder = pluginFolder.resolve(provider.getMeta().getName());
+
+ return new PluginProviderContextImpl(provider.getMeta(), dataFolder, provider.getLogger(), provider.getSource());
+ }
@ -966,7 +966,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ PluginMeta config = this.configuration;
+ PluginDescriptionFile pluginDescriptionFile = new PluginDescriptionFile(
+ config.getName(),
+ config.getName().replace('_', ' '),
+ config.getName(),
+ config.getProvidedPlugins(),
+ config.getMainClass(),
+ "", // Classloader load order api
@ -4393,6 +4393,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@
+package io.papermc.paper.plugin.provider.configuration;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import io.leangen.geantyref.TypeToken;
+import io.papermc.paper.configuration.constraint.Constraint;
@ -4411,6 +4412,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import org.bukkit.plugin.PluginLoadOrder;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.annotations.TestOnly;
+import org.spongepowered.configurate.CommentedConfigurationNode;
+import org.spongepowered.configurate.ConfigurateException;
+import org.spongepowered.configurate.loader.HeaderMode;
@ -4456,8 +4458,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ @PluginConfigConstraints.PluginVersion
+ private String apiVersion;
+
+ private transient String displayName;
+
+ public PaperPluginMeta() {
+ }
+
@ -4500,8 +4500,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ .build();
+ }
+
+ pluginConfiguration.displayName = pluginConfiguration.name.replace('_', ' ') + " v" + pluginConfiguration.version;
+
+ return pluginConfiguration;
+ }
+
@ -4510,6 +4508,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return this.name;
+ }
+
+ @TestOnly
+ public void setName(@NotNull String name) {
+ Preconditions.checkNotNull(name, "name");
+ this.name = name;
+ }
+
+ @Override
+ public @NotNull String getMainClass() {
+ return this.main;
@ -4520,9 +4524,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return this.version;
+ }
+
+ @Override
+ public @NotNull String getDisplayName() {
+ return this.displayName;
+ @TestOnly
+ public void setVersion(@NotNull String version) {
+ Preconditions.checkNotNull(version, "version");
+ this.version = version;
+ }
+
+ @Override
@ -7052,6 +7057,40 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ assertThat(pm.getPermissions(), is(empty()));
+ }
+}
diff --git a/src/test/java/io/papermc/paper/plugin/PluginNamingTest.java b/src/test/java/io/papermc/paper/plugin/PluginNamingTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/test/java/io/papermc/paper/plugin/PluginNamingTest.java
@@ -0,0 +0,0 @@
+package io.papermc.paper.plugin;
+
+import io.papermc.paper.plugin.provider.configuration.PaperPluginMeta;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PluginNamingTest {
+ private static final String TEST_NAME = "Test_Plugin";
+ private static final String TEST_VERSION = "1.0";
+
+ private final PaperPluginMeta pluginMeta;
+
+ public PluginNamingTest() {
+ this.pluginMeta = new PaperPluginMeta();
+ this.pluginMeta.setName(TEST_NAME);
+ this.pluginMeta.setVersion(TEST_VERSION);
+ }
+
+ @Test
+ public void testName() {
+ Assert.assertEquals(TEST_NAME, this.pluginMeta.getName());
+ }
+
+ @Test
+ public void testDisplayName() {
+ Assert.assertEquals(TEST_NAME + " v" + TEST_VERSION, this.pluginMeta.getDisplayName());
+ }
+}
diff --git a/src/test/java/io/papermc/paper/plugin/SyntheticEventTest.java b/src/test/java/io/papermc/paper/plugin/SyntheticEventTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000

View file

@ -44,14 +44,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ List<BukkitWorker> overdueWorkers = getScheduler().getActiveWorkers();
+ for (BukkitWorker worker : overdueWorkers) {
+ Plugin plugin = worker.getOwner();
+ String author = "<NoAuthorGiven>";
+ if (plugin.getDescription().getAuthors().size() > 0) {
+ author = plugin.getDescription().getAuthors().get(0);
+ }
+ getLogger().log(Level.SEVERE, String.format(
+ "Nag author: '%s' of '%s' about the following: %s",
+ author,
+ plugin.getDescription().getName(),
+ "Nag author(s): '%s' of '%s' about the following: %s",
+ plugin.getPluginMeta().getAuthors(),
+ plugin.getPluginMeta().getDisplayName(),
+ "This plugin is not properly shutting down its async tasks when it is being shut down. This task may throw errors during the final shutdown logs and might not complete before process dies."
+ ));
+ }