Add /f seechunk command for visualizing a chunk

This commit is contained in:
Byteflux 2014-10-19 14:04:27 -07:00 committed by t00thpick1
parent 81fc029736
commit 5569e5076a
6 changed files with 155 additions and 2 deletions

View File

@ -0,0 +1,63 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.VisualizeUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class CmdSeeChunk extends FCommand {
public CmdSeeChunk() {
super();
aliases.add("seechunk");
aliases.add("sc");
permission = Permission.SEECHUNK.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
World world = me.getWorld();
FLocation flocation = new FLocation(me);
int chunkX = (int) flocation.getX();
int chunkZ = (int) flocation.getZ();
int blockX;
int blockZ;
blockX = chunkX*16;
blockZ = chunkZ*16;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16;
blockZ = chunkZ*16 + 15;
showPillar(me, world, blockX, blockZ);
blockX = chunkX*16 + 15;
blockZ = chunkZ*16 + 15;
showPillar(me, world, blockX, blockZ);
}
@SuppressWarnings("deprecation")
public static void showPillar(Player player, World world, int blockX, int blockZ) {
for (int blockY = 0; blockY < world.getMaxHeight(); blockY++) {
Location loc = new Location(world, blockX, blockY, blockZ);
if (loc.getBlock().getType() != Material.AIR) continue;
int typeId = blockY % 5 == 0 ? Material.GLOWSTONE.getId() : Material.GLASS.getId();
VisualizeUtil.addLocation(player, loc, typeId);
}
}
}

View File

@ -55,6 +55,7 @@ public class FCmdRoot extends FCommand {
public CmdSB cmdSB = new CmdSB(); public CmdSB cmdSB = new CmdSB();
public CmdShowInvites cmdShowInvites = new CmdShowInvites(); public CmdShowInvites cmdShowInvites = new CmdShowInvites();
public CmdAnnounce cmdAnnounce = new CmdAnnounce(); public CmdAnnounce cmdAnnounce = new CmdAnnounce();
public CmdSeeChunk cmdSeeChunk = new CmdSeeChunk();
public FCmdRoot() { public FCmdRoot() {
super(); super();
@ -126,6 +127,7 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdSB); this.addSubCommand(this.cmdSB);
this.addSubCommand(this.cmdShowInvites); this.addSubCommand(this.cmdShowInvites);
this.addSubCommand(this.cmdAnnounce); this.addSubCommand(this.cmdAnnounce);
this.addSubCommand(this.cmdSeeChunk);
} }
@Override @Override

View File

@ -8,6 +8,7 @@ import com.massivecraft.factions.scoreboards.sidebar.FDefaultSidebar;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.factions.zcore.util.TextUtil; import com.massivecraft.factions.zcore.util.TextUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -90,6 +91,11 @@ public class FactionsPlayerListener implements Listener {
return; return;
} }
// clear visualization
if (event.getFrom().getBlockX() != event.getTo().getBlockX() || event.getFrom().getBlockY() != event.getTo().getBlockY() || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {
VisualizeUtil.clear(event.getPlayer());
}
// quick check to make sure player is moving between chunks; good performance boost // quick check to make sure player is moving between chunks; good performance boost
if (event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4 && event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4 && event.getFrom().getWorld() == event.getTo().getWorld()) { if (event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4 && event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4 && event.getFrom().getWorld() == event.getTo().getWorld()) {
return; return;

View File

@ -67,7 +67,8 @@ public enum Permission {
UNCLAIM("unclaim"), UNCLAIM("unclaim"),
UNCLAIM_ALL("unclaimall"), UNCLAIM_ALL("unclaimall"),
VERSION("version"), VERSION("version"),
SCOREBOARD("scoreboard"); SCOREBOARD("scoreboard"),
SEECHUNK("seechunk");
public final String node; public final String node;

View File

@ -0,0 +1,78 @@
package com.massivecraft.factions.util;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.*;
import java.util.Map.Entry;
public class VisualizeUtil {
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<UUID, Set<Location>>();
public static Set<Location> getPlayerLocations(Player player) {
return getPlayerLocations(player.getUniqueId());
}
public static Set<Location> getPlayerLocations(UUID uuid) {
Set<Location> ret = playerLocations.get(uuid);
if (ret == null) {
ret = new HashSet<Location>();
playerLocations.put(uuid, ret);
}
return ret;
}
@SuppressWarnings("deprecation")
public static void addLocation(Player player, Location location, int typeId, byte data) {
getPlayerLocations(player).add(location);
player.sendBlockChange(location, typeId, data);
}
@SuppressWarnings("deprecation")
public static void addLocation(Player player, Location location, int typeId) {
getPlayerLocations(player).add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
@SuppressWarnings("deprecation")
public static void addLocations(Player player, Map<Location, Integer> locationMaterialIds) {
Set<Location> ploc = getPlayerLocations(player);
for (Entry<Location, Integer> entry : locationMaterialIds.entrySet()) {
ploc.add(entry.getKey());
player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0);
}
}
@SuppressWarnings("deprecation")
public static void addLocations(Player player, Collection<Location> locations, int typeId) {
Set<Location> ploc = getPlayerLocations(player);
for (Location location : locations) {
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
@SuppressWarnings("deprecation")
public static void addBlocks(Player player, Collection<Block> blocks, int typeId) {
Set<Location> ploc = getPlayerLocations(player);
for (Block block : blocks) {
Location location = block.getLocation();
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
@SuppressWarnings("deprecation")
public static void clear(Player player) {
Set<Location> locations = getPlayerLocations(player);
if (locations == null) return;
for (Location location : locations) {
Block block = location.getWorld().getBlockAt(location);
player.sendBlockChange(location, block.getTypeId(), block.getData());
}
locations.clear();
}
}

View File

@ -88,6 +88,7 @@ permissions:
factions.unclaimall: true factions.unclaimall: true
factions.scoreboard: true factions.scoreboard: true
factions.showinvites: true factions.showinvites: true
factions.seechunk: true
factions.admin: factions.admin:
description: hand over your admin rights description: hand over your admin rights
factions.admin.any: factions.admin.any:
@ -230,4 +231,6 @@ permissions:
factions.scoreboard: factions.scoreboard:
description: ability to toggle scoreboards description: ability to toggle scoreboards
factions.showinvites: factions.showinvites:
description: show pending invites to your faction description: show pending invites to your faction
factions.seechunk:
description: see the chunk you stand in