mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-07-30 00:15:57 -04:00
add aliases to command service
This commit is contained in:
@@ -22,8 +22,11 @@
|
||||
package services.command;
|
||||
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import main.NGECore;
|
||||
|
||||
import org.apache.mina.core.buffer.IoBuffer;
|
||||
@@ -50,6 +53,8 @@ import resources.objects.weapon.WeaponObject;
|
||||
public class CommandService implements INetworkDispatch {
|
||||
|
||||
private Vector<BaseSWGCommand> commandLookup = new Vector<BaseSWGCommand>();
|
||||
private ConcurrentHashMap<String,BaseSWGCommand> aliases = new ConcurrentHashMap<String,BaseSWGCommand>();
|
||||
private ConcurrentHashMap<Integer,BaseSWGCommand> aliasesByCRC = new ConcurrentHashMap<Integer,BaseSWGCommand>();
|
||||
private NGECore core;
|
||||
|
||||
public CommandService(NGECore core) {
|
||||
@@ -125,9 +130,29 @@ public class CommandService implements INetworkDispatch {
|
||||
return command;
|
||||
|
||||
}
|
||||
|
||||
//FIXME: CRC could just be generated as well.
|
||||
public void registerAlias(String name, String target) {
|
||||
Vector<BaseSWGCommand> commands = new Vector<BaseSWGCommand>(commandLookup); // copy for thread safety
|
||||
BaseSWGCommand targetCommand = null;
|
||||
for(BaseSWGCommand command : commands) {
|
||||
if(command.getCommandName().equalsIgnoreCase(target)) {
|
||||
targetCommand = command;
|
||||
}
|
||||
}
|
||||
if (targetCommand == null) { return; }
|
||||
|
||||
aliases.put(name, targetCommand);
|
||||
aliasesByCRC.put(CRC.StringtoCRC(name), targetCommand);
|
||||
|
||||
}
|
||||
|
||||
public BaseSWGCommand getCommandByCRC(int CRC) {
|
||||
|
||||
if (aliasesByCRC.containsKey(CRC)) {
|
||||
return aliasesByCRC.get(CRC);
|
||||
}
|
||||
|
||||
Vector<BaseSWGCommand> commands = new Vector<BaseSWGCommand>(commandLookup); // copy for thread safety
|
||||
|
||||
for(BaseSWGCommand command : commands) {
|
||||
@@ -140,6 +165,10 @@ public class CommandService implements INetworkDispatch {
|
||||
|
||||
public BaseSWGCommand getCommandByName(String name) {
|
||||
|
||||
if (aliases.containsKey(name)) {
|
||||
return aliases.get(name);
|
||||
}
|
||||
|
||||
Vector<BaseSWGCommand> commands = new Vector<BaseSWGCommand>(commandLookup); // copy for thread safety
|
||||
|
||||
for(BaseSWGCommand command : commands) {
|
||||
|
||||
Reference in New Issue
Block a user