Finish impementing /dial

This commit is contained in:
Steven Scott
2012-03-14 23:25:25 -07:00
parent bb69d412a8
commit 933b7f9893
3 changed files with 35 additions and 21 deletions

View File

@@ -1,6 +1,8 @@
package net.TheDgtl.StargateCommand;
import net.TheDgtl.Stargate.Gate;
import net.TheDgtl.Stargate.Portal;
import net.TheDgtl.Stargate.Stargate;
import net.TheDgtl.Stargate.event.StargateActivateEvent;
import net.TheDgtl.StargateCommand.StargateCommand.Action;
@@ -80,15 +82,25 @@ public class SGCListener implements Listener {
@EventHandler
public void onStargateActivate(StargateActivateEvent event) {
Portal portal = event.getPortal();
Player player = event.getPlayer();
SGCPlayer sPlayer = sgc.players.get(player);
if (sPlayer == null) return;
if (sPlayer.action != Action.DIAL) return;
if (event.getDestinations().contains(sPlayer.args[0])) {
event.setDestination(sPlayer.args[0]);
} else {
sgc.players.remove(player);
Portal destPortal = Portal.getByName(sPlayer.args[0], portal.getNetwork());
if (destPortal == null) {
StargateCommand.sendMessage(player, "The specified destination does not exist for this gate. Exiting", true);
sgc.players.remove(player);
} else {
if (!Stargate.canAccessNetwork(player, portal.getNetwork())) {
StargateCommand.sendMessage(player, "You do not have access to that network.", true);
return;
}
event.setCancelled(true);
portal.activate(player);
portal.setDestination(destPortal);
Stargate.openPortal(player, portal);
portal.drawSign();
}
}
}

View File

@@ -279,11 +279,10 @@ public class StargateCommand extends JavaPlugin {
sendMessage(player, "You do not have access to that gate network", true);
return;
}
sourcePortal.activate(player);
sourcePortal.setDestination(destPortal);
if (!sourcePortal.open(player, false)) {
sendMessage(player, "There was an error opening the gate", true);
return;
}
Stargate.openPortal(player, sourcePortal);
sourcePortal.drawSign();
sendMessage(player, "The gate has been connected and opened", false);
}
@@ -345,22 +344,23 @@ public class StargateCommand extends JavaPlugin {
}
return true;
} else if (command.getName().equalsIgnoreCase("dial")) {
if (args.length < 1 || args.length > 2) return false;
if (args.length < 1 || args.length > 3) return false;
String dest = null;
String source = null;
String network = null;
dest = args[0];
if (args.length > 1) {
if (args.length < 2) {
sendMessage(player, "You must provide a network to direct dial a gate", true);
return true;
}
source = args[1];
network = args[2];
dialGate(player, dest, source, network);
} else {
if (args.length == 1) {
dest = args[0];
players.put(player, new SGCPlayer(player, Action.DIAL, args));
sendMessage(player, "The next Stargate you activate will have " + dest + " set as the destination if available", false);
sendMessage(player, "The next Stargate you activate will connect to " + dest + " if available", false);
} else if (args.length > 1) {
source = args[0];
dest = args[1];
if (args.length < 2) {
network = args[2];
} else {
network = Stargate.getDefaultNetwork();
}
dialGate(player, dest, source, network);
}
return true;
}

View File

@@ -15,7 +15,9 @@ commands:
Type: "/<command> cancel" to cancel any pending SGC action
dial:
description: Dial a stargate
usage: /<command> <destination> [source] [network]
usage: |
/<command> <destination>
/<command> <source> <destination> [network]
permissions:
stargate.command.import:
description: Allow the use of /sgc import