mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-09-11 21:45:26 -04:00
Added Java Callbacks for commands
This commit is contained in:
@@ -8,7 +8,7 @@ public class Command {
|
||||
// defaultPriority
|
||||
private String scriptCallback;
|
||||
// fail
|
||||
//private ICommandCallback javaCallback;
|
||||
private ICmdCallback javaCallback;
|
||||
// fail
|
||||
private float defaultTime;
|
||||
private String characterAbility;
|
||||
@@ -47,6 +47,9 @@ public class Command {
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getScriptCallback() { return scriptCallback; }
|
||||
public void setScriptCallback(String scriptCallback) { this.scriptCallback = scriptCallback; }
|
||||
public ICmdCallback getJavaCallback() { return javaCallback; }
|
||||
public void setJavaCallback(ICmdCallback javaCallback) { this.javaCallback = javaCallback; }
|
||||
public boolean hasJavaCallback() { return javaCallback != null; }
|
||||
public float getDefaultTime() { return defaultTime; }
|
||||
public void setDefaultTime(float defaultTime) { this.defaultTime = defaultTime; }
|
||||
public String getCharacterAbility() { return characterAbility; }
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package resources.commands;
|
||||
|
||||
import resources.objects.SWGObject;
|
||||
import resources.player.Player;
|
||||
import services.objects.ObjectManager;
|
||||
|
||||
public interface ICmdCallback {
|
||||
public void execute(ObjectManager objManager, Player player, SWGObject target, String args);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import intents.GalacticPacketIntent;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.DatatableData;
|
||||
import resources.commands.Command;
|
||||
import resources.commands.ICmdCallback;
|
||||
import resources.common.CRC;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Service;
|
||||
@@ -32,6 +33,7 @@ public class CommandService extends Service {
|
||||
commandCrcLookup = new ConcurrentHashMap<String, Integer>();
|
||||
registerForIntent(GalacticPacketIntent.TYPE);
|
||||
loadBaseCommands();
|
||||
registerCallbacks();
|
||||
return super.initialize();
|
||||
}
|
||||
|
||||
@@ -78,7 +80,10 @@ public class CommandService extends Service {
|
||||
|
||||
// TODO: Handle for different targetType
|
||||
|
||||
Scripts.execute("commands/generic/" + command.getScriptCallback(), "execute", objManager, player, target, args);
|
||||
if (command.hasJavaCallback())
|
||||
command.getJavaCallback().execute(objManager, player, target, args);
|
||||
else
|
||||
Scripts.execute("commands/generic/" + command.getScriptCallback(), "execute", objManager, player, target, args);
|
||||
}
|
||||
|
||||
private void loadBaseCommands() {
|
||||
@@ -98,4 +103,11 @@ public class CommandService extends Service {
|
||||
commandCrcLookup.put(command.getName(), command.getCrc());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void registerCallback(String command, ICmdCallback callback) { commands.get(commandCrcLookup.get(command)).setJavaCallback(callback); }
|
||||
|
||||
private void registerCallbacks() {
|
||||
// Example: registerCallback("spatialChatInternal", new SpatialChatCallback());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user