Skip to content

Commit

Permalink
Add BungeeRun command
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Oct 5, 2016
1 parent 0949bc0 commit 5ea8a20
Show file tree
Hide file tree
Showing 124 changed files with 688 additions and 411 deletions.
Expand Up @@ -16,7 +16,7 @@ public class BattleNightCommands extends AbstractCommand {
// @Name BN
// @Syntax bn [add/kick/start/end]
// @Group Depenizen
// @Plugin Depenizen, BattleNight
// @Plugin DepenizenBukkit, BattleNight
// @Required 1
// @Stable stable
// @Short Adds/kicks player, starts/ends battle.
Expand Down
Expand Up @@ -17,7 +17,7 @@ public class JobsCommands extends AbstractCommand {
// @Name Jobs
// @Syntax jobs [promote/demote/join/quit] [<job>] (<#>)
// @Group Depenizen
// @Plugin Depenizen, Jobs
// @Plugin DepenizenBukkit, Jobs
// @Required 2
// @Stable untested
// @Short Modifies the specified job of a player.
Expand Down
Expand Up @@ -23,7 +23,7 @@ public class McMMOCommands extends AbstractCommand {
// @Name mcMMO
// @Syntax mcmmo [add/remove/set] [levels/xp/xprate/vampirism/hardcore/leader] (skill:<skill>) (state:{toggle}/true/false) (qty:<#>) (party:<party>)
// @Group Depenizen
// @Plugin Depenizen, mcMMO
// @Plugin DepenizenBukkit, mcMMO
// @Required 1
// @Stable untested
// @Short Edits mcMMO information.
Expand Down
Expand Up @@ -21,17 +21,20 @@ public class BungeeCommand extends BracedCommand {
// @Name Bungee
// @Syntax bungee [<server>|...] [<commands>]
// @Group Depenizen
// @Plugin Depenizen, BungeeCord
// @Required 2
// @Plugin DepenizenBukkit, DepenizenBungee
// @Required 1
// @Stable stable
// @Short Sends commands to other servers via BungeeCord.
// @Short Sends commands to other Bukkit servers via BungeeCord.
// @Author Morphan1

// @Description
// This command allows you to send multiple lines of script to your BungeeCord
// server, which then relays it to the dServer you specified. Tags and definitions
// will be parsed on the dServer, and the definitions in the current queue will
// server, which then relays it to the dServer(s) you specified. Tags and definitions
// will be parsed on the destination(s), and the definitions in the current queue will
// carry over.
//
// NOTE: This command will only work for Bukkit servers. For a cross-compatible
// option, use the BungeeRun command.

// @Tags
// None
Expand Down Expand Up @@ -79,8 +82,6 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

// TODO: deprecate

dList servers = scriptEntry.getdObject("servers");
List<ScriptEntry> bracedCommands = ((List<BracedData>) scriptEntry.getObject("braces")).get(0).value;

Expand Down
@@ -0,0 +1,125 @@
package com.denizenscript.depenizen.bukkit.commands.bungee;

import com.denizenscript.depenizen.bukkit.objects.bungee.dServer;
import com.denizenscript.depenizen.bukkit.support.bungee.BungeeSupport;
import com.denizenscript.depenizen.common.socket.client.packet.ClientPacketOutRunScript;
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.objects.dList;
import net.aufdemrand.denizencore.scripts.ScriptEntry;
import net.aufdemrand.denizencore.scripts.commands.BracedCommand;
import net.aufdemrand.denizencore.utilities.debugging.dB;

import java.util.HashMap;
import java.util.Map;

public class BungeeRunCommand extends BracedCommand {

// <--[command]
// @Name BungeeRun
// @Syntax bungeerun [<server>|...] [<script_name>] (def:<name>|<value>|...) (debug:<boolean>)
// @Plugin DepenizenBukkit, DepenizenBungee
// @Required 2
// @Stable stable
// @Short Runs a script on other servers by name via BungeeCord socket.
// @Author Morphan1

// @Description
// This command allows you to run a named script on the specified servers
// connected to your BungeeCord socket. You may optionally specify a list
// of definitions to send for the script to use.
//
// By default, the script will run with the same debug mode as the queue
// that runs this command, but you may also specify true or false to force
// it one way or the other.

// @Tags
// None

// @Usage
// Use to send network-wide join messages with a script called JoinMessageScript that takes a definition of the player's name.
// - bungeerun <bungee.list_servers> JoinMessageScript def:<player.name.display>

// @Usage
// Use to keep a player's inventory consistent across 2 creative servers.
// - define player <player>
// - define contents <player.inventory.list_contents>
// - bungeerun creative2 UpdatePlayerInventory def:<player>|<player.inventory.list_contents>

// -->

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

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

if (!scriptEntry.hasObject("servers")
&& arg.matchesArgumentList(dServer.class)) {
scriptEntry.addObject("servers", arg.asType(dList.class));
}

else if (!scriptEntry.hasObject("definitions")
&& arg.matchesPrefix("d", "def", "define")) {
scriptEntry.addObject("definitions", arg.asType(dList.class));
}

else if (!scriptEntry.hasObject("debug")
&& arg.matchesPrefix("debug")
&& arg.matchesPrimitive(aH.PrimitiveType.Boolean)) {
scriptEntry.addObject("debug", arg.asElement());
}

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

}

if (!scriptEntry.hasObject("servers")) {
throw new InvalidArgumentsException("Must specify valid server(s)!");
}
else if (!scriptEntry.hasObject("script_name")) {
throw new InvalidArgumentsException("Must specify a script name!");
}
}

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

dList servers = scriptEntry.getdObject("servers");
Element scriptName = scriptEntry.getElement("script_name");
dList definitions = scriptEntry.getdObject("definitions");
Element debug = scriptEntry.getElement("debug");

dList serverNames = new dList();
serverNames.setPrefix("servers");

for (dServer server : servers.filter(dServer.class)) {
serverNames.add(server.getName());
}

dB.report(scriptEntry, getName(), serverNames.debug() + scriptName.debug()
+ (definitions != null ? definitions.debug() : "")
+ (debug != null ? debug.debug() : ""));

if (BungeeSupport.isSocketConnected()) {
Map<String, String> finalDefs = new HashMap<String, String>();
if (definitions != null) {
if (definitions.size() % 2 != 0) {
throw new CommandExecutionException("Uneven number of elements in definitions list!");
}
for (int i = 0; i < definitions.size(); i++) {
finalDefs.put(definitions.get(i), definitions.get(++i));
}
}
boolean finalDebug = debug != null ? debug.asBoolean() : scriptEntry.shouldDebug();
ClientPacketOutRunScript runScript = new ClientPacketOutRunScript(serverNames, scriptName.asString(), finalDefs, finalDebug);
BungeeSupport.getSocketClient().trySend(runScript);
}
else {
dB.echoError("Server is not connected to a BungeeCord Socket.");
}
}
}
Expand Up @@ -23,7 +23,7 @@ public class BungeeTagCommand extends AbstractCommand implements Holdable {
// @Name BungeeTag
// @Syntax bungeetag [<tag>] [server:<server>]
// @Group Depenizen
// @Plugin Depenizen, BungeeCord
// @Plugin DepenizenBukkit, DepenizenBungee
// @Required 2
// @Stable stable
// @Short Gets tags from other servers on the BungeeCord network. Requires you ~wait for it.
Expand Down
Expand Up @@ -18,7 +18,7 @@ public class TraderCommand extends AbstractCommand {
// @Name Trader
// @Syntax trader [open/close] ({buy}/sell) ({stock}/relation)
// @Group Depenizen
// @Plugin Depenizen, dtlTraders
// @Plugin DepenizenBukkit, dtlTraders
// @Required 1
// @Stable stable
// @Short Opens or closes an NPC's trading menu.
Expand Down
Expand Up @@ -19,7 +19,7 @@
// @Name HeroesXP
// @Syntax heroesxp [add/remove/set] [<heroesclass>] [quantity:<#.#>]
// @Group Depenizen
// @Plugin Depenizen, Heroes
// @Plugin DepenizenBukkit, Heroes
// @Required 3
// @Stable stable
// @Short Manipulate Heroes' experience.
Expand Down
Expand Up @@ -17,7 +17,7 @@
// @Name MobArena
// @Syntax mobarena [<mobarena>] (add:<player>|...) (remove:<player>|...) (spectate:<player>|...)
// @Group Depenizen
// @Plugin Depenizen, MobArena
// @Plugin DepenizenBukkit, MobArena
// @Required 1
// @Stable untested
// @Short Make a player join, remove a player from or make a player spectate a MobArena.
Expand Down
Expand Up @@ -19,7 +19,7 @@ public class MythicSpawnCommand extends AbstractCommand {
// @Name MythicSpawn
// @Syntax mythicspawn [<name>] [<location>] (level:<#>)
// @Group Depenizen
// @Plugin Depenizen, MythicMobs
// @Plugin DepenizenBukkit, MythicMobs
// @Required 2
// @Stable untested
// @Short Spawns a MythicMob at a location.
Expand Down
Expand Up @@ -32,7 +32,7 @@ public class HeroesEvents implements Listener {
// <context.hero> returns the Hero changing classes.
// @Determine
// "CANCELLED" to stop the hero from changing classes.
// @Plugin Depenizen, Heroes
// @Plugin DepenizenBukkit, Heroes
// -->
@EventHandler
public void changeClass(ClassChangeEvent event) {
Expand Down Expand Up @@ -78,7 +78,7 @@ else if (hero.isPlayer()) {
// <context.reason> returns the reason the Hero is changing experience.
// @Determine
// "CANCELLED" to stop the hero from gaining experience.
// @Plugin Depenizen, Heroes
// @Plugin DepenizenBukkit, Heroes
// -->
@EventHandler
public void changeExperience(ExperienceChangeEvent event) {
Expand Down Expand Up @@ -122,7 +122,7 @@ else if (hero.isPlayer()) {
// <context.level> returns the level the Hero is changing to.
// @Determine
// None
// @Plugin Depenizen, Heroes
// @Plugin DepenizenBukkit, Heroes
// -->
@EventHandler
public void changeLevel(HeroChangeLevelEvent event) {
Expand Down
Expand Up @@ -24,7 +24,7 @@ public class VotifierEvents implements Listener {
// <context.time> returns the time the vote was sent.
// <context.service> returns what service was used to send the vote.
// <context.username> returns the username input with the vote.
// @Plugin Depenizen, Votifier
// @Plugin DepenizenBukkit, Votifier
// -->
@EventHandler
public void onVotifierEvent(VotifierEvent event) {
Expand Down
Expand Up @@ -28,7 +28,7 @@
// @Context
// <context.shop> Returns the AreaShop that's expiring.
//
// @Plugin Depenizen, AreaShop
// @Plugin DepenizenBukkit, AreaShop
//
// -->

Expand Down
Expand Up @@ -33,7 +33,7 @@
// <context.item_rewards> Returns a list of items to be awarded.
// NOTE: item rewards is dependant on how the plugin handles item rewards. Untested and no guarantee of working.
//
// @Plugin Depenizen, A SkyBlock
// @Plugin DepenizenBukkit, A SkyBlock
//
// -->

Expand Down
Expand Up @@ -29,7 +29,7 @@
// <context.island_location> Returns the location of the island.
// <context.location> Returns the location the player entered at.
//
// @Plugin Depenizen, A SkyBlock
// @Plugin DepenizenBukkit, A SkyBlock
//
// -->

Expand Down
Expand Up @@ -29,7 +29,7 @@
// <context.island_location> Returns the location of the island.
// <context.location> Returns the location the player exited at.
//
// @Plugin Depenizen, A SkyBlock
// @Plugin DepenizenBukkit, A SkyBlock
//
// -->

Expand Down
Expand Up @@ -30,7 +30,7 @@
// <context.location> Returns the location of the island.
// <context.schematic> Returns the name of the schematic used for the island.
//
// @Plugin Depenizen, A SkyBlock
// @Plugin DepenizenBukkit, A SkyBlock
//
// -->

Expand Down
Expand Up @@ -28,7 +28,7 @@
// <context.owner> Returns the owner of the island.
// <context.location> Returns the location of the island.
//
// @Plugin Depenizen, A SkyBlock
// @Plugin DepenizenBukkit, A SkyBlock
//
// -->

Expand Down
Expand Up @@ -24,7 +24,7 @@ public class PlayerDisconnectScriptEvent extends BungeeScriptEvent {
// <context.uuid> returns an Element of the player's UUID.
// <context.name> returns an Element of the player's current name.
//
// @Plugin Depenizen, BungeeCord
// @Plugin DepenizenBukkit, DepenizenBungee
// -->


Expand Down
Expand Up @@ -24,7 +24,7 @@ public class PostLoginScriptEvent extends BungeeScriptEvent {
// <context.uuid> returns an Element of the player's UUID.
// <context.name> returns an Element of the player's current name.
//
// @Plugin Depenizen, BungeeCord
// @Plugin DepenizenBukkit, DepenizenBungee
// -->


Expand Down
Expand Up @@ -35,7 +35,7 @@ public class ProxyPingScriptEvent extends BungeeScriptEvent {
// "VERSION:" + Element to change the response for the server version.
// "MOTD:" + Element to change the MOTD.
//
// @Plugin Depenizen, BungeeCord
// @Plugin DepenizenBukkit, DepenizenBungee
// -->


Expand Down
Expand Up @@ -27,7 +27,7 @@ public class ServerSwitchScriptEvent extends BungeeScriptEvent {
// <context.name> returns an Element of the player's current name.
// <context.server> returns the dServer the player is switching to.
//
// @Plugin Depenizen, BungeeCord
// @Plugin DepenizenBukkit, DepenizenBungee
// -->


Expand Down
Expand Up @@ -29,7 +29,7 @@
// @Context
// <context.status> Returns the player's afk status.
//
// @Plugin Depenizen, Essentials
// @Plugin DepenizenBukkit, Essentials
//
// -->

Expand Down
Expand Up @@ -29,7 +29,7 @@
// @Context
// <context.status> Returns the player's god mode status.
//
// @Plugin Depenizen, Essentials
// @Plugin DepenizenBukkit, Essentials
//
// -->

Expand Down
Expand Up @@ -30,7 +30,7 @@
// @Context
// <context.status> Returns the player's jail status.
//
// @Plugin Depenizen, Essentials
// @Plugin DepenizenBukkit, Essentials
//
// -->

Expand Down
Expand Up @@ -30,7 +30,7 @@
// @Context
// <context.status> Returns the player's jail status.
//
// @Plugin Depenizen, Essentials
// @Plugin DepenizenBukkit, Essentials
//
// -->

Expand Down

0 comments on commit 5ea8a20

Please sign in to comment.