diff --git a/resources/config.yml b/resources/config.yml index 7c3f801..9e81c94 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -1,5 +1,6 @@ maxGateBlocks: 50 playerGateBlockUpdateRadius: 64 +highlightDuration: 5 saveOnChanges: true checkForBrokenGateFrames: true gateTeleportMessage: "Thank you for traveling with Craft Inc. Gates." diff --git a/src/de/craftinc/gates/Plugin.java b/src/de/craftinc/gates/Plugin.java index 4b1e400..db90339 100644 --- a/src/de/craftinc/gates/Plugin.java +++ b/src/de/craftinc/gates/Plugin.java @@ -51,6 +51,7 @@ public class Plugin extends JavaPlugin public static final String confGateTeleportNoPermissionMessageKey = "gateTeleportNoPermissionMessage"; public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage"; public static final String confSaveOnChangesKey = "saveOnChanges"; + public static final String confHighlightDurationKey = "highlightDuration"; private static Plugin instance; private static Permission permission; @@ -154,6 +155,7 @@ public class Plugin extends JavaPlugin commands.add(new CommandHide()); commands.add(new CommandUnhide()); commands.add(new CommandExitOpen()); + commands.add(new CommandNearby()); // Register events diff --git a/src/de/craftinc/gates/commands/CommandHelp.java b/src/de/craftinc/gates/commands/CommandHelp.java index f9cd682..76efa42 100644 --- a/src/de/craftinc/gates/commands/CommandHelp.java +++ b/src/de/craftinc/gates/commands/CommandHelp.java @@ -45,6 +45,7 @@ public class CommandHelp extends BaseCommand allUsageStrings.add( new CommandHide().getUsageTemplate(true, true) ); allUsageStrings.add( new CommandUnhide().getUsageTemplate(true, true) ); allUsageStrings.add( new CommandExitOpen().getUsageTemplate(true, true) ); + allUsageStrings.add( new CommandNearby().getUsageTemplate(true, true) ); Collections.sort(allUsageStrings); diff --git a/src/de/craftinc/gates/commands/CommandLocation.java b/src/de/craftinc/gates/commands/CommandLocation.java index 0ff15b4..61b631e 100644 --- a/src/de/craftinc/gates/commands/CommandLocation.java +++ b/src/de/craftinc/gates/commands/CommandLocation.java @@ -29,7 +29,6 @@ import org.bukkit.block.Block; public class CommandLocation extends BaseLocationCommand { - public CommandLocation() { aliases.add("location"); diff --git a/src/de/craftinc/gates/commands/CommandNearby.java b/src/de/craftinc/gates/commands/CommandNearby.java new file mode 100644 index 0000000..25943f5 --- /dev/null +++ b/src/de/craftinc/gates/commands/CommandNearby.java @@ -0,0 +1,29 @@ +package de.craftinc.gates.commands; + + +import de.craftinc.gates.Plugin; +import de.craftinc.gates.util.GateBlockChangeSender; + +public class CommandNearby extends BaseLocationCommand +{ + public CommandNearby() + { + aliases.add("nearby"); + aliases.add("nb"); + + helpDescription = "Highlight nearby gates"; + + requiredPermission = Plugin.permissionInfo; + + needsPermissionAtCurrentLocation = true; + shouldPersistToDisk = false; + senderMustBePlayer = true; + hasGateParam = false; + } + + + public void perform() + { + GateBlockChangeSender.temporaryHighlightGatesFrames(player); + } +} diff --git a/src/de/craftinc/gates/util/GateBlockChangeSender.java b/src/de/craftinc/gates/util/GateBlockChangeSender.java index f092e78..93a412b 100644 --- a/src/de/craftinc/gates/util/GateBlockChangeSender.java +++ b/src/de/craftinc/gates/util/GateBlockChangeSender.java @@ -22,6 +22,7 @@ import de.craftinc.gates.Gate; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; import java.util.ArrayList; @@ -30,6 +31,65 @@ import java.util.Set; public class GateBlockChangeSender { + /** + * Replaces gate frame blocks with glowstone for a short period of time. + * Uses the value stored in 'highlightDuration' inside the config file + * for determining when to de-highlight the frames. + * @param player The player for whom the frame should be highlighted. + * Must not be null! + */ + public static void temporaryHighlightGatesFrames(final Player player) + { + if (player == null) { + throw new IllegalArgumentException("'player' must not be 'null'!"); + } + + Location location = player.getLocation(); + final Set gatesNearby = Plugin.getPlugin().getGatesManager().getNearbyGates(location.getChunk()); + + if (gatesNearby == null) { + return; // no gates nearby + } + + highlightGatesFrames(player, gatesNearby); + + + Plugin plugin = Plugin.getPlugin(); + long highlightDuration = 20 * plugin.getConfig().getLong(Plugin.confHighlightDurationKey); + + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { + @Override + public void run() { + dehighlightGateFrame(player, gatesNearby); + } + }, highlightDuration); + } + + + protected static void highlightGatesFrames(final Player player, final Set gates) + { + for (Gate g : gates) { + Set frameBlocks = g.getGateFrameBlocks(); + + for (Block b : frameBlocks) { + player.sendBlockChange(b.getLocation(), Material.GLOWSTONE, (byte)0); + } + } + } + + + protected static void dehighlightGateFrame(final Player player, final Set gates) + { + for (Gate g : gates) { + Set frameBlocks = g.getGateFrameBlocks(); + + for (Block b : frameBlocks) { + player.sendBlockChange(b.getLocation(), b.getType(), (byte)0); + } + } + } + + /** * Sends gate blocks to player at a given location. Will send the updates either immediately or * immediately and after a short delay.