Added searchForMaterial Function and List of transparentMaterials

master
Ruakij 4 years ago
parent b819fcb9f5
commit 3695315d42

@ -2,11 +2,14 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.util.Vector;
import java.util.Arrays;
import java.util.InvalidPropertiesFormatException; import java.util.InvalidPropertiesFormatException;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Random; import java.util.Random;
public class Function { public class Function {
@ -38,4 +41,115 @@ public class Function {
} }
return str; return str;
} }
public static List<Material> transparentMaterials = Arrays.asList(
Material.AIR,
Material.GLASS,
Material.GLASS_PANE,
Material.BLACK_STAINED_GLASS,
Material.BLACK_STAINED_GLASS_PANE,
Material.BLUE_STAINED_GLASS,
Material.BLUE_STAINED_GLASS_PANE,
Material.BROWN_STAINED_GLASS,
Material.BROWN_STAINED_GLASS_PANE,
Material.CYAN_STAINED_GLASS,
Material.CYAN_STAINED_GLASS_PANE,
Material.GRAY_STAINED_GLASS,
Material.GRAY_STAINED_GLASS_PANE,
Material.GREEN_STAINED_GLASS,
Material.GREEN_STAINED_GLASS_PANE,
Material.LIGHT_BLUE_STAINED_GLASS,
Material.LIGHT_BLUE_STAINED_GLASS_PANE,
Material.LIGHT_GRAY_STAINED_GLASS,
Material.LIGHT_GRAY_STAINED_GLASS_PANE,
Material.LIME_STAINED_GLASS,
Material.LIME_STAINED_GLASS_PANE,
Material.MAGENTA_STAINED_GLASS,
Material.MAGENTA_STAINED_GLASS_PANE,
Material.ORANGE_STAINED_GLASS,
Material.ORANGE_STAINED_GLASS_PANE,
Material.PINK_STAINED_GLASS,
Material.PINK_STAINED_GLASS_PANE,
Material.PURPLE_STAINED_GLASS,
Material.PURPLE_STAINED_GLASS_PANE,
Material.RED_STAINED_GLASS,
Material.RED_STAINED_GLASS_PANE,
Material.WHITE_STAINED_GLASS,
Material.WHITE_STAINED_GLASS_PANE,
Material.YELLOW_STAINED_GLASS,
Material.YELLOW_STAINED_GLASS_PANE,
Material.PISTON,
Material.PISTON_HEAD,
Material.MOVING_PISTON,
Material.STICKY_PISTON,
Material.ACACIA_LEAVES,
Material.BIRCH_LEAVES,
Material.DARK_OAK_LEAVES,
Material.JUNGLE_LEAVES,
Material.OAK_LEAVES,
Material.SPRUCE_LEAVES,
Material.ACACIA_SLAB,
Material.ANDESITE_SLAB,
Material.BIRCH_SLAB,
Material.BLACKSTONE_SLAB,
Material.BRICK_SLAB,
Material.COBBLESTONE_SLAB,
Material.CRIMSON_SLAB,
Material.CUT_RED_SANDSTONE_SLAB,
Material.CUT_SANDSTONE_SLAB,
Material.DARK_OAK_SLAB,
Material.DARK_PRISMARINE_SLAB,
Material.DIORITE_SLAB,
Material.END_STONE_BRICK_SLAB,
Material.GRANITE_SLAB,
Material.JUNGLE_SLAB,
Material.MOSSY_COBBLESTONE_SLAB,
Material.MOSSY_STONE_BRICK_SLAB,
Material.NETHER_BRICK_SLAB,
Material.OAK_SLAB,
Material.PETRIFIED_OAK_SLAB,
Material.POLISHED_ANDESITE_SLAB,
Material.POLISHED_BLACKSTONE_BRICK_SLAB,
Material.POLISHED_BLACKSTONE_SLAB,
Material.POLISHED_DIORITE_SLAB,
Material.POLISHED_GRANITE_SLAB,
Material.PRISMARINE_BRICK_SLAB,
Material.PRISMARINE_SLAB,
Material.PURPUR_SLAB,
Material.QUARTZ_SLAB,
Material.RED_NETHER_BRICK_SLAB,
Material.RED_SANDSTONE_SLAB,
Material.SANDSTONE_SLAB,
Material.SMOOTH_QUARTZ_SLAB,
Material.SMOOTH_RED_SANDSTONE_SLAB,
Material.SMOOTH_SANDSTONE_SLAB,
Material.SMOOTH_STONE_SLAB,
Material.SPRUCE_SLAB,
Material.STONE_BRICK_SLAB,
Material.STONE_SLAB,
Material.WARPED_SLAB
);
public static Block searchForMaterial(Location startLoc, Vector searchDirection, Material searchMaterial, List<Material> ignoreMaterials){
Location loc = new Location(startLoc.getWorld(), startLoc.getBlockX(), startLoc.getBlockY(), startLoc.getBlockZ());
for(int i=0; loc.getBlockY()>=0 && loc.getBlockY()<=255; loc.add(searchDirection)){
Block block = loc.getBlock();
// Check for correct material
if(block.getType() == searchMaterial) return block;
// Check for non-ignore-block
boolean found = false;
for(Material ignoreMaterial : ignoreMaterials){
if(block.getType() == ignoreMaterial){
found = true;
break;
}
}
// If not found, searchMaterial not found
if(!found) return null;
}
// Reached 0 or 255, searchMaterial not found
return null;
}
} }

Loading…
Cancel
Save