Skip to content

Commit c8a8c0e

Browse files
EmilxyzlynxplayMachine-Maker
authored
feat(plugin): make Plugin extend Namespaced (#12867)
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
1 parent 602ea9f commit c8a8c0e

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

paper-api/src/main/java/io/papermc/paper/plugin/configuration/PluginMeta.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.papermc.paper.plugin.configuration;
22

33
import java.util.List;
4+
import java.util.Locale;
5+
import net.kyori.adventure.key.KeyPattern;
6+
import net.kyori.adventure.key.Namespaced;
47
import org.bukkit.permissions.Permission;
58
import org.bukkit.permissions.PermissionDefault;
69
import org.bukkit.plugin.PluginLoadOrder;
@@ -14,7 +17,7 @@
1417
*/
1518
@NullMarked
1619
@ApiStatus.NonExtendable
17-
public interface PluginMeta {
20+
public interface PluginMeta extends Namespaced {
1821

1922
/**
2023
* Provides the name of the plugin. This name uniquely identifies the plugin amongst all loaded plugins on the
@@ -180,4 +183,10 @@ default String getDisplayName() {
180183
*/
181184
@Nullable String getAPIVersion();
182185

186+
@KeyPattern.Namespace
187+
@SuppressWarnings("PatternValidation")
188+
@Override
189+
default String namespace() {
190+
return this.getName().toLowerCase(Locale.ROOT);
191+
}
183192
}

paper-api/src/main/java/org/bukkit/NamespacedKey.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public NamespacedKey(@NotNull String namespace, @NotNull String key) {
7272
public NamespacedKey(@NotNull Plugin plugin, @NotNull String key) {
7373
Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
7474
Preconditions.checkArgument(key != null, "Key cannot be null");
75-
this.namespace = plugin.getName().toLowerCase(Locale.ROOT);
75+
this.namespace = plugin.namespace();
7676
this.key = key.toLowerCase(Locale.ROOT);
7777

7878
// Check validity after normalization

paper-api/src/main/java/org/bukkit/plugin/Plugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.File;
44
import java.io.InputStream;
55
import java.util.logging.Logger;
6+
import net.kyori.adventure.key.Namespaced;
67
import org.bukkit.Server;
78
import org.bukkit.command.TabExecutor;
89
import org.bukkit.configuration.file.FileConfiguration;
@@ -16,7 +17,7 @@
1617
* <p>
1718
* The use of {@link PluginBase} is recommended for actual Implementation
1819
*/
19-
public interface Plugin extends TabExecutor, io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner { // Paper
20+
public interface Plugin extends TabExecutor, io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner, Namespaced { // Paper
2021
/**
2122
* Returns the folder that the plugin data files are located in. The
2223
* folder may not yet exist.

paper-api/src/main/java/org/bukkit/plugin/PluginBase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.bukkit.plugin;
22

33
import org.jetbrains.annotations.NotNull;
4+
import java.util.Locale;
45

56
/**
67
* Represents a base {@link Plugin}
@@ -33,4 +34,10 @@ public final boolean equals(Object obj) {
3334
public final String getName() {
3435
return getPluginMeta().getName(); // Paper
3536
}
37+
38+
@Override
39+
@NotNull
40+
public String namespace() {
41+
return this.getPluginMeta().namespace();
42+
}
3643
}

paper-server/src/main/java/io/papermc/paper/command/brigadier/PaperCommands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public CommandDispatcher<CommandSourceStack> getDispatcher() {
9191

9292
@Override
9393
public @Unmodifiable Set<String> registerWithFlags(final PluginMeta pluginMeta, final LiteralCommandNode<CommandSourceStack> node, final @Nullable String description, final Collection<String> aliases, final Set<CommandRegistrationFlag> flags) {
94-
return registerWithFlagsInternal(pluginMeta, pluginMeta.getName().toLowerCase(Locale.ROOT), null, node, description, aliases, flags);
94+
return this.registerWithFlagsInternal(pluginMeta, pluginMeta.namespace(), null, node, description, aliases, flags);
9595
}
9696

9797
public @Unmodifiable Set<String> registerWithFlagsInternal(final @Nullable PluginMeta pluginMeta, final String namespace, final @Nullable String helpNamespaceOverride, final LiteralCommandNode<CommandSourceStack> node, final @Nullable String description, final Collection<String> aliases, final Set<CommandRegistrationFlag> flags) {

0 commit comments

Comments
 (0)