Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In event handler
- Block block = event.getBlock();
- if(block.getType() == Material.STONE) { // Check if block placed was stone
- boolean found = true;
- Block newBlock;
- for(int i=1;i<=4;i++) { // Check +1-4 in x direction
- newBlock = block.getRealtive(i, 0, 0);
- if(newBlock.getType() != Material.STONE) {
- // If any of them are not stone, break and declare false
- found = false;
- break;
- }
- }
- // At the end of this, if all the blocks were stone, "found" will still be true.
- if(!found) {
- // Otherwise, try in the opposite x direction (-1-4)
- found = true;
- for(int i=1;i<=4;i++) {
- newBlock = block.getRealtive(-i, 0, 0);
- if(newBlock.getType() != Material.STONE) {
- found = false;
- break;
- }
- }
- }
- // Continue for +1-4 z and -1-4 z
- if(!found) {
- found = true;
- for(int i=1;i<=4;i++) {
- newBlock = block.getRealtive(0, 0, i);
- if(newBlock.getType() != Material.STONE) {
- found = false;
- break;
- }
- }
- }
- if(!found) {
- found = true;
- for(int i=1;i<=4;i++) {
- newBlock = block.getRealtive(0, 0, -i);
- if(newBlock.getType() != Material.STONE) {
- found = false;
- break;
- }
- }
- }
- if(found) {
- // 4 in a row
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment