mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-12-25 17:37:34 +01:00
7b6d7d59bd
- 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)
63 lines
2.2 KiB
Java
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;
|
|
}
|
|
}
|