Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler(priority=EventPriority.LOW)
- public void onPlace(BlockPlaceEvent e) {
- ItemStack is = e.getItemInHand();
- Block b = e.getBlock();
- Location l = b.getLocation();
- String loc = locationString(l);
- if(is.getType() == Material.MOB_SPAWNER) {
- int level = getTierFromItemStack(is);
- String type = getTypeFromTag(is);
- plugin.getSpawners().set("Spawners." + loc, level);
- plugin.saveSpawners();
- handleSpawnerPlacement(level, l);
- setCreatureType(is, type);
- }
- }
- public void handleSpawnerPlacement(int level, final Location l) {
- l.getBlock().setType(Material.MOB_SPAWNER);
- final Block b = l.getBlock();
- int delay = (plugin.getConfig().getInt("Settings.Time.Tier"+level)) * 20;
- int amount = plugin.getConfig().getInt("Settings.Amount.Tier"+level);
- int radius = (plugin.getConfig().getInt("Settings.SpawnRadius")) / 2;
- if(b.getType() == Material.MOB_SPAWNER) {
- final World w = ((CraftWorld) b.getWorld()).getHandle();
- final BlockPosition bp = new BlockPosition(b.getX(), b.getY(), b.getZ());
- final TileEntity tileEntity = w.getTileEntity(bp);
- if((tileEntity instanceof TileEntityMobSpawner)) {
- final TileEntityMobSpawner mobSpawner = (TileEntityMobSpawner) tileEntity;
- final NBTTagCompound spawnerTag = new NBTTagCompound();
- mobSpawner.b(spawnerTag);
- spawnerTag.setShort("SpawnCount", (short) amount);
- spawnerTag.setShort("Delay", (short) delay);
- spawnerTag.setShort("MinSpawnDelay", (short) delay);
- spawnerTag.setShort("MaxSpawnDelay", (short) delay);
- spawnerTag.setShort("SpawnRange", (short) radius);
- mobSpawner.a(spawnerTag);
- }
- }
- }
- public ItemStack setCreatureType(ItemStack is, String type) {
- ItemMeta im = is.getItemMeta();
- BlockStateMeta bsm = (BlockStateMeta)im;
- CreatureSpawner cs = (CreatureSpawner) bsm.getBlockState();
- cs.setCreatureTypeByName(type);
- bsm.setBlockState(cs);
- is.setItemMeta(im);
- return is;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement