Guest User

Sahee

a guest
Dec 29th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.15 KB | None | 0 0
  1. package com.modcrafting.diablodrops.listeners;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.bukkit.Chunk;
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.World;
  10. import org.bukkit.World.Environment;
  11. import org.bukkit.block.Biome;
  12. import org.bukkit.block.Block;
  13. import org.bukkit.block.BlockFace;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.world.ChunkPopulateEvent;
  17.  
  18.  
  19. import com.modcrafting.diablodrops.DiabloDrops;
  20. import com.modcrafting.diablodrops.events.RuinGenerateEvent;
  21.  
  22. public class ChunkListener implements Listener
  23. {
  24.  
  25.     private final DiabloDrops plugin;
  26.  
  27.     private int blockType;
  28.  
  29.     public ChunkListener(final DiabloDrops plugin)
  30.     {
  31.         this.plugin = plugin;
  32.     }
  33.  
  34.     private void addRuin1Pattern(final Block block, final int size)
  35.     {
  36.         World world = block.getWorld();
  37.         Location location = block.getRelative(BlockFace.DOWN).getLocation();
  38.         Block start = world.getBlockAt(location);
  39.         pillarRuin1(world, northRuin1(start, size), size);
  40.         pillarRuin1(world, southRuin1(start, size), size);
  41.         pillarRuin1(world, eastRuin1(start, size), size);
  42.         pillarRuin1(world, westRuin1(start, size), size);
  43.         pillarRuin1(world, northwestRuin1(start, size), size);
  44.         pillarRuin1(world, northeastRuin1(start, size), size);
  45.         pillarRuin1(world, southwestRuin1(start, size), size);
  46.         pillarRuin1(world, southeastRuin1(start, size), size);
  47.         Block newStart = world
  48.                 .getBlockAt(new Location(world, location.getBlockX(), location
  49.                         .getBlockY() + size, location.getBlockZ()));
  50.         northRuin1(newStart, size);
  51.         southRuin1(newStart, size);
  52.         eastRuin1(newStart, size);
  53.         westRuin1(newStart, size);
  54.         northwestRuin1(newStart, size);
  55.         northeastRuin1(newStart, size);
  56.         southwestRuin1(newStart, size);
  57.         southeastRuin1(newStart, size);
  58.     }
  59.  
  60.     /**
  61.      * Builds a nether temple.
  62.      *
  63.      * @param loc
  64.      * @return
  65.      */
  66.     private boolean buildNetherTemple(final Location loc)
  67.     {
  68.         int square = 5;
  69.         World world = loc.getWorld();
  70.         double maxX = Math.max(loc.getX() - square, loc.getX() + square);
  71.         double maxZ = Math.max(loc.getZ() - square, loc.getZ() + square);
  72.         double minX = Math.min(loc.getX() - square, loc.getX() + square);
  73.         double minZ = Math.min(loc.getZ() - square, loc.getZ() + square);
  74.         for (int i = 0; i <= Math.abs(maxX - minX); i++)
  75.         {
  76.             for (int ii = 0; ii <= Math.abs(maxZ - minZ); ii++)
  77.             {
  78.                 ;
  79.                 if ((world.getBlockTypeIdAt((int) minX + i, (int) loc.getY(),
  80.                         (int) minZ + ii) == Material.AIR.getId())
  81.                         || (world.getBlockTypeIdAt((int) minX + i,
  82.                                 (int) loc.getY(), (int) minZ + ii) == Material.STATIONARY_WATER
  83.                                 .getId()))
  84.                     return false;
  85.             }
  86.         }
  87.         for (double i = 0; i <= Math.abs(maxX - minX); i++)
  88.         {
  89.             for (double ii = 0; ii <= Math.abs(maxZ - minZ); ii++)
  90.             {
  91.                 if ((i == 0) || (ii == 0) || (i == Math.abs(maxX - minX))
  92.                         || (ii == Math.abs(maxZ - minZ)))
  93.                 {
  94.                     for (int iii = 0; iii < 5; iii++)
  95.                     {
  96.                         if (((i == 0) && (ii == 0))
  97.                                 || ((i == Math.abs(maxX - minX)) && (ii == Math
  98.                                         .abs(maxZ - minZ)))
  99.                                 || ((i == 0) && (ii == Math.abs(maxZ - minZ)))
  100.                                 || ((ii == 0) && (i == Math.abs(maxX - minX))))
  101.                         {
  102.                             continue;
  103.                         }
  104.                         Location t = new Location(world, minX + i, loc.getY()
  105.                                 + iii, minZ + ii);
  106.                         t.getBlock().setType(Material.NETHER_BRICK);
  107.                     }
  108.                 }
  109.                 Location t = new Location(world, minX + i, loc.getY(), minZ
  110.                         + ii);
  111.                 t.getBlock().setType(Material.NETHER_BRICK);
  112.                 Location r = new Location(world, minX + i,
  113.                         (loc.getY() + (square * 2)) - (t.distance(loc)), minZ
  114.                                 + ii);
  115.                 r.getBlock().setType(Material.NETHER_BRICK);
  116.  
  117.             }
  118.         }
  119.         int faceX = 0;
  120.         int faceZ = 0;
  121.         switch (plugin.getSingleRandom().nextInt(4))
  122.         {
  123.             case 0:
  124.             {
  125.                 faceX = square;
  126.                 break;
  127.             }
  128.             case 1:
  129.             {
  130.                 faceX = -square;
  131.                 break;
  132.             }
  133.             case 2:
  134.             {
  135.                 faceZ = square;
  136.                 break;
  137.             }
  138.             case 3:
  139.             {
  140.                 faceZ = -square;
  141.                 break;
  142.             }
  143.         }
  144.         for (int i = 1; i < 3; i++)
  145.         {
  146.             world.getBlockAt((int) loc.getX() + faceX, (int) loc.getY() + i,
  147.                     (int) loc.getZ() + faceZ).setTypeId(0);
  148.             world.getBlockAt((int) loc.getX() - 2, (int) loc.getY() + i,
  149.                     (int) loc.getZ()).setType(Material.NETHER_BRICK);
  150.             world.getBlockAt((int) loc.getX(), (int) loc.getY() + i,
  151.                     (int) loc.getZ() - 2).setType(Material.NETHER_BRICK);
  152.             world.getBlockAt((int) loc.getX() + 2, (int) loc.getY() + i,
  153.                     (int) loc.getZ()).setType(Material.NETHER_BRICK);
  154.             world.getBlockAt((int) loc.getX(), (int) loc.getY() + i,
  155.                     (int) loc.getZ() + 2).setType(Material.NETHER_BRICK);
  156.         }
  157.         world.getBlockAt((int) loc.getX() - 2, (int) loc.getY() + 3,
  158.                 (int) loc.getZ()).setType(Material.TORCH);
  159.         world.getBlockAt((int) loc.getX(), (int) loc.getY() + 3,
  160.                 (int) loc.getZ() - 2).setType(Material.TORCH);
  161.         world.getBlockAt((int) loc.getX() + 2, (int) loc.getY() + 3,
  162.                 (int) loc.getZ()).setType(Material.TORCH);
  163.         world.getBlockAt((int) loc.getX(), (int) loc.getY() + 3,
  164.                 (int) loc.getZ() + 2).setType(Material.TORCH);
  165.         Block door = world.getBlockAt((int) loc.getX() + faceX,
  166.                 (int) loc.getY() + 1, (int) loc.getZ() + faceZ);
  167.         door.getRelative(BlockFace.NORTH_EAST).setType(Material.NETHER_FENCE);
  168.         door.getRelative(BlockFace.NORTH_WEST).setType(Material.NETHER_FENCE);
  169.         door.getRelative(BlockFace.SOUTH_EAST).setType(Material.NETHER_FENCE);
  170.         door.getRelative(BlockFace.SOUTH_WEST).setType(Material.NETHER_FENCE);
  171.         return true;
  172.  
  173.     }
  174.  
  175.     /**
  176.      * Builds death's ruins.
  177.      *
  178.      * @param loc
  179.      */
  180.     private boolean deathRuin(final Location loc)
  181.     {
  182.         int square = plugin.getSingleRandom().nextInt(6);
  183.         if (square < 1)
  184.             return false;
  185.         List<Material> mats = getBiomeMaterials(loc.getBlock().getBiome());
  186.         if (mats.size() < 1)
  187.             return false;
  188.         double maxX = Math.max(loc.getX() - square, loc.getX() + square);
  189.         double maxZ = Math.max(loc.getZ() - square, loc.getZ() + square);
  190.         double minX = Math.min(loc.getX() - square, loc.getX() + square);
  191.         double minZ = Math.min(loc.getZ() - square, loc.getZ() + square);
  192.         for (double i = 0; i <= Math.abs(maxX - minX); i++)
  193.         {
  194.             for (double ii = 0; ii <= Math.abs(maxZ - minZ); ii++)
  195.             {
  196.                 Location nt = new Location(loc.getWorld(), minX + i,
  197.                         loc.getY(), minZ + ii);
  198.                 Block n = nt.getBlock();
  199.                 if (!n.getType().equals(Material.STATIONARY_WATER)
  200.                         && !n.getType().equals(Material.AIR))
  201.                 {
  202.                     n.setTypeId(mats.get(plugin.getSingleRandom().nextInt(mats.size()))
  203.                             .getId());
  204.  
  205.                     if ((i == 0) || (ii == 0) || (i == Math.abs(maxX - minX))
  206.                             || (ii == Math.abs(maxZ - minZ)))
  207.                     {
  208.                         for (int iii = plugin.getSingleRandom().nextInt(6); iii > 0; iii--)
  209.                         {
  210.                             Location t = new Location(loc.getWorld(), minX + i,
  211.                                     loc.getY() + iii, minZ + ii);
  212.                             t.getBlock().setTypeId(
  213.                                     mats.get(plugin.getSingleRandom().nextInt(mats.size()))
  214.                                             .getId());
  215.  
  216.                         }
  217.                     }
  218.                 }
  219.             }
  220.         }
  221.         return true;
  222.     }
  223.  
  224.     private Location eastRuin1(final Block start, final int size)
  225.     {
  226.         Block block = start;
  227.         for (int i = 0; i < size; i++)
  228.         {
  229.             Block next = block.getRelative(BlockFace.EAST);
  230.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  231.                     false);
  232.             block = next;
  233.         }
  234.         return block.getLocation();
  235.     }
  236.  
  237.     private void generateRuin1(final Block block, final int size)
  238.     {
  239.         Biome b = block.getBiome();
  240.         List<Material> allowedTypes = new ArrayList<Material>();
  241.         if ((b == Biome.DESERT) || (b == Biome.DESERT_HILLS)
  242.                 || (b == Biome.BEACH))
  243.         {
  244.             blockType = 24;
  245.             allowedTypes.add(Material.SAND);
  246.             allowedTypes.add(Material.SANDSTONE);
  247.         }
  248.         else if ((b == Biome.FOREST) || (b == Biome.FOREST_HILLS)
  249.                 || (b == Biome.JUNGLE) || (b == Biome.JUNGLE_HILLS))
  250.         {
  251.             blockType = 17;
  252.             allowedTypes.add(Material.DIRT);
  253.             allowedTypes.add(Material.GRASS);
  254.         }
  255.         else if ((b == Biome.TAIGA) || (b == Biome.TAIGA_HILLS)
  256.                 || (b == Biome.FROZEN_OCEAN) || (b == Biome.FROZEN_RIVER)
  257.                 || (b == Biome.ICE_MOUNTAINS) || (b == Biome.ICE_PLAINS))
  258.         {
  259.             if (plugin.getSingleRandom().nextBoolean())
  260.             {
  261.                 blockType = 79;
  262.             }
  263.             else
  264.             {
  265.                 blockType = 80;
  266.             }
  267.             allowedTypes.add(Material.SNOW);
  268.             allowedTypes.add(Material.ICE);
  269.             allowedTypes.add(Material.GRASS);
  270.             allowedTypes.add(Material.DIRT);
  271.         }
  272.         else if ((b == Biome.PLAINS) || (b == Biome.SWAMPLAND)
  273.                 || (b == Biome.SMALL_MOUNTAINS))
  274.         {
  275.             blockType = 98;
  276.             allowedTypes.add(Material.DIRT);
  277.             allowedTypes.add(Material.GRASS);
  278.         }
  279.         else if (b == Biome.EXTREME_HILLS)
  280.         {
  281.             int chance = plugin.getSingleRandom().nextInt(100);
  282.             if (chance <= 75)
  283.             {
  284.                 blockType = 98;
  285.             }
  286.             else if ((chance > 75) && (chance <= 85))
  287.             {
  288.                 blockType = 73;
  289.             }
  290.             else if ((chance > 85) && (chance <= 90))
  291.             {
  292.                 blockType = 15;
  293.             }
  294.             else if ((chance > 90) && (chance <= 95))
  295.             {
  296.                 blockType = 56;
  297.             }
  298.             else
  299.             {
  300.                 blockType = 129;
  301.             }
  302.             allowedTypes.add(Material.DIRT);
  303.             allowedTypes.add(Material.GRASS);
  304.             allowedTypes.add(Material.STONE);
  305.         }
  306.         Block blockUnder = block.getRelative(BlockFace.DOWN);
  307.         if (!allowedTypes.contains(blockUnder.getType()))
  308.             return;
  309.         addRuin1Pattern(block, size);
  310.     }
  311.  
  312.     private void generateRuin2(final Block block)
  313.     {
  314.         Biome b = block.getBiome();
  315.         List<Material> allowedTypes = new ArrayList<Material>();
  316.         if ((b == Biome.DESERT) || (b == Biome.DESERT_HILLS)
  317.                 || (b == Biome.BEACH))
  318.         {
  319.             blockType = 24;
  320.             allowedTypes.add(Material.SAND);
  321.             allowedTypes.add(Material.SANDSTONE);
  322.         }
  323.         else if ((b == Biome.FOREST) || (b == Biome.FOREST_HILLS)
  324.                 || (b == Biome.JUNGLE) || (b == Biome.JUNGLE_HILLS))
  325.         {
  326.             blockType = 17;
  327.             allowedTypes.add(Material.DIRT);
  328.             allowedTypes.add(Material.GRASS);
  329.         }
  330.         else if ((b == Biome.TAIGA) || (b == Biome.TAIGA_HILLS)
  331.                 || (b == Biome.FROZEN_OCEAN) || (b == Biome.FROZEN_RIVER)
  332.                 || (b == Biome.ICE_MOUNTAINS) || (b == Biome.ICE_PLAINS))
  333.         {
  334.             if (plugin.getSingleRandom().nextBoolean())
  335.             {
  336.                 blockType = 79;
  337.             }
  338.             else
  339.             {
  340.                 blockType = 80;
  341.             }
  342.             allowedTypes.add(Material.SNOW);
  343.             allowedTypes.add(Material.ICE);
  344.             allowedTypes.add(Material.GRASS);
  345.             allowedTypes.add(Material.DIRT);
  346.         }
  347.         else if ((b == Biome.PLAINS) || (b == Biome.EXTREME_HILLS)
  348.                 || (b == Biome.SWAMPLAND) || (b == Biome.SMALL_MOUNTAINS))
  349.         {
  350.             blockType = 98;
  351.             allowedTypes.add(Material.DIRT);
  352.             allowedTypes.add(Material.GRASS);
  353.         }
  354.         Block blockUnder = block.getRelative(BlockFace.DOWN);
  355.         if (!allowedTypes.contains(blockUnder.getType()))
  356.             return;
  357.         Block[] blockSurround = new Block[] { block,
  358.                 block.getRelative(BlockFace.NORTH),
  359.                 block.getRelative(BlockFace.NORTH_EAST),
  360.                 block.getRelative(BlockFace.EAST),
  361.                 block.getRelative(BlockFace.SOUTH_EAST),
  362.                 block.getRelative(BlockFace.SOUTH),
  363.                 block.getRelative(BlockFace.SOUTH_WEST),
  364.                 block.getRelative(BlockFace.WEST),
  365.                 block.getRelative(BlockFace.NORTH_WEST) };
  366.         Block northern = block.getRelative(BlockFace.NORTH).getRelative(
  367.                 BlockFace.NORTH);
  368.         Block eastern = block.getRelative(BlockFace.EAST).getRelative(
  369.                 BlockFace.EAST);
  370.         Block southern = block.getRelative(BlockFace.SOUTH).getRelative(
  371.                 BlockFace.SOUTH);
  372.         Block western = block.getRelative(BlockFace.WEST).getRelative(
  373.                 BlockFace.WEST);
  374.         Block[] ruinBase = new Block[] {
  375.                 northern,
  376.                 northern.getRelative(BlockFace.EAST),
  377.                 northern.getRelative(BlockFace.EAST)
  378.                         .getRelative(BlockFace.EAST),
  379.                 northern.getRelative(BlockFace.EAST)
  380.                         .getRelative(BlockFace.EAST)
  381.                         .getRelative(BlockFace.SOUTH),
  382.                 eastern,
  383.                 eastern.getRelative(BlockFace.SOUTH),
  384.                 eastern.getRelative(BlockFace.SOUTH).getRelative(
  385.                         BlockFace.SOUTH),
  386.                 eastern.getRelative(BlockFace.SOUTH)
  387.                         .getRelative(BlockFace.SOUTH)
  388.                         .getRelative(BlockFace.WEST),
  389.                 southern,
  390.                 southern.getRelative(BlockFace.WEST),
  391.                 southern.getRelative(BlockFace.WEST)
  392.                         .getRelative(BlockFace.WEST),
  393.                 southern.getRelative(BlockFace.WEST)
  394.                         .getRelative(BlockFace.WEST)
  395.                         .getRelative(BlockFace.NORTH),
  396.                 western,
  397.                 western.getRelative(BlockFace.NORTH),
  398.                 western.getRelative(BlockFace.NORTH).getRelative(
  399.                         BlockFace.NORTH),
  400.                 western.getRelative(BlockFace.NORTH)
  401.                         .getRelative(BlockFace.NORTH)
  402.                         .getRelative(BlockFace.EAST) };
  403.         for (Block b1 : ruinBase)
  404.         {
  405.             pillarRuin2(b1, plugin.getSingleRandom().nextInt(4) + 3, blockType);
  406.         }
  407.         for (Block b2 : blockSurround)
  408.         {
  409.             b2.getRelative(0, -1, 0).setType(Material.LAVA);
  410.             for (int i = 2; i < (plugin.getSingleRandom().nextInt(5) + 2); i++)
  411.             {
  412.                 b2.getRelative(0, -i, 0).setTypeId(blockType);
  413.             }
  414.             b2.setType(Material.GLASS);
  415.             switch (plugin.getSingleRandom().nextInt(7))
  416.             {
  417.                 case 1:
  418.                     b2.getRelative(0, 1, 0).setType(Material.IRON_BLOCK);
  419.                     break;
  420.                 case 2:
  421.                     b2.getRelative(0, 1, 0).setType(Material.GOLD_BLOCK);
  422.                     break;
  423.                 case 3:
  424.                     b2.getRelative(0, 1, 0).setType(Material.LAPIS_BLOCK);
  425.                     break;
  426.                 default:
  427.                     break;
  428.             }
  429.         }
  430.     }
  431.  
  432.     private List<Material> getBiomeMaterials(final Biome b)
  433.     {
  434.         List<Material> mats = new ArrayList<Material>();
  435.         switch (b)
  436.         {
  437.             case BEACH:
  438.             {
  439.                 mats.add(Material.SANDSTONE);
  440.                 break;
  441.             }
  442.             case DESERT:
  443.             {
  444.                 mats.add(Material.SANDSTONE);
  445.                 break;
  446.             }
  447.             case DESERT_HILLS:
  448.             {
  449.                 mats.add(Material.SANDSTONE);
  450.                 break;
  451.             }
  452.             case EXTREME_HILLS:
  453.             {
  454.                 mats.add(Material.COBBLESTONE);
  455.                 mats.add(Material.COBBLESTONE);
  456.                 break;
  457.             }
  458.             case FOREST:
  459.             {
  460.                 mats.add(Material.SMOOTH_BRICK);
  461.                 mats.add(Material.STONE);
  462.                 break;
  463.             }
  464.             case FOREST_HILLS:
  465.             {
  466.                 mats.add(Material.SMOOTH_BRICK);
  467.                 mats.add(Material.STONE);
  468.                 break;
  469.             }
  470.             case FROZEN_OCEAN:
  471.                 break;
  472.             case FROZEN_RIVER:
  473.                 break;
  474.             case HELL:
  475.             {
  476.                 mats.add(Material.NETHER_BRICK);
  477.                 break;
  478.             }
  479.             case ICE_MOUNTAINS:
  480.             {
  481.                 mats.add(Material.ICE);
  482.                 mats.add(Material.SNOW_BLOCK);
  483.                 break;
  484.             }
  485.             case ICE_PLAINS:
  486.             {
  487.                 mats.add(Material.ICE);
  488.                 mats.add(Material.SNOW_BLOCK);
  489.                 break;
  490.             }
  491.             case JUNGLE:
  492.             {
  493.                 mats.add(Material.LOG);
  494.                 mats.add(Material.WOOD);
  495.                 break;
  496.             }
  497.             case JUNGLE_HILLS:
  498.             {
  499.                 mats.add(Material.LOG);
  500.                 mats.add(Material.WOOD);
  501.                 break;
  502.             }
  503.             case MUSHROOM_ISLAND:
  504.                 break;
  505.             case MUSHROOM_SHORE:
  506.                 break;
  507.             case OCEAN:
  508.                 break;
  509.             case PLAINS:
  510.             {
  511.                 mats.add(Material.DOUBLE_STEP);
  512.                 break;
  513.             }
  514.             case RIVER:
  515.                 break;
  516.             case SKY:
  517.                 break;
  518.             case SMALL_MOUNTAINS:
  519.                 break;
  520.             case SWAMPLAND:
  521.             {
  522.                 mats.add(Material.DOUBLE_STEP);
  523.                 break;
  524.             }
  525.             case TAIGA:
  526.             {
  527.                 mats.add(Material.SMOOTH_BRICK);
  528.                 mats.add(Material.STONE);
  529.                 break;
  530.             }
  531.             case TAIGA_HILLS:
  532.             {
  533.                 mats.add(Material.SMOOTH_BRICK);
  534.                 mats.add(Material.STONE);
  535.                 break;
  536.             }
  537.             default:
  538.                 break;
  539.  
  540.         }
  541.         return mats;
  542.     }
  543.  
  544.     public Block getBlockAt(final World world, final int x, final int y,
  545.             final int z)
  546.     {
  547.         return world.getBlockAt(x, y, z);
  548.     }
  549.  
  550.     private Location northeastRuin1(final Block start, final int size)
  551.     {
  552.         Block block = start;
  553.         for (int i = 0; i < size; i++)
  554.         {
  555.             Block next = block.getRelative(BlockFace.NORTH_EAST);
  556.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  557.                     false);
  558.             block = next;
  559.         }
  560.         return block.getLocation();
  561.     }
  562.  
  563.     private Location northRuin1(final Block start, final int size)
  564.     {
  565.         Block block = start;
  566.         for (int i = 0; i < size; i++)
  567.         {
  568.             Block next = block.getRelative(BlockFace.NORTH);
  569.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  570.                     false);
  571.             block = next;
  572.         }
  573.         return block.getLocation();
  574.     }
  575.  
  576.     private Location northwestRuin1(final Block start, final int size)
  577.     {
  578.         Block block = start;
  579.         for (int i = 0; i < size; i++)
  580.         {
  581.             Block next = block.getRelative(BlockFace.NORTH_WEST);
  582.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  583.                     false);
  584.             block = next;
  585.         }
  586.         return block.getLocation();
  587.     }
  588.  
  589.     @EventHandler
  590.     public void onChunkPopulate(final ChunkPopulateEvent event)
  591.     {
  592.         if (!plugin.getConfig().getBoolean("Ruins.Enabled", true))
  593.             return;
  594.         if (!plugin.worlds.contains(event.getWorld().getName())
  595.                 && plugin.getConfig().getBoolean("Worlds.Enabled", false))
  596.             return;
  597.         Chunk chunk = event.getChunk();
  598.         int genInt = plugin.getSingleRandom().nextInt(100) + 1;
  599.         int confChance = plugin.getConfig().getInt("Ruins.Chance", 1);
  600.         if (genInt > confChance)
  601.             return;
  602.         int realX = (chunk.getX() * 16) + plugin.getSingleRandom().nextInt(15);
  603.         int realZ = (chunk.getZ() * 16) + plugin.getSingleRandom().nextInt(15);
  604.         //int itemID = chunk.getWorld().getHighestBlockYAt(realX, realZ);
  605.        
  606.        if(chunk.getWorld().getBiome(realX + 5, realZ + 5) == chunk.getWorld().getBiome(realX, realZ)
  607.                 && chunk.getWorld().getBiome(realX - 5, realZ + 5) == chunk.getWorld().getBiome(realX, realZ)
  608.                 && chunk.getWorld().getBiome(realX - 5, realZ - 5) == chunk.getWorld().getBiome(realX, realZ)
  609.                 && chunk.getWorld().getBiome(realX + 5, realZ - 5) == chunk.getWorld().getBiome(realX, realZ)
  610.                
  611.                 ){
  612.  
  613.         if (chunk.getWorld().getEnvironment() != Environment.NETHER
  614.                 && chunk.getWorld().getBiome(realX, realZ) != Biome.OCEAN
  615.                 && chunk.getWorld().getBiome(realX, realZ) != Biome.RIVER)
  616.         {
  617.             Block block = chunk.getWorld().getHighestBlockAt(realX, realZ);
  618.             switch(plugin.getSingleRandom().nextInt(4)){
  619.             case 0:{
  620.                 int size = plugin.getSingleRandom().nextInt(4) + 3;
  621.                 generateRuin1(block, size);
  622.                 RuinGenerateEvent rge = new RuinGenerateEvent(chunk, block);
  623.                 plugin.getServer().getPluginManager().callEvent(rge);
  624.                 if (rge.isCancelled())
  625.                     return;
  626.                 block = rge.getChest();
  627.                 block.setType(Material.CHEST);
  628.                 plugin.getDropAPI().fillChest(block, size);
  629.                 break; 
  630.             }
  631.             case 1:{
  632.                 generateRuin2(block);
  633.                 break;             
  634.             }
  635.             case 2:
  636.             {
  637.                 Block under = block.getRelative(BlockFace.DOWN);
  638.                 Location loc = under.getLocation();
  639.                 if (buildNetherTemple(loc))
  640.                 {
  641.                     RuinGenerateEvent rge = new RuinGenerateEvent(chunk, block);
  642.                     plugin.getServer().getPluginManager().callEvent(rge);
  643.                     if (rge.isCancelled())
  644.                         return;
  645.                     block = rge.getChest();
  646.                     block.setType(Material.CHEST);
  647.                     plugin.getDropAPI().fillChest(block);
  648.                 }
  649.                 break;
  650.             }
  651.             case 3:{
  652.                 Block under = block.getRelative(BlockFace.DOWN);
  653.                 Location loc = under.getLocation();
  654.                 if (deathRuin(loc))
  655.                 {
  656.                     RuinGenerateEvent rge = new RuinGenerateEvent(chunk, block);
  657.                     plugin.getServer().getPluginManager().callEvent(rge);
  658.                     if (rge.isCancelled())
  659.                         return;
  660.                     block = rge.getChest();
  661.                     block.setType(Material.CHEST);
  662.                     plugin.getDropAPI().fillChest(block);
  663.                 }
  664.                 break;
  665.             }
  666.             }
  667.         }//TU SIE KONCZY 1 IF
  668.     } }
  669.  
  670.  
  671.  
  672.     private void pillarRuin1(final World world, final Location location,
  673.             final int size)
  674.     {
  675.         Block start = world.getBlockAt(location);
  676.         Block block = start;
  677.         for (int i = 0; i < size; i++)
  678.         {
  679.             Block next = block.getRelative(BlockFace.UP);
  680.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  681.                     false);
  682.             block = next;
  683.         }
  684.     }
  685.  
  686.     private void pillarRuin2(final Block block, final int size, final int type)
  687.     {
  688.         List<Block> blocks = new ArrayList<Block>();
  689.         blocks.add(block);
  690.         for (int i = 0; i <= Math.abs(size); i++)
  691.         {
  692.             blocks.add(block.getRelative(0, i, 0));
  693.             blocks.add(block.getRelative(0, -i, 0));
  694.         }
  695.         for (Block b : blocks)
  696.         {
  697.             b.setTypeIdAndData(type, (byte) plugin.getSingleRandom().nextInt(4), false);
  698.         }
  699.     }
  700.  
  701.     public void setBlockAt(final World world, final int x, final int y,
  702.             final int z, final int id)
  703.     {
  704.         getBlockAt(world, x, y, z).setTypeId(id);
  705.     }
  706.  
  707.     public void setBlockAt(final World world, final int x, final int y,
  708.             final int z, final int id, final int data)
  709.     {
  710.         getBlockAt(world, x, y, z).setTypeId(id);
  711.         switch (data)
  712.         {
  713.             case 1:
  714.                 byte b1 = 1;
  715.                 getBlockAt(world, x, y, z).setData(b1);
  716.             case 2:
  717.                 byte b2 = 2;
  718.                 getBlockAt(world, x, y, z).setData(b2);
  719.             case 3:
  720.                 byte b3 = 3;
  721.                 getBlockAt(world, x, y, z).setData(b3);
  722.             default:
  723.                 byte bd = 0;
  724.                 getBlockAt(world, x, y, z).setData(bd);
  725.         }
  726.     }
  727.  
  728.     private Location southeastRuin1(final Block start, final int size)
  729.     {
  730.         Block block = start;
  731.         for (int i = 0; i < size; i++)
  732.         {
  733.             Block next = block.getRelative(BlockFace.SOUTH_EAST);
  734.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  735.                     false);
  736.             block = next;
  737.         }
  738.         return block.getLocation();
  739.     }
  740.  
  741.     private Location southRuin1(final Block start, final int size)
  742.     {
  743.         Block block = start;
  744.         for (int i = 0; i < size; i++)
  745.         {
  746.             Block next = block.getRelative(BlockFace.SOUTH);
  747.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  748.                     false);
  749.             block = next;
  750.         }
  751.         return block.getLocation();
  752.     }
  753.  
  754.     private Location southwestRuin1(final Block start, final int size)
  755.     {
  756.         Block block = start;
  757.         for (int i = 0; i < size; i++)
  758.         {
  759.             Block next = block.getRelative(BlockFace.SOUTH_WEST);
  760.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  761.                     false);
  762.             block = next;
  763.         }
  764.         return block.getLocation();
  765.     }
  766.  
  767.     private Location westRuin1(final Block start, final int size)
  768.     {
  769.         Block block = start;
  770.         for (int i = 0; i < size; i++)
  771.         {
  772.             Block next = block.getRelative(BlockFace.WEST);
  773.             next.setTypeIdAndData(blockType, (byte) plugin.getSingleRandom().nextInt(4),
  774.                     false);
  775.             block = next;
  776.         }
  777.         return block.getLocation();
  778.     }
  779. }
Advertisement
Add Comment
Please, Sign In to add comment