Start of /dial command, still needs work

This commit is contained in:
Steven Scott
2012-03-14 21:58:15 -07:00
parent 17b225e924
commit bb69d412a8
3 changed files with 511 additions and 438 deletions

View File

@@ -1,79 +1,94 @@
package net.TheDgtl.StargateCommand; package net.TheDgtl.StargateCommand;
import net.TheDgtl.Stargate.Gate; import net.TheDgtl.Stargate.Gate;
import net.TheDgtl.StargateCommand.StargateCommand.Action; import net.TheDgtl.Stargate.event.StargateActivateEvent;
import net.TheDgtl.StargateCommand.StargateCommand.Action;
import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.block.Block;
import org.bukkit.event.EventHandler; import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.EventHandler;
import org.bukkit.event.Event.Result; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.Event.Result;
import org.bukkit.event.player.PlayerInteractEvent;
public class SGCListener implements Listener {
StargateCommand sgc; public class SGCListener implements Listener {
public SGCListener(StargateCommand plugin) { StargateCommand sgc;
sgc = plugin; public SGCListener(StargateCommand plugin) {
} sgc = plugin;
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { @EventHandler
// We want right-click block only public void onPlayerInteract(PlayerInteractEvent event) {
if (event.getAction() != org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) return; // We want right-click block only
if (event.getAction() != org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) return;
Player player = event.getPlayer();
Block block = event.getClickedBlock(); Player player = event.getPlayer();
SGCPlayer sPlayer = sgc.players.get(player); Block block = event.getClickedBlock();
if (sPlayer == null || block == null) return; SGCPlayer sPlayer = sgc.players.get(player);
if (sPlayer.action == Action.IMPORT) { if (sPlayer == null || block == null) return;
event.setCancelled(true); if (sPlayer.action == Action.IMPORT) {
event.setUseInteractedBlock(Result.DENY); event.setCancelled(true);
event.setUseItemInHand(Result.DENY); event.setUseInteractedBlock(Result.DENY);
// First block event.setUseItemInHand(Result.DENY);
if (sPlayer.blocks.size() == 0) { // First block
sPlayer.blocks.add(block); if (sPlayer.blocks.size() == 0) {
StargateCommand.sendMessage(player, "Please select a second block by right-clicking it", false); sPlayer.blocks.add(block);
return; StargateCommand.sendMessage(player, "Please select a second block by right-clicking it", false);
} else { return;
Block fb = sPlayer.blocks.poll(); } else {
int modX = fb.getX() - block.getX(); Block fb = sPlayer.blocks.poll();
int modZ = fb.getZ() - block.getZ(); int modX = fb.getX() - block.getX();
int modY = fb.getY() - block.getY(); int modZ = fb.getZ() - block.getZ();
if (modY != 0 || modX > 1 || modX < -1 || modZ > 1 || modZ < -1 || (modX != 0 && modZ != 0)) { int modY = fb.getY() - block.getY();
StargateCommand.sendMessage(player, "The blocks you selected were not next to eachother. Exiting", true); if (modY != 0 || modX > 1 || modX < -1 || modZ > 1 || modZ < -1 || (modX != 0 && modZ != 0)) {
sgc.players.remove(player); StargateCommand.sendMessage(player, "The blocks you selected were not next to eachother. Exiting", true);
return; sgc.players.remove(player);
} return;
Gate gate = Gate.getGateByName(sPlayer.args[1] + ".gate"); }
boolean force = false; Gate gate = Gate.getGateByName(sPlayer.args[1] + ".gate");
if (sPlayer.args.length > 2 && sPlayer.args[2].equalsIgnoreCase("force")) force = true; boolean force = false;
sgc.importGate(player, gate, fb, modX, modZ, force); if (sPlayer.args.length > 2 && sPlayer.args[2].equalsIgnoreCase("force")) force = true;
sgc.players.remove(player); sgc.importGate(player, gate, fb, modX, modZ, force);
} sgc.players.remove(player);
} else if (sPlayer.action == Action.EXPORT) { }
event.setCancelled(true); } else if (sPlayer.action == Action.EXPORT) {
event.setUseInteractedBlock(Result.DENY); event.setCancelled(true);
event.setUseItemInHand(Result.DENY); event.setUseInteractedBlock(Result.DENY);
if (sPlayer.blocks.size() == 0) { event.setUseItemInHand(Result.DENY);
sPlayer.blocks.add(block); if (sPlayer.blocks.size() == 0) {
StargateCommand.sendMessage(player, "Please select the button location", false); sPlayer.blocks.add(block);
} else if (sPlayer.blocks.size() == 1) { StargateCommand.sendMessage(player, "Please select the button location", false);
sPlayer.blocks.add(block); } else if (sPlayer.blocks.size() == 1) {
StargateCommand.sendMessage(player, "Please select the exit location", false); sPlayer.blocks.add(block);
} else if (sPlayer.blocks.size() == 2) { StargateCommand.sendMessage(player, "Please select the exit location", false);
sPlayer.blocks.add(block); } else if (sPlayer.blocks.size() == 2) {
StargateCommand.sendMessage(player, "Please select the top-left block of the bedrock frame", false); sPlayer.blocks.add(block);
} else if (sPlayer.blocks.size() == 3) { StargateCommand.sendMessage(player, "Please select the top-left block of the bedrock frame", false);
// First we find the dimensions of the frame } else if (sPlayer.blocks.size() == 3) {
if (block.getType() != Material.BEDROCK) { // First we find the dimensions of the frame
StargateCommand.sendMessage(player, "You did not select bedrock, exiting export mode", true); if (block.getType() != Material.BEDROCK) {
sgc.players.remove(player); StargateCommand.sendMessage(player, "You did not select bedrock, exiting export mode", true);
return; sgc.players.remove(player);
} return;
sgc.exportGate(player, block); }
sgc.players.remove(player); sgc.exportGate(player, block);
} sgc.players.remove(player);
} }
} }
} }
@EventHandler
public void onStargateActivate(StargateActivateEvent event) {
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 {
StargateCommand.sendMessage(player, "The specified destination does not exist for this gate. Exiting", true);
sgc.players.remove(player);
}
}
}

View File

@@ -1,341 +1,390 @@
package net.TheDgtl.StargateCommand; package net.TheDgtl.StargateCommand;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.TheDgtl.Stargate.Blox; import net.TheDgtl.Stargate.Blox;
import net.TheDgtl.Stargate.Gate; import net.TheDgtl.Stargate.Gate;
import net.TheDgtl.Stargate.Stargate; import net.TheDgtl.Stargate.Portal;
import net.TheDgtl.Stargate.Stargate;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.Server;
import org.bukkit.block.BlockFace; import org.bukkit.block.Block;
import org.bukkit.command.Command; import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender; import org.bukkit.command.Command;
import org.bukkit.entity.Player; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginManager; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class StargateCommand extends JavaPlugin {
private Logger log; public class StargateCommand extends JavaPlugin {
private Server server; private Logger log;
private PluginManager pm; private Server server;
private PluginManager pm;
private Stargate sg = null;
private Stargate sg = null;
public HashMap<Player, SGCPlayer> players = new HashMap<Player, SGCPlayer>();
public HashMap<Player, SGCPlayer> players = new HashMap<Player, SGCPlayer>();
public void onEnable() {
this.server = getServer(); public void onEnable() {
this.pm = server.getPluginManager(); this.server = getServer();
this.log = server.getLogger(); this.pm = server.getPluginManager();
this.log = server.getLogger();
sg = (Stargate)pm.getPlugin("Stargate");
sg = (Stargate)pm.getPlugin("Stargate");
if (sg == null) {
log.severe("[SGC] Error, Stargate not found. Disabling"); if (sg == null) {
pm.disablePlugin(this); log.severe("[SGC] Error, Stargate not found. Disabling");
return; pm.disablePlugin(this);
} return;
}
pm.registerEvents(new SGCListener(this), this);
} pm.registerEvents(new SGCListener(this), this);
}
public void onDisable() {
public void onDisable() {
}
}
public void importGate(Player player, Gate gate, Block baseBlock, int modX, int modZ, boolean force) {
if (gate == null) { public void importGate(Player player, Gate gate, Block baseBlock, int modX, int modZ, boolean force) {
StargateCommand.sendMessage(player, "The gate specified does not exist", true); if (gate == null) {
return; StargateCommand.sendMessage(player, "The gate specified does not exist", true);
} return;
}
Blox topLeft = new Blox(baseBlock.getLocation().add(0, gate.getLayout().length, 0));
Blox topLeft = new Blox(baseBlock.getLocation().add(0, gate.getLayout().length, 0));
if (!drawGate(topLeft, gate, modX, modZ, force)) {
StargateCommand.sendMessage(player, "Gate interfered with existing terrain. Import cancelled. User force to ignore", true); if (!drawGate(topLeft, gate, modX, modZ, force)) {
return; StargateCommand.sendMessage(player, "Gate interfered with existing terrain. Import cancelled. User force to ignore", true);
} return;
sendMessage(player, "Your gate has been imported successfully", false); }
} sendMessage(player, "Your gate has been imported successfully", false);
}
public boolean drawGate(Blox topleft, Gate gate, int modX, int modZ, boolean force) {
Character[][] layout = gate.getLayout(); public boolean drawGate(Blox topleft, Gate gate, int modX, int modZ, boolean force) {
HashMap<Character, Integer> types = gate.getTypes(); Character[][] layout = gate.getLayout();
HashMap<Character, Integer> metadata = gate.getMetaData(); HashMap<Character, Integer> types = gate.getTypes();
int closedType = gate.getPortalBlockClosed(); HashMap<Character, Integer> metadata = gate.getMetaData();
int closedType = gate.getPortalBlockClosed();
// Queue used incase we need to undo
ArrayList<BlockChange> blockQueue = new ArrayList<BlockChange>(); // Queue used incase we need to undo
ArrayList<BlockChange> blockQueue = new ArrayList<BlockChange>();
for (int y = 0; y < layout.length; y++) {
for (int x = 0; x < layout[y].length; x++) { for (int y = 0; y < layout.length; y++) {
int id = types.get(layout[y][x]); for (int x = 0; x < layout[y].length; x++) {
Integer mData = metadata.get(layout[y][x]); int id = types.get(layout[y][x]);
Integer mData = metadata.get(layout[y][x]);
if (id == Gate.ANYTHING) {
continue; if (id == Gate.ANYTHING) {
} continue;
}
if (id == Gate.ENTRANCE || id == Gate.EXIT) {
id = closedType; if (id == Gate.ENTRANCE || id == Gate.EXIT) {
} id = closedType;
}
Blox block = topleft.modRelative(x, y, 0, modX, 1, modZ);
if (block.getType() != Material.AIR.getId() && !force) { Blox block = topleft.modRelative(x, y, 0, modX, 1, modZ);
return false; if (block.getType() != Material.AIR.getId() && !force) {
} return false;
}
BlockChange bc = new BlockChange();
bc.block = block; BlockChange bc = new BlockChange();
bc.newType = id; bc.block = block;
bc.newData = mData; bc.newType = id;
blockQueue.add(bc); bc.newData = mData;
} blockQueue.add(bc);
} }
}
for(BlockChange bc : blockQueue) {
bc.block.setType(bc.newType); for(BlockChange bc : blockQueue) {
if (bc.newData != null) bc.block.setType(bc.newType);
bc.block.setData(bc.newData); if (bc.newData != null)
} bc.block.setData(bc.newData);
return true; }
} return true;
}
private boolean checkOffset(Location a, Location b, int modX, int modZ, int width, int height) {
int offX = Math.abs(a.getBlockX() - b.getBlockX()); private boolean checkOffset(Location a, Location b, int modX, int modZ, int width, int height) {
int offY = Math.abs(a.getBlockY() - b.getBlockY()); int offX = Math.abs(a.getBlockX() - b.getBlockX());
int offZ = Math.abs(a.getBlockZ() - b.getBlockZ()); int offY = Math.abs(a.getBlockY() - b.getBlockY());
if (modX == 0 && (offX != 0 || offZ > width)) return false; int offZ = Math.abs(a.getBlockZ() - b.getBlockZ());
if (modZ == 0 && (offZ != 0 || offX > width)) return false; if (modX == 0 && (offX != 0 || offZ > width)) return false;
if (offY > height) return false; if (modZ == 0 && (offZ != 0 || offX > width)) return false;
return true; if (offY > height) return false;
} return true;
}
public void exportGate(Player player, Block topleft) {
SGCPlayer sPlayer = players.get(player); public void exportGate(Player player, Block topleft) {
// Determine facing SGCPlayer sPlayer = players.get(player);
int tmp = 0; // Determine facing
int modX = 0; int tmp = 0;
int modZ = 0; int modX = 0;
if (topleft.getRelative(BlockFace.EAST).getType() == Material.BEDROCK) { int modZ = 0;
modZ = -1; if (topleft.getRelative(BlockFace.EAST).getType() == Material.BEDROCK) {
tmp++; modZ = -1;
} tmp++;
if (topleft.getRelative(BlockFace.WEST).getType() == Material.BEDROCK) { }
modZ = 1; if (topleft.getRelative(BlockFace.WEST).getType() == Material.BEDROCK) {
tmp++; modZ = 1;
} tmp++;
if (topleft.getRelative(BlockFace.NORTH).getType() == Material.BEDROCK) { }
modX = -1; if (topleft.getRelative(BlockFace.NORTH).getType() == Material.BEDROCK) {
tmp++; modX = -1;
} tmp++;
if (topleft.getRelative(BlockFace.SOUTH).getType() == Material.BEDROCK) { }
modX = 1; if (topleft.getRelative(BlockFace.SOUTH).getType() == Material.BEDROCK) {
tmp++; modX = 1;
} tmp++;
if (tmp != 1 || topleft.getRelative(BlockFace.DOWN).getType() != Material.BEDROCK) { }
StargateCommand.sendMessage(player, "There was an error determining your frame. Exiting export mode", true); if (tmp != 1 || topleft.getRelative(BlockFace.DOWN).getType() != Material.BEDROCK) {
players.remove(player); StargateCommand.sendMessage(player, "There was an error determining your frame. Exiting export mode", true);
return; players.remove(player);
} return;
}
// Check offset of control blocks
Block signBlock = sPlayer.blocks.poll(); // Check offset of control blocks
Block buttonBlock = sPlayer.blocks.poll(); Block signBlock = sPlayer.blocks.poll();
Block buttonBlock = sPlayer.blocks.poll();
// Check offset of exit block
Block exitBlock = sPlayer.blocks.poll(); // Check offset of exit block
Block exitBlock = sPlayer.blocks.poll();
// Determine frame width/height
int frameWidth = 1; // Determine frame width/height
int frameHeight = 1; int frameWidth = 1;
while (topleft.getRelative(modX * frameWidth, 0, modZ * frameWidth).getType() == Material.BEDROCK) { int frameHeight = 1;
frameWidth++; while (topleft.getRelative(modX * frameWidth, 0, modZ * frameWidth).getType() == Material.BEDROCK) {
} frameWidth++;
while (topleft.getRelative(0, -frameHeight, 0).getType() == Material.BEDROCK) { }
frameHeight++; while (topleft.getRelative(0, -frameHeight, 0).getType() == Material.BEDROCK) {
} frameHeight++;
frameWidth = frameWidth - 2; }
frameHeight = frameHeight - 2; frameWidth = frameWidth - 2;
Block startBlock = topleft.getRelative(modX, -1, modZ); frameHeight = frameHeight - 2;
Block startBlock = topleft.getRelative(modX, -1, modZ);
if (!checkOffset(signBlock.getLocation(), startBlock.getLocation(), modX, modZ, frameWidth, frameHeight)) {
sendMessage(player, "Your sign block is outside of your stargate. Exiting", true); if (!checkOffset(signBlock.getLocation(), startBlock.getLocation(), modX, modZ, frameWidth, frameHeight)) {
return; sendMessage(player, "Your sign block is outside of your stargate. Exiting", true);
} return;
if (!checkOffset(buttonBlock.getLocation(), startBlock.getLocation(), modX, modZ, frameWidth, frameHeight)) { }
sendMessage(player, "Your button block is outside of your stargate. Exiting", true); if (!checkOffset(buttonBlock.getLocation(), startBlock.getLocation(), modX, modZ, frameWidth, frameHeight)) {
return; sendMessage(player, "Your button block is outside of your stargate. Exiting", true);
} return;
if (!checkOffset(exitBlock.getLocation(), startBlock.getLocation(), modX, modZ, frameWidth, frameHeight)) { }
sendMessage(player, "Your exit block is outside of your stargate. Exiting", true); if (!checkOffset(exitBlock.getLocation(), startBlock.getLocation(), modX, modZ, frameWidth, frameHeight)) {
return; sendMessage(player, "Your exit block is outside of your stargate. Exiting", true);
} return;
}
Gate gate = storeGate(player, startBlock, signBlock, buttonBlock, exitBlock, modX, modZ, frameWidth, frameHeight);
if (gate != null) { Gate gate = storeGate(player, startBlock, signBlock, buttonBlock, exitBlock, modX, modZ, frameWidth, frameHeight);
Gate.registerGate(gate); if (gate != null) {
sendMessage(player, "Your gate layout has been exported and loaded", false); Gate.registerGate(gate);
} sendMessage(player, "Your gate layout has been exported and loaded", false);
} }
}
public Gate storeGate(Player player, Block startBlock, Block signBlock, Block buttonBlock, Block exitBlock, int modX, int modZ, int width, int height) {
SGCPlayer sPlayer = players.get(player); public Gate storeGate(Player player, Block startBlock, Block signBlock, Block buttonBlock, Block exitBlock, int modX, int modZ, int width, int height) {
// Store the gate layout SGCPlayer sPlayer = players.get(player);
HashMap<Integer, Character> typeLookup = new HashMap<Integer, Character>(); // Store the gate layout
HashMap<Integer, Character> typeLookup = new HashMap<Integer, Character>();
Character[][] layout = new Character[height][width];
HashMap<Character, Integer> types = new HashMap<Character, Integer>(); Character[][] layout = new Character[height][width];
HashMap<Character, Integer> metadata = new HashMap<Character, Integer>(); HashMap<Character, Integer> types = new HashMap<Character, Integer>();
HashMap<Character, Integer> metadata = new HashMap<Character, Integer>();
// Validate gate before saving
boolean exitFound = false; // Validate gate before saving
int controlsFound = 0; boolean exitFound = false;
int controlsFound = 0;
// Init types map
Character nextChar = 'A'; // Init types map
types.put('.', Gate.ENTRANCE); Character nextChar = 'A';
types.put('*', Gate.EXIT); types.put('.', Gate.ENTRANCE);
types.put(' ', Gate.ANYTHING); types.put('*', Gate.EXIT);
for (int y = 0; y < height; y++) { types.put(' ', Gate.ANYTHING);
for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) {
Block fBlock = startBlock.getRelative(modX * x, -y, modZ * x); for (int x = 0; x < width; x++) {
int type = fBlock.getTypeId(); Block fBlock = startBlock.getRelative(modX * x, -y, modZ * x);
int data = fBlock.getData(); int type = fBlock.getTypeId();
int lookup = type + (data << 16); int data = fBlock.getData();
// Anything int lookup = type + (data << 16);
if (type == Material.AIR.getId()) { // Anything
layout[y][x] = ' '; if (type == Material.AIR.getId()) {
continue; layout[y][x] = ' ';
} continue;
// Entrance }
if (type == Material.BEDROCK.getId()) { // Entrance
if (fBlock.equals(exitBlock)) { if (type == Material.BEDROCK.getId()) {
exitFound = true; if (fBlock.equals(exitBlock)) {
layout[y][x] = '*'; exitFound = true;
continue; layout[y][x] = '*';
} continue;
layout[y][x] = '.'; }
continue; layout[y][x] = '.';
} continue;
if (fBlock.equals(signBlock) || fBlock.equals(buttonBlock)) { }
controlsFound++; if (fBlock.equals(signBlock) || fBlock.equals(buttonBlock)) {
layout[y][x] = '-'; controlsFound++;
Integer cType = types.get('-'); layout[y][x] = '-';
if (cType != null && cType != type) { Integer cType = types.get('-');
sendMessage(player, "Both your control blocks must be on the same block type. Exiting", true); if (cType != null && cType != type) {
return null; sendMessage(player, "Both your control blocks must be on the same block type. Exiting", true);
} return null;
types.put('-', type); }
continue; types.put('-', type);
} continue;
// Store block/metadata for gate }
if (!typeLookup.containsKey(lookup)) { // Store block/metadata for gate
typeLookup.put(lookup, nextChar); if (!typeLookup.containsKey(lookup)) {
types.put(nextChar, type); typeLookup.put(lookup, nextChar);
if (data != 0) types.put(nextChar, type);
metadata.put(nextChar, data); if (data != 0)
nextChar++; metadata.put(nextChar, data);
} nextChar++;
layout[y][x] = typeLookup.get(lookup); }
} layout[y][x] = typeLookup.get(lookup);
} }
}
if (!exitFound) {
sendMessage(player, "Your exit was not in an entrance block. Exiting", true); if (!exitFound) {
return null; sendMessage(player, "Your exit was not in an entrance block. Exiting", true);
} return null;
if (controlsFound != 2) { }
sendMessage(player, "One of your control blocks was missing. Exiting", true); if (controlsFound != 2) {
return null; sendMessage(player, "One of your control blocks was missing. Exiting", true);
} return null;
}
Gate gate = new Gate(sPlayer.args[1] + ".gate", layout, types, metadata);
gate.setPortalBlockOpen(Material.PORTAL.getId()); Gate gate = new Gate(sPlayer.args[1] + ".gate", layout, types, metadata);
gate.setPortalBlockClosed(Material.AIR.getId()); gate.setPortalBlockOpen(Material.PORTAL.getId());
gate.save(Stargate.getGateFolder()); gate.setPortalBlockClosed(Material.AIR.getId());
return gate; gate.save(Stargate.getGateFolder());
} return gate;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public void dialGate(Player player, String dest, String source, String network) {
if (!(sender instanceof Player)) { Portal sourcePortal = Portal.getByName(source, network);
sender.sendMessage("[SGC] This command can only be used ingame"); Portal destPortal = Portal.getByName(dest, network);
return true; if (sourcePortal == null || destPortal == null) {
} sendMessage(player, "The specified Stargate connection does not exist", true);
Player player = (Player)sender; return;
// SGC import/export }
if (command.getName().equalsIgnoreCase("sgc") && args.length > 0) { if (sourcePortal.getWorld() != player.getWorld() && destPortal.getWorld() != player.getWorld()) {
// Import sendMessage(player, "Neither of the specified gates are on your world", true);
if (args[0].equalsIgnoreCase("import")) { return;
if (!player.hasPermission("stargate.command.import")) { }
StargateCommand.sendMessage(player, "Permission Denied", true); if (!Stargate.canAccessNetwork(player, network)) {
return true; sendMessage(player, "You do not have access to that gate network", true);
} return;
if (args.length < 2) { }
StargateCommand.sendMessage(player, "You did not specify a gate to import", true); sourcePortal.setDestination(destPortal);
return true; if (!sourcePortal.open(player, false)) {
} sendMessage(player, "There was an error opening the gate", true);
if (Gate.getGateByName(args[1] + ".gate") == null) { return;
StargateCommand.sendMessage(player, "The gate you specified does not exist", true); }
return true; sendMessage(player, "The gate has been connected and opened", false);
} }
StargateCommand.sendMessage(player, "Please select two blocks to define gate location/direction", false); @Override
StargateCommand.sendMessage(player, "Do this by right-clicking two blocks next to each other", false); public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
players.put(player, new SGCPlayer(player, Action.IMPORT, args)); if (!(sender instanceof Player)) {
// Export sender.sendMessage("[SGC] This command can only be used ingame");
} else if (args[0].equalsIgnoreCase("export")) { return true;
if (!player.hasPermission("stargate.command.export")) { }
StargateCommand.sendMessage(player, "Permission Denied", true); Player player = (Player)sender;
return true; // SGC import/export
} if (command.getName().equalsIgnoreCase("sgc")) {
if (args.length < 2) { if (args.length == 0) return false;
sendMessage(player, "You must provide a gate name", true); // Import
return true; if (args[0].equalsIgnoreCase("import")) {
} if (!player.hasPermission("stargate.command.import")) {
boolean force = false; StargateCommand.sendMessage(player, "Permission Denied", true);
if (args.length > 2 && args[2].equalsIgnoreCase("force")) force = true; return true;
if (Gate.getGateByName(args[1] + ".gate") != null && !force) { }
sendMessage(player, "A gate by that name exists. Use force to overwrite", true); if (args.length < 2) {
return true; sendMessage(player, "Usage: /sgc import <gate> [force]", false);
} sendMessage(player, "Use force to ignore terrain intersection", false);
StargateCommand.sendMessage(player, "Please select where you would like the sign placed", false); sendMessage(player, "Example: /sgc import super force", false);
StargateCommand.sendMessage(player, "Do this by right-clicking the block", false); return true;
players.put(player, new SGCPlayer(player, Action.EXPORT, args)); }
// Cancel if (Gate.getGateByName(args[1] + ".gate") == null) {
} else if (args[0].equalsIgnoreCase("cancel")) { StargateCommand.sendMessage(player, "The gate you specified does not exist", true);
players.remove(player); return true;
StargateCommand.sendMessage(player, "Command cancelled", false); }
}
return true; StargateCommand.sendMessage(player, "Please select two blocks to define gate location/direction", false);
} StargateCommand.sendMessage(player, "Do this by right-clicking two blocks next to each other", false);
return false; players.put(player, new SGCPlayer(player, Action.IMPORT, args));
} // Export
} else if (args[0].equalsIgnoreCase("export")) {
public static void sendMessage(CommandSender sender, String message, boolean error) { if (!player.hasPermission("stargate.command.export")) {
if (error) { StargateCommand.sendMessage(player, "Permission Denied", true);
message = ChatColor.RED + "[SGC] " + ChatColor.WHITE + message; return true;
} else { }
message = ChatColor.BLUE + "[SGC] " + ChatColor.WHITE + message; if (args.length < 2) {
} StargateCommand.sendMessage(player, "Usage: /sgc export <gate> [force]", false);
sender.sendMessage(message); StargateCommand.sendMessage(player, "Use force to overwrite existing .gate files", false);
} sendMessage(player, "Example: /sgc export super force", false);
return true;
private class BlockChange { }
public Blox block; boolean force = false;
public Integer newType; if (args.length > 2 && args[2].equalsIgnoreCase("force")) force = true;
public Integer newData; if (Gate.getGateByName(args[1] + ".gate") != null && !force) {
} sendMessage(player, "A gate by that name exists. Use force to overwrite", true);
return true;
public enum Action { }
IMPORT, StargateCommand.sendMessage(player, "Please select where you would like the sign placed", false);
EXPORT StargateCommand.sendMessage(player, "Do this by right-clicking the block", false);
} players.put(player, new SGCPlayer(player, Action.EXPORT, args));
} // Cancel
} else if (args[0].equalsIgnoreCase("cancel")) {
players.remove(player);
StargateCommand.sendMessage(player, "Command cancelled", false);
}
return true;
} else if (command.getName().equalsIgnoreCase("dial")) {
if (args.length < 1 || args.length > 2) 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 {
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);
}
return true;
}
return false;
}
public static void sendMessage(CommandSender sender, String message, boolean error) {
if (error) {
message = ChatColor.RED + "[SGC] " + ChatColor.WHITE + message;
} else {
message = ChatColor.BLUE + "[SGC] " + ChatColor.WHITE + message;
}
sender.sendMessage(message);
}
private class BlockChange {
public Blox block;
public Integer newType;
public Integer newData;
}
public enum Action {
IMPORT,
EXPORT,
DIAL
}
}

View File

@@ -1,18 +1,27 @@
name: StargateCommand name: StargateCommand
main: net.TheDgtl.StargateCommand.StargateCommand main: net.TheDgtl.StargateCommand.StargateCommand
version: 0.0.1 version: 0.0.1
description: Command addon for the Stargate plugin for Bukkit description: Command addon for the Stargate plugin for Bukkit
author: Drakia author: Drakia
depend: [Stargate] depend: [Stargate]
website: http://www.thedgtl.net website: http://www.thedgtl.net
commands: commands:
sgc: sgc:
description: Used to reload the plugin. Console use only. description: StargateCommand import/export commands.
usage: /<command> reload - Used to reload the plugin. Console use only. usage: |
permissions: /<command> <import/export/cancel> <gate> [force]
stargate.command.import: Type: "/<command> import" for help with import
description: Allow the user of /sgc import Type: "/<command> export" for help with export
default: op Type: "/<command> cancel" to cancel any pending SGC action
stargate.command.export: dial:
description: Allow the user of /sgc export description: Dial a stargate
default: op usage: /<command> <destination> [source] [network]
permissions:
stargate.command.import:
description: Allow the use of /sgc import
default: op
stargate.command.export:
description: Allow the use of /sgc export
default: op
stargate.command.dial:
description: Allow the use of /dial