Improved the seechunk command.

This commit is contained in:
Olof Larsson 2012-01-28 19:49:01 +01:00
parent 87dc76716e
commit fafad0f590
6 changed files with 129 additions and 37 deletions

View File

@ -67,6 +67,7 @@ permissions:
factions.power: true factions.power: true
factions.power.any: true factions.power.any: true
factions.relation: true factions.relation: true
factions.seechunk: true
factions.sethome: true factions.sethome: true
factions.show: true factions.show: true
factions.tag: true factions.tag: true
@ -165,6 +166,8 @@ permissions:
description: reload data file(s) from disk description: reload data file(s) from disk
factions.save: factions.save:
description: save all data to disk description: save all data to disk
factions.seechunk:
description: see the chunk you stand in
factions.sethome: factions.sethome:
description: set the faction home description: set the faction home
factions.show: factions.show:

View File

@ -112,6 +112,7 @@ public class CmdHelp extends FCommand
pageLines = new ArrayList<String>(); pageLines = new ArrayList<String>();
pageLines.add( p.cmdBase.cmdMap.getUseageTemplate(true) ); pageLines.add( p.cmdBase.cmdMap.getUseageTemplate(true) );
pageLines.add( p.cmdBase.cmdSeeChunks.getUseageTemplate(true) );
pageLines.add(p.txt.parse("<i>Claimed land with ownership set is further protected so")); pageLines.add(p.txt.parse("<i>Claimed land with ownership set is further protected so"));
pageLines.add(p.txt.parse("<i>that only the owner(s), faction admin, and possibly the")); pageLines.add(p.txt.parse("<i>that only the owner(s), faction admin, and possibly the"));
pageLines.add(p.txt.parse("<i>faction moderators have full access.")); pageLines.add(p.txt.parse("<i>faction moderators have full access."));

View File

@ -1,28 +1,21 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.VisualizeUtil;
// !!!! This is just an experiment.
// Proof of concept. We could use fake block updates to visualize the territories.
public class CmdSeeChunk extends FCommand public class CmdSeeChunk extends FCommand
{ {
public CmdSeeChunk() public CmdSeeChunk()
{ {
super(); super();
this.aliases.add("sc"); this.aliases.add("sc");
this.aliases.add("seechunks"); this.aliases.add("seechunk");
//this.requiredArgs.add(""); this.permission = Permission.SEE_CHUNK.node;
//this.optionalArgs.put("", "");
this.permission = Permission.ADMIN.node;
this.disableOnLock = false; this.disableOnLock = false;
senderMustBePlayer = true; senderMustBePlayer = true;
@ -64,38 +57,12 @@ public class CmdSeeChunk extends FCommand
public void showPillar(Player player, World world, int blockX, int blockZ) public void showPillar(Player player, World world, int blockX, int blockZ)
{ {
Location loc = new Location(world, blockX, 0, blockZ); Location loc = new Location(world, blockX, 0, blockZ);
//Block block = loc.getBlock();
for (int blockY = 0; blockY <=127; blockY++) for (int blockY = 0; blockY <=127; blockY++)
{ {
loc.setY(blockY); loc.setY(blockY);
if (loc.getBlock().getTypeId() != 0) continue; if (loc.getBlock().getTypeId() != 0) continue;
player.sendBlockChange(loc, blockY % 5 == 0 ? Material.GLOWSTONE : Material.GLASS, (byte) 0); VisualizeUtil.addLocation(player, loc.clone(), blockY % 5 == 0 ? Material.GLOWSTONE.getId() : Material.GLASS.getId());
} }
} }
// DEV DIRT BELOW...
public ArrayList<Location> getChunkPillarLocations(int chunkX, int chunkZ)
{
ArrayList<Location> ret = new ArrayList<Location>();
return ret;
}
public ArrayList<Location> getPillar(Block block)
{
ArrayList<Location> ret = new ArrayList<Location>();
// y 0-127
for (int i = 0; i <=127; i++)
{
}
return ret;
}
} }

View File

@ -21,6 +21,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent; import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPreLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
@ -34,6 +35,7 @@ import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FFlag;
import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.util.VisualizeUtil;
import java.util.logging.Level; import java.util.logging.Level;
@ -452,4 +454,26 @@ public class FactionsPlayerListener implements Listener
badGuy.detach(); badGuy.detach();
} }
} }
// -------------------------------------------- //
// VisualizeUtil
// -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerMoveClearVisualizations(PlayerMoveEvent event)
{
if (event.isCancelled()) return;
Block blockFrom = event.getFrom().getBlock();
Block blockTo = event.getTo().getBlock();
if (blockFrom.equals(blockTo)) return;
VisualizeUtil.clear(event.getPlayer());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerPreLogin(PlayerPreLoginEvent event)
{
VisualizeUtil.onPlayerPreLogin(event.getName());
}
} }

View File

@ -46,6 +46,7 @@ public enum Permission
RELATION("relation"), RELATION("relation"),
RELOAD("reload"), RELOAD("reload"),
SAVE("save"), SAVE("save"),
SEE_CHUNK("seechunk"),
SETHOME("sethome"), SETHOME("sethome"),
SHOW("show"), SHOW("show"),
TAG("tag"), TAG("tag"),

View File

@ -0,0 +1,96 @@
package com.massivecraft.factions.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import com.massivecraft.factions.P;
// TODO: Only send blocks in visual range
// TODO: Only send blocks that where changed when clearing?
// TODO: Create packed queue to avoid freezes.
public class VisualizeUtil
{
protected static Map<String, Set<Location>> playerLocations = new HashMap<String, Set<Location>>();
public static void onPlayerPreLogin(String name)
{
playerLocations.put(name, new HashSet<Location>());
}
// -------------------------------------------- //
// SINGLE
// -------------------------------------------- //
public static void addLocation(Player player, Location location, int typeId, byte data)
{
playerLocations.get(player.getName()).add(location);
player.sendBlockChange(location, typeId, data);
}
public static void addLocation(Player player, Location location, int typeId)
{
playerLocations.get(player.getName()).add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
// -------------------------------------------- //
// MANY
// -------------------------------------------- //
public static void addLocations(Player player, Map<Location, Integer> locationMaterialIds)
{
Set<Location> ploc = playerLocations.get(player.getName());
for (Entry<Location, Integer> entry : locationMaterialIds.entrySet())
{
ploc.add(entry.getKey());
player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0);
}
}
public static void addLocations(Player player, Collection<Location> locations, int typeId)
{
Set<Location> ploc = playerLocations.get(player.getName());
for (Location location : locations)
{
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
public static void addBlocks(Player player, Collection<Block> blocks, int typeId)
{
Set<Location> ploc = playerLocations.get(player.getName());
for (Block block : blocks)
{
Location location = block.getLocation();
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
// -------------------------------------------- //
// CLEAR
// -------------------------------------------- //
public static void clear(Player player)
{
Set<Location> locations = playerLocations.get(player.getName());
if (locations == null) return;
for (Location location : locations)
{
Block block = location.getWorld().getBlockAt(location);
player.sendBlockChange(location, block.getTypeId(), block.getData());
}
playerLocations.remove(player);
}
}