diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java b/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java new file mode 100644 index 00000000..945d7934 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSeeChunk.java @@ -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); + } + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 7843722a..a9b1cb61 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -55,6 +55,7 @@ public class FCmdRoot extends FCommand { public CmdSB cmdSB = new CmdSB(); public CmdShowInvites cmdShowInvites = new CmdShowInvites(); public CmdAnnounce cmdAnnounce = new CmdAnnounce(); + public CmdSeeChunk cmdSeeChunk = new CmdSeeChunk(); public FCmdRoot() { super(); @@ -126,6 +127,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdSB); this.addSubCommand(this.cmdShowInvites); this.addSubCommand(this.cmdAnnounce); + this.addSubCommand(this.cmdSeeChunk); } @Override diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index bf9a8cb8..2b7610cc 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -8,6 +8,7 @@ import com.massivecraft.factions.scoreboards.sidebar.FDefaultSidebar; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.zcore.util.TextUtil; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -90,6 +91,11 @@ public class FactionsPlayerListener implements Listener { 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 if (event.getFrom().getBlockX() >> 4 == event.getTo().getBlockX() >> 4 && event.getFrom().getBlockZ() >> 4 == event.getTo().getBlockZ() >> 4 && event.getFrom().getWorld() == event.getTo().getWorld()) { return; diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index b65baff9..31172cc4 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -67,7 +67,8 @@ public enum Permission { UNCLAIM("unclaim"), UNCLAIM_ALL("unclaimall"), VERSION("version"), - SCOREBOARD("scoreboard"); + SCOREBOARD("scoreboard"), + SEECHUNK("seechunk"); public final String node; diff --git a/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java b/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java new file mode 100644 index 00000000..f607874d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/util/VisualizeUtil.java @@ -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> playerLocations = new HashMap>(); + + public static Set getPlayerLocations(Player player) { + return getPlayerLocations(player.getUniqueId()); + } + + public static Set getPlayerLocations(UUID uuid) { + Set ret = playerLocations.get(uuid); + if (ret == null) { + ret = new HashSet(); + 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 locationMaterialIds) { + Set ploc = getPlayerLocations(player); + for (Entry entry : locationMaterialIds.entrySet()) { + ploc.add(entry.getKey()); + player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0); + } + } + + @SuppressWarnings("deprecation") + public static void addLocations(Player player, Collection locations, int typeId) { + Set 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 blocks, int typeId) { + Set 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 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(); + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1ea99931..ce604805 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -88,6 +88,7 @@ permissions: factions.unclaimall: true factions.scoreboard: true factions.showinvites: true + factions.seechunk: true factions.admin: description: hand over your admin rights factions.admin.any: @@ -230,4 +231,6 @@ permissions: factions.scoreboard: description: ability to toggle scoreboards factions.showinvites: - description: show pending invites to your faction \ No newline at end of file + description: show pending invites to your faction + factions.seechunk: + description: see the chunk you stand in \ No newline at end of file