9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-28 11:19:24 +00:00

Update XSound

This commit is contained in:
SamB440
2022-04-14 17:11:16 +01:00
parent 212b359b92
commit 010f3518f8
2 changed files with 50 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ import java.util.concurrent.ConcurrentMap;
public interface IStorageManager {
List<Long> TIMINGS = new LinkedList<>();
List<Long> TIMINGS = new LinkedList<>();
/**
* Gets a player's account from the storage.

View File

@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2021 Crypto Morin
* Copyright (c) 2022 Crypto Morin
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -57,7 +57,7 @@ import java.util.concurrent.CompletableFuture;
* play command: https://minecraft.gamepedia.com/Commands/play
*
* @author Crypto Morin
* @version 7.0.0
* @version 7.0.2
* @see Sound
*/
public enum XSound {
@@ -278,6 +278,7 @@ public enum XSound {
BLOCK_GRAVEL_PLACE,
BLOCK_GRAVEL_STEP("STEP_GRAVEL"),
BLOCK_GRINDSTONE_USE,
BLOCK_GROWING_PLANT_CROP,
BLOCK_HANGING_ROOTS_BREAK,
BLOCK_HANGING_ROOTS_FALL,
BLOCK_HANGING_ROOTS_HIT,
@@ -1191,6 +1192,9 @@ public enum XSound {
ITEM_BUCKET_FILL_FISH,
ITEM_BUCKET_FILL_LAVA,
ITEM_BUCKET_FILL_POWDER_SNOW,
ITEM_BUNDLE_DROP_CONTENTS,
ITEM_BUNDLE_INSERT,
ITEM_BUNDLE_REMOVE_ONE,
ITEM_CHORUS_FRUIT_TELEPORT,
ITEM_CROP_PLANT,
ITEM_CROSSBOW_HIT,
@@ -1236,6 +1240,7 @@ public enum XSound {
MUSIC_DISC_FAR("RECORD_FAR"),
MUSIC_DISC_MALL("RECORD_MALL"),
MUSIC_DISC_MELLOHI("RECORD_MELLOHI"),
MUSIC_DISC_OTHERSIDE,
MUSIC_DISC_PIGSTEP,
MUSIC_DISC_STAL("RECORD_STAL"),
MUSIC_DISC_STRAD("RECORD_STRAD"),
@@ -1250,6 +1255,14 @@ public enum XSound {
MUSIC_NETHER_NETHER_WASTES,
MUSIC_NETHER_SOUL_SAND_VALLEY,
MUSIC_NETHER_WARPED_FOREST,
MUSIC_OVERWORLD_DRIPSTONE_CAVES,
MUSIC_OVERWORLD_FROZEN_PEAKS,
MUSIC_OVERWORLD_GROVE,
MUSIC_OVERWORLD_JAGGED_PEAKS,
MUSIC_OVERWORLD_LUSH_CAVES,
MUSIC_OVERWORLD_MEADOW,
MUSIC_OVERWORLD_SNOWY_SLOPES,
MUSIC_OVERWORLD_STONY_PEAKS,
MUSIC_UNDER_WATER,
PARTICLE_SOUL_ESCAPE,
UI_BUTTON_CLICK("CLICK"),
@@ -1679,7 +1692,7 @@ public enum XSound {
}
/**
* Used for datas that need to be accessed during enum initilization.
* Used for data that need to be accessed during enum initialization.
*
* @since 5.0.0
*/
@@ -1709,8 +1722,7 @@ public enum XSound {
*/
public static class Record {
@Nonnull public final XSound sound;
public final float volume;
public final float pitch;
public final float volume, pitch;
public boolean playAtLocation;
@Nullable public Player player;
@Nullable public Location location;
@@ -1724,16 +1736,27 @@ public enum XSound {
this.playAtLocation = playAtLocation;
}
/**
* Plays the sound only for a single player and no one else can hear it.
*/
public Record forPlayer(@Nullable Player player) {
this.player = player;
return this;
}
/**
* Plays the sound to all the nearby players (based on the specified volume)
*/
public Record atLocation(@Nullable Location location) {
this.location = location;
return this;
}
/**
* Plays the sound only for a single player and no on else can hear it.
* The source of the sound is different and players using headphones may
* hear the sound with a <a href="https://en.wikipedia.org/wiki/3D_audio_effect">3D audio effect</a>.
*/
public Record forPlayerAtLocation(@Nullable Player player, @Nullable Location location) {
this.player = player;
this.location = location;
@@ -1741,7 +1764,7 @@ public enum XSound {
}
/**
* Plays the sound with the given options and updating the players location.
* Plays the sound with the given options and updating the player's location.
*
* @since 3.0.0
*/
@@ -1753,7 +1776,7 @@ public enum XSound {
/**
* Plays the sound with the updated location.
*
* @param updatedLocation the upated location.
* @param updatedLocation the updated location.
*
* @since 3.0.0
*/
@@ -1762,5 +1785,24 @@ public enum XSound {
if (playAtLocation || player == null) location.getWorld().playSound(updatedLocation, sound.parseSound(), volume, pitch);
else player.playSound(updatedLocation, sound.parseSound(), volume, pitch);
}
/**
* Stops the sound playing to the players that this sound was played to.
* Note this works fine if the sound was played to one specific player, but for
* location-based sounds this only works if the players were within the same range as the original
* volume level.
* <p>
* If this is a critical issue you can extend this class and add a cache for all the players that heard the sound.
*
* @since 7.0.2
*/
public void stopSound() {
if (playAtLocation) {
for (Entity entity : location.getWorld().getNearbyEntities(location, volume, volume, volume)) {
if (entity instanceof Player) ((Player) entity).stopSound(sound.parseSound());
}
}
if (player != null) player.stopSound(sound.parseSound());
}
}
}