|
| 1 | +package org.FamousL.Entity_hide.Entity_Hide; |
| 2 | +import java.util.ArrayList; |
| 3 | + |
| 4 | +import org.bukkit.Bukkit; |
| 5 | +import org.bukkit.Chunk; |
| 6 | +import org.bukkit.Location; |
| 7 | +import org.bukkit.Material; |
| 8 | +import org.bukkit.entity.Entity; |
| 9 | +import org.bukkit.entity.Player; |
| 10 | +import org.bukkit.inventory.BlockInventoryHolder; |
| 11 | +import org.bukkit.plugin.Plugin; |
| 12 | +import org.bukkit.scheduler.BukkitRunnable; |
| 13 | +import org.bukkit.block.BlockState; |
| 14 | +import org.bukkit.block.Sign; |
| 15 | +import org.bukkit.block.data.BlockData; |
| 16 | + |
| 17 | +public class Hide_Stuff { |
| 18 | + |
| 19 | + private Entity_Hide pluginManager; |
| 20 | + |
| 21 | + public Hide_Stuff( Plugin pluginManager) { |
| 22 | + |
| 23 | + this.pluginManager = (Entity_Hide) pluginManager; |
| 24 | + this.hideSigns(); |
| 25 | + } |
| 26 | + |
| 27 | + public void hideSigns() { |
| 28 | + new BukkitRunnable() { |
| 29 | + @Override |
| 30 | + public void run() { |
| 31 | + for (Player player : Bukkit.getOnlinePlayers()) { |
| 32 | + |
| 33 | + ArrayList<Chunk> playerChunks=getChunks((Entity) player); |
| 34 | + for (Chunk curchunk: playerChunks) { |
| 35 | + |
| 36 | + for (BlockState block: curchunk.getTileEntities()) { |
| 37 | + |
| 38 | + if (block instanceof Sign) { |
| 39 | + |
| 40 | + if(!inrange(player,block,Entity_Hide.instance.config.signrenderdistance)) { |
| 41 | + BlockData air= Bukkit.createBlockData(Material.AIR); |
| 42 | + player.sendBlockChange(block.getLocation(), air); |
| 43 | + |
| 44 | + continue; |
| 45 | + } |
| 46 | + else |
| 47 | + { |
| 48 | + player.sendBlockChange(block.getLocation(),block.getBlockData()); |
| 49 | + Sign thissign=(Sign) block; |
| 50 | + thissign.update(); |
| 51 | + |
| 52 | + continue; |
| 53 | + } |
| 54 | + |
| 55 | + } |
| 56 | + if(block instanceof BlockInventoryHolder) |
| 57 | + { |
| 58 | + if(inrange(player,block,Entity_Hide.instance.config.invrenderdistance)) |
| 59 | + { |
| 60 | + player.sendBlockChange(block.getLocation(),block.getBlockData()); |
| 61 | + block.setBlockData(block.getBlockData()); |
| 62 | + continue; |
| 63 | + } |
| 64 | + else |
| 65 | + { |
| 66 | + BlockData air= Bukkit.createBlockData(Material.AIR); |
| 67 | + player.sendBlockChange(block.getLocation(), air); |
| 68 | + |
| 69 | + continue; |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + }.runTaskTimer((Plugin) pluginManager,(long) 0, (long)20); // Run every 20 ticks (1 second) |
| 79 | + } |
| 80 | + public boolean inrange(Player player, BlockState block,int distance) |
| 81 | + { |
| 82 | + Location playerloc=player.getLocation(); |
| 83 | + Location sign=block.getLocation(); |
| 84 | + if (playerloc.getX()<sign.getX()+distance&&playerloc.getX()>sign.getX()-distance) |
| 85 | + { |
| 86 | + if (playerloc.getY()<sign.getY()+distance&&playerloc.getY()>sign.getY()-distance) |
| 87 | + { |
| 88 | + if (playerloc.getZ()<sign.getZ()+distance&&playerloc.getZ()>sign.getZ()-distance) |
| 89 | + { |
| 90 | + return true; |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + } |
| 95 | + return false; |
| 96 | + |
| 97 | + } |
| 98 | + public ArrayList<Chunk> getChunks(Entity entity) { |
| 99 | + ArrayList<Chunk> chunks = new ArrayList<Chunk>(); |
| 100 | + |
| 101 | + |
| 102 | + int renderDistance = entity.getServer().getViewDistance()*16;//viewdistance is number of chunks :S |
| 103 | + |
| 104 | + Location playerat=entity.getLocation(); |
| 105 | + |
| 106 | + |
| 107 | + for (double x = playerat.getX() - renderDistance; x <= playerat.getX() + renderDistance+16; x+=16) { |
| 108 | + for (double z = playerat.getZ() - renderDistance; z <= playerat.getZ() + renderDistance+16; z+=16) { |
| 109 | + if (!chunks.contains(new Location(entity.getWorld(), x, 1, z).getChunk())) { |
| 110 | + |
| 111 | + chunks.add(new Location(entity.getWorld(), x, 1, z).getChunk()); |
| 112 | + |
| 113 | + |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + return chunks; |
| 119 | + } |
| 120 | + |
| 121 | +} |
0 commit comments