Events.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package de.Linus122.customoregen;
  2. import java.util.HashMap;
  3. import java.util.HashSet;
  4. import java.util.Random;
  5. import java.util.Set;
  6. import java.util.UUID;
  7. import org.bukkit.Bukkit;
  8. import org.bukkit.EntityEffect;
  9. import org.bukkit.Location;
  10. import org.bukkit.Material;
  11. import org.bukkit.block.Block;
  12. import org.bukkit.block.BlockFace;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.block.BlockFromToEvent;
  17. public class Events implements Listener {
  18. @SuppressWarnings({ "deprecation", "unused" })
  19. @EventHandler
  20. public void onFromTo(BlockFromToEvent event){
  21. int id = event.getBlock().getTypeId();
  22. if ((id >= 8) && (id <= 11)){
  23. Block b = event.getToBlock();
  24. int toid = b.getTypeId();
  25. if ((toid == 0) && (generatesCobble(id, b))){
  26. GeneratorConfig gc = null;
  27. Player p = Main.getOwner(b.getLocation());
  28. if(p == null){
  29. gc = Main.generatorConfigs.get(0);
  30. }else{
  31. int islandLevel = Main.getLevel(p);
  32. if(Main.activeInWorld.getName().equals(b.getWorld().getName())){
  33. for(GeneratorConfig gc2 : Main.generatorConfigs){
  34. if(gc2 == null){
  35. continue;
  36. }
  37. if(p.hasPermission(gc2.permission) &&
  38. islandLevel >=
  39. gc2.unlock_islandLevel ){
  40. //Weiter
  41. gc = gc2;
  42. }
  43. }
  44. }
  45. }
  46. if(gc == null) return;
  47. if(getObject(gc) == null) return;
  48. GeneratorItem winning = getObject(gc);
  49. if(Material.getMaterial(winning.name) == null) return;
  50. //b.setType(Material.getMaterial(winning));
  51. b.setTypeIdAndData(Material.getMaterial(winning.name).getId() , winning.damage, true);
  52. }
  53. }
  54. }
  55. public GeneratorItem getObject(GeneratorConfig gc){
  56. Random random = new Random();
  57. double d = random.nextDouble() * 100;
  58. for(GeneratorItem key : gc.itemList){
  59. if ((d -= key.chance) < 0) return key;
  60. }
  61. return new GeneratorItem("COBBLESTONE", (byte) 0, 0); //DEFAULT
  62. }
  63. private final BlockFace[] faces = { BlockFace.SELF, BlockFace.UP, BlockFace.DOWN, BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
  64. public boolean generatesCobble(int id, Block b){
  65. int mirrorID1 = (id == 8) || (id == 9) ? 10 : 8;
  66. int mirrorID2 = (id == 8) || (id == 9) ? 11 : 9;
  67. for(BlockFace face : this.faces){
  68. Block r = b.getRelative(face, 1);
  69. if ((r.getTypeId() == mirrorID1) || (r.getTypeId() == mirrorID2)) {
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. }