Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. @EventHandler(priority=EventPriority.LOW)
  2. public void onPlace(BlockPlaceEvent e) {
  3. ItemStack is = e.getItemInHand();
  4. Block b = e.getBlock();
  5. Location l = b.getLocation();
  6. String loc = locationString(l);
  7.  
  8. if(is.getType() == Material.MOB_SPAWNER) {
  9. int level = getTierFromItemStack(is);
  10. String type = getTypeFromTag(is);
  11.  
  12. plugin.getSpawners().set("Spawners." + loc, level);
  13. plugin.saveSpawners();
  14.  
  15. handleSpawnerPlacement(level, l);
  16. setCreatureType(is, type);
  17. }
  18. }
  19.  
  20. public void handleSpawnerPlacement(int level, final Location l) {
  21. l.getBlock().setType(Material.MOB_SPAWNER);
  22. final Block b = l.getBlock();
  23. int delay = (plugin.getConfig().getInt("Settings.Time.Tier"+level)) * 20;
  24. int amount = plugin.getConfig().getInt("Settings.Amount.Tier"+level);
  25. int radius = (plugin.getConfig().getInt("Settings.SpawnRadius")) / 2;
  26.  
  27. if(b.getType() == Material.MOB_SPAWNER) {
  28. final World w = ((CraftWorld) b.getWorld()).getHandle();
  29. final BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
  30. final TileEntity tileEntity = w.getTileEntity(bp);
  31.  
  32. if((tileEntity instanceof TileEntityMobSpawner)) {
  33. final TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) tileEntity;
  34. final NBTTagCompound spawnerTag = new NBTTagCompound();
  35. mobSpawner.b(spawnerTag);
  36. spawnerTag.setShort("SpawnCount", (short) amount);
  37. spawnerTag.setShort("Delay", (short) delay);
  38. spawnerTag.setShort("MinSpawnDelay", (short) delay);
  39. spawnerTag.setShort("MaxSpawnDelay", (short) delay);
  40. spawnerTag.setShort("SpawnRange", (short) radius);
  41.  
  42. mobSpawner.a(spawnerTag);
  43. }
  44. }
  45. }
  46.  
  47. public ItemStack setCreatureType(ItemStack is, String type) {
  48. ItemMeta im = is.getItemMeta();
  49. BlockStateMeta bsm = (BlockStateMeta)im;
  50. CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
  51. cs.setCreatureTypeByName(type);
  52.  
  53. bsm.setBlockState(cs);
  54.  
  55. is.setItemMeta(im);
  56.  
  57. return is;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement