mirror of
https://github.com/PaperMC/Paper.git
synced 2025-07-26 09:42:06 -07:00
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>
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
package io.papermc.paper.plugin.configuration;
|
package io.papermc.paper.plugin.configuration;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import net.kyori.adventure.key.KeyPattern;
|
||||||
|
import net.kyori.adventure.key.Namespaced;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.PluginLoadOrder;
|
import org.bukkit.plugin.PluginLoadOrder;
|
||||||
@@ -14,7 +17,7 @@ import org.jspecify.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
@NullMarked
|
@NullMarked
|
||||||
@ApiStatus.NonExtendable
|
@ApiStatus.NonExtendable
|
||||||
public interface PluginMeta {
|
public interface PluginMeta extends Namespaced {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the name of the plugin. This name uniquely identifies the plugin amongst all loaded plugins on the
|
* Provides the name of the plugin. This name uniquely identifies the plugin amongst all loaded plugins on the
|
||||||
@@ -180,4 +183,10 @@ public interface PluginMeta {
|
|||||||
*/
|
*/
|
||||||
@Nullable String getAPIVersion();
|
@Nullable String getAPIVersion();
|
||||||
|
|
||||||
|
@KeyPattern.Namespace
|
||||||
|
@SuppressWarnings("PatternValidation")
|
||||||
|
@Override
|
||||||
|
default String namespace() {
|
||||||
|
return this.getName().toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,7 +72,7 @@ public final class NamespacedKey implements Key, com.destroystokyo.paper.Namespa
|
|||||||
public NamespacedKey(@NotNull Plugin plugin, @NotNull String key) {
|
public NamespacedKey(@NotNull Plugin plugin, @NotNull String key) {
|
||||||
Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
|
Preconditions.checkArgument(plugin != null, "Plugin cannot be null");
|
||||||
Preconditions.checkArgument(key != null, "Key cannot be null");
|
Preconditions.checkArgument(key != null, "Key cannot be null");
|
||||||
this.namespace = plugin.getName().toLowerCase(Locale.ROOT);
|
this.namespace = plugin.namespace();
|
||||||
this.key = key.toLowerCase(Locale.ROOT);
|
this.key = key.toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
// Check validity after normalization
|
// Check validity after normalization
|
||||||
|
@@ -3,6 +3,7 @@ package org.bukkit.plugin;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import net.kyori.adventure.key.Namespaced;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@@ -16,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* <p>
|
* <p>
|
||||||
* The use of {@link PluginBase} is recommended for actual Implementation
|
* The use of {@link PluginBase} is recommended for actual Implementation
|
||||||
*/
|
*/
|
||||||
public interface Plugin extends TabExecutor, io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner { // Paper
|
public interface Plugin extends TabExecutor, io.papermc.paper.plugin.lifecycle.event.LifecycleEventOwner, Namespaced { // Paper
|
||||||
/**
|
/**
|
||||||
* Returns the folder that the plugin data files are located in. The
|
* Returns the folder that the plugin data files are located in. The
|
||||||
* folder may not yet exist.
|
* folder may not yet exist.
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package org.bukkit.plugin;
|
package org.bukkit.plugin;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a base {@link Plugin}
|
* Represents a base {@link Plugin}
|
||||||
@@ -33,4 +34,10 @@ public abstract class PluginBase implements Plugin {
|
|||||||
public final String getName() {
|
public final String getName() {
|
||||||
return getPluginMeta().getName(); // Paper
|
return getPluginMeta().getName(); // Paper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NotNull
|
||||||
|
public String namespace() {
|
||||||
|
return this.getPluginMeta().namespace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -91,7 +91,7 @@ public class PaperCommands implements Commands, PaperRegistrar<LifecycleEventOwn
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Unmodifiable Set<String> registerWithFlags(final PluginMeta pluginMeta, final LiteralCommandNode<CommandSourceStack> node, final @Nullable String description, final Collection<String> aliases, final Set<CommandRegistrationFlag> flags) {
|
public @Unmodifiable Set<String> registerWithFlags(final PluginMeta pluginMeta, final LiteralCommandNode<CommandSourceStack> node, final @Nullable String description, final Collection<String> aliases, final Set<CommandRegistrationFlag> flags) {
|
||||||
return registerWithFlagsInternal(pluginMeta, pluginMeta.getName().toLowerCase(Locale.ROOT), null, node, description, aliases, flags);
|
return this.registerWithFlagsInternal(pluginMeta, pluginMeta.namespace(), null, node, description, aliases, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
||||||
|
Reference in New Issue
Block a user