Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-26 02:50:06 +01:00
Extracted CommandMapping interface.
Dieser Commit ist enthalten in:
Ursprung
61053564fa
Commit
f3fe8f2ad8
@ -19,70 +19,37 @@
|
||||
|
||||
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 {
|
||||
|
||||
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;
|
||||
}
|
||||
public interface CommandMapping {
|
||||
|
||||
/**
|
||||
* Get the primary alias.
|
||||
*
|
||||
*
|
||||
* @return the primary alias
|
||||
*/
|
||||
public String getPrimaryAlias() {
|
||||
return aliases[0];
|
||||
}
|
||||
|
||||
String getPrimaryAlias();
|
||||
|
||||
/**
|
||||
* Get a list of all aliases.
|
||||
*
|
||||
*
|
||||
* @return aliases
|
||||
*/
|
||||
public String[] getAllAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
String[] getAllAliases();
|
||||
|
||||
/**
|
||||
* Get the callable
|
||||
*
|
||||
*
|
||||
* @return the callable
|
||||
*/
|
||||
public CommandCallable getCallable() {
|
||||
return callable;
|
||||
}
|
||||
CommandCallable getCallable();
|
||||
|
||||
/**
|
||||
* Get the {@link Description} form the callable.
|
||||
*
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
public Description getDescription() {
|
||||
return getCallable().getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CommandMapping{" +
|
||||
"aliases=" + Arrays.toString(aliases) +
|
||||
", callable=" + callable +
|
||||
'}';
|
||||
}
|
||||
Description getDescription();
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
public void registerCommand(CommandCallable callable, String... alias) {
|
||||
CommandMapping mapping = new CommandMapping(callable, alias);
|
||||
CommandMapping mapping = new SimpleCommandMapping(callable, alias);
|
||||
|
||||
// Check for replacements
|
||||
for (String a : alias) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren