Skip to content

Commit

Permalink
Add BungeeExecute command, for #129
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Dec 17, 2016
1 parent 4af58e0 commit eab6933
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 1 deletion.
@@ -0,0 +1,63 @@
package com.denizenscript.depenizen.bukkit.commands.bungee;

import com.denizenscript.depenizen.bukkit.support.bungee.BungeeSupport;
import com.denizenscript.depenizen.common.socket.client.packet.ClientPacketOutExecute;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.AbstractCommand;
import net.aufdemrand.denizencore.utilities.debugging.dB;

public class BungeeExecuteCommand extends AbstractCommand {

// <--[command]
// @Name BungeeExecute
// @Syntax bungeeexecute [<command>]
// @Group Depenizen
// @Plugin DepenizenBukkit, DepenizenBungee
// @Required 1
// @Stable stable
// @Short Executes a command on the BungeeCord proxy server.
// @Author Morphan1

// @Description
// This command allows you to execute a BungeeCord command, as if it
// was typed into the proxy server's console.

// @Tags
// None

// @Usage
// Send an alert message through BungeeCord.
// - bungeeexecute "alert Hey! Listen!"

// -->

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("command")) {
scriptEntry.addObject("command", arg.asElement());
}

}

if (!scriptEntry.hasObject("command")) {
throw new InvalidArgumentsException("Must specify a command to execute!");
}
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

Element command = scriptEntry.getElement("command");

dB.report(scriptEntry, getName(), command.debug());

BungeeSupport.getSocketClient().trySend(new ClientPacketOutExecute(command.asString()));
}
}
Expand Up @@ -2,6 +2,7 @@

import com.denizenscript.depenizen.bukkit.Settings;
import com.denizenscript.depenizen.bukkit.commands.bungee.BungeeCommand;
import com.denizenscript.depenizen.bukkit.commands.bungee.BungeeExecuteCommand;
import com.denizenscript.depenizen.bukkit.commands.bungee.BungeeReconnectCommand;
import com.denizenscript.depenizen.bukkit.commands.bungee.BungeeRunCommand;
import com.denizenscript.depenizen.bukkit.commands.bungee.BungeeTagCommand;
Expand All @@ -26,6 +27,7 @@ public BungeeSupport() {
new BungeeRunCommand().activate().as("BUNGEERUN").withOptions("bungeerun [<server>|...] [<script_name>]", 2);
new BungeeTagCommand().activate().as("BUNGEETAG").withOptions("bungeetag [<tag>] [server:<server>]", 2);
new BungeeReconnectCommand().activate().as("BUNGEERECONNECT").withOptions("bungeereconnect", 0);
new BungeeExecuteCommand().activate().as("BUNGEEEXECUTE").withOptions("bungeeexecute [<command>]", 1);
registerObjects(dServer.class);
registerProperty(BungeePlayerExtension.class, dPlayer.class);
registerAdditionalTags("bungee");
Expand Down
Expand Up @@ -40,4 +40,10 @@ protected void handleSendPlayer(ClientConnection client, String player, String d
}
}
}

@Override
protected void handleExecute(ClientConnection client, String command) {
ProxyServer server = ProxyServer.getInstance();
server.getPluginManager().dispatchCommand(server.getConsole(), command);
}
}
Expand Up @@ -24,7 +24,8 @@ public enum ServerBound {
PARSED_TAG(6),
EVENT_SUBSCRIPTION(7),
EVENT_RESPONSE(8),
SEND_PLAYER(9);
SEND_PLAYER(9),
EXECUTE(10);

private final int id;

Expand Down
@@ -0,0 +1,19 @@
package com.denizenscript.depenizen.common.socket.client.packet;

import com.denizenscript.depenizen.common.socket.DataSerializer;
import com.denizenscript.depenizen.common.socket.Packet;

public class ClientPacketOutExecute extends Packet {

private String command;

public ClientPacketOutExecute(String command) {
this.command = command;
}

@Override
public void serialize(DataSerializer serializer) {
serializer.writeUnsignedByte(Packet.ServerBound.EXECUTE.getId());
serializer.writeString(command);
}
}
Expand Up @@ -272,6 +272,11 @@ public void run() {
sendPlayer.deserialize(data);
server.handleSendPlayer(this, sendPlayer.getPlayer(), sendPlayer.getDestination());
break;
case EXECUTE:
ServerPacketInExecute execute = new ServerPacketInExecute();
execute.deserialize(data);
server.handleExecute(this, execute.getCommand());
break;
}
}
}
Expand Down
Expand Up @@ -164,4 +164,6 @@ public void run() {
protected abstract void handleEventResponse(ClientConnection client, long id, Map<String, String> response);

protected abstract void handleSendPlayer(ClientConnection client, String player, String destination);

protected abstract void handleExecute(ClientConnection client, String command);
}
@@ -0,0 +1,18 @@
package com.denizenscript.depenizen.common.socket.server.packet;

import com.denizenscript.depenizen.common.socket.DataDeserializer;
import com.denizenscript.depenizen.common.socket.Packet;

public class ServerPacketInExecute extends Packet {

private String command;

@Override
public void deserialize(DataDeserializer deserializer) {
command = deserializer.readString();
}

public String getCommand() {
return command;
}
}

0 comments on commit eab6933

Please sign in to comment.