2011-07-05 19:08:55 +02:00
|
|
|
package com.Acrobot.ChestShop.Protection;
|
|
|
|
|
|
|
|
import com.Acrobot.ChestShop.ChestShop;
|
|
|
|
import com.Acrobot.ChestShop.Utils.uBlock;
|
|
|
|
import com.Acrobot.ChestShop.Utils.uSign;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
2011-07-23 21:00:47 +02:00
|
|
|
import org.bukkit.World;
|
2011-07-05 19:08:55 +02:00
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.BlockFace;
|
|
|
|
import org.bukkit.block.Chest;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class MaskChest implements Runnable {
|
2011-07-23 21:00:47 +02:00
|
|
|
private final BlockFace[] bf = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN};
|
2011-07-05 19:08:55 +02:00
|
|
|
|
|
|
|
public void run() {
|
|
|
|
Player[] players = ChestShop.getBukkitServer().getOnlinePlayers();
|
|
|
|
|
|
|
|
for (Player player : players) {
|
2011-07-23 21:00:47 +02:00
|
|
|
World world = player.getWorld();
|
2011-07-05 19:08:55 +02:00
|
|
|
Location location = player.getLocation();
|
|
|
|
|
|
|
|
int pX = location.getBlockX();
|
|
|
|
int pY = location.getBlockY();
|
|
|
|
int pZ = location.getBlockZ();
|
|
|
|
|
|
|
|
int radius = 25;
|
|
|
|
|
|
|
|
for (int x = -radius; x < radius; x++) {
|
|
|
|
for (int y = -radius; y < radius; y++) {
|
|
|
|
for (int z = -radius; z < radius; z++) {
|
2011-07-23 21:00:47 +02:00
|
|
|
Block block = world.getBlockAt(x + pX, y + pY, z + pZ);
|
2011-07-05 19:08:55 +02:00
|
|
|
|
|
|
|
if (block.getType() == Material.CHEST) {
|
|
|
|
if (uBlock.findSign(block) != null) {
|
|
|
|
Chest neighbor = uBlock.findNeighbor(block);
|
|
|
|
Material nMat = returnNearestMat(block);
|
|
|
|
if (neighbor != null) {
|
|
|
|
player.sendBlockChange(neighbor.getBlock().getLocation(), nMat, (byte) 0);
|
|
|
|
}
|
|
|
|
player.sendBlockChange(block.getLocation(), nMat, (byte) 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-23 21:00:47 +02:00
|
|
|
private Material returnNearestMat(Block block) {
|
2011-07-05 19:08:55 +02:00
|
|
|
for (BlockFace face : bf) {
|
2011-07-23 21:00:47 +02:00
|
|
|
Block faceBlock = block.getRelative(face);
|
2011-07-05 19:08:55 +02:00
|
|
|
Material type = faceBlock.getType();
|
2011-07-23 21:00:47 +02:00
|
|
|
if (type != Material.AIR && !uSign.isSign(faceBlock) && type != Material.CHEST) return type;
|
2011-07-05 19:08:55 +02:00
|
|
|
}
|
|
|
|
return Material.CHEST;
|
|
|
|
}
|
|
|
|
}
|