Factions3/src/com/massivecraft/factions/util/VisualizeUtil.java

111 lines
3.1 KiB
Java
Raw Normal View History

2012-01-28 19:49:01 +01:00
package com.massivecraft.factions.util;
2017-03-24 13:05:58 +01:00
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
2012-01-28 19:49:01 +01:00
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;
2014-05-14 15:27:27 +02:00
import java.util.UUID;
2012-01-28 19:49:01 +01:00
// TODO: Only send blocks in visual range
// TODO: Only send blocks that where changed when clearing?
// TODO: Create packed queue to avoid freezes.
2012-01-28 19:49:01 +01:00
public class VisualizeUtil
{
2014-05-14 15:27:27 +02:00
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<UUID, Set<Location>>();
public static Set<Location> getPlayerLocations(Player player)
{
2014-05-14 15:27:27 +02:00
return getPlayerLocations(player.getUniqueId());
}
2014-05-14 15:27:27 +02:00
public static Set<Location> getPlayerLocations(UUID uuid)
2012-01-28 19:49:01 +01:00
{
2014-05-14 15:27:27 +02:00
Set<Location> ret = playerLocations.get(uuid);
if (ret == null)
{
ret = new HashSet<Location>();
2014-05-14 15:27:27 +02:00
playerLocations.put(uuid, ret);
}
return ret;
2012-01-28 19:49:01 +01:00
}
// -------------------------------------------- //
// SINGLE
// -------------------------------------------- //
@SuppressWarnings("deprecation")
2012-01-28 19:49:01 +01:00
public static void addLocation(Player player, Location location, int typeId, byte data)
{
getPlayerLocations(player).add(location);
2012-01-28 19:49:01 +01:00
player.sendBlockChange(location, typeId, data);
}
@SuppressWarnings("deprecation")
2012-01-28 19:49:01 +01:00
public static void addLocation(Player player, Location location, int typeId)
{
getPlayerLocations(player).add(location);
2012-01-28 19:49:01 +01:00
player.sendBlockChange(location, typeId, (byte) 0);
}
// -------------------------------------------- //
// MANY
// -------------------------------------------- //
@SuppressWarnings("deprecation")
2012-01-28 19:49:01 +01:00
public static void addLocations(Player player, Map<Location, Integer> locationMaterialIds)
{
Set<Location> ploc = getPlayerLocations(player);
2012-01-28 19:49:01 +01:00
for (Entry<Location, Integer> entry : locationMaterialIds.entrySet())
{
ploc.add(entry.getKey());
player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0);
}
}
@SuppressWarnings("deprecation")
2012-01-28 19:49:01 +01:00
public static void addLocations(Player player, Collection<Location> locations, int typeId)
{
Set<Location> ploc = getPlayerLocations(player);
2012-01-28 19:49:01 +01:00
for (Location location : locations)
{
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
@SuppressWarnings("deprecation")
2012-01-28 19:49:01 +01:00
public static void addBlocks(Player player, Collection<Block> blocks, int typeId)
{
Set<Location> ploc = getPlayerLocations(player);
2012-01-28 19:49:01 +01:00
for (Block block : blocks)
{
Location location = block.getLocation();
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
// -------------------------------------------- //
// CLEAR
// -------------------------------------------- //
@SuppressWarnings("deprecation")
2012-01-28 19:49:01 +01:00
public static void clear(Player player)
{
Set<Location> locations = getPlayerLocations(player);
2012-01-28 19:49:01 +01:00
if (locations == null) return;
for (Location location : locations)
{
Block block = location.getWorld().getBlockAt(location);
player.sendBlockChange(location, block.getTypeId(), block.getData());
}
locations.clear();
2012-01-28 19:49:01 +01:00
}
}