mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Extracted CommandMapping interface.
This commit is contained in:
parent
61053564fa
commit
f3fe8f2ad8
@ -19,70 +19,37 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.command;
|
package com.sk89q.worldedit.util.command;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks a command registration.
|
* Provides information about a mapping between a command and its aliases.
|
||||||
*/
|
*/
|
||||||
public class CommandMapping {
|
public interface CommandMapping {
|
||||||
|
|
||||||
private final String[] aliases;
|
|
||||||
private final CommandCallable callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance.
|
|
||||||
*
|
|
||||||
* @param callable the command callable
|
|
||||||
* @param alias a list of all aliases, where the first one is the primary one
|
|
||||||
*/
|
|
||||||
public CommandMapping(CommandCallable callable, String... alias) {
|
|
||||||
super();
|
|
||||||
this.aliases = alias;
|
|
||||||
this.callable = callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the primary alias.
|
* Get the primary alias.
|
||||||
*
|
*
|
||||||
* @return the primary alias
|
* @return the primary alias
|
||||||
*/
|
*/
|
||||||
public String getPrimaryAlias() {
|
String getPrimaryAlias();
|
||||||
return aliases[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of all aliases.
|
* Get a list of all aliases.
|
||||||
*
|
*
|
||||||
* @return aliases
|
* @return aliases
|
||||||
*/
|
*/
|
||||||
public String[] getAllAliases() {
|
String[] getAllAliases();
|
||||||
return aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the callable
|
* Get the callable
|
||||||
*
|
*
|
||||||
* @return the callable
|
* @return the callable
|
||||||
*/
|
*/
|
||||||
public CommandCallable getCallable() {
|
CommandCallable getCallable();
|
||||||
return callable;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the {@link Description} form the callable.
|
* Get the {@link Description} form the callable.
|
||||||
*
|
*
|
||||||
* @return the description
|
* @return the description
|
||||||
*/
|
*/
|
||||||
public Description getDescription() {
|
Description getDescription();
|
||||||
return getCallable().getDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "CommandMapping{" +
|
|
||||||
"aliases=" + Arrays.toString(aliases) +
|
|
||||||
", callable=" + callable +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* WorldEdit, a Minecraft world manipulation toolkit
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldEdit team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldedit.util.command;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks a command registration.
|
||||||
|
*/
|
||||||
|
public class SimpleCommandMapping implements CommandMapping {
|
||||||
|
|
||||||
|
private final String[] aliases;
|
||||||
|
private final CommandCallable callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance.
|
||||||
|
*
|
||||||
|
* @param callable the command callable
|
||||||
|
* @param alias a list of all aliases, where the first one is the primary one
|
||||||
|
*/
|
||||||
|
public SimpleCommandMapping(CommandCallable callable, String... alias) {
|
||||||
|
super();
|
||||||
|
this.aliases = alias;
|
||||||
|
this.callable = callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPrimaryAlias() {
|
||||||
|
return aliases[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getAllAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CommandCallable getCallable() {
|
||||||
|
return callable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Description getDescription() {
|
||||||
|
return getCallable().getDescription();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "CommandMapping{" +
|
||||||
|
"aliases=" + Arrays.toString(aliases) +
|
||||||
|
", callable=" + callable +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -55,7 +55,7 @@ public class SimpleDispatcher implements Dispatcher {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerCommand(CommandCallable callable, String... alias) {
|
public void registerCommand(CommandCallable callable, String... alias) {
|
||||||
CommandMapping mapping = new CommandMapping(callable, alias);
|
CommandMapping mapping = new SimpleCommandMapping(callable, alias);
|
||||||
|
|
||||||
// Check for replacements
|
// Check for replacements
|
||||||
for (String a : alias) {
|
for (String a : alias) {
|
||||||
|
Loading…
Reference in New Issue
Block a user