org.bukkit.World#playSound ( )源码实例Demo

下面列出了org.bukkit.World#playSound ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: civcraft   文件: ArenaControlBlock.java
public void explode() {
	World world = Bukkit.getWorld(coord.getWorldname());
	ItemManager.setTypeId(coord.getLocation().getBlock(), CivData.AIR);
	world.playSound(coord.getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
	world.playSound(coord.getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
	
	FireworkEffect effect = FireworkEffect.builder().with(Type.BURST).withColor(Color.YELLOW).withColor(Color.RED).withTrail().withFlicker().build();
	FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
	for (int i = 0; i < 3; i++) {
		try {
			fePlayer.playFirework(world, coord.getLocation(), effect);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
 
源代码2 项目: NBTEditor   文件: TimeFirework.java
@Override
public final void onExplode(FireworkPlayerDetails details) {
	final Location loc = details.getFirework().getLocation();
	if (!_changing && loc.getY() > 255) {
		_changing = true;
		final World world = loc.getWorld();
		world.setStorm(false);
		world.playSound(loc, Sound.ENTITY_LIGHTNING_BOLT_THUNDER, 100, 0);
		final BukkitTask[] task = new BukkitTask[1];
		task[0] = Bukkit.getScheduler().runTaskTimer(getPlugin(), new Runnable() {
			@Override
			public void run() {
				long time = world.getFullTime() + 250;
				world.setFullTime(time);
				if (Math.abs(_finalTime - Math.abs(time%24000)) < 500) {
					world.playSound(loc, Sound.ENTITY_LIGHTNING_BOLT_THUNDER, 100, 0);
					task[0].cancel();
					_changing = false;
				}
			}
		}, 0, 5);
	}
}
 
源代码3 项目: PGM   文件: TNTMatchModule.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void handleInstantActivation(BlockPlaceEvent event) {
  if (this.properties.instantIgnite && event.getBlock().getType() == Material.TNT) {
    World world = event.getBlock().getWorld();
    TNTPrimed tnt =
        world.spawn(
            event.getBlock().getLocation().clone().add(new Location(world, 0.5, 0.5, 0.5)),
            TNTPrimed.class);

    if (this.properties.fuse != null) {
      tnt.setFuseTicks(this.getFuseTicks());
    }

    if (this.properties.power != null) {
      tnt.setYield(this.properties.power); // Note: not related to EntityExplodeEvent.yield
    }

    if (callPrimeEvent(tnt, event.getPlayer())) {
      event.setCancelled(true); // Allow the block to be placed if priming is cancelled
      world.playSound(tnt.getLocation(), Sound.FUSE, 1, 1);

      ItemStack inHand = event.getPlayer().getItemInHand();
      if (inHand.getAmount() == 1) {
        event.getPlayer().setItemInHand(null);
      } else {
        inHand.setAmount(inHand.getAmount() - 1);
      }
    }
  }
}
 
源代码4 项目: ProjectAres   文件: TNTMatchModule.java
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void handleInstantActivation(BlockPlaceEvent event) {
    if(this.properties.instantIgnite && event.getBlock().getType() == Material.TNT) {
        World world = event.getBlock().getWorld();
        TNTPrimed tnt = world.spawn(BlockUtils.base(event.getBlock()), TNTPrimed.class);

        if(this.properties.fuse != null) {
            tnt.setFuseTicks(this.getFuseTicks());
        }

        if(this.properties.power != null) {
            tnt.setYield(this.properties.power); // Note: not related to EntityExplodeEvent.yield
        }

        if(callPrimeEvent(tnt, event.getPlayer(), true)) {
            // Only cancel the block placement if the prime event is NOT cancelled.
            // If priming is cancelled, the block is allowed to stay (unless some
            // other handler has already cancelled the place event).
            event.setCancelled(true);
            world.playSound(tnt.getLocation(), Sound.ENTITY_TNT_PRIMED, 1, 1);

            ItemStack inHand = event.getItemInHand();
            if(inHand.getAmount() == 1) {
                inHand = null;
            } else {
                inHand.setAmount(inHand.getAmount() - 1);
            }
            event.getPlayer().getInventory().setItem(event.getHand(), inHand);
        }
    }
}
 
源代码5 项目: Skript   文件: EffPlaySound.java
private static void playSound(Location location, String[] sounds, SoundCategory category, float volume, float pitch) {
	World w = location.getWorld();
	for (String sound : sounds) {
		Sound soundEnum = null;
		try {
			soundEnum = Sound.valueOf(sound.toUpperCase(Locale.ENGLISH));
		} catch (IllegalArgumentException ignored) {}
		if (SOUND_CATEGORIES_EXIST) {
			if (soundEnum == null) {
				sound = sound.toLowerCase(Locale.ENGLISH);
				if (!SOUND_VALID_PATTERN.matcher(sound).matches())
					continue;
				w.playSound(location, sound, category, volume, pitch);
			} else {
				w.playSound(location, soundEnum, category, volume, pitch);
			}
		} else {
			if (soundEnum == null) {
				sound = sound.toLowerCase(Locale.ENGLISH);
				if (!SOUND_VALID_PATTERN.matcher(sound).matches())
					continue;
				w.playSound(location, sound, volume, pitch);
			} else {
				w.playSound(location, soundEnum, volume, pitch);
			}
		}
	}
}
 
源代码6 项目: civcraft   文件: TownHall.java
public void onControlBlockHit(ControlPoint cp, World world, Player player, StructureBlock hit) {
	world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1);
	world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
	
	CivMessage.send(player, CivColor.LightGray+"Damaged Control Block ("+cp.getHitpoints()+" / "+cp.getMaxHitpoints()+")");
	CivMessage.sendTown(hit.getTown(), CivColor.Yellow+"One of our Town Hall's Control Points is under attack!");
}
 
源代码7 项目: civcraft   文件: Road.java
@Override
public void onDamage(int amount, World world, Player player, BlockCoord coord, BuildableDamageBlock hit) {
	boolean wasTenPercent = false;
	
	if(hit.getOwner().isDestroyed()) {
		CivMessage.sendError(player, hit.getOwner().getDisplayName()+" is already destroyed.");
		return;
	}
	
	if (!hit.getOwner().isComplete() && !(hit.getOwner() instanceof Wonder)) {
		CivMessage.sendError(player, hit.getOwner().getDisplayName()+" is still being built, cannot be destroyed.");
		return;		
	}
	
	if ((hit.getOwner().getDamagePercentage() % 10) == 0) {
		wasTenPercent = true;
	}
		
	this.damage(amount);
	
	world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1);
	world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
	
	if ((hit.getOwner().getDamagePercentage() % 10) == 0 && !wasTenPercent) {
		onDamageNotification(player, hit);
	}
}
 
源代码8 项目: civcraft   文件: Camp.java
public void onControlBlockHit(ControlPoint cp, World world, Player player) {
	world.playSound(cp.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1);
	world.playEffect(cp.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
	
	CivMessage.send(player, CivColor.LightGray+"Damaged Control Block ("+cp.getHitpoints()+" / "+cp.getMaxHitpoints()+")");
	CivMessage.sendCamp(this, CivColor.Yellow+"One of our camp's Control Points is under attack!");
}
 
源代码9 项目: civcraft   文件: Camp.java
public void onControlBlockDestroy(ControlPoint cp, World world, Player player) {		
	ItemManager.setTypeId(cp.getCoord().getLocation().getBlock(), CivData.AIR);
	world.playSound(cp.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
	world.playSound(cp.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
	
	FireworkEffect effect = FireworkEffect.builder().with(org.bukkit.FireworkEffect.Type.BURST).withColor(Color.YELLOW).withColor(Color.RED).withTrail().withFlicker().build();
	FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
	for (int i = 0; i < 3; i++) {
		try {
			fePlayer.playFirework(world, cp.getCoord().getLocation(), effect);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	boolean allDestroyed = true;
	for (ControlPoint c : this.controlBlocks.values()) {
		if (c.isDestroyed() == false) {
			allDestroyed = false;
			break;
		}
	}

	if (allDestroyed) {
		CivMessage.sendCamp(this, CivColor.Rose+"Our camp has been destroyed!");
		this.destroy();
	} else {
		CivMessage.sendCamp(this, CivColor.Rose+"One of camps's Control Points has been destroyed!");
	}
	
}
 
源代码10 项目: civcraft   文件: WarCamp.java
public void onControlBlockDestroy(ControlPoint cp, World world, Player player, StructureBlock hit) {
	//Should always have a resident and a town at this point.
	Resident attacker = CivGlobal.getResident(player);
	
	ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR);
	world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
	world.playSound(hit.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
	
	FireworkEffect effect = FireworkEffect.builder().with(org.bukkit.FireworkEffect.Type.BURST).withColor(Color.OLIVE).withColor(Color.RED).withTrail().withFlicker().build();
	FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
	for (int i = 0; i < 3; i++) {
		try {
			fePlayer.playFirework(world, hit.getCoord().getLocation(), effect);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	boolean allDestroyed = true;
	for (ControlPoint c : this.controlPoints.values()) {
		if (c.isDestroyed() == false) {
			allDestroyed = false;
			break;
		}
	}

	if (allDestroyed) {
		this.onWarCampDestroy();	
	}
	else {
		CivMessage.sendCiv(attacker.getTown().getCiv(), CivColor.LightGreen+"We've destroyed a control block in "+getCiv().getName()+"'s War Camp!");
		CivMessage.sendCiv(getCiv(), CivColor.Rose+"A control block in our War Camp has been destroyed!");
	}
	
}
 
源代码11 项目: civcraft   文件: WarCamp.java
public void onControlBlockHit(ControlPoint cp, World world, Player player, StructureBlock hit) {
	world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1);
	world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
	
	CivMessage.send(player, CivColor.LightGray+"Damaged Control Block ("+cp.getHitpoints()+" / "+cp.getMaxHitpoints()+")");
	CivMessage.sendCiv(getCiv(), CivColor.Yellow+"Our War Camp's Control Points are under attack!");
}
 
源代码12 项目: NBTEditor   文件: FireBomb.java
@Override
public void onExplode(Item item, Location location) {
	World world = location.getWorld();
	world.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 2f, 1f);
	world.playEffect(location, Effect.ENDER_SIGNAL, 0);
	world.playEffect(location, Effect.STEP_SOUND, Material.FIRE.getId());
	super.onExplode(item, location);
}
 
源代码13 项目: NBTEditor   文件: RepulsionBomb.java
@Override
public void onExplode(Item item, Location location) {
	World world = location.getWorld();
	world.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 2f, 2f);
	world.playEffect(location, Effect.ENDER_SIGNAL, 0);
	world.playEffect(location, Effect.STEP_SOUND, Material.OBSIDIAN.getId());
	super.onExplode(item, location);
}
 
源代码14 项目: civcraft   文件: Buildable.java
public void onDamage(int amount, World world, Player player, BlockCoord coord, BuildableDamageBlock hit) {
	boolean wasTenPercent = false;
	
	if(hit.getOwner().isDestroyed()) {
		if (player != null) {
			CivMessage.sendError(player, hit.getOwner().getDisplayName()+" is already destroyed.");
		}
		return;
	}
	
	if (!hit.getOwner().isComplete() && !(hit.getOwner() instanceof Wonder)) {
		if (player != null) {
			CivMessage.sendError(player, hit.getOwner().getDisplayName()+" is still being built, cannot be destroyed.");
		}
		return;		
	}
	
	if ((hit.getOwner().getDamagePercentage() % 10) == 0) {
		wasTenPercent = true;
	}
		
	this.damage(amount);
	
	world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_USE, 0.2f, 1);
	world.playEffect(hit.getCoord().getLocation(), Effect.MOBSPAWNER_FLAMES, 0);
	
	if ((hit.getOwner().getDamagePercentage() % 10) == 0 && !wasTenPercent) {
		if (player != null) {
			onDamageNotification(player, hit);
		}
	}
	
	if (player != null) {
	Resident resident = CivGlobal.getResident(player);
		if (resident.isCombatInfo()) {
			CivMessage.send(player, CivColor.LightGray+hit.getOwner().getDisplayName()+" has been damaged ("+
					hit.getOwner().hitpoints+"/"+hit.getOwner().getMaxHitPoints()+")");
		}
	}
	
}
 
源代码15 项目: civcraft   文件: TownHall.java
public void onControlBlockDestroy(ControlPoint cp, World world, Player player, StructureBlock hit) {
	//Should always have a resident and a town at this point.
	Resident attacker = CivGlobal.getResident(player);
	
	ItemManager.setTypeId(hit.getCoord().getLocation().getBlock(), CivData.AIR);
	world.playSound(hit.getCoord().getLocation(), Sound.ANVIL_BREAK, 1.0f, -1.0f);
	world.playSound(hit.getCoord().getLocation(), Sound.EXPLODE, 1.0f, 1.0f);
	
	FireworkEffect effect = FireworkEffect.builder().with(Type.BURST).withColor(Color.YELLOW).withColor(Color.RED).withTrail().withFlicker().build();
	FireworkEffectPlayer fePlayer = new FireworkEffectPlayer();
	for (int i = 0; i < 3; i++) {
		try {
			fePlayer.playFirework(world, hit.getCoord().getLocation(), effect);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	boolean allDestroyed = true;
	for (ControlPoint c : this.controlPoints.values()) {
		if (c.isDestroyed() == false) {
			allDestroyed = false;
			break;
		}
	}
	CivMessage.sendTownSound(hit.getTown(), Sound.AMBIENCE_CAVE, 1.0f, 0.5f);

	if (allDestroyed) {
		
		if (this.getTown().getCiv().getCapitolName().equals(this.getTown().getName())) {
			CivMessage.global(CivColor.LightBlue+ChatColor.BOLD+"The civilization of "+this.getTown().getCiv().getName()+" has been conquered by "+attacker.getCiv().getName()+"!");
			for (Town town : this.getTown().getCiv().getTowns()) {
				town.defeated = true;
			}
			
			War.transferDefeated(this.getTown().getCiv(), attacker.getTown().getCiv());
			WarStats.logCapturedCiv(attacker.getTown().getCiv(), this.getTown().getCiv());
			War.saveDefeatedCiv(this.getCiv(), attacker.getTown().getCiv());
		
			if (CivGlobal.isCasualMode()) {
				HashMap<Integer, ItemStack> leftovers = player.getInventory().addItem(this.getCiv().getRandomLeaderSkull("Victory Over "+this.getCiv().getName()+"!"));
				for (ItemStack stack : leftovers.values()) {
					player.getWorld().dropItem(player.getLocation(), stack);
				}
			}
			
		} else {
			CivMessage.global(CivColor.Yellow+ChatColor.BOLD+"The town of "+getTown().getName()+" in "+this.getCiv().getName()+" has been conquered by "+attacker.getCiv().getName()+"!");
			//this.getTown().onDefeat(attacker.getTown().getCiv());
			this.getTown().defeated = true;
			//War.defeatedTowns.put(this.getTown().getName(), attacker.getTown().getCiv());
			WarStats.logCapturedTown(attacker.getTown().getCiv(), this.getTown());
			War.saveDefeatedTown(this.getTown().getName(), attacker.getTown().getCiv());
		}
		
	}
	else {
		CivMessage.sendTown(hit.getTown(), CivColor.Rose+"One of our Town Hall's Control Points has been destroyed!");
		CivMessage.sendCiv(attacker.getTown().getCiv(), CivColor.LightGreen+"We've destroyed a control block in "+hit.getTown().getName()+"!");
		CivMessage.sendCiv(hit.getTown().getCiv(), CivColor.Rose+"A control block in "+hit.getTown().getName()+" has been destroyed!");
	}
	
}
 
源代码16 项目: NBTEditor   文件: GravitationalAxe.java
@Override
public void onBlockBreak(BlockBreakEvent event, PlayerDetails details) {
	Block root = event.getBlock();
	if (isLog(root.getType())) {
		// Initialize some variables:
		World world = event.getPlayer().getWorld();
		Location location = root.getLocation();
		Random random = new Random();
		Vector vel = event.getPlayer().getLocation().toVector().subtract(location.toVector()).normalize().setY(0).multiply(0.2);
		// Find the blocks
		Set<Block> blocks = getTreeBlocks(root);
		if (blocks.size() > 0) {
			world.playSound(location, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 0.5f, 1);
		}
		double durability = blocks.size()*0.25;
		// Bring 'em down.
		for (Block block : blocks) {
			Material mat = block.getType();
			if (random.nextFloat() < 0.1f && isLog(mat)) {
				world.playSound(block.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 0.6f, 1);
				block.breakNaturally();
				durability += 1;
			} else if (random.nextFloat() < 0.4f && isLeaves(mat)) {
				world.playSound(block.getLocation(), Sound.BLOCK_GRASS_BREAK, 0.5f, 1);
				block.breakNaturally();
				durability += 1;
			} else {
				FallingBlock fallingBlock = world.spawnFallingBlock(block.getLocation(), block.getBlockData());
				fallingBlock.setVelocity(vel.multiply(random.nextFloat()*0.2 + 0.9));
				if (isLeaves(mat)) {
					fallingBlock.setDropItem(false);
				}
				block.setType(Material.AIR);
			}
		}
		// Apply durability.
		if (event.getPlayer().getGameMode() != GameMode.CREATIVE) {
			UtilsMc.offsetItemStackDamage(details.getItem(), (int) durability);
		}
	}
}