commands rework progress

- Wrote EcoDelegatedBukkitCommand.kt
- Wrote EcoHandledCommand.kt
- Wrote Eco#createSubCommand
- Renamed RegistrableCommandBase.java to PluginCommandBase
- Moved most of EcoPluginCommand.kt to EcoHandledCommand.kt
- Changed Delegate type in PluginCommand from CommandBase to PluginCommandBase
This commit is contained in:
Samuel Pizette
2022-12-04 18:52:19 -05:00
parent 6f97f47712
commit a396754e2e
10 changed files with 313 additions and 237 deletions

View File

@@ -1,7 +1,7 @@
package com.willfp.eco.core;
import com.willfp.eco.core.command.CommandBase;
import com.willfp.eco.core.command.RegistrableCommandBase;
import com.willfp.eco.core.command.PluginCommandBase;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.eco.core.config.ConfigType;
import com.willfp.eco.core.config.interfaces.Config;
@@ -160,10 +160,10 @@ public interface Eco {
EcoPlugin getEcoPlugin();
@NotNull
RegistrableCommandBase createPluginCommand(@NotNull EcoPlugin plugin,
@NotNull String name,
@NotNull String permission,
boolean playersOnly
PluginCommandBase createPluginCommand(@NotNull EcoPlugin plugin,
@NotNull String name,
@NotNull String permission,
boolean playersOnly
);
@NotNull

View File

@@ -0,0 +1,39 @@
package com.willfp.eco.core.command;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public interface PluginCommandBase extends CommandBase {
/**
* Register the PluginCommandBase to the bukkit commandMap.
*/
void register();
/**
* Unregister the PluginCommandBase from the bukkit commandMap.
*/
void unregister();
/**
* Get aliases. Leave null if this command is from plugin.yml.
*
* @return The aliases.
*/
@NotNull
default List<String> getAliases() {
return new ArrayList<>();
}
/**
* Get description.
*
* @return The description.
*/
@Nullable
default String getDescription() {
return null;
}
}

View File

@@ -1,7 +0,0 @@
package com.willfp.eco.core.command;
public interface RegistrableCommandBase extends CommandBase {
void register();
void unregister();
}

View File

@@ -3,9 +3,11 @@ package com.willfp.eco.core.command.impl;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandBase;
import com.willfp.eco.core.command.RegistrableCommandBase;
import com.willfp.eco.core.command.PluginCommandBase;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* PluginCommands are the class to be used instead of CommandExecutor, they function as the base
* command, e.g. {@code /ecoenchants} would be a base command, with each subsequent argument
@@ -15,9 +17,12 @@ import org.jetbrains.annotations.NotNull;
* <p>
* The name cannot be the same as an existing command as this will conflict.
*/
public abstract class PluginCommand implements RegistrableCommandBase {
public abstract class PluginCommand implements PluginCommandBase {
private final RegistrableCommandBase delegate;
/**
* The delegate command.
*/
private final PluginCommandBase delegate;
/**
@@ -55,6 +60,11 @@ public abstract class PluginCommand implements RegistrableCommandBase {
return delegate.addSubcommand(command);
}
@Override
public @NotNull List<CommandBase> getSubcommands() {
return delegate.getSubcommands();
}
@Override
public void register() {
delegate.register();

View File

@@ -3,11 +3,9 @@ package com.willfp.eco.core.command.impl;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandBase;
import com.willfp.eco.core.command.NotificationException;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.Optional;
import java.util.List;
/**
* Subcommands can be added to PluginCommands or to other Subcommands.
@@ -65,20 +63,14 @@ public abstract class Subcommand implements CommandBase {
}
@Override
public @NotNull Optional<Player> notifyPlayerRequired(@NotNull String player,
@NotNull String langTarget)
throws NotificationException {
return delegate.notifyPlayerRequired(player, langTarget);
}
@Override
public boolean notifyFalse(boolean condition, @NotNull String langTarget)
throws NotificationException {
return delegate.notifyFalse(condition, langTarget);
public @NotNull List<CommandBase> getSubcommands() {
return delegate.getSubcommands();
}
@Override
public EcoPlugin getPlugin() {
return delegate.getPlugin();
}
}