Java Code Examples for org.bukkit.entity.Player#playSound()

The following examples show how to use org.bukkit.entity.Player#playSound() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JumpPads.java    From HubBasics with GNU Lesser General Public License v3.0 7 votes vote down vote up
@EventHandler
public void onPlayerMove(PlayerMoveEvent event) {
    if (needsPressurePlate(event.getPlayer()) || !isBlockRequired(event.getPlayer())) return;
    Player player = event.getPlayer();
    if (!isEnabledInWorld(player.getWorld())) return;
    Location loc = player.getLocation().subtract(0, 1, 0);
    if (loc.getBlock().getType() == getMaterial(player)) {
        player.setVelocity(calculateVector(player));
        if (getSound(player) != null) {
            player.playSound(player.getLocation(), getSound(player), 1, 1);
        }
        if (getEffect(player) != null) {
            Effect effect = this.getEffect(player);
            ReflectionUtils.invokeMethod(player.spigot(), this.playEffectMethod, player.getLocation(),
                    getEffect(player), effect.getId(), 0, 1, 1, 1, 1, 40, 3);
        }
    }
}
 
Example 2
Source File: Acrobat.java    From AnnihilationPro with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void AcrobatDoubleJump(PlayerToggleFlightEvent event) 
{  
	Player player = event.getPlayer();
	if(player.getGameMode() != GameMode.CREATIVE) 
	{
		AnniPlayer p = AnniPlayer.getPlayer(player.getUniqueId());
		if(Game.isGameRunning() && p != null && p.getKit().equals(this))
		{
			Delays.getInstance().addDelay(player, System.currentTimeMillis()+10000, this.getInternalName());
		    event.setCancelled(true);
		    player.setAllowFlight(false);
		    player.setFlying(false);		    
		    player.setVelocity(player.getLocation().getDirection().setY(1).multiply(1));
		    player.playSound(player.getLocation(), Sound.ZOMBIE_INFECT, 1.0F, 2.0F);
		}
		else
		{
			player.setAllowFlight(false);
			player.setFlying(false);
		}
	}
}
 
Example 3
Source File: PrivateMessageCommands.java    From CardinalPGM with MIT License 6 votes vote down vote up
@Command(aliases = {"msg", "message", "pm", "privatemessage", "whisper", "tell"}, desc = "Send a private message to a player.", usage = "<player> <message>", min = 2)
public static void pm(final CommandContext cmd, CommandSender sender) throws CommandException {
    if (!(sender instanceof Player)) {
        throw new CommandException(ChatConstant.ERROR_PLAYER_COMMAND.getMessage(ChatUtil.getLocale(sender)));
    }
    Player target = Bukkit.getPlayer(cmd.getString(0), sender);
    if (target == null) {
        throw new CommandException(ChatConstant.ERROR_PLAYER_NOT_FOUND.getMessage(ChatUtil.getLocale(sender)));
    }
    if (Settings.getSettingByName("PrivateMessages") == null || Settings.getSettingByName("PrivateMessages").getValueByPlayer(target).getValue().equalsIgnoreCase("all")) {
        target.sendMessage(ChatColor.GRAY + "From " + Players.getName(sender) + ChatColor.GRAY + ": " + ChatColor.RESET + cmd.getJoinedStrings(1));
        sender.sendMessage(ChatColor.GRAY + "To " + Players.getName(target) + ChatColor.GRAY + ": " + ChatColor.RESET + cmd.getJoinedStrings(1));
        if (Settings.getSettingByName("PrivateMessageSounds") == null || Settings.getSettingByName("PrivateMessageSounds").getValueByPlayer(target).getValue().equalsIgnoreCase("on")) {
            target.playSound(target.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 2F);
        }
        target.setMetadata("reply", new FixedMetadataValue(Cardinal.getInstance(), sender));
    } else {
        sender.sendMessage(new LocalizedChatMessage(ChatConstant.ERROR_PLAYER_DISABLED_PMS, Players.getName(target) + ChatColor.RED).getMessage(ChatUtil.getLocale(sender)));
    }
}
 
Example 4
Source File: DeathTracker.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDeath(CardinalDeathEvent event) {
    TrackerDamageEvent tracker = DamageTracker.getEvent(event.getPlayer());
    boolean time = tracker != null && System.currentTimeMillis() - tracker.getTime() <= 7500;
    if (time) {
        if (event.getTrackerDamageEvent() == null) {
            event.setTrackerDamageEvent(tracker);
        }
        if (event.getKiller() == null && tracker.getDamager() != null) {
            event.setKiller(tracker.getDamager().getPlayer());
        }
    }

    for (Player player : Bukkit.getOnlinePlayers()) {
        if (player == event.getPlayer()) {
            player.playSound(player.getLocation(), Sound.ENTITY_IRONGOLEM_DEATH, 1, 1);
        } else if (event.getKiller() != null && player == event.getKiller()) {
            player.playSound(player.getLocation(), Sound.ENTITY_IRONGOLEM_DEATH, 1, 1.35F);
        } else {
            player.playSound(event.getPlayer().getLocation(), Sound.ENTITY_IRONGOLEM_HURT, 1, 1.35F);
        }
    }
}
 
Example 5
Source File: BackpackListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private void openBackpack(Player p, ItemStack item, PlayerProfile profile, int size) {
    List<String> lore = item.getItemMeta().getLore();
    for (int line = 0; line < lore.size(); line++) {
        if (lore.get(line).equals(ChatColor.GRAY + "ID: <ID>")) {
            setBackpackId(p, item, line, profile.createBackpack(size).getId());
            break;
        }
    }

    if (!backpacks.containsValue(item)) {
        p.playSound(p.getLocation(), Sound.ENTITY_HORSE_ARMOR, 1F, 1F);
        backpacks.put(p.getUniqueId(), item);

        PlayerProfile.getBackpack(item, backpack -> {
            if (backpack != null) {
                backpack.open(p);
            }
        });
    }
    else {
        SlimefunPlugin.getLocalization().sendMessage(p, "backpack.already-open", true);
    }
}
 
Example 6
Source File: Portal.java    From CardinalPGM with MIT License 6 votes vote down vote up
private void tryTeleport(Player player, Location from, RegionModule destination, int dir) {
    if ((filter == null || filter.evaluate(player).equals(FilterState.ALLOW)) || ObserverModule.testObserver(player)) {
        if (destination != null) {
            from.setPosition(destination.getRandomPoint().getLocation().position());
        } else {
            from.setX(x.getLeft() ? from.getX() + (x.getRight() * dir) : x.getRight());
            from.setY(y.getLeft() ? from.getY() + (y.getRight() * dir) : y.getRight());
            from.setZ(z.getLeft() ? from.getZ() + (z.getRight() * dir) : z.getRight());
        }
        from.setYaw((float) (yaw.getLeft() ? from.getYaw() + (yaw.getRight() * dir) : yaw.getRight()));
        from.setPitch((float) (pitch.getLeft() ? from.getPitch() + (pitch.getRight() * dir) : pitch.getRight()));
        player.setFallDistance(0);
        player.teleport(from);
        if (sound) player.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 0.2F, 1);
    }
}
 
Example 7
Source File: NotifyIO.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show a notify to a collection of players
 */
public void sendNotify(String message, Collection<? extends Player> players) {
    if (getData().containsKey("sound")) {
        for (Player player : players) {
            try {
                player.playSound(player.getLocation(), Sound.valueOf(getData().get("sound")), 1F, 1F);
            } catch (IllegalArgumentException e) {
                player.playSound(player.getLocation(), getData().get("sound"), 1F, 1F);
                LogUtils.getLogger().log(Level.WARNING, "Could not play the right sound: " + e.getMessage());
                LogUtils.logThrowable(e);
            }
        }
    }
}
 
Example 8
Source File: MiddleCollectEffect.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void handleReadData() {
	//TODO: send needed collect packets from middle packet itself after implementing serverside entity position cache
	if (
		(collectorId == cache.getEntityCache().getSelfId()) &&
		(version.getProtocolType() == ProtocolType.PC) &&
		version.isBefore(ProtocolVersion.MINECRAFT_1_9)
	) {
		Player player = connection.getPlayer();
		NetworkEntity entity = cache.getEntityCache().getEntity(entityId);
		if ((entity != null) && (player != null)) {
			switch (entity.getType()) {
				case ITEM: {
					player.playSound(
						player.getLocation(), Sound.ENTITY_ITEM_PICKUP,
						0.2F, (((ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.7F) + 1.0F) * 2.0F
					);
					break;
				}
				case EXP_ORB: {
					player.playSound(
						player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,
						0.2F, (((ThreadLocalRandom.current().nextFloat() - ThreadLocalRandom.current().nextFloat()) * 0.7F) + 1.0F) * 2.0F
					);
					break;
				}
				default: {
					break;
				}
			}
		}
	}
}
 
Example 9
Source File: Menu.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public void openIndividually(Player p, List<ItemStack> items) {
	Inventory inv = Bukkit.createInventory(null, Calculator.formToLine(items.size()) * 9, ChatColor.translateAlternateColorCodes('&', this.name));
	for (int i = 0; i < items.size(); i++) {
		inv.setItem(i, items.get(i));
	}
	p.openInventory(inv);
	if (sounds != null) {
		if (sounds.getOpeningSound() != null) p.playSound(p.getLocation(), sounds.getOpeningSound(), 1F, 1F);
		if (sounds.getClosingSound() != null) Maps.getInstance().sounds.put(p.getUniqueId(), sounds);
	}
}
 
Example 10
Source File: RaindropUtil.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void showRaindrops(Player player, int delta, int multiplier, @Nullable BaseComponent reason, boolean show) {
    eventBus.callEvent(new PlayerRecieveRaindropsEvent(player, delta, multiplier, reason));
    if (show) {
        final Audience audience = audiences.get(player);
        audience.sendMessage(raindropsMessage(delta, multiplier, reason));
        player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1f, 1.5f);
        raindropDisplay(player, delta);
    }
}
 
Example 11
Source File: PlaysoundEvent.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Player player = PlayerConverter.getPlayer(playerID);
    if (location != null) {
        player.playSound(location.getLocation(playerID), sound, soundCategoty, volume, pitch);
    } else {
        player.playSound(player.getLocation(), sound, soundCategoty, volume, pitch);
    }
    return null;
}
 
Example 12
Source File: Util.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void playSound(Player player, Location location, String sound, float volume, float pitch) {
	if (SkyWarsReloaded.getCfg().soundsEnabled()) {
		try {
			if (player != null) {
				player.playSound(location, Sound.valueOf(sound), volume, pitch);
			}
		} catch (IllegalArgumentException | NullPointerException e) {
			SkyWarsReloaded.get().getLogger().info("ERROR: " + sound + " is not a valid bukkit sound. Please check your configs");
		}
	}
}
 
Example 13
Source File: UCMessages.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
public static String mention(Object sender, CommandSender receiver, String msg) {
    if (UChat.get().getUCConfig().getBoolean("mention.enable")) {
        for (Player p : UChat.get().getServer().getOnlinePlayers()) {
            if (!sender.equals(p) && Arrays.stream(msg.split(" ")).anyMatch(p.getName()::equalsIgnoreCase)) {
                if (receiver instanceof Player && receiver.equals(p)) {

                    String mentionc = UChat.get().getUCConfig().getColorStr("mention.color-template").replace("{mentioned-player}", p.getName());
                    mentionc = formatTags("", mentionc, sender, receiver, "", new UCChannel("mention"));

                    if (msg.contains(mentionc) || sender instanceof CommandSender && !UCPerms.hasPerm((CommandSender) sender, "chat.mention")) {
                        msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", p.getName());
                        continue;
                    }

                    for (Sound sound : Sound.values()) {
                        if (StringUtils.containsIgnoreCase(sound.toString(), UChat.get().getUCConfig().getString("mention.playsound"))) {
                            p.playSound(p.getLocation(), sound, 1F, 1F);
                            break;
                        }
                    }
                    msg = msg.replace(mentionc, p.getName());
                    msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", mentionc);
                } else {
                    msg = msg.replaceAll("(?i)\\b" + p.getName() + "\\b", p.getName());
                }
            }
        }
    }
    return msg;
}
 
Example 14
Source File: Menu.java    From CS-CoreLib with GNU General Public License v3.0 5 votes vote down vote up
public void open(Player p) {
	p.openInventory(this.inv);
	if (sounds != null) {
		if (sounds.getOpeningSound() != null) p.playSound(p.getLocation(), sounds.getOpeningSound(), 1F, 1F);
		if (sounds.getClosingSound() != null) Maps.getInstance().sounds.put(p.getUniqueId(), sounds);
	}
}
 
Example 15
Source File: SoundIconCommand.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(Player player) {
	if (hasVariables) {
		parseSound(getParsedCommand(player));
	}
	if (errorMessage != null) {
		player.sendMessage(errorMessage);
		return;
	}

	player.playSound(player.getLocation(), sound, volume, pitch);
}
 
Example 16
Source File: Sounds.java    From TradePlus with GNU General Public License v3.0 4 votes vote down vote up
public static void levelUp(Player player, float v1) {
  if (levelUp != null) player.playSound(player.getEyeLocation(), levelUp, 1, v1);
}
 
Example 17
Source File: PlayerCustomItemDamage.java    From AdditionsAPI with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerCustomItemDamage(PlayerCustomItemDamageEvent event) {
	if (event.isCancelled())
		return;
	Player player = event.getPlayer();
	/*
	 * Somehow, someone got an NPE here. No idea how, but let's just prevent it from
	 * happening in the future. They were using PaperSpigot so it's probably
	 * something to do with that. Or I messed something up elsewhere xD
	 * 
	 * EDIT: I messed up - it's treefeller that dropped the axe's durability to
	 * below 0, it got removed and thus got nulled. Same for sickles.
	 */
	if (event.getCustomItem() == null)
		return;

	CustomItem cItem = event.getCustomItem();
	ItemStack item = event.getItem();
	CustomItemStack cStack = new CustomItemStack(item);
	int durability = 0;
	if (cItem.hasFakeDurability())
		durability = cStack.getFakeDurability();
	else
		durability = item.getType().getMaxDurability() - item.getDurability();
	// TODO: Check if you can modify the durability for items that are not
	// unbreakable and with Fake Durability.
	if (!item.containsEnchantment(Enchantment.DURABILITY)) {
		durability -= event.getDamage();
	} else {
		for (int i = 1; i <= event.getDamage(); i++) {
			if (NumberUtils.calculateChance(1 / ((double) item.getEnchantmentLevel(Enchantment.DURABILITY) + 1D))) {
				durability -= 1;
			}
		}
	}
	if (cItem.hasFakeDurability()) {
		cStack.setFakeDurability(durability);
	} else if (!cItem.isUnbreakable()) {
		item.setDurability((short) (item.getType().getMaxDurability() - durability));
	}
	if (durability < 0) {
		PlayerCustomItemBreakEvent breakEvent = new PlayerCustomItemBreakEvent(player, item, cItem);
		Bukkit.getPluginManager().callEvent(breakEvent);
		if (!event.isCancelled()) {
			player.getInventory().remove(item);
			player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
		}
		return;
	}
}
 
Example 18
Source File: UHPluginListener.java    From KTP with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerInteract(PlayerInteractEvent ev) {
	if ((ev.getAction() == Action.RIGHT_CLICK_AIR || ev.getAction() == Action.RIGHT_CLICK_BLOCK) && ev.getPlayer().getItemInHand().getType() == Material.COMPASS && p.getConfig().getBoolean("compass")) {
		Player pl = ev.getPlayer();
		Boolean foundRottenFlesh = false;
		for (ItemStack is : pl.getInventory().getContents()) {
			if (is != null && is.getType() == Material.ROTTEN_FLESH) {
				p.getLogger().info(""+is.getAmount());
				if (is.getAmount() != 1) is.setAmount(is.getAmount()-1);
				else { p.getLogger().info("lol"); pl.getInventory().removeItem(is); }
				pl.updateInventory();
				foundRottenFlesh = true;
				break;
			}
		}
		if (!foundRottenFlesh) {
			pl.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+"Vous n'avez pas de chair de zombie.");
			pl.playSound(pl.getLocation(), Sound.BLOCK_WOOD_STEP, 1F, 1F);
			return;
		}
		pl.playSound(pl.getLocation(), Sound.ENTITY_PLAYER_BURP, 1F, 1F);
		Player nearest = null;
		Double distance = 99999D;
		for (Player pl2 : p.getServer().getOnlinePlayers()) {
			try {	
				Double calc = pl.getLocation().distance(pl2.getLocation());
				if (calc > 1 && calc < distance) {
					distance = calc;
					if (pl2 != pl && !this.p.inSameTeam(pl, pl2)) nearest = pl2.getPlayer();
				}
			} catch (Exception e) {}
		}
		if (nearest == null) {
			pl.sendMessage(ChatColor.GRAY+""+ChatColor.ITALIC+"Seul le silence comble votre requĂȘte.");
			return;
		}
		pl.sendMessage(ChatColor.GRAY+"La boussole pointe sur le joueur le plus proche.");
		pl.setCompassTarget(nearest.getLocation());
	}
}
 
Example 19
Source File: ExoticGardenFruit.java    From ExoticGarden with GNU General Public License v3.0 4 votes vote down vote up
private void restoreHunger(Player p) {
    int level = p.getFoodLevel() + getFoodValue();
    p.playSound(p.getEyeLocation(), Sound.ENTITY_GENERIC_EAT, 1, 1);
    p.setFoodLevel(Math.min(level, 20));
    p.setSaturation(p.getSaturation() + getFoodValue());
}
 
Example 20
Source File: StickTools.java    From StackMob-3 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void sendMessage(Player player, String message, int pitch){
    player.sendActionBar(message);
    player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP,1, pitch);
}