Skip to content

Instantly share code, notes, and snippets.

@cmoore
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmoore/a825f222f9c9f4fd585a to your computer and use it in GitHub Desktop.
Save cmoore/a825f222f9c9f4fd585a to your computer and use it in GitHub Desktop.
public class Utils {
public static List<Chest> find_all_chests(World world) {
List<Chest> chests = new ArrayList();
int tile_entities = 0;
for (Chunk c : world.getLoadedChunks()) {
for (BlockState b : c.getTileEntities()) {
tile_entities++;
Bukkit.getLogger().info("U WOT M8: " + b.toString());
if (b instanceof Chest || b instanceof DoubleChest) {
// if (b.getType() == Material.CHEST) {
Bukkit.getLogger().info("Looky there.");
chests.add((Chest) b);
}
}
}
Bukkit.getLogger().info("Found " + String.valueOf(tile_entities) + " TileEntities.");
return chests;
}
}
/*
[21:03:46 INFO]: Hunger Games V3 1825 60 -2641 3 0 DIRT
[21:03:46 INFO]: Hunger Games V3 1861 80 -2068 0 0 AIR
[21:03:46 INFO]: Hunger Games V3 1861 62 -2070 9 0 STATIONARY_WATER
[21:03:46 INFO]: Hunger Games V3 1861 62 -2068 9 0 STATIONARY_WATER
[21:03:46 INFO]: Hunger Games V3 1861 74 -2070 0 0 AIR
[21:03:46 INFO]: Hunger Games V3 1861 74 -2068 0 0 AIR
[21:03:46 INFO]: Hunger Games V3 1861 68 -2070 0 0 AIR
[21:03:46 INFO]: Hunger Games V3 1861 68 -2068 0 0 AIR
[21:03:46 INFO]: Hunger Games V3 1861 80 -2070 0 0 AIR
[21:03:46 INFO]: Hunger Games V3 1739 56 -2077 9 0 STATIONARY_WATER
*/
@ryantheleach
Copy link

private void onChunkLoad(Chunk c){
    for(BlockState b:c.getTileEntities()) {
        Bukkit.broadcastMessage(String.join(" ", (String) b.getWorld().getName(), Integer.toString(b.getX()), Integer.toString(b.getY()), Integer.toString(b.getZ()), Integer.toString(b.getBlock().getTypeId()), Byte.toString(b.getBlock().getData()), b.getData().getItemType().name()));
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment