Added the nearby command. Issue #12
This commit is contained in:
parent
f4111fb34f
commit
efc30d0ae0
@ -1,5 +1,6 @@
|
|||||||
maxGateBlocks: 50
|
maxGateBlocks: 50
|
||||||
playerGateBlockUpdateRadius: 64
|
playerGateBlockUpdateRadius: 64
|
||||||
|
highlightDuration: 5
|
||||||
saveOnChanges: true
|
saveOnChanges: true
|
||||||
checkForBrokenGateFrames: true
|
checkForBrokenGateFrames: true
|
||||||
gateTeleportMessage: "Thank you for traveling with Craft Inc. Gates."
|
gateTeleportMessage: "Thank you for traveling with Craft Inc. Gates."
|
||||||
|
@ -51,6 +51,7 @@ public class Plugin extends JavaPlugin
|
|||||||
public static final String confGateTeleportNoPermissionMessageKey = "gateTeleportNoPermissionMessage";
|
public static final String confGateTeleportNoPermissionMessageKey = "gateTeleportNoPermissionMessage";
|
||||||
public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage";
|
public static final String confShowTeleportNoPermissionMessageKey = "showTeleportNoPermissionMessage";
|
||||||
public static final String confSaveOnChangesKey = "saveOnChanges";
|
public static final String confSaveOnChangesKey = "saveOnChanges";
|
||||||
|
public static final String confHighlightDurationKey = "highlightDuration";
|
||||||
|
|
||||||
private static Plugin instance;
|
private static Plugin instance;
|
||||||
private static Permission permission;
|
private static Permission permission;
|
||||||
@ -154,6 +155,7 @@ public class Plugin extends JavaPlugin
|
|||||||
commands.add(new CommandHide());
|
commands.add(new CommandHide());
|
||||||
commands.add(new CommandUnhide());
|
commands.add(new CommandUnhide());
|
||||||
commands.add(new CommandExitOpen());
|
commands.add(new CommandExitOpen());
|
||||||
|
commands.add(new CommandNearby());
|
||||||
|
|
||||||
|
|
||||||
// Register events
|
// Register events
|
||||||
|
@ -45,6 +45,7 @@ public class CommandHelp extends BaseCommand
|
|||||||
allUsageStrings.add( new CommandHide().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandHide().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandUnhide().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandUnhide().getUsageTemplate(true, true) );
|
||||||
allUsageStrings.add( new CommandExitOpen().getUsageTemplate(true, true) );
|
allUsageStrings.add( new CommandExitOpen().getUsageTemplate(true, true) );
|
||||||
|
allUsageStrings.add( new CommandNearby().getUsageTemplate(true, true) );
|
||||||
|
|
||||||
Collections.sort(allUsageStrings);
|
Collections.sort(allUsageStrings);
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ import org.bukkit.block.Block;
|
|||||||
|
|
||||||
public class CommandLocation extends BaseLocationCommand
|
public class CommandLocation extends BaseLocationCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
public CommandLocation()
|
public CommandLocation()
|
||||||
{
|
{
|
||||||
aliases.add("location");
|
aliases.add("location");
|
||||||
|
29
src/de/craftinc/gates/commands/CommandNearby.java
Normal file
29
src/de/craftinc/gates/commands/CommandNearby.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,7 @@ import de.craftinc.gates.Gate;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -30,6 +31,65 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class GateBlockChangeSender
|
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<Gate> 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<Gate> gates)
|
||||||
|
{
|
||||||
|
for (Gate g : gates) {
|
||||||
|
Set<Block> frameBlocks = g.getGateFrameBlocks();
|
||||||
|
|
||||||
|
for (Block b : frameBlocks) {
|
||||||
|
player.sendBlockChange(b.getLocation(), Material.GLOWSTONE, (byte)0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected static void dehighlightGateFrame(final Player player, final Set<Gate> gates)
|
||||||
|
{
|
||||||
|
for (Gate g : gates) {
|
||||||
|
Set<Block> 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
|
* Sends gate blocks to player at a given location. Will send the updates either immediately or
|
||||||
* immediately and after a short delay.
|
* immediately and after a short delay.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user