mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 19:16:41 +01:00
Add checkspawns command.
This commit is contained in:
parent
325b252696
commit
adb8ee1668
@ -173,6 +173,7 @@ public class CommandHandler implements CommandExecutor
|
||||
register(AddSpawnpointCommand.class);
|
||||
register(ArenaCommand.class);
|
||||
register(CheckDataCommand.class);
|
||||
register(CheckSpawnsCommand.class);
|
||||
register(ConfigCommand.class);
|
||||
register(ContainersCommand.class);
|
||||
register(EditArenaCommand.class);
|
||||
|
@ -0,0 +1,61 @@
|
||||
package com.garbagemule.MobArena.commands.setup;
|
||||
|
||||
import com.garbagemule.MobArena.Messenger;
|
||||
import com.garbagemule.MobArena.Msg;
|
||||
import com.garbagemule.MobArena.commands.Command;
|
||||
import com.garbagemule.MobArena.commands.CommandInfo;
|
||||
import com.garbagemule.MobArena.commands.Commands;
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandInfo(
|
||||
name = "checkspawns",
|
||||
pattern = "checkspawn(point)?s",
|
||||
usage = "/ma checkspawns (<arena>)",
|
||||
desc = "show spawnpoints that cover your location",
|
||||
permission = "mobarena.setup.checkspawns"
|
||||
)
|
||||
public class CheckSpawnsCommand implements Command
|
||||
{
|
||||
@Override
|
||||
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
|
||||
if (!Commands.isPlayer(sender)) {
|
||||
Messenger.tellPlayer(sender, Msg.MISC_NOT_FROM_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Grab the argument, if any.
|
||||
String arg1 = (args.length > 0 ? args[0] : "");
|
||||
|
||||
// Cast the sender.
|
||||
Player p = (Player) sender;
|
||||
|
||||
Arena arena;
|
||||
|
||||
if (arg1.equals("")) {
|
||||
arena = am.getArenaAtLocation(p.getLocation());
|
||||
if (arena == null) {
|
||||
arena = am.getSelectedArena();
|
||||
}
|
||||
|
||||
if (arena.getRegion().getSpawnpoints().isEmpty()) {
|
||||
Messenger.tellPlayer(sender, "There are no spawnpoints in the selected arena.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
arena = am.getArenaWithName(arg1);
|
||||
|
||||
if (arena == null) {
|
||||
Messenger.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
arena.getRegion().checkSpawns(p);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||
|
||||
@CommandInfo(
|
||||
name = "showregion",
|
||||
pattern = "show(region)?",
|
||||
pattern = "showregion",
|
||||
usage = "/ma showregion (<arena>)",
|
||||
desc = "show an arena region",
|
||||
permission = "mobarena.setup.showregion"
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -458,33 +459,73 @@ public class ArenaRegion
|
||||
if (!isDefined()) {
|
||||
return;
|
||||
}
|
||||
showBlocks(p, getFramePoints());
|
||||
}
|
||||
|
||||
public void showSpawns(final Player p) {
|
||||
if (spawnpoints.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
showBlocks(p, spawnpoints.values());
|
||||
}
|
||||
|
||||
public void checkSpawns(Player p) {
|
||||
if (spawnpoints.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find all the spawnpoints that cover the location
|
||||
Map<String,Location> map = new HashMap<String,Location>();
|
||||
for (Map.Entry<String,Location> entry : spawnpoints.entrySet()) {
|
||||
if (p.getLocation().distanceSquared(entry.getValue()) < MobArena.MIN_PLAYER_DISTANCE_SQUARED) {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (map.isEmpty()) {
|
||||
Messenger.tellPlayer(p, "No spawnpoints cover your location!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Notify the player
|
||||
Messenger.tellPlayer(p, "The following points cover your location:");
|
||||
for (Map.Entry<String,Location> entry : map.entrySet()) {
|
||||
Location l = entry.getValue();
|
||||
String coords = l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ();
|
||||
p.sendMessage(ChatColor.AQUA + entry.getKey() + ChatColor.WHITE + " : " + coords);
|
||||
}
|
||||
|
||||
// And show the blocks
|
||||
showBlocks(p, map.values());
|
||||
}
|
||||
|
||||
private void showBlocks(final Player p, Collection<Location> points) {
|
||||
// Grab all the blocks, and send block change events.
|
||||
final Map<Location,BlockState> blocks = new HashMap<Location,BlockState>();
|
||||
for (Location l : getFramePoints()) {
|
||||
for (Location l : points) {
|
||||
Block b = l.getBlock();
|
||||
blocks.put(l, b.getState());
|
||||
p.sendBlockChange(l, 35, (byte) 14);
|
||||
}
|
||||
|
||||
arena.scheduleTask(new Runnable() {
|
||||
public void run() {
|
||||
// If the player isn't online, just forget it.
|
||||
if (!p.isOnline()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Send block "restore" events.
|
||||
for (Map.Entry<Location,BlockState> entry : blocks.entrySet()) {
|
||||
Location l = entry.getKey();
|
||||
BlockState b = entry.getValue();
|
||||
int id = b.getTypeId();
|
||||
byte data = b.getRawData();
|
||||
|
||||
p.sendBlockChange(l, id, data);
|
||||
}
|
||||
public void run() {
|
||||
// If the player isn't online, just forget it.
|
||||
if (!p.isOnline()) {
|
||||
return;
|
||||
}
|
||||
}, 100);
|
||||
|
||||
// Send block "restore" events.
|
||||
for (Map.Entry<Location,BlockState> entry : blocks.entrySet()) {
|
||||
Location l = entry.getKey();
|
||||
BlockState b = entry.getValue();
|
||||
int id = b.getTypeId();
|
||||
byte data = b.getRawData();
|
||||
|
||||
p.sendBlockChange(l, id, data);
|
||||
}
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
private List<Location> getFramePoints() {
|
||||
|
Loading…
Reference in New Issue
Block a user