ChestShop-3/com/Acrobot/ChestShop/Protection/MaskChest.java
Acrobot 7b6d7d59bd - Long name (>15 chars) support
- Added Bukkit Persistence Reimplemented by LennardF1989
- Made the plugin faster
- Deleted unnecessary files (.jar size went down by 10 KB)
- Added final and private keywords
- Support for Bukkit's built-in permissions
- Updated to newest Bukkit's standard (getFace -> getRelative)
2011-07-23 21:00:47 +02:00

63 lines
2.2 KiB
Java

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;
import org.bukkit.World;
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 {
private final BlockFace[] bf = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN};
public void run() {
Player[] players = ChestShop.getBukkitServer().getOnlinePlayers();
for (Player player : players) {
World world = player.getWorld();
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++) {
Block block = world.getBlockAt(x + pX, y + pY, z + pZ);
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);
}
}
}
}
}
}
}
private Material returnNearestMat(Block block) {
for (BlockFace face : bf) {
Block faceBlock = block.getRelative(face);
Material type = faceBlock.getType();
if (type != Material.AIR && !uSign.isSign(faceBlock) && type != Material.CHEST) return type;
}
return Material.CHEST;
}
}