Skip to content

Commit aa5ab90

Browse files
committed
Allow changing sound effect for msg
1 parent b8f16ff commit aa5ab90

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

CONFIG.md

+18-23
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ All config file are stored in the JSON format, and a default config file will be
44
The config file are located in `Your Fabric Instance/config/svrutil/feature.json`.
55

66
### join_message
7-
This section describes a list of join message to show when player joined the server.
7+
This section describes the list of join message entry to show when player joined the server, described below.
88

9-
#### Welcome Message Entry
9+
| Key | Description |
10+
|---------|---------------------------------------------|
11+
| entries | An array of Join Message Object, see below. |
1012

11-
| Key | Description | Default Value |
12-
|--------------|------------------------------------------------------------------------------------------|----------------------------------------------------|
13-
| title | A Color-Text entry for the main title to appear at the center of the screen | 2 (Vanilla) |
14-
| subtitle | A Color-Text entry for the subtitle to appear below title at the center of the screen | false |
15-
| message | A Color-Text entry for the chat message to be sent. | 0 (All) |
16-
| delayTick | How much Minecraft tick to delay before sending this welcome message to the player. | "Internal Exception: java.lang.StackOverflowError" |
17-
| permLevels | The OP level that this welcome message is sent to. | [1, 2, 3, 4] |
18-
19-
#### Color-Text Entry
20-
| Key | Description |
21-
|-----------------------------|-------------------------------------------------------------------------------------------------------|
22-
| color | Human readable color name (i.e. "green") |
23-
| text | The text content to show |
13+
#### Join Message Object
14+
| Key | Description |
15+
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
16+
| title | The title that are displayed to the player. ([Simplified Text Format](https://placeholders.pb4.eu/user/text-format/)) |
17+
| subtitle | The subtitle that are displayed to the player. ([Simplified Text Format](https://placeholders.pb4.eu/user/text-format/)) |
18+
| message | The chat message that are displayed to the player. ([Simplified Text Format](https://placeholders.pb4.eu/user/text-format/)) |
19+
| delayTick | How long to wait (in Minecraft tick) before showing the welcome message to the player. |
20+
| permLevels | An array of numbers representing the op level of the player.<br>Player that are inside the OP Level range will have the welcome message be shown. |
2421

2522
### hunger
2623
This section enforces the hunger range for all players, at a scale from 0 to 20.
@@ -39,14 +36,12 @@ This section contains configurations that overrides Vanilla Minecraft mechanics.
3936
| minItemFrameInteractOpLevel | The minimum OP Level required to be able to interact with item frame. |
4037
| fallingBlockDelay | How much tick it should take for falling block (i.e. Sand & Gravel) to start falling after placing. |
4138

42-
### Welcome Message Object
43-
| Key | Description |
44-
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
45-
| title | The title that are displayed to the player. ([Simplified Text Format](https://placeholders.pb4.eu/user/text-format/)) |
46-
| subtitle | The subtitle that are displayed to the player. ([Simplified Text Format](https://placeholders.pb4.eu/user/text-format/)) |
47-
| message | The chat message that are displayed to the player. ([Simplified Text Format](https://placeholders.pb4.eu/user/text-format/)) |
48-
| delayTick | How long to wait (in Minecraft tick) before showing the welcome message to the player. |
49-
| permLevels | An array of numbers representing the op level of the player.<br>Player that are inside the OP Level range will have the welcome message be shown. |
39+
### fancy_msg
40+
If enabled, this enables a fancier msg of vanilla's `/msg`, `/w` and `/tell` command.
41+
42+
| Key | Description |
43+
|-------------|---------------------------------------------------------------------------------------------------------------|
44+
| soundEffect | A string containing the sound ID you want to play to the receiver when message, null to disable sound effect. |
5045

5146
## Command Config
5247
The config file are located in `Your Fabric Instance/config/svrutil/commands.json`.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Note: These are just the default command configuration, you may optionally disab
2424
| /gmc | Change your gamemode to Creative Mode. | Op Level 2 |
2525
| /gmsp | Change your gamemode to Spectator Mode. | Op Level 2 |
2626
| /heal (Target Player) | Sets the health & hunger to full for you,<br>or the player you specified. | Op Level 2 |
27+
| /playsoundarea <pos1> <pos2> <sound id> <volume> (pitch) | Play sound id to players between pos1 and pos2 | Op Level 2 |
2728
| /svrutil<br>/svrutil reload | Main SvrUtil command.`/svrutil` to see the version and homepage.<br>`/svrutil reload` to reload the config | Op Level 2 |
2829
| /spd (speed) | Set the player's walking and flying speed factor.<br>If "speed" argument is not provided, it will reset to the vanilla default speed. | Op Level 2 |
2930
| /msg <Target Player> <Message> | This sends a private message to the target player,<br>along with a "ding" sound.<br><br>Note: This will deregister the default vanilla `/msg` command. | Op Level 0<br>(Anyone) |
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package com.lx862.svrutil.feature;
22

33
import com.google.gson.JsonObject;
4+
import net.minecraft.util.Identifier;
5+
import net.minecraft.util.JsonHelper;
46

57
public class FancyMessageFeature extends Feature {
8+
private Identifier messageSound = Identifier.of("minecraft", "entity.experience_orb.pickup");
69

710
public FancyMessageFeature() {
811
super("Fancy Message", "fancy_msg");
@@ -11,10 +14,17 @@ public FancyMessageFeature() {
1114
@Override
1215
public void readConfig(JsonObject jsonObject) {
1316
super.readConfig(jsonObject);
17+
messageSound = Identifier.tryParse(JsonHelper.getString(jsonObject, "messageSound", "!"));
1418
}
1519

1620
@Override
1721
public JsonObject writeConfig() {
18-
return super.writeConfig();
22+
JsonObject jsonObject = super.writeConfig();
23+
jsonObject.addProperty("messageSound", messageSound == null ? null : messageSound.toString());
24+
return jsonObject;
25+
}
26+
27+
public Identifier getMessageSound() {
28+
return messageSound;
1929
}
2030
}

src/main/java/com/lx862/svrutil/mixin/MessageCommandMixin.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
import com.lx862.svrutil.SvrUtil;
44
import com.lx862.svrutil.commands.afk;
5+
import com.lx862.svrutil.feature.FancyMessageFeature;
56
import com.lx862.svrutil.feature.FeatureSet;
67
import net.minecraft.command.argument.MessageArgumentType;
78
import net.minecraft.server.command.MessageCommand;
89
import net.minecraft.server.command.ServerCommandSource;
910
import net.minecraft.server.network.ServerPlayerEntity;
1011
import net.minecraft.sound.SoundCategory;
12+
import net.minecraft.sound.SoundEvent;
1113
import net.minecraft.sound.SoundEvents;
1214
import net.minecraft.text.Text;
1315
import net.minecraft.util.Formatting;
16+
import net.minecraft.util.Identifier;
1417
import org.spongepowered.asm.mixin.Mixin;
1518
import org.spongepowered.asm.mixin.injection.At;
1619
import org.spongepowered.asm.mixin.injection.Inject;
@@ -38,7 +41,11 @@ private static void execute(ServerCommandSource source, Collection<ServerPlayerE
3841

3942
source.sendFeedback(Text.literal(String.format("§6[me §r-> §6%s]: ", target.getGameProfile().getName())).append(msgContent), false);
4043
target.sendMessage(Text.literal(String.format("§6[%s §r-> §6me]: ", playerName)).append(msgContent), false);
41-
target.playSound(SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP, SoundCategory.MASTER, 1, 1);
44+
45+
Identifier soundEffect = ((FancyMessageFeature)FeatureSet.FANCY_MESSAGE.feature).getMessageSound();
46+
if(soundEffect != null) {
47+
target.playSound(new SoundEvent(soundEffect), SoundCategory.MASTER, 1, 1);
48+
}
4249

4350
if(afk.afkList.containsKey(target.getUuid()) && source.isExecutedByPlayer()) {
4451
source.getPlayer().sendMessageToClient(Text.literal("").append(target.getDisplayName()).append(" are AFK and may not be available at the moment.").formatted(Formatting.YELLOW), true);

0 commit comments

Comments
 (0)