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;
|
2018-12-22 23:59:12 +01:00
|
|
|
import org.bukkit.Material;
|
2017-03-24 13:05:58 +01:00
|
|
|
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?
|
2014-09-17 14:18:27 +02:00
|
|
|
// TODO: Create packed queue to avoid freezes.
|
2012-01-28 19:49:01 +01:00
|
|
|
|
|
|
|
public class VisualizeUtil
|
|
|
|
{
|
2017-03-24 14:03:29 +01:00
|
|
|
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<>();
|
2012-05-09 05:56:37 +02:00
|
|
|
public static Set<Location> getPlayerLocations(Player player)
|
|
|
|
{
|
2014-05-14 15:27:27 +02:00
|
|
|
return getPlayerLocations(player.getUniqueId());
|
2012-05-09 05:56:37 +02:00
|
|
|
}
|
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);
|
2012-05-09 05:56:37 +02:00
|
|
|
if (ret == null)
|
|
|
|
{
|
2017-03-24 14:03:29 +01:00
|
|
|
ret = new HashSet<>();
|
2014-05-14 15:27:27 +02:00
|
|
|
playerLocations.put(uuid, ret);
|
2012-05-09 05:56:37 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// SINGLE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-09-20 12:50:32 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-12-22 23:59:12 +01:00
|
|
|
public static void addLocation(Player player, Location location, Material material, byte data)
|
2012-01-28 19:49:01 +01:00
|
|
|
{
|
2012-05-09 05:56:37 +02:00
|
|
|
getPlayerLocations(player).add(location);
|
2018-12-22 23:59:12 +01:00
|
|
|
player.sendBlockChange(location, material, data);
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
|
|
|
|
2013-09-20 12:50:32 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-12-22 23:59:12 +01:00
|
|
|
public static void addLocation(Player player, Location location, Material material)
|
2012-01-28 19:49:01 +01:00
|
|
|
{
|
2012-05-09 05:56:37 +02:00
|
|
|
getPlayerLocations(player).add(location);
|
2018-12-22 23:59:12 +01:00
|
|
|
player.sendBlockChange(location, material, (byte) 0);
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// MANY
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-09-20 12:50:32 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-12-22 23:59:12 +01:00
|
|
|
public static void addLocations(Player player, Map<Location, Material> locationMaterialIds)
|
2012-01-28 19:49:01 +01:00
|
|
|
{
|
2012-05-09 05:56:37 +02:00
|
|
|
Set<Location> ploc = getPlayerLocations(player);
|
2018-12-22 23:59:12 +01:00
|
|
|
for (Entry<Location, Material> entry : locationMaterialIds.entrySet())
|
2012-01-28 19:49:01 +01:00
|
|
|
{
|
|
|
|
ploc.add(entry.getKey());
|
|
|
|
player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 12:50:32 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-12-22 23:59:12 +01:00
|
|
|
public static void addLocations(Player player, Collection<Location> locations, Material material)
|
2012-01-28 19:49:01 +01:00
|
|
|
{
|
2012-05-09 05:56:37 +02:00
|
|
|
Set<Location> ploc = getPlayerLocations(player);
|
2012-01-28 19:49:01 +01:00
|
|
|
for (Location location : locations)
|
|
|
|
{
|
|
|
|
ploc.add(location);
|
2018-12-22 23:59:12 +01:00
|
|
|
player.sendBlockChange(location, material, (byte) 0);
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-20 12:50:32 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2018-12-22 23:59:12 +01:00
|
|
|
public static void addBlocks(Player player, Collection<Block> blocks, Material material)
|
2012-01-28 19:49:01 +01:00
|
|
|
{
|
2012-05-09 05:56:37 +02:00
|
|
|
Set<Location> ploc = getPlayerLocations(player);
|
2012-01-28 19:49:01 +01:00
|
|
|
for (Block block : blocks)
|
|
|
|
{
|
|
|
|
Location location = block.getLocation();
|
|
|
|
ploc.add(location);
|
2018-12-22 23:59:12 +01:00
|
|
|
player.sendBlockChange(location, material, (byte) 0);
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// CLEAR
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-09-20 12:50:32 +02:00
|
|
|
@SuppressWarnings("deprecation")
|
2012-01-28 19:49:01 +01:00
|
|
|
public static void clear(Player player)
|
|
|
|
{
|
2012-05-09 05:56:37 +02:00
|
|
|
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);
|
2018-12-22 23:59:12 +01:00
|
|
|
player.sendBlockChange(location, block.getType(), block.getData());
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
2012-05-09 05:56:37 +02:00
|
|
|
locations.clear();
|
2012-01-28 19:49:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|