Skip to content

Commit 5dab05e

Browse files
authored
refactor: move sound methods and refactor sound structure (#292)
1 parent 4b8df70 commit 5dab05e

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package minevalley.core.api.audio;
2+
3+
import net.kyori.adventure.sound.Sound;
4+
import org.bukkit.Location;
5+
6+
import javax.annotation.Nonnull;
7+
8+
@SuppressWarnings("unused")
9+
public interface SoundReceiver {
10+
11+
/**
12+
* Plays a specific sound.
13+
*
14+
* @param sound sound to be played
15+
* @throws IllegalArgumentException if sound is null or an empty string
16+
*/
17+
void playSound(@Nonnull Sound.Type sound) throws IllegalArgumentException;
18+
19+
/**
20+
* Plays a specific sound.
21+
*
22+
* @param sound sound to be played
23+
* @param location location where the sound will be played
24+
* @param spatial defines whether the sound should be spatial
25+
* @throws IllegalArgumentException if sound or location is null, or the location is not in the same world as the user
26+
*/
27+
void playSound(@Nonnull Sound.Type sound, @Nonnull Location location, boolean spatial) throws IllegalArgumentException;
28+
}

src/main/java/minevalley/core/api/enums/sounds/Sound.java renamed to src/main/java/minevalley/core/api/audio/sounds/SystemSound.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
package minevalley.core.api.enums.sounds;
1+
package minevalley.core.api.audio.sounds;
22

33
import lombok.AccessLevel;
4-
import lombok.Getter;
54
import lombok.RequiredArgsConstructor;
5+
import net.kyori.adventure.key.Key;
6+
import net.kyori.adventure.sound.Sound;
7+
import org.bukkit.NamespacedKey;
68

7-
@Getter
9+
import javax.annotation.Nonnull;
10+
11+
@SuppressWarnings("unused")
812
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
9-
public enum Sound {
13+
public enum SystemSound implements Sound.Type {
1014

1115
/**
1216
* Used to get the user's attention.
@@ -23,5 +27,10 @@ public enum Sound {
2327
*/
2428
NOTIFICATION_ERROR("notification_error");
2529

26-
private final String name;
30+
private final String key;
31+
32+
@Override
33+
public @Nonnull Key key() {
34+
return new NamespacedKey("minevalley", key);
35+
}
2736
}

src/main/java/minevalley/core/api/enums/sounds/AmbientSound.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/minevalley/core/api/server/Server.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package minevalley.core.api.server;
22

3+
import minevalley.core.api.audio.SoundReceiver;
34
import minevalley.core.api.messaging.MessageReceiver;
45

56
import javax.annotation.Nonnull;
67

78
@SuppressWarnings("unused")
8-
public interface Server extends MessageReceiver {
9+
public interface Server extends MessageReceiver, SoundReceiver {
910

1011
/**
1112
* Get the server type.

src/main/java/minevalley/core/api/team/Team.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package minevalley.core.api.team;
22

3+
import minevalley.core.api.audio.SoundReceiver;
34
import minevalley.core.api.messaging.MessageReceiver;
45
import minevalley.core.api.messaging.instruction.Instruction;
56

67
import javax.annotation.Nonnull;
78

89
@SuppressWarnings("unused")
9-
public interface Team extends MessageReceiver {
10+
public interface Team extends MessageReceiver, SoundReceiver {
1011

1112
/**
1213
* Send a message to the team chat.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package minevalley.core.api.users;
2+
3+
public enum Ambient {
4+
5+
NONE,
6+
TRAIN_STATION
7+
}

src/main/java/minevalley/core/api/users/OnlineUser.java

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package minevalley.core.api.users;
22

3+
import minevalley.core.api.audio.SoundReceiver;
34
import minevalley.core.api.economy.AccountUser;
45
import minevalley.core.api.economy.BankAccount;
5-
import minevalley.core.api.enums.sounds.AmbientSound;
6-
import minevalley.core.api.enums.sounds.Sound;
76
import minevalley.core.api.messaging.MessageReceiver;
87
import minevalley.core.api.messaging.instruction.Instruction;
98
import minevalley.core.api.regions.utils.PlayerLocation;
@@ -31,7 +30,7 @@
3130
import java.util.function.Consumer;
3231

3332
@SuppressWarnings("unused")
34-
public interface OnlineUser extends User, MessageReceiver {
33+
public interface OnlineUser extends User, MessageReceiver, SoundReceiver {
3534

3635
/**
3736
* Gets the player object of this user.
@@ -137,60 +136,22 @@ void input(@Nonnull String text, @Nonnull Instruction instruction, @Nonnull Cons
137136
@Contract(pure = true)
138137
McVersion getVersion();
139138

140-
// Sounds
141-
142-
/**
143-
* Plays a specific sound.
144-
*
145-
* @param sound sound to be played
146-
* @throws IllegalArgumentException if sound is null or an empty string
147-
*/
148-
void playSound(@Nonnull String sound) throws IllegalArgumentException;
149-
150-
/**
151-
* Plays a specific sound.
152-
*
153-
* @param sound sound to be played
154-
* @throws IllegalArgumentException if sound is null
155-
*/
156-
void playSound(@Nonnull Sound sound) throws IllegalArgumentException;
157-
158-
/**
159-
* Plays a specific sound.
160-
*
161-
* @param sound sound to be played
162-
* @param location location where the sound will be played
163-
* @param spatial defines whether the sound should be spatial
164-
* @throws IllegalArgumentException if sound or location is null, or the location is not in the same world as the user
165-
*/
166-
void playSound(@Nonnull Sound sound, @Nonnull Location location, boolean spatial) throws IllegalArgumentException;
167-
168-
/**
169-
* Plays a specific sound.
170-
*
171-
* @param sound sound to be played
172-
* @param location location where the sound will be played
173-
* @param spatial defines whether the sound should be spatial
174-
* @throws IllegalArgumentException if sound or location is null, or the location is not in the same world as the user
175-
*/
176-
void playSound(@Nonnull String sound, @Nonnull Location location, boolean spatial) throws IllegalArgumentException;
177-
178139
/**
179140
* Gets the ambient this user is currently hearing
180141
*
181142
* @return ambient this user is hearing
182143
*/
183144
@Nonnull
184145
@Contract(pure = true)
185-
AmbientSound getAmbient();
146+
Ambient getAmbient();
186147

187148
/**
188149
* Sets the ambient this user is hearing
189150
*
190151
* @param ambient ambient to be set
191152
* @throws IllegalArgumentException if ambient is null
192153
*/
193-
void setAmbient(@Nonnull AmbientSound ambient) throws IllegalArgumentException;
154+
void setAmbient(@Nonnull Ambient ambient) throws IllegalArgumentException;
194155

195156
/**
196157
* Starts the credits sequence.

0 commit comments

Comments
 (0)