From 7c44e0c9b7ed69be46d1061747dce9ef9ab06274 Mon Sep 17 00:00:00 2001 From: Steven Scott Date: Sun, 16 Sep 2012 16:31:18 -0700 Subject: [PATCH] [v0.0.3] Added /sgc owner command --- README | 5 ++- .../TheDgtl/StargateCommand/SGCListener.java | 33 ++++++++++++++++--- .../StargateCommand/StargateCommand.java | 14 +++++++- src/plugin.yml | 8 +++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/README b/README index 7489b49..81fb45b 100644 --- a/README +++ b/README @@ -11,7 +11,7 @@ StargateCommand is an addon for Stargate that adds three very useful commands: i ============= Dependencies ============= -Stargate -- http://thedgtl.net/bukkit/ +Stargate v0.7.8.0 -- http://thedgtl.net/bukkit/ ============= Permissions @@ -74,6 +74,9 @@ If the network is not supplied, the default Stargate network will be used. If th ============= Changes ============= +[Version 0.0.3] + - Added /sgc owner command + - Now requires at least Stargate v0.7.8.0 [Version 0.0.2] - Fix an issue with dialing on a specific network - Change permission checks to use Stargate, this allows proper permission debugging diff --git a/src/net/TheDgtl/StargateCommand/SGCListener.java b/src/net/TheDgtl/StargateCommand/SGCListener.java index f5b0bb3..7259275 100644 --- a/src/net/TheDgtl/StargateCommand/SGCListener.java +++ b/src/net/TheDgtl/StargateCommand/SGCListener.java @@ -23,12 +23,23 @@ public class SGCListener implements Listener { @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { // 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(); + Block block = null; + if (event.isCancelled() && event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_AIR) { + try { + block = player.getTargetBlock(null, 5); + } catch (IllegalStateException ex) { + // We can safely ignore this exception, it only happens in void or max height + return; + } + } else { + block = event.getClickedBlock(); + } + + if (block == null || block.getType() == Material.AIR) return; + SGCPlayer sPlayer = sgc.players.get(player); - if (sPlayer == null || block == null) return; + if (sPlayer == null) return; if (sPlayer.action == Action.IMPORT) { event.setCancelled(true); event.setUseInteractedBlock(Result.DENY); @@ -77,6 +88,20 @@ public class SGCListener implements Listener { sgc.exportGate(player, block); sgc.players.remove(player); } + } else if (sPlayer.action == Action.OWNER) { + event.setCancelled(true); + event.setUseInteractedBlock(Result.DENY); + event.setUseItemInHand(Result.DENY); + Portal portal = Portal.getByBlock(block); + if (portal == null) { + StargateCommand.sendMessage(player, "You did not select a gate, exiting", true); + sgc.players.remove(player); + return; + } + portal.setOwner(sPlayer.args[1]); + Portal.saveAllGates(portal.getWorld()); + sgc.players.remove(player); + StargateCommand.sendMessage(player, "Owner of " + portal.getName() + " on network " + portal.getNetwork() + " set to " + sPlayer.args[1], false); } } diff --git a/src/net/TheDgtl/StargateCommand/StargateCommand.java b/src/net/TheDgtl/StargateCommand/StargateCommand.java index 7d4aae1..262a188 100644 --- a/src/net/TheDgtl/StargateCommand/StargateCommand.java +++ b/src/net/TheDgtl/StargateCommand/StargateCommand.java @@ -341,6 +341,17 @@ public class StargateCommand extends JavaPlugin { } else if (args[0].equalsIgnoreCase("cancel")) { players.remove(player); StargateCommand.sendMessage(player, "Command cancelled", false); + } else if (args[0].equalsIgnoreCase("owner")) { + if (!Stargate.hasPerm(player, "stargate.command.owner")) { + StargateCommand.sendMessage(player, "Permission Denied", true); + return true; + } + if (args.length != 2) { + StargateCommand.sendMessage(player, "Usage: /sgc owner ", false); + return true; + } + StargateCommand.sendMessage(player, "Please right-click a target gate to assign ownership", false); + players.put(player, new SGCPlayer(player, Action.OWNER, args)); } return true; } else if (command.getName().equalsIgnoreCase("dial")) { @@ -393,6 +404,7 @@ public class StargateCommand extends JavaPlugin { public enum Action { IMPORT, EXPORT, - DIAL + DIAL, + OWNER } } diff --git a/src/plugin.yml b/src/plugin.yml index 6cbc071..b707664 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,24 +1,28 @@ name: StargateCommand main: net.TheDgtl.StargateCommand.StargateCommand -version: 0.0.2 +version: 0.0.3 description: Command addon for the Stargate plugin for Bukkit author: Drakia depend: [Stargate] website: http://www.thedgtl.net commands: sgc: - description: StargateCommand import/export commands. + description: StargateCommand import/export/owner commands. usage: | / [force] Type: "/ import" for help with import Type: "/ export" for help with export Type: "/ cancel" to cancel any pending SGC action + / owner dial: description: Dial a stargate usage: | / / [network] permissions: + stargate.command.owner: + description: Allow the user of /sgc owner + default: op stargate.command.import: description: Allow the use of /sgc import default: op