Add command meta & add new guided builder methods for components
This commit is contained in:
parent
0c0428e8d4
commit
90d37f1df8
21 changed files with 540 additions and 169 deletions
|
|
@ -33,7 +33,7 @@ import java.util.function.Function;
|
|||
* Command manager for the Bukkit platform, using {@link BukkitCommandSender} as the
|
||||
* command sender type
|
||||
*/
|
||||
public class BukkitCommandManager extends CommandManager<BukkitCommandSender> {
|
||||
public class BukkitCommandManager extends CommandManager<BukkitCommandSender, BukkitCommandMeta> {
|
||||
|
||||
private final Plugin owningPlugin;
|
||||
|
||||
|
|
@ -45,8 +45,8 @@ public class BukkitCommandManager extends CommandManager<BukkitCommandSender> {
|
|||
* @throws Exception If the construction of the manager fails
|
||||
*/
|
||||
public BukkitCommandManager(@Nonnull final Plugin owningPlugin,
|
||||
@Nonnull final Function<CommandTree<BukkitCommandSender>,
|
||||
CommandExecutionCoordinator<BukkitCommandSender>> commandExecutionCoordinator)
|
||||
@Nonnull final Function<CommandTree<BukkitCommandSender, BukkitCommandMeta>,
|
||||
CommandExecutionCoordinator<BukkitCommandSender, BukkitCommandMeta>> commandExecutionCoordinator)
|
||||
throws Exception {
|
||||
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler());
|
||||
((BukkitPluginRegistrationHandler) this.getCommandRegistrationHandler()).initialize(this);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2020 IntellectualSites
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class BukkitCommandMeta extends SimpleCommandMeta {
|
||||
|
||||
public BukkitCommandMeta(@Nonnull final SimpleCommandMeta simpleCommandMeta) {
|
||||
super(simpleCommandMeta.getAll());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2020 IntellectualSites
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package com.intellectualsites.commands;
|
||||
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public final class BukkitCommandMetaBuilder {
|
||||
|
||||
private BukkitCommandMetaBuilder() {
|
||||
}
|
||||
|
||||
@Nonnull public static BuilderStage1 builder() {
|
||||
return new BuilderStage1();
|
||||
}
|
||||
|
||||
public static final class BuilderStage1 {
|
||||
|
||||
private BuilderStage1() {
|
||||
}
|
||||
|
||||
@Nonnull public BuilderStage2 withDescription(@Nonnull final String description) {
|
||||
return new BuilderStage2(description);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static final class BuilderStage2 {
|
||||
|
||||
private final String description;
|
||||
|
||||
private BuilderStage2(@Nonnull final String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Nonnull public BukkitCommandMeta build() {
|
||||
return new BukkitCommandMeta(CommandMeta.simple().with("description", this.description).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ import java.lang.reflect.Method;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
final class BukkitPluginRegistrationHandler implements CommandRegistrationHandler {
|
||||
final class BukkitPluginRegistrationHandler implements CommandRegistrationHandler<BukkitCommandMeta> {
|
||||
|
||||
private final Map<CommandComponent<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ final class BukkitPluginRegistrationHandler implements CommandRegistrationHandle
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerCommand(@Nonnull final Command<?> command) {
|
||||
public boolean registerCommand(@Nonnull final Command<?, BukkitCommandMeta> command) {
|
||||
/* We only care about the root command component */
|
||||
final CommandComponent<?, ?> commandComponent = command.getComponents().get(0);
|
||||
if (this.registeredCommands.containsKey(commandComponent)) {
|
||||
|
|
@ -71,6 +71,7 @@ final class BukkitPluginRegistrationHandler implements CommandRegistrationHandle
|
|||
} else {
|
||||
label = commandComponent.getName();
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
final BukkitCommand bukkitCommand = new BukkitCommand((CommandComponent<BukkitCommandSender, ?>) commandComponent,
|
||||
this.bukkitCommandManager);
|
||||
this.bukkitCommands.put(label, bukkitCommand);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue